From 2e9857b5604461e76805373f2974a0c922ec4277 Mon Sep 17 00:00:00 2001 From: Thomas Thurman Date: Thu, 23 Oct 2008 04:01:14 +0000 Subject: [PATCH] support builds outside tree properly. 2008-10-22 Thomas Thurman * src/core/schema-bindings.c: support builds outside tree properly. svn path=/trunk/; revision=3988 --- ChangeLog | 4 +++ src/core/schema-bindings.c | 74 +++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index abf757254..1d9e1561d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-10-22 Thomas Thurman + + * src/core/schema-bindings.c: support builds outside tree properly. + 2008-10-22 Thomas Thurman * NEWS: 2.25.3 release. diff --git a/src/core/schema-bindings.c b/src/core/schema-bindings.c index 37914a63b..e283a9f38 100644 --- a/src/core/schema-bindings.c +++ b/src/core/schema-bindings.c @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -44,6 +45,9 @@ static void single_stanza (gboolean is_window, const char *name, char *about_keybindings, *about_reversible_keybindings; +char *source_filename, *target_filename; +FILE *source_file, *target_file; + const char* window_string = \ " \n" \ " /schemas/apps/metacity/%s_keybindings/%s%s\n" \ @@ -75,22 +79,22 @@ single_stanza (gboolean is_window, const char *name, escaped_default_value = default_value==NULL? "disabled": g_markup_escape_text (description, -1); - printf (" \n"); - printf (" /schemas/apps/metacity/%s_keybindings/%s\n", + fprintf (target_file, " \n"); + fprintf (target_file, " /schemas/apps/metacity/%s_keybindings/%s\n", keybinding_type, name); - printf (" /apps/metacity/%s_keybindings/%s\n", + fprintf (target_file, " /apps/metacity/%s_keybindings/%s\n", keybinding_type, name); - printf (" metacity\n"); - printf (" string\n"); - printf (" %s\n", escaped_default_value); + fprintf (target_file, " metacity\n"); + fprintf (target_file, " string\n"); + fprintf (target_file, " %s\n", escaped_default_value); - printf (" \n"); - printf (" %s\n", description); - printf (" %s\n", + fprintf (target_file, " \n"); + fprintf (target_file, " %s\n", description); + fprintf (target_file, " %s\n", can_reverse? about_reversible_keybindings: about_keybindings); - printf (" \n"); - printf (" \n\n"); + fprintf (target_file, " \n"); + fprintf (target_file, " \n\n"); g_free (escaped_description); @@ -103,30 +107,38 @@ static void produce_bindings (); static void produce_bindings () { - FILE *metacity_schemas_in_in = fopen("metacity.schemas.in.in", "r"); + source_file = fopen(source_filename, "r"); - if (!metacity_schemas_in_in) + if (!source_file) { - g_error ("Cannot compile without metacity.schemas.in.in: %s\n", - strerror (errno)); + g_error ("Cannot compile without %s: %s\n", + source_filename, strerror (errno)); } - while (!feof (metacity_schemas_in_in)) + target_file = fopen(target_filename, "w"); + + if (!target_file) + { + g_error ("Cannot create %s: %s\n", + target_filename, strerror (errno)); + } + + while (!feof (source_file)) { /* 10240 is ridiculous overkill; we're writing the input file and * the lines are always 80 chars or less. */ char buffer[10240]; - fgets (buffer, sizeof (buffer), metacity_schemas_in_in); + fgets (buffer, sizeof (buffer), source_file); if (strstr (buffer, "")) break; - printf ("%s", buffer); + fprintf (target_file, "%s", buffer); } - if (!feof (metacity_schemas_in_in)) + if (!feof (source_file)) { #define keybind(name, handler, param, flags, stroke, description) \ single_stanza ( \ @@ -140,21 +152,35 @@ produce_bindings () #undef keybind } - while (!feof (metacity_schemas_in_in)) + while (!feof (source_file)) { char buffer[10240]; - fgets (buffer, sizeof (buffer), metacity_schemas_in_in); + fgets (buffer, sizeof (buffer), source_file); - printf ("%s", buffer); + fprintf (target_file, "%s", buffer); } - fclose (metacity_schemas_in_in); + if (fclose (source_file)!=0) + g_error ("Cannot close %s: %s\n", + source_filename, strerror (errno)); + + if (fclose (target_file)!=0) + g_error ("Cannot close %s: %s\n", + target_filename, strerror (errno)); } int -main () +main (int argc, char **argv) { + if (argc!=3) + { + g_error ("Syntax: %s \n", argv[0]); + } + + source_filename = argv[1]; + target_filename = argv[2]; + /* Translators: Please don't translate "Control", "Shift", etc, since these * are hardcoded (in gtk/gtkaccelgroup.c; it's not metacity's fault). * "disabled" must also stay as it is.