* $Id$
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2014, MinGW.org Project
+ * Copyright (C) 2014, 2017, 2018, MinGW.org Project
*
* ---------------------------------------------------------------------------
*
* ---------------------------------------------------------------------------
*
*/
+#define _ISOC99_SOURCE
+
#include <glob.h>
#include <string.h>
#include <ctype.h>
{
/* Implementation of the MinGW replacement command line interpreter.
*/
- char cmdbuf[1 + strlen( cmdline ) << 1];
+ char cmdbuf[(1 + strlen( cmdline )) << 1];
int c, gotarg = 0, quoted = 0, bracket = 0, bslash = 0;
char *argptr = cmdbuf; const char *cmdptr = cmdline;
glob_t gl_argv;
/* Capture any non-default globbing options, which the user may have
* specified via a custom setting for _CRT_glob.
*/
- int gl_opts = GLOB_NOCHECK;
- if( _CRT_glob & __CRT_GLOB_CASE_SENSITIVE__ )
- gl_opts |= GLOB_CASEMATCH;
+ int gl_opts = GLOB_NOCHECK | (_CRT_glob & (GLOB_CASEMATCH | GLOB_BRACE));
/* We explicitly DO NOT use the GLOB_DOOFFS capability; ensure that
* the associated field, in the glob_t structure, is initialized to
/* Scan the command line, and prepare it for globbing.
*/
- while( c = *cmdptr++ )
+ while( (c = *cmdptr++) != '\0' )
{
/* Got a character to process...
*/
* need special handling.
*/
case '\\':
- /* We don't (yet) know if this is a literal backslash,
- * (directory separator), or an escape for a following
- * quote character; just note its presence, until we
- * have looked far enough ahead to decide.
- */
- ++bslash;
+ if( quoted == '\'' )
+ /* Backslashes within single quotes are always literal.
+ */
+ *argptr++ = '\\';
+
+ else
+ /* We don't (yet) know if this is a literal backslash,
+ * (directory separator), or an escape for a following
+ * quote character; just note its presence, until we
+ * have looked far enough ahead to decide.
+ */
+ ++bslash;
break;
case '[':
*/
bracket = (_CRT_glob & ARGV_NOGROUP) ? 0 : ARGV_NOGROUP;
- case '*':
- case '?':
- /* These standard globbing tokens...
+ case '*': case '?':
+ /* These standard globbing tokens,...
+ */
+ case '{': case ',': case '}':
+ /* ...this additional triplet, non-standard, but required
+ * to support GNU's GLOB_BRACE extension; (strictly we need
+ * to consider these only if GLOB_BRACE is enabled, but it
+ * should do no harm to consider them regardless),...
*/
case ARGV_ESCAPE:
/* ...and the escape character itself, need to be escaped
* literally, after flushing out any pending backslashes.
*/
argptr = backslash( bslash, argptr );
- if( (quoted == 0) && isspace( c ) )
+ if( (quoted == 0) && isblank( c ) )
{
- /* The one exception is any white space character,
+ /* The one exception is any blank or tab character,
* when it is not contained within quotes; this acts
* as an argument separator, (or is simply discarded
* if there is no argument already collected)...