[Xfce4-commits] [xfce/exo] 01/01: Add the possibility to write exo-csource output directly to a file (Bug #12901)
noreply at xfce.org
noreply at xfce.org
Thu Jun 15 05:10:10 CEST 2017
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository xfce/exo.
commit f6e0495bda40c493bb2d59241489ece69aed8909
Author: Flo <flo.xfce at gmx-topmail.de>
Date: Wed Jun 14 23:09:57 2017 -0400
Add the possibility to write exo-csource output directly to a file (Bug #12901)
---
docs/reference/exo-csource.xml | 11 +++++++++++
exo-csource/main.c | 37 ++++++++++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/docs/reference/exo-csource.xml b/docs/reference/exo-csource.xml
index 0a232bd..fa60787 100644
--- a/docs/reference/exo-csource.xml
+++ b/docs/reference/exo-csource.xml
@@ -104,6 +104,17 @@
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><option>--output=identifier</option></term>
+ <listitem>
+ <para>
+ Prints the output to <parameter>identifier</parameter> instead of
+ stdout (only used if <option>--build-list</option> was
+ not specified as well).
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect2>
</refsect1>
diff --git a/exo-csource/main.c b/exo-csource/main.c
index 3a948a8..627e34f 100644
--- a/exo-csource/main.c
+++ b/exo-csource/main.c
@@ -42,6 +42,7 @@
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <glib/gprintf.h>
+#include <glib/gstdio.h>
@@ -63,6 +64,7 @@ static gboolean gen_stripcomments = FALSE;
static gboolean gen_stripcontent = FALSE;
static const gchar *gen_linkage = "static ";
static const gchar *gen_varname = "my_data";
+static const gchar *out_name = NULL;
@@ -132,6 +134,23 @@ parse_args (gint *argc_p,
gen_stripcontent = TRUE;
argv[n] = NULL;
}
+ else if (strcmp (argv[n], "--output") == 0
+ || strncmp (argv[n], "--output=", 9) == 0)
+ {
+ s = argv[n] + 8;
+
+ if (G_LIKELY (*s == '='))
+ {
+ out_name = g_strdup (s + 1);
+ }
+ else if (n + 1 < argc)
+ {
+ out_name = g_strdup (argv[n + 1]);
+ argv[n++] = NULL;
+ }
+
+ argv[n] = NULL;
+ }
}
for (m = 0, n = 1; n < argc; ++n)
@@ -292,6 +311,7 @@ print_usage (void)
g_print (_(" --build-list Parse (name, file) pairs\n"));
g_print (_(" --strip-comments Remove comments from XML files\n"));
g_print (_(" --strip-content Remove node contents from XML files\n"));
+ g_print (_(" --output=filename Write generated csource to specified file\n"));
g_print ("\n");
}
@@ -324,6 +344,7 @@ main (int argc, char **argv)
gchar *data;
gsize length;
gint n;
+ FILE *out_file;
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
@@ -348,6 +369,17 @@ main (int argc, char **argv)
return EXIT_FAILURE;
}
+ if (out_name == NULL)
+ out_file = stdout;
+ else
+ {
+ out_file = g_fopen (out_name, "w");
+ if (out_file == NULL) {
+ g_fprintf (stderr, "Failed to open output file \"%s\"\n", out_name);
+ return EXIT_FAILURE;
+ }
+ }
+
#ifdef G_OS_WIN32
filename = g_local_to_utf8 (argv[1], -1, NULL, NULL, NULL);
#else
@@ -362,7 +394,10 @@ main (int argc, char **argv)
return EXIT_FAILURE;
}
- print_csource (stdout, data, length, filename);
+ print_csource (out_file, data, length, filename);
+
+ if (out_file != NULL && out_file != stdout)
+ fclose (out_file);
g_free (data);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list