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/add-pronunciation.c | 24 --------------------
src/stardict-private.h | 2 ++
src/stardict.c | 24 ++++++++++++++++++++
src/tabfile.c | 60 ++++++++++++++++++++++++++++++++++++++++++++-----
src/transform.c | 25 ---------------------
5 files changed, 80 insertions(+), 55 deletions(-)
(limited to 'src')
diff --git a/src/add-pronunciation.c b/src/add-pronunciation.c
index d409c9d..9aedd42 100644
--- a/src/add-pronunciation.c
+++ b/src/add-pronunciation.c
@@ -250,30 +250,6 @@ worker (WorkerData *data)
// --- Main --------------------------------------------------------------------
-/// Copy the contents of one StardictInfo object into another. Ignores path.
-static 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);
- }
-}
-
int
main (int argc, char *argv[])
{
diff --git a/src/stardict-private.h b/src/stardict-private.h
index 3d5b73a..6b8e75b 100644
--- a/src/stardict-private.h
+++ b/src/stardict-private.h
@@ -79,4 +79,6 @@ extern const struct stardict_ifo_key _stardict_ifo_keys[];
/// Denotes the length of _stardict_ifo_keys.
extern gsize _stardict_ifo_keys_length;
+void stardict_info_copy (StardictInfo *dest, const StardictInfo *src);
+
#endif // ! STARDICTPRIVATE_H
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)
{
diff --git a/src/tabfile.c b/src/tabfile.c
index 10700b0..b2ceefa 100644
--- a/src/tabfile.c
+++ b/src/tabfile.c
@@ -25,11 +25,15 @@
#include
", lines);
+ g_strfreev (lines);
+ template.description = in_one_line;
+ }
+ if (template.collation)
+ validate_collation_locale (template.collation);
+
// This actually implements stardict_strcmp(), POSIX-compatibly.
// Your sort(1) is not expected to be stable by default, like bsdsort is.
FILE *fsorted = popen ("LC_ALL=C sort -t'\t' -k1f,1", "r");
@@ -149,11 +201,7 @@ main (int argc, char *argv[])
StardictInfo *info = generator->info;
info->version = SD_VERSION_3_0_0;
- info->book_name = g_strdup (argv[1]);
- info->same_type_sequence = g_strdup ("m");
-
- // This gets incremented each time an entry is finished
- info->word_count = 0;
+ stardict_info_copy (info, &template);
if (!transform (fsorted, generator, &error)
|| !generator_finish (generator, &error))
diff --git a/src/transform.c b/src/transform.c
index 2144c6b..38bdad6 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -140,31 +140,6 @@ update_from_filter (StardictDict *dict, Generator *generator,
return TRUE;
}
-// FIXME: copied from add-pronunciation.c, should merge it somewhere (utils?)
-/// Copy the contents of one StardictInfo object into another. Ignores path.
-static 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);
- }
-}
-
int
main (int argc, char *argv[])
{
--
cgit v1.2.3-70-g09d2