[PATCH app/xrdb] Add -E flag to show cpp command line & processed input file

Alan Coopersmith alan.coopersmith at oracle.com
Sun Mar 25 06:32:50 UTC 2018


https://bugs.freedesktop.org/show_bug.cgi?id=98300

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---

I used "-E" in imitation of "cc -E" since I couldn't think of a better name.
"-v" or "-verbose" didn't seem right, since it's only making this one specific
aspect verbose, not all the resource additions/deletions/etc.
I'm open to suggestions, but don't want a bikeshed of many colors either.

 man/xrdb.man |  6 ++++++
 xrdb.c       | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/man/xrdb.man b/man/xrdb.man
index 211c0a2..7ed14fc 100644
--- a/man/xrdb.man
+++ b/man/xrdb.man
@@ -231,6 +231,12 @@ into properties.
 This option is passed to the C preprocessor if used. It prevents it from
 predefining any system specific macros.
 .TP 8
+.B \-E
+This option indicates that any cpp command run and the output from it should
+be shown on standard output.  If \fB\-nocpp\fP was also specified, the input
+file will be shown as read.  The specified changes will also be performed
+unless the \fB\-n\fP option is also specified.
+.TP 8
 .B \-symbols
 This option indicates that the symbols that are defined for the preprocessor
 should be printed onto the standard output.
diff --git a/xrdb.c b/xrdb.c
index 72e526c..6054790 100644
--- a/xrdb.c
+++ b/xrdb.c
@@ -127,6 +127,7 @@ static const char *cpp_program = NULL;
 static const char * const cpp_locations[] = { CPP };
 static const char *backup_suffix = BACKUP_SUFFIX;
 static Bool dont_execute = False;
+static Bool show_cpp = False;
 static String defines;
 static size_t defines_base;
 #define MAX_CMD_DEFINES 512
@@ -428,6 +429,8 @@ ReadFile(Buffer *b, FILE *input)
         }
 #endif
         AppendToBuffer(b, buf, bytes);
+        if (show_cpp)
+            fwrite(buf, 1, bytes, stdout);
     }
     AppendToBuffer(b, "", 1);
 }
@@ -779,6 +782,7 @@ Syntax(const char *errmsg)
             " -n                  show but don't do changes\n"
             " -cpp filename       preprocessor to use [%s]\n"
             " -nocpp              do not use a preprocessor\n"
+            " -E                  show preprocessor command & processed input file\n"
             " -query              query resources\n"
             " -load               load resources from file [default]\n"
             " -override           add in resources from file\n"
@@ -962,6 +966,10 @@ main(int argc, char *argv[])
                 cpp_program = argv[i];
                 continue;
             }
+            else if (!strcmp("-E", arg)) {
+                show_cpp = True;
+                continue;
+            }
             else if (!strcmp("-n", arg)) {
                 dont_execute = True;
                 continue;
@@ -1349,6 +1357,8 @@ Process(int scrno, Bool doScreen, Bool execute)
             if (asprintf(&cmd, "%s %s %s %s > %s", cpp_program, cpp_addflags,
                          includes.val, tmpname2, tmpname3) == -1)
                 fatal("%s: Out of memory\n", ProgramName);
+            if (show_cpp)
+                puts(cmd);
             if (system(cmd) < 0)
                 fatal("%s: cannot run '%s'\n", ProgramName, cmd);
             free(cmd);
@@ -1364,6 +1374,8 @@ Process(int scrno, Bool doScreen, Bool execute)
             if (asprintf(&cmd, "%s %s %s", cpp_program, cpp_addflags,
                          includes.val) == -1)
                 fatal("%s: Out of memory\n", ProgramName);
+            if (show_cpp)
+                puts(cmd);
             if (!(input = popen(cmd, "r")))
                 fatal("%s: cannot run '%s'\n", ProgramName, cmd);
             free(cmd);
@@ -1382,6 +1394,8 @@ Process(int scrno, Bool doScreen, Bool execute)
                              cpp_addflags, includes.val, defines.val,
                              filename ? filename : "", tmpname3) == -1)
                     fatal("%s: Out of memory\n", ProgramName);
+                if (show_cpp)
+                    puts(cmd);
                 if (system(cmd) < 0)
                     fatal("%s: cannot run '%s'\n", ProgramName, cmd);
                 free(cmd);
@@ -1392,6 +1406,8 @@ Process(int scrno, Bool doScreen, Bool execute)
                              cpp_addflags, includes.val, defines.val,
                              filename ? filename : "") == -1)
                     fatal("%s: Out of memory\n", ProgramName);
+                if (show_cpp)
+                    puts(cmd);
                 if (!(input = popen(cmd, "r")))
                     fatal("%s: cannot run '%s'\n", ProgramName, cmd);
                 free(cmd);
-- 
2.15.0



More information about the xorg-devel mailing list