{PATCH] - Revised -### patch

Ira Ruben ira@apple.com
Wed Nov 7 12:14:00 GMT 2001


This is a somewhat revised version of my -### patch.  The code has
been slightly simplified, I fixed a small formatting error, and
added -### to the help info.

In case you missed it the first time...

The -### is similar to -v except that the driver commands are not
executed and all the command arguments are quoted.  It is useful
for shell scripts where they want to capture the driver-generated
lines for some purpose (e.g., for passing to a debugger).

Ira

                             -------------------------

2001-11-07  Ira Ruben	<ira@apple.com>

	Add -### option (displays driver-generated commands without
	executing and quotes all arguments).
	* doc/invoke.texi: Add -###.
	* gcc.c (verbose_only_flag) - New flag.
	* (execute): If -### write quoted arguments and return.
	* (display_help): Print meaning of -###.
	* (process_command): Handle -###.


Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.72
diff -c -3 -p -r1.72 invoke.texi
*** invoke.texi 2001/11/03 23:45:02     1.72
--- invoke.texi 2001/11/07 19:49:44
*************** in the following sections.
*** 152,158 ****
   @xref{Overall Options,,Options Controlling the Kind of Output}.
   @gccoptlist{
   -c  -S  -E  -o @var{file}  -pipe  -pass-exit-codes  -x @var{language} @gol
! -v  --target-help  --help}

   @item C Language Options
   @xref{C Dialect Options,,Options Controlling C Dialect}.
--- 152,158 ----
   @xref{Overall Options,,Options Controlling the Kind of Output}.
   @gccoptlist{
   -c  -S  -E  -o @var{file}  -pipe  -pass-exit-codes  -x @var{language} @gol
! -v  -###  --target-help  --help}

   @item C Language Options
   @xref{C Dialect Options,,Options Controlling C Dialect}.
*************** all preprocessed C source on standard ou
*** 837,842 ****
--- 837,848 ----
   Print (on standard error output) the commands executed to run the stages
   of compilation.  Also print the version number of the compiler driver
   program and of the preprocessor and the compiler proper.
+
+ @item -###
+ @opindex ###
+ Like @option{-v} except the commands are not executed and all command
+ arguments are quoted.  This is useful for shell scripts to capture the
+ driver-generated command lines.

   @item -pipe
   @opindex pipe
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.263
diff -c -3 -p -r1.263 gcc.c
*** gcc.c	2001/11/04 02:47:36	1.263
--- gcc.c	2001/11/07 19:47:35
*************** static int print_help_list;
*** 186,191 ****
--- 186,199 ----

   static int verbose_flag;

+ /* Flag indicating whether we should ONLY print the command and
+    arguments (like verbose_flag) without executing the command.
+    Displayed arguments are quoted so that the generated command
+    line is suitable for execution.  Flag is either a string
+    contaaining a quote or null.  This is intended for use in
+    shell scripts to capture the driver-generated command line.  */
+ static char *verbose_only_flag = "";
+
   /* Flag indicating to print target specific command line options.  */

   static int target_help_flag;
*************** execute ()
*** 2702,2708 ****
   	  const char *const *j;

   	  for (j = commands[i].argv; *j; j++)
! 	    fprintf (stderr, " %s", *j);

   	  /* Print a pipe symbol after all but the last command.  */
   	  if (i + 1 != n_commands)
--- 2710,2717 ----
   	  const char *const *j;

   	  for (j = commands[i].argv; *j; j++)
! 	    fprintf (stderr, " %s%s%s", verbose_only_flag, *j,
! 	    	     verbose_only_flag);

   	  /* Print a pipe symbol after all but the last command.  */
   	  if (i + 1 != n_commands)
*************** execute ()
*** 2710,2715 ****
--- 2719,2726 ----
   	  fprintf (stderr, "\n");
   	}
         fflush (stderr);
+       if (*verbose_only_flag != 0)
+         return 0;
   #ifdef DEBUG
         notice ("\nGo ahead? (y or n) ");
         fflush (stderr);
*************** display_help ()
*** 2991,2996 ****
--- 3002,3008 ----
     fputs (_("  -b <machine>             Run gcc for target 
<machine>, if installed\n"), stdout);
     fputs (_("  -V <version>             Run gcc version number 
<version>, if installed\n"), stdout);
     fputs (_("  -v                       Display the programs invoked 
by the compiler\n"), stdout);
+   fputs (_("  -###                     Like -v but options quoted 
and commands not executed\n"), stdout);
     fputs (_("  -E                       Preprocess only; do not 
compile, assemble or link\n"), stdout);
     fputs (_("  -S                       Compile only; do not 
assemble or link\n"), stdout);
     fputs (_("  -c                       Compile and assemble, but do 
not link\n"), stdout);
*************** process_command (argc, argv)
*** 3421,3426 ****
--- 3433,3447 ----
   	}
         else if (strcmp (argv[i], "-time") == 0)
   	report_times = 1;
+       else if (strcmp (argv[i], "-###") == 0)
+ 	{
+ 	  /* This is similar to -v except that there is no execution
+ 	     of the commands and the echoed arguments are quoted.  It
+ 	     is intended for use in shell scripts to capture the
+ 	     driver-generated command line.  */
+ 	  verbose_only_flag = "\"";
+ 	  verbose_flag++;
+ 	}
         else if (argv[i][0] == '-' && argv[i][1] != 0)
   	{
   	  const char *p = &argv[i][1];
*************** process_command (argc, argv)
*** 3870,3875 ****
--- 3891,3898 ----
   	  else if (report_times)
   	    error ("Warning: -pipe ignored because -time specified");
   	}
+       else if (strcmp (argv[i], "-###") == 0)
+ 	;
         else if (argv[i][0] == '-' && argv[i][1] != 0)
   	{
   	  const char *p = &argv[i][1];



More information about the Gcc-patches mailing list