Add a tool to transform dictionaries

This commit is contained in:
p
2020-09-04 00:13:34 +02:00
parent dd2bd04a07
commit 8d19acd91a
6 changed files with 317 additions and 39 deletions
+29 -1
View File
@@ -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)