[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/support cmdline.c,1.8,1.9
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/support cmdline.c,1.8,1.9 |
Date: |
Mon, 16 Dec 2002 05:16:15 -0500 |
Update of /cvsroot/dotgnu-pnet/pnet/support
In directory subversions:/tmp/cvs-serv32192/support
Modified Files:
cmdline.c
Log Message:
Expand wildcards on the command-line.
Index: cmdline.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/support/cmdline.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** cmdline.c 16 Dec 2002 06:26:13 -0000 1.8
--- cmdline.c 16 Dec 2002 10:16:11 -0000 1.9
***************
*** 22,25 ****
--- 22,27 ----
#include "il_system.h"
#include "il_utils.h"
+ #include "il_regex.h"
+ #include "il_sysio.h"
#ifdef __cplusplus
***************
*** 382,385 ****
--- 384,535 ----
}
+ /*
+ * Do we need to expand wildcard specifications?
+ */
+ #ifdef IL_WIN32_NATIVE
+ #define IL_EXPAND_WILDCARDS 1
+ #endif
+
+ #ifdef IL_EXPAND_WILDCARDS
+
+ /*
+ * Expand wildcards from an argument specification.
+ */
+ static void ExpandWildcards(int *argc, char ***argv, int *maxArgc, char
*value)
+ {
+ int len;
+ char *directory;
+ char *baseName;
+ char *regex;
+ int posn, ch;
+ regex_t state;
+ ILDir *dir;
+ ILDirEnt *entry;
+ int first;
+ int sawMatch;
+ const char *name;
+ char *full;
+
+ /* Split the value into directory and base name components */
+ len = strlen(value);
+ while(len > 0 && value[len - 1] != '/' && value[len - 1] != '\\' &&
+ value[len - 1] != ':')
+ {
+ --len;
+ }
+ directory = ILDupNString(value, len);
+ if(!directory)
+ {
+ OutOfMemory();
+ }
+ baseName = value + len;
+
+ /* Convert the base name into a regular expression */
+ regex = (char *)ILMalloc(strlen(baseName) * 2 + 16);
+ if(!regex)
+ {
+ OutOfMemory();
+ }
+ posn = 0;
+ regex[posn++] = '^';
+ first = 1;
+ while(*baseName != '\0')
+ {
+ ch = *baseName++;
+ if(ch == '?')
+ {
+ if(first)
+ {
+ /* Don't match '.' at the start of the name */
+ regex[posn++] = '[';
+ regex[posn++] = '^';
+ regex[posn++] = '.';
+ regex[posn++] = ']';
+ }
+ else
+ {
+ regex[posn++] = '.';
+ }
+ }
+ else if(ch == '*')
+ {
+ if(first)
+ {
+ /* Don't match '.' at the start of the name */
+ regex[posn++] = '[';
+ regex[posn++] = '^';
+ regex[posn++] = '.';
+ regex[posn++] = ']';
+ regex[posn++] = '*';
+ }
+ else
+ {
+ regex[posn++] = '.';
+ regex[posn++] = '*';
+ }
+ }
+ else if(ch == '.' || ch == '^' || ch == '$' || ch == '[' ||
+ ch == ']' || ch == '\\' || ch == '(' || ch ==
')')
+ {
+ regex[posn++] = '\\';
+ regex[posn++] = (char)ch;
+ }
+ else
+ {
+ regex[posn++] = (char)ch;
+ }
+ first = 0;
+ }
+ regex[posn++] = '$';
+ regex[posn] = '\0';
+ if(IL_regcomp(&state, regex, REG_EXTENDED | REG_NOSUB) != 0)
+ {
+ fprintf(stderr, "Invalid regular expression: %s\n", regex);
+ exit(1);
+ }
+
+ /* Scan the directory for regular expression matches */
+ sawMatch = 0;
+ dir = ILOpenDir(directory);
+ while(dir && (entry = ILReadDir(dir)) != 0)
+ {
+ name = ILDirEntName(entry);
+ if(IL_regexec(&state, name, 0, 0, 0) == 0)
+ {
+ /* We have found a match against the regular expression
*/
+ sawMatch = 1;
+ full = (char *)ILMalloc(strlen(directory) +
strlen(name) + 1);
+ if(!full)
+ {
+ ILCloseDir(dir);
+ OutOfMemory();
+ }
+ strcpy(full, directory);
+ strcat(full, name);
+ AddNewArg(argc, argv, maxArgc, full);
+ }
+ ILFree(entry);
+ }
+ if(dir)
+ {
+ ILCloseDir(dir);
+ }
+
+ /* If we didn't find any matches, then add the wildcard specification
+ as an argument. The program will probably report "File not found",
+ which is what we want it to do. */
+ if(!sawMatch)
+ {
+ AddNewArg(argc, argv, maxArgc, value);
+ }
+
+ /* Clean up and exit */
+ IL_regfree(&state);
+ ILFree(directory);
+ ILFree(regex);
+ }
+
+ #endif /* IL_EXPAND_WILDCARDS */
+
void ILCmdLineExpand(int *argc, char ***argv)
{
***************
*** 395,399 ****
char *respfile;
! /* See if we have any response file references first */
for(arg = 1; arg < *argc; ++arg)
{
--- 545,549 ----
char *respfile;
! /* See if we have any response file or wildcard references first */
for(arg = 1; arg < *argc; ++arg)
{
***************
*** 402,409 ****
break;
}
}
if(arg >= *argc)
{
! /* No response files, so nothing further to do */
return;
}
--- 552,566 ----
break;
}
+ #ifdef IL_EXPAND_WILDCARDS
+ if(strchr((*argv)[arg], '?') != 0 ||
+ strchr((*argv)[arg], '*') != 0)
+ {
+ break;
+ }
+ #endif
}
if(arg >= *argc)
{
! /* No response files or wildcards, so nothing further to do */
return;
}
***************
*** 481,484 ****
--- 638,649 ----
}
}
+ #ifdef IL_EXPAND_WILDCARDS
+ else if(strchr((*argv)[arg], '?') != 0 ||
+ strchr((*argv)[arg], '*') != 0)
+ {
+ /* Expand wildcards within the argument */
+ ExpandWildcards(&newArgc, &newArgv, &maxArgc,
(*argv)[arg]);
+ }
+ #endif
else
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/support cmdline.c,1.8,1.9,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: treecc ChangeLog,1.62,1.63 configure.in,1.24,1.25
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.2001,1.2002
- Previous by thread:
[Dotgnu-pnet-commits] CVS: treecc ChangeLog,1.62,1.63 configure.in,1.24,1.25
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.2001,1.2002
- Index(es):