From 8d19acd91af9592d862ef2a7aa8e95eea4160152 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Thu, 3 Sep 2020 23:17:17 +0200 Subject: Add a tool to transform dictionaries --- src/generator.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/generator.c') 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
+ * Copyright (c) 2013 - 2020, Přemysl Eric Janouch
* * 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) -- cgit v1.2.3-70-g09d2