[PATCH:xrdb] Add a command line flag -cppargs which allows passing arguments to cpp (while still complying with the access(2) check for the cpp executable).

Thomas Klausner wiz at NetBSD.org
Fri May 31 02:55:47 PDT 2013


Any comments?
 Thomas

On Thu, Aug 23, 2012 at 04:48:10PM +0200, Thomas Klausner wrote:
> See thread starting at
> http://mail-index.netbsd.org/tech-x11/2009/12/01/msg000687.html
> ---
>  man/xrdb.man |  4 ++++
>  xrdb.c       | 27 +++++++++++++++++++++++----
>  2 files changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/man/xrdb.man b/man/xrdb.man
> index e30b0d5..d024210 100644
> --- a/man/xrdb.man
> +++ b/man/xrdb.man
> @@ -217,6 +217,10 @@ Although
>  was designed to use CPP, any program that acts as a filter
>  and accepts the -D, -I, and -U options may be used.
>  .TP 8
> +.B -cppargs \fIargs\fP
> +This option specifies the arguments to provide to the C preprocessor
> +program to be used.
> +.TP 8
>  .B -nocpp
>  This option indicates that
>  .I xrdb
> diff --git a/xrdb.c b/xrdb.c
> index cf2758a..4447c56 100644
> --- a/xrdb.c
> +++ b/xrdb.c
> @@ -127,6 +127,10 @@ static char tmpname3[32];
>  static int oper = OPLOAD;
>  static char *editFile = NULL;
>  static const char *cpp_program = NULL;
> +#ifndef CPP_ARGS
> +#define CPP_ARGS	NULL
> +#endif
> +static const char *cpp_args = CPP_ARGS;
>  static const char* const cpp_locations[] = { CPP };
>  static char *backup_suffix = BACKUP_SUFFIX;
>  static Bool dont_execute = False;
> @@ -729,6 +733,7 @@ Syntax (void)
>  	     " -screens            do screen-specific resources for all screens\n"
>  	     " -n                  show but don't do changes\n"
>  	     " -cpp filename       preprocessor to use [%s]\n"
> +	     " -cppargs args       arguments for preprocessor\n"
>  	     " -nocpp              do not use a preprocessor\n"
>  	     " -query              query resources\n"
>  	     " -load               load resources from file [default]\n"
> @@ -886,6 +891,10 @@ main(int argc, char *argv[])
>  		if (++i >= argc) Syntax ();
>  		cpp_program = argv[i];
>  		continue;
> +	    } else if (isabbreviation ("-cppargs", arg, 2)) {
> +		if (++i >= argc) Syntax ();
> +		cpp_args = argv[i];
> +		continue;
>  	    } else if (!strcmp ("-n", arg)) {
>  		dont_execute = True;
>  		continue;
> @@ -1230,7 +1239,10 @@ Process(int scrno, Bool doScreen, Bool execute)
>  	    fprintf(input, "\n#include \"%s\"\n", filename);
>  	    fclose(input);
>  	    (void) mktemp(tmpname3);
> -	    if (asprintf(&cmd, "%s -P%s %s > %s", cpp_program, includes.val,
> +	    if (asprintf(&cmd, "%s%s%s -P%s %s > %s", cpp_program,
> +		         cpp_args ? " " : "",
> +		         cpp_args ? cpp_args : "",
> +			 includes.val,
>  			 tmpname2, tmpname3) == -1)
>  		fatal("%s: Out of memory\n", ProgramName);
>  	    if (system(cmd) < 0)
> @@ -1245,7 +1257,10 @@ Process(int scrno, Bool doScreen, Bool execute)
>  	    fprintf(stdin, "\n#include \"%s\"\n", filename);
>  	    fflush(stdin);
>  	    fseek(stdin, 0, 0);
> -	    if (asprintf(&cmd, "%s -P%s", cpp_program, includes.val) == -1)
> +	    if (asprintf(&cmd, "%s%s%s -P%s", cpp_program,
> +		         cpp_args ? " " : "",
> +		         cpp_args ? cpp_args : "",
> +			 includes.val) == -1)
>  		fatal("%s: Out of memory\n", ProgramName);
>  	    if (!(input = popen(cmd, "r")))
>  		fatal("%s: cannot run '%s'\n", ProgramName, cmd);
> @@ -1260,7 +1275,9 @@ Process(int scrno, Bool doScreen, Bool execute)
>  	if (cpp_program) {
>  #ifdef WIN32
>  	    (void) mktemp(tmpname3);
> -	    if (asprintf(&cmd, "%s -P%s %s %s > %s", cpp_program,
> +	    if (asprintf(&cmd, "%s%s%s -P%s %s %s > %s", cpp_program,
> +		         cpp_args ? " " : "",
> +		         cpp_args ? cpp_args : "",
>  			 includes.val, defines.val,
>  			 filename ? filename : "", tmpname3) == -1)
>  		fatal("%s: Out of memory\n", ProgramName);
> @@ -1270,7 +1287,9 @@ Process(int scrno, Bool doScreen, Bool execute)
>  	    if (!(input = fopen(tmpname3, "r")))
>  		fatal("%s: can't open file '%s'\n", ProgramName, tmpname3);
>  #else
> -	    if (asprintf(&cmd, "%s -P%s %s %s", cpp_program,
> +	    if (asprintf(&cmd, "%s%s%s -P%s %s %s", cpp_program,
> +		         cpp_args ? " " : "",
> +		         cpp_args ? cpp_args : "",
>  			 includes.val, defines.val,
>  			 filename ? filename : "") == -1)
>  		fatal("%s: Out of memory\n", ProgramName);
> -- 
> 1.7.11.3


More information about the xorg-devel mailing list