diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2020-09-03 23:17:17 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2020-09-04 00:13:34 +0200 |
commit | 8d19acd91af9592d862ef2a7aa8e95eea4160152 (patch) | |
tree | fb2a422cf9446829c41e152415f128b47babe938 /src/generator.c | |
parent | dd2bd04a07030f15e6eb6875041f95c74023dd35 (diff) | |
download | tdv-8d19acd91af9592d862ef2a7aa8e95eea4160152.tar.gz tdv-8d19acd91af9592d862ef2a7aa8e95eea4160152.tar.xz tdv-8d19acd91af9592d862ef2a7aa8e95eea4160152.zip |
Add a tool to transform dictionaries
Diffstat (limited to 'src/generator.c')
-rw-r--r-- | src/generator.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/generator.c b/src/generator.c index 9f6be9b..25c8e43 100644 --- a/src/generator.c +++ b/src/generator.c @@ -1,7 +1,7 @@ /* * generator.c: dictionary generator * - * Copyright (c) 2013, Přemysl Eric Janouch <p@janouch.name> + * Copyright (c) 2013 - 2020, Přemysl Eric Janouch <p@janouch.name> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -170,6 +170,34 @@ generator_write_string (Generator *self, return TRUE; } +/// Write a list of data fields back to a dictionary. The list has to be +/// acceptable for the generated dictionary's sametypesequence (or lack of). +gboolean +generator_write_fields (Generator *self, const GList *fields, GError **error) +{ + gboolean sts = self->info->same_type_sequence != NULL; + while (fields) + { + StardictEntryField *field = fields->data; + if (!sts && !generator_write_type (self, field->type, error)) + return FALSE; + + gboolean mark_end = !sts || fields->next != NULL; + if (g_ascii_islower (field->type)) + { + if (!generator_write_string (self, + field->data, mark_end, error)) + return FALSE; + } + else if (!generator_write_raw (self, + field->data, field->data_size, mark_end, error)) + return FALSE; + + fields = fields->next; + } + return TRUE; +} + /// Finishes the current entry and writes it into the index. gboolean generator_finish_entry (Generator *self, const gchar *word, GError **error) |