delorie.com/djgpp/bugs/show.cgi   search  
Bug 000358

When Created: 12/12/2002 23:25:08
Against DJGPP version: 2.03
By whom: ajo@andrew.cmu.edu
Abstract: Design flaw in globbing code
Program "test.c" shows its arguments:

int main(int argc, char *argv[])
{
  int i;
  for (i=1; i < argc; i++) printf(":%s:\n", argv[i]);
  return 0;
}

When invoked as

  test "*\"

the \ escapes the ", producing

  :*":

but when invoked as

  test "*\\"

the \ does not escape the second \, producing

  :*\":

I think this is inconsistent behavior; it's certainly not intuitive.
The current behavior is documented in the FAQ, I know; but I think
the current behavior is broken and needs to be fixed, rather than merely
documented.

I'd like to have the following two rules added to the rules for globbing:

 * The \ character escapes every character, including itself

 * Mismatched quotes and double quotes are caught by the globbing
   code, and reported to the user in an error message something like
   Mismatched '   or   Mismatched "

For example, the command line

  % test "*\"

should report mismatched quotes, and

  % test "*\\"

should produce

  :*\:


Thank you.
-Arthur

Note added: 12/12/2002 23:31:22
By whom: ajo@andrew.cmu.edu
In addition, I'd like to see more information in the FAQ or
in the libc documentation about the "workaround" solution

char **crt0_glob_function(char *arg)
{
   /* what can go here besides "return 0;" ? */
}

Obviously some sort of expansion is still occurring, since
the program breaks arguments at whitespace, removes quotes,
and otherwise messes with the raw data provided by MS-DOS.
What is 'arg' and where is it going?

-Arthur

Note added: 12/13/2002 06:34:12
By whom: eliz@is.elta.co.il
First, this is not a bug at all, and as such, shouldn't have submitted here.

 * The \ character escapes every character, including itself

This will require users to double every backslash when they type DOS-style file names like c:\foo\bar -- a ridiculous requirement on DOS/Windows systems.

 * Mismatched quotes and double quotes are caught by the globbing
   code, and reported to the user in an error message something like
   Mismatched '   or   Mismatched "

This might be a good idea (volunteers are welcome to submit code), but it could also break Makefile's inherited from Borland programs, since Borland's globbing code actually _required_ one to use mismatched quotes.

I'm closing this report.  The submitter is encouraged to continue the discussion on the news group, which is the proper place to talk about design.

Note added: 12/13/2002 06:36:45
By whom: eliz@is.elta.co.il
As for the other note, about the details of the __crt0_glob_function
function, it is documented in the library reference manual, type
"info libc alpha __crt0_glob_function" from the shell prompt to see
that documentation.

Closed on 12/13/2002 06:37:13: Not a bug, but a feature (and a useful one at that)
By whom: eliz@is.elta.co.il



  webmaster     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010