From 20fcf2a0c79b8433bf67594d45af54001ca1b613 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Thu, 7 Oct 2021 16:26:57 +0200 Subject: tabfile: make it possible to set metadata And some related clean-up. --- src/stardict.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/stardict.c') diff --git a/src/stardict.c b/src/stardict.c index a757590..d371eb1 100644 --- a/src/stardict.c +++ b/src/stardict.c @@ -209,6 +209,30 @@ const struct stardict_ifo_key _stardict_ifo_keys[] = gsize _stardict_ifo_keys_length = G_N_ELEMENTS (_stardict_ifo_keys); +/// Copy the contents of one StardictInfo object into another. Ignores path. +void +stardict_info_copy (StardictInfo *dest, const StardictInfo *src) +{ + dest->version = src->version; + + guint i; + for (i = 0; i < _stardict_ifo_keys_length; i++) + { + const struct stardict_ifo_key *key = &_stardict_ifo_keys[i]; + if (key->type == IFO_STRING) + { + gchar **p = &G_STRUCT_MEMBER (gchar *, dest, key->offset); + gchar *q = G_STRUCT_MEMBER (gchar *, src, key->offset); + + g_free (*p); + *p = q ? g_strdup (q) : NULL; + } + else + G_STRUCT_MEMBER (gulong, dest, key->offset) = + G_STRUCT_MEMBER (gulong, src, key->offset); + } +} + static gboolean load_ifo (StardictInfo *sti, const gchar *path, GError **error) { -- cgit v1.2.3-70-g09d2