[PATCH] For -### only quote what is needed

Jakub Jelinek jakub@redhat.com
Fri Apr 16 17:55:00 GMT 2010


On Fri, Apr 16, 2010 at 07:08:45PM +0200, Jakub Jelinek wrote:
> On Fri, Apr 16, 2010 at 09:55:24AM -0700, Jim Wilson wrote:
> > On Fri, 2010-04-16 at 17:46 +0200, Jakub Jelinek wrote:
> > > I think we should keep -Wl, as is and instead change the linker not
> > > to give so confusing error message (for empty filename add quotes
> > > around it or add them around always).
> > 
> > This was my next option to try, but it doesn't directly address the
> > problem.  How is the user supposed to realize that a mis-typed -Wl,
> > option is responsible for the empty filename?  There is no way for the
> > user to make that connection without help.  In an industrial
> 
> The user can just rerun the command with -### and see where the ""
> appears.

Talking about -###, I wonder why it must quote everything.
"./cc1" "-quiet" "-iprefix" "/usr/src/gcc/obj/gcc/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/" "-isystem" "./include" "-isystem" "./include-fixed" "a.c" "-quiet" "-dumpbase" "a.c" "-mtune=generic" "-march=x86-64" "-auxbase" "a" "-o" "/tmp/ccw4rhFl.s"
seems to be quite unreadable for me, while
./cc1 -quiet -iprefix /usr/src/gcc/obj/gcc/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/ -isystem ./include -isystem ./include-fixed a.c -quiet -dumpbase a.c "-mtune=generic" "-march=x86-64" -auxbase a -o /tmp/ccw4rhFl.s
with the patch below is exactly the same thing.

2010-04-16  Jakub Jelinek  <jakub@redhat.com>

	* gcc.c (execute): For -### don't quote arguments that
	contain just alphanumerics and _/-. characters.

--- gcc/gcc.c.jj	2010-04-13 14:16:43.000000000 +0200
+++ gcc/gcc.c	2010-04-16 19:31:26.000000000 +0200
@@ -3011,14 +3011,23 @@ execute (void)
 	      for (j = commands[i].argv; *j; j++)
 		{
 		  const char *p;
-		  fprintf (stderr, " \"");
 		  for (p = *j; *p; ++p)
+		    if (!ISALNUM ((unsigned char) *p)
+			&& *p != '_' && *p != '/' && *p != '-' && *p != '.')
+		      break;
+		  if (*p || !*j)
 		    {
-		      if (*p == '"' || *p == '\\' || *p == '$')
-			fputc ('\\', stderr);
-		      fputc (*p, stderr);
+		      fprintf (stderr, " \"");
+		      for (p = *j; *p; ++p)
+			{
+			  if (*p == '"' || *p == '\\' || *p == '$')
+			    fputc ('\\', stderr);
+			  fputc (*p, stderr);
+			}
+		      fputc ('"', stderr);
 		    }
-		  fputc ('"', stderr);
+		  else
+		    fprintf (stderr, " %s", *j);
 		}
 	    }
 	  else


	Jakub



More information about the Gcc-patches mailing list