[recipes] Add a tool to extract strings from recipes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add a tool to extract strings from recipes
- Date: Sat, 31 Dec 2016 02:06:32 +0000 (UTC)
commit 81cc5fe24a9eeace5eb4806e916fcef509a95d61
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Dec 30 15:57:51 2016 -0500
Add a tool to extract strings from recipes
This is a quick hack that will get the job done until we get
a better storage layer.
Makefile.am | 2 +-
configure.ac | 1 +
tools/Makefile.am | 11 ++++++
tools/recipe-extract.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 104 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index e0a258b..c9c3c7c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = . libgd data src po tests
+SUBDIRS = . libgd tools data src po tests
EXTRA_DIST = AUTHORS NEWS
diff --git a/configure.ac b/configure.ac
index 9c9a8c5..f5693c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -141,6 +141,7 @@ AC_CONFIG_FILES([
Makefile
libgd/Makefile
src/Makefile
+ tools/Makefile
data/Makefile
tests/Makefile
po/Makefile.in
diff --git a/tools/Makefile.am b/tools/Makefile.am
new file mode 100644
index 0000000..0cd5900
--- /dev/null
+++ b/tools/Makefile.am
@@ -0,0 +1,11 @@
+noinst_PROGRAMS = recipe-extract
+
+recipe_extract_CFLAGS = \
+ $(WARN_CFLAGS) \
+ $(RECIPES_CFLAGS)
+
+recipe_extract_LDADD = \
+ $(RECIPES_LIBS)
+
+recipe_extract_SOURCES = \
+ recipe-extract.c
diff --git a/tools/recipe-extract.c b/tools/recipe-extract.c
new file mode 100644
index 0000000..1938552
--- /dev/null
+++ b/tools/recipe-extract.c
@@ -0,0 +1,91 @@
+/* recipe-extract.c:
+ *
+ * Copyright (C) 2016 Matthias Clasen
+ *
+ * Licensed under the GNU General Public License Version 3
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <locale.h>
+
+#include <glib.h>
+
+
+static void
+emit_string (const char *s)
+{
+ g_auto(GStrv) strv = NULL;
+ int i;
+
+ strv = g_strsplit (s, "\n", -1);
+
+ for (i = 0; strv[i]; i++) {
+ if (strv[i][0] != 0)
+ g_print ("N_(\"%s\")\n", strv[i]);
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_autoptr(GKeyFile) keyfile = NULL;
+ g_autoptr(GError) error = NULL;
+ g_auto(GStrv) groups = NULL;
+ gsize length;
+ const char *keys[] = {
+ "Name",
+ "Description",
+ "Instructions"
+ };
+ unsigned int i, j;
+
+ if (argc != 2)
+ return 1;
+
+ setlocale (LC_ALL, "");
+
+ keyfile = g_key_file_new ();
+
+ if (!g_key_file_load_from_file (keyfile, argv[1], G_KEY_FILE_NONE, &error)) {
+ g_print ("Failed to parse %s: %s\n", argv[1], error->message);
+ return 1;
+ }
+
+ g_print ("#if 0\n\n");
+
+ groups = g_key_file_get_groups (keyfile, &length);
+ for (i = 0; i < length; i++) {
+ if (g_str_has_prefix (groups[i], "TEST"))
+ continue;
+
+ for (j = 0; j < G_N_ELEMENTS (keys); j++) {
+ g_autofree char *s = NULL;
+ s = g_key_file_get_string (keyfile, groups[i], keys[j], &error);
+ if (!s) {
+ g_print ("Failed to get key '%s' for group '%s': %s\n", keys[j], groups[i],
error->message);
+ g_clear_error (&error);
+ continue;
+ }
+
+ emit_string (s);
+ }
+ }
+
+ g_print ("\n\n#endif\n");
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]