|
|
623fdc |
diff -up unzip60/match.c.recmatch unzip60/match.c
|
|
|
623fdc |
--- unzip60/match.c.recmatch 2005-08-14 13:00:36.000000000 -0400
|
|
|
623fdc |
+++ unzip60/match.c 2013-05-28 10:29:57.949077543 -0400
|
|
|
623fdc |
@@ -27,16 +27,14 @@
|
|
|
623fdc |
|
|
|
623fdc |
---------------------------------------------------------------------------
|
|
|
623fdc |
|
|
|
623fdc |
- Copyright on recmatch() from Zip's util.c (although recmatch() was almost
|
|
|
623fdc |
- certainly written by Mark Adler...ask me how I can tell :-) ):
|
|
|
623fdc |
+ Copyright on recmatch() from Zip's util.c
|
|
|
623fdc |
+ Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
|
|
|
623fdc |
|
|
|
623fdc |
- Copyright (C) 1990-1992 Mark Adler, Richard B. Wales, Jean-loup Gailly,
|
|
|
623fdc |
- Kai Uwe Rommel and Igor Mandrichenko.
|
|
|
623fdc |
+ See the accompanying file LICENSE, version 2004-May-22 or later
|
|
|
623fdc |
+ for terms of use.
|
|
|
623fdc |
+ If, for some reason, both of these files are missing, the Info-ZIP license
|
|
|
623fdc |
+ also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
|
|
|
623fdc |
|
|
|
623fdc |
- Permission is granted to any individual or institution to use, copy,
|
|
|
623fdc |
- or redistribute this software so long as all of the original files are
|
|
|
623fdc |
- included unmodified, that it is not sold for profit, and that this copy-
|
|
|
623fdc |
- right notice is retained.
|
|
|
623fdc |
|
|
|
623fdc |
---------------------------------------------------------------------------
|
|
|
623fdc |
|
|
|
623fdc |
@@ -53,7 +51,7 @@
|
|
|
623fdc |
|
|
|
623fdc |
A set is composed of characters or ranges; a range looks like ``character
|
|
|
623fdc |
hyphen character'' (as in 0-9 or A-Z). [0-9a-zA-Z_] is the minimal set of
|
|
|
623fdc |
- characters allowed in the [..] pattern construct. Other characters are
|
|
|
623fdc |
+ characters ALlowed in the [..] pattern construct. Other characters are
|
|
|
623fdc |
allowed (i.e., 8-bit characters) if your system will support them.
|
|
|
623fdc |
|
|
|
623fdc |
To suppress the special syntactic significance of any of ``[]*?!^-\'', in-
|
|
|
623fdc |
@@ -101,8 +99,32 @@
|
|
|
623fdc |
# define WILDCHAR '?'
|
|
|
623fdc |
# define BEG_RANGE '['
|
|
|
623fdc |
# define END_RANGE ']'
|
|
|
623fdc |
+# define WILDCHR_SINGLE '?'
|
|
|
623fdc |
+# define DIRSEP_CHR '/'
|
|
|
623fdc |
+# define WILDCHR_MULTI '*'
|
|
|
623fdc |
#endif
|
|
|
623fdc |
|
|
|
623fdc |
+#ifdef WILD_STOP_AT_DIR
|
|
|
623fdc |
+ int wild_stop_at_dir = 1; /* default wildcards do not include / in matches */
|
|
|
623fdc |
+#else
|
|
|
623fdc |
+ int wild_stop_at_dir = 0; /* default wildcards do include / in matches */
|
|
|
623fdc |
+#endif
|
|
|
623fdc |
+
|
|
|
623fdc |
+
|
|
|
623fdc |
+
|
|
|
623fdc |
+/*
|
|
|
623fdc |
+ * case mapping functions. case_map is used to ignore case in comparisons,
|
|
|
623fdc |
+ * to_up is used to force upper case even on Unix (for dosify option).
|
|
|
623fdc |
+ */
|
|
|
623fdc |
+#ifdef USE_CASE_MAP
|
|
|
623fdc |
+# define case_map(c) upper[(c) & 0xff]
|
|
|
623fdc |
+# define to_up(c) upper[(c) & 0xff]
|
|
|
623fdc |
+#else
|
|
|
623fdc |
+# define case_map(c) (c)
|
|
|
623fdc |
+# define to_up(c) ((c) >= 'a' && (c) <= 'z' ? (c)-'a'+'A' : (c))
|
|
|
623fdc |
+#endif /* USE_CASE_MAP */
|
|
|
623fdc |
+
|
|
|
623fdc |
+
|
|
|
623fdc |
#if 0 /* GRR: add this to unzip.h someday... */
|
|
|
623fdc |
#if !(defined(MSDOS) && defined(DOSWILD))
|
|
|
623fdc |
#ifdef WILD_STOP_AT_DIR
|
|
|
623fdc |
@@ -114,8 +136,8 @@ int recmatch OF((ZCONST uch *pattern, ZC
|
|
|
623fdc |
int ignore_case __WDLPRO));
|
|
|
623fdc |
#endif
|
|
|
623fdc |
#endif /* 0 */
|
|
|
623fdc |
-static int recmatch OF((ZCONST uch *pattern, ZCONST uch *string,
|
|
|
623fdc |
- int ignore_case __WDLPRO));
|
|
|
623fdc |
+static int recmatch OF((ZCONST char *, ZCONST char *,
|
|
|
623fdc |
+ int));
|
|
|
623fdc |
static char *isshexp OF((ZCONST char *p));
|
|
|
623fdc |
static int namecmp OF((ZCONST char *s1, ZCONST char *s2));
|
|
|
623fdc |
|
|
|
623fdc |
@@ -154,192 +176,240 @@ int match(string, pattern, ignore_case _
|
|
|
623fdc |
}
|
|
|
623fdc |
dospattern[j-1] = '\0'; /* nuke the end "." */
|
|
|
623fdc |
}
|
|
|
623fdc |
- j = recmatch((uch *)dospattern, (uch *)string, ignore_case __WDL);
|
|
|
623fdc |
+ j = recmatch(dospattern, string, ignore_case);
|
|
|
623fdc |
free(dospattern);
|
|
|
623fdc |
return j == 1;
|
|
|
623fdc |
} else
|
|
|
623fdc |
#endif /* MSDOS && DOSWILD */
|
|
|
623fdc |
- return recmatch((uch *)pattern, (uch *)string, ignore_case __WDL) == 1;
|
|
|
623fdc |
+ return recmatch(pattern, string, ignore_case) == 1;
|
|
|
623fdc |
}
|
|
|
623fdc |
|
|
|
623fdc |
+#ifdef _MBCS
|
|
|
623fdc |
+
|
|
|
623fdc |
+char *___tmp_ptr;
|
|
|
623fdc |
|
|
|
623fdc |
+#endif
|
|
|
623fdc |
|
|
|
623fdc |
-static int recmatch(p, s, ic __WDL)
|
|
|
623fdc |
- ZCONST uch *p; /* sh pattern to match */
|
|
|
623fdc |
- ZCONST uch *s; /* string to which to match it */
|
|
|
623fdc |
- int ic; /* true for case insensitivity */
|
|
|
623fdc |
- __WDLDEF /* directory sepchar for WildStopAtDir mode, or 0 */
|
|
|
623fdc |
+static int recmatch(p, s, cs)
|
|
|
623fdc |
+ZCONST char *p; /* sh pattern to match */
|
|
|
623fdc |
+ZCONST char *s; /* string to match it to */
|
|
|
623fdc |
+int cs; /* flag: force case-sensitive matching */
|
|
|
623fdc |
/* Recursively compare the sh pattern p with the string s and return 1 if
|
|
|
623fdc |
- * they match, and 0 or 2 if they don't or if there is a syntax error in the
|
|
|
623fdc |
- * pattern. This routine recurses on itself no more deeply than the number
|
|
|
623fdc |
- * of characters in the pattern. */
|
|
|
623fdc |
+ they match, and 0 or 2 if they don't or if there is a syntax error in the
|
|
|
623fdc |
+ pattern. This routine recurses on itself no deeper than the number of
|
|
|
623fdc |
+ characters in the pattern. */
|
|
|
623fdc |
{
|
|
|
623fdc |
- unsigned int c; /* pattern char or start of range in [-] loop */
|
|
|
623fdc |
+ int c; /* pattern char or start of range in [-] loop */
|
|
|
623fdc |
+ /* Get first character, the pattern for new recmatch calls follows */
|
|
|
623fdc |
+ /* borrowed from Zip's global.c */
|
|
|
623fdc |
+ int no_wild = 0;
|
|
|
623fdc |
+ int allow_regex=1;
|
|
|
623fdc |
+ /* This fix provided by akt@m5.dion.ne.jp for Japanese.
|
|
|
623fdc |
+ See 21 July 2006 mail.
|
|
|
623fdc |
+ It only applies when p is pointing to a doublebyte character and
|
|
|
623fdc |
+ things like / and wildcards are not doublebyte. This probably
|
|
|
623fdc |
+ should not be needed. */
|
|
|
623fdc |
|
|
|
623fdc |
- /* Get first character, the pattern for new recmatch calls follows */
|
|
|
623fdc |
- c = *p; INCSTR(p);
|
|
|
623fdc |
+#ifdef _MBCS
|
|
|
623fdc |
+ if (CLEN(p) == 2) {
|
|
|
623fdc |
+ if (CLEN(s) == 2) {
|
|
|
623fdc |
+ return (*p == *s && *(p+1) == *(s+1)) ?
|
|
|
623fdc |
+ recmatch(p + 2, s + 2, cs) : 0;
|
|
|
623fdc |
+ } else {
|
|
|
623fdc |
+ return 0;
|
|
|
623fdc |
+ }
|
|
|
623fdc |
+ }
|
|
|
623fdc |
+#endif /* ?_MBCS */
|
|
|
623fdc |
|
|
|
623fdc |
- /* If that was the end of the pattern, match if string empty too */
|
|
|
623fdc |
- if (c == 0)
|
|
|
623fdc |
- return *s == 0;
|
|
|
623fdc |
+ c = *POSTINCSTR(p);
|
|
|
623fdc |
|
|
|
623fdc |
- /* '?' (or '%') matches any character (but not an empty string). */
|
|
|
623fdc |
- if (c == WILDCHAR)
|
|
|
623fdc |
-#ifdef WILD_STOP_AT_DIR
|
|
|
623fdc |
- /* If uO.W_flag is non-zero, it won't match '/' */
|
|
|
623fdc |
- return (*s && (!sepc || *s != (uch)sepc))
|
|
|
623fdc |
- ? recmatch(p, s + CLEN(s), ic, sepc) : 0;
|
|
|
623fdc |
-#else
|
|
|
623fdc |
- return *s ? recmatch(p, s + CLEN(s), ic) : 0;
|
|
|
623fdc |
-#endif
|
|
|
623fdc |
+ /* If that was the end of the pattern, match if string empty too */
|
|
|
623fdc |
+ if (c == 0)
|
|
|
623fdc |
+ return *s == 0;
|
|
|
623fdc |
+
|
|
|
623fdc |
+ /* '?' (or '%' or '#') matches any character (but not an empty string) */
|
|
|
623fdc |
+ if (c == WILDCHR_SINGLE) {
|
|
|
623fdc |
+ if (wild_stop_at_dir)
|
|
|
623fdc |
+ return (*s && *s != DIRSEP_CHR) ? recmatch(p, s + CLEN(s), cs) : 0;
|
|
|
623fdc |
+ else
|
|
|
623fdc |
+ return *s ? recmatch(p, s + CLEN(s), cs) : 0;
|
|
|
623fdc |
+ }
|
|
|
623fdc |
|
|
|
623fdc |
- /* '*' matches any number of characters, including zero */
|
|
|
623fdc |
+ /* WILDCHR_MULTI ('*') matches any number of characters, including zero */
|
|
|
623fdc |
#ifdef AMIGA
|
|
|
623fdc |
- if (c == '#' && *p == '?') /* "#?" is Amiga-ese for "*" */
|
|
|
623fdc |
- c = '*', p++;
|
|
|
623fdc |
+ if (!no_wild && c == '#' && *p == '?') /* "#?" is Amiga-ese for "*" */
|
|
|
623fdc |
+ c = WILDCHR_MULTI, p++;
|
|
|
623fdc |
#endif /* AMIGA */
|
|
|
623fdc |
- if (c == '*') {
|
|
|
623fdc |
-#ifdef WILD_STOP_AT_DIR
|
|
|
623fdc |
- if (sepc) {
|
|
|
623fdc |
- /* check for single "*" or double "**" */
|
|
|
623fdc |
-# ifdef AMIGA
|
|
|
623fdc |
- if ((c = p[0]) == '#' && p[1] == '?') /* "#?" is Amiga-ese for "*" */
|
|
|
623fdc |
- c = '*', p++;
|
|
|
623fdc |
- if (c != '*') {
|
|
|
623fdc |
-# else /* !AMIGA */
|
|
|
623fdc |
- if (*p != '*') {
|
|
|
623fdc |
-# endif /* ?AMIGA */
|
|
|
623fdc |
- /* single "*": this doesn't match the dirsep character */
|
|
|
623fdc |
- for (; *s && *s != (uch)sepc; INCSTR(s))
|
|
|
623fdc |
- if ((c = recmatch(p, s, ic, sepc)) != 0)
|
|
|
623fdc |
- return (int)c;
|
|
|
623fdc |
- /* end of pattern: matched if at end of string, else continue */
|
|
|
623fdc |
- if (*p == '\0')
|
|
|
623fdc |
- return (*s == 0);
|
|
|
623fdc |
- /* continue to match if at sepc in pattern, else give up */
|
|
|
623fdc |
- return (*p == (uch)sepc || (*p == '\\' && p[1] == (uch)sepc))
|
|
|
623fdc |
- ? recmatch(p, s, ic, sepc) : 2;
|
|
|
623fdc |
- }
|
|
|
623fdc |
- /* "**": this matches slashes */
|
|
|
623fdc |
- ++p; /* move p behind the second '*' */
|
|
|
623fdc |
- /* and continue with the non-W_flag code variant */
|
|
|
623fdc |
- }
|
|
|
623fdc |
-#endif /* WILD_STOP_AT_DIR */
|
|
|
623fdc |
+ if (!no_wild && c == WILDCHR_MULTI)
|
|
|
623fdc |
+ {
|
|
|
623fdc |
+ if (wild_stop_at_dir) {
|
|
|
623fdc |
+ /* Check for an immediately following WILDCHR_MULTI */
|
|
|
623fdc |
+# ifdef AMIGA
|
|
|
623fdc |
+ if ((c = p[0]) == '#' && p[1] == '?') /* "#?" is Amiga-ese for "*" */
|
|
|
623fdc |
+ c = WILDCHR_MULTI, p++;
|
|
|
623fdc |
+ if (c != WILDCHR_MULTI) {
|
|
|
623fdc |
+# else /* !AMIGA */
|
|
|
623fdc |
+ if (*p != WILDCHR_MULTI) {
|
|
|
623fdc |
+# endif /* ?AMIGA */
|
|
|
623fdc |
+ /* Single WILDCHR_MULTI ('*'): this doesn't match slashes */
|
|
|
623fdc |
+ for (; *s && *s != DIRSEP_CHR; INCSTR(s))
|
|
|
623fdc |
+ if ((c = recmatch(p, s, cs)) != 0)
|
|
|
623fdc |
+ return c;
|
|
|
623fdc |
+ /* end of pattern: matched if at end of string, else continue */
|
|
|
623fdc |
if (*p == 0)
|
|
|
623fdc |
- return 1;
|
|
|
623fdc |
- if (isshexp((ZCONST char *)p) == NULL) {
|
|
|
623fdc |
- /* Optimization for rest of pattern being a literal string:
|
|
|
623fdc |
- * If there are no other shell expression chars in the rest
|
|
|
623fdc |
- * of the pattern behind the multi-char wildcard, then just
|
|
|
623fdc |
- * compare the literal string tail.
|
|
|
623fdc |
- */
|
|
|
623fdc |
- ZCONST uch *srest;
|
|
|
623fdc |
-
|
|
|
623fdc |
- srest = s + (strlen((ZCONST char *)s) - strlen((ZCONST char *)p));
|
|
|
623fdc |
- if (srest - s < 0)
|
|
|
623fdc |
- /* remaining literal string from pattern is longer than rest
|
|
|
623fdc |
- * of test string, there can't be a match
|
|
|
623fdc |
- */
|
|
|
623fdc |
- return 0;
|
|
|
623fdc |
- else
|
|
|
623fdc |
- /* compare the remaining literal pattern string with the last
|
|
|
623fdc |
- * bytes of the test string to check for a match
|
|
|
623fdc |
- */
|
|
|
623fdc |
+ return (*s == 0);
|
|
|
623fdc |
+ /* continue to match if at DIRSEP_CHR in pattern, else give up */
|
|
|
623fdc |
+ return (*p == DIRSEP_CHR || (*p == '\\' && p[1] == DIRSEP_CHR))
|
|
|
623fdc |
+ ? recmatch(p, s, cs) : 2;
|
|
|
623fdc |
+ }
|
|
|
623fdc |
+ /* Two consecutive WILDCHR_MULTI ("**"): this matches DIRSEP_CHR ('/') */
|
|
|
623fdc |
+ p++; /* move p past the second WILDCHR_MULTI */
|
|
|
623fdc |
+ /* continue with the normal non-WILD_STOP_AT_DIR code */
|
|
|
623fdc |
+ } /* wild_stop_at_dir */
|
|
|
623fdc |
+
|
|
|
623fdc |
+ /* Not wild_stop_at_dir */
|
|
|
623fdc |
+ if (*p == 0)
|
|
|
623fdc |
+ return 1;
|
|
|
623fdc |
+ if (!isshexp((char *)p))
|
|
|
623fdc |
+ {
|
|
|
623fdc |
+ /* optimization for rest of pattern being a literal string */
|
|
|
623fdc |
+
|
|
|
623fdc |
+ /* optimization to handle patterns like *.txt */
|
|
|
623fdc |
+ /* if the first char in the pattern is '*' and there */
|
|
|
623fdc |
+ /* are no other shell expression chars, i.e. a literal string */
|
|
|
623fdc |
+ /* then just compare the literal string at the end */
|
|
|
623fdc |
+
|
|
|
623fdc |
+ ZCONST char *srest;
|
|
|
623fdc |
+
|
|
|
623fdc |
+ srest = s + (strlen(s) - strlen(p));
|
|
|
623fdc |
+ if (srest - s < 0)
|
|
|
623fdc |
+ /* remaining literal string from pattern is longer than rest of
|
|
|
623fdc |
+ test string, there can't be a match
|
|
|
623fdc |
+ */
|
|
|
623fdc |
+ return 0;
|
|
|
623fdc |
+ else
|
|
|
623fdc |
+ /* compare the remaining literal pattern string with the last bytes
|
|
|
623fdc |
+ of the test string to check for a match */
|
|
|
623fdc |
#ifdef _MBCS
|
|
|
623fdc |
- {
|
|
|
623fdc |
- ZCONST uch *q = s;
|
|
|
623fdc |
+ {
|
|
|
623fdc |
+ ZCONST char *q = s;
|
|
|
623fdc |
|
|
|
623fdc |
- /* MBCS-aware code must not scan backwards into a string from
|
|
|
623fdc |
- * the end.
|
|
|
623fdc |
- * So, we have to move forward by character from our well-known
|
|
|
623fdc |
- * character position s in the test string until we have
|
|
|
623fdc |
- * advanced to the srest position.
|
|
|
623fdc |
- */
|
|
|
623fdc |
- while (q < srest)
|
|
|
623fdc |
- INCSTR(q);
|
|
|
623fdc |
- /* In case the byte *srest is a trailing byte of a multibyte
|
|
|
623fdc |
- * character in the test string s, we have actually advanced
|
|
|
623fdc |
- * past the position (srest).
|
|
|
623fdc |
- * For this case, the match has failed!
|
|
|
623fdc |
- */
|
|
|
623fdc |
- if (q != srest)
|
|
|
623fdc |
- return 0;
|
|
|
623fdc |
- return ((ic
|
|
|
623fdc |
- ? namecmp((ZCONST char *)p, (ZCONST char *)q)
|
|
|
623fdc |
- : strcmp((ZCONST char *)p, (ZCONST char *)q)
|
|
|
623fdc |
- ) == 0);
|
|
|
623fdc |
- }
|
|
|
623fdc |
+ /* MBCS-aware code must not scan backwards into a string from
|
|
|
623fdc |
+ * the end.
|
|
|
623fdc |
+ * So, we have to move forward by character from our well-known
|
|
|
623fdc |
+ * character position s in the test string until we have advanced
|
|
|
623fdc |
+ * to the srest position.
|
|
|
623fdc |
+ */
|
|
|
623fdc |
+ while (q < srest)
|
|
|
623fdc |
+ INCSTR(q);
|
|
|
623fdc |
+ /* In case the byte *srest is a trailing byte of a multibyte
|
|
|
623fdc |
+ * character, we have actually advanced past the position (srest).
|
|
|
623fdc |
+ * For this case, the match has failed!
|
|
|
623fdc |
+ */
|
|
|
623fdc |
+ if (q != srest)
|
|
|
623fdc |
+ return 0;
|
|
|
623fdc |
+ return ((cs ? strcmp(p, q) : namecmp(p, q)) == 0);
|
|
|
623fdc |
+ }
|
|
|
623fdc |
#else /* !_MBCS */
|
|
|
623fdc |
- return ((ic
|
|
|
623fdc |
- ? namecmp((ZCONST char *)p, (ZCONST char *)srest)
|
|
|
623fdc |
- : strcmp((ZCONST char *)p, (ZCONST char *)srest)
|
|
|
623fdc |
- ) == 0);
|
|
|
623fdc |
+ return ((cs ? strcmp(p, srest) : namecmp(p, srest)) == 0);
|
|
|
623fdc |
#endif /* ?_MBCS */
|
|
|
623fdc |
- } else {
|
|
|
623fdc |
- /* pattern contains more wildcards, continue with recursion... */
|
|
|
623fdc |
- for (; *s; INCSTR(s))
|
|
|
623fdc |
- if ((c = recmatch(p, s, ic __WDL)) != 0)
|
|
|
623fdc |
- return (int)c;
|
|
|
623fdc |
- return 2; /* 2 means give up--match will return false */
|
|
|
623fdc |
- }
|
|
|
623fdc |
}
|
|
|
623fdc |
-
|
|
|
623fdc |
- /* Parse and process the list of characters and ranges in brackets */
|
|
|
623fdc |
- if (c == BEG_RANGE) {
|
|
|
623fdc |
- int e; /* flag true if next char to be taken literally */
|
|
|
623fdc |
- ZCONST uch *q; /* pointer to end of [-] group */
|
|
|
623fdc |
- int r; /* flag true to match anything but the range */
|
|
|
623fdc |
-
|
|
|
623fdc |
- if (*s == 0) /* need a character to match */
|
|
|
623fdc |
- return 0;
|
|
|
623fdc |
- p += (r = (*p == '!' || *p == '^')); /* see if reverse */
|
|
|
623fdc |
- for (q = p, e = 0; *q; INCSTR(q)) /* find closing bracket */
|
|
|
623fdc |
- if (e)
|
|
|
623fdc |
- e = 0;
|
|
|
623fdc |
- else
|
|
|
623fdc |
- if (*q == '\\') /* GRR: change to ^ for MS-DOS, OS/2? */
|
|
|
623fdc |
- e = 1;
|
|
|
623fdc |
- else if (*q == END_RANGE)
|
|
|
623fdc |
- break;
|
|
|
623fdc |
- if (*q != END_RANGE) /* nothing matches if bad syntax */
|
|
|
623fdc |
- return 0;
|
|
|
623fdc |
- for (c = 0, e = (*p == '-'); p < q; INCSTR(p)) {
|
|
|
623fdc |
- /* go through the list */
|
|
|
623fdc |
- if (!e && *p == '\\') /* set escape flag if \ */
|
|
|
623fdc |
- e = 1;
|
|
|
623fdc |
- else if (!e && *p == '-') /* set start of range if - */
|
|
|
623fdc |
- c = *(p-1);
|
|
|
623fdc |
- else {
|
|
|
623fdc |
- unsigned int cc = Case(*s);
|
|
|
623fdc |
-
|
|
|
623fdc |
- if (*(p+1) != '-')
|
|
|
623fdc |
- for (c = c ? c : *p; c <= *p; c++) /* compare range */
|
|
|
623fdc |
- if ((unsigned)Case(c) == cc) /* typecast for MSC bug */
|
|
|
623fdc |
- return r ? 0 : recmatch(q + 1, s + 1, ic __WDL);
|
|
|
623fdc |
- c = e = 0; /* clear range, escape flags */
|
|
|
623fdc |
- }
|
|
|
623fdc |
- }
|
|
|
623fdc |
- return r ? recmatch(q + CLEN(q), s + CLEN(s), ic __WDL) : 0;
|
|
|
623fdc |
- /* bracket match failed */
|
|
|
623fdc |
+ else
|
|
|
623fdc |
+ {
|
|
|
623fdc |
+ /* pattern contains more wildcards, continue with recursion... */
|
|
|
623fdc |
+ for (; *s; INCSTR(s))
|
|
|
623fdc |
+ if ((c = recmatch(p, s, cs)) != 0)
|
|
|
623fdc |
+ return c;
|
|
|
623fdc |
+ return 2; /* 2 means give up--shmatch will return false */
|
|
|
623fdc |
}
|
|
|
623fdc |
+ }
|
|
|
623fdc |
|
|
|
623fdc |
- /* if escape ('\\'), just compare next character */
|
|
|
623fdc |
- if (c == '\\' && (c = *p++) == 0) /* if \ at end, then syntax error */
|
|
|
623fdc |
- return 0;
|
|
|
623fdc |
+#ifndef VMS /* No bracket matching in VMS */
|
|
|
623fdc |
+ /* Parse and process the list of characters and ranges in brackets */
|
|
|
623fdc |
+ if (!no_wild && allow_regex && c == '[')
|
|
|
623fdc |
+ {
|
|
|
623fdc |
+ int e; /* flag true if next char to be taken literally */
|
|
|
623fdc |
+ ZCONST char *q; /* pointer to end of [-] group */
|
|
|
623fdc |
+ int r; /* flag true to match anything but the range */
|
|
|
623fdc |
+
|
|
|
623fdc |
+ if (*s == 0) /* need a character to match */
|
|
|
623fdc |
+ return 0;
|
|
|
623fdc |
+ p += (r = (*p == '!' || *p == '^')); /* see if reverse */
|
|
|
623fdc |
+ for (q = p, e = 0; *q; q++) /* find closing bracket */
|
|
|
623fdc |
+ if (e)
|
|
|
623fdc |
+ e = 0;
|
|
|
623fdc |
+ else
|
|
|
623fdc |
+ if (*q == '\\')
|
|
|
623fdc |
+ e = 1;
|
|
|
623fdc |
+ else if (*q == ']')
|
|
|
623fdc |
+ break;
|
|
|
623fdc |
+ if (*q != ']') /* nothing matches if bad syntax */
|
|
|
623fdc |
+ return 0;
|
|
|
623fdc |
+ for (c = 0, e = *p == '-'; p < q; p++) /* go through the list */
|
|
|
623fdc |
+ {
|
|
|
623fdc |
+ if (e == 0 && *p == '\\') /* set escape flag if \ */
|
|
|
623fdc |
+ e = 1;
|
|
|
623fdc |
+ else if (e == 0 && *p == '-') /* set start of range if - */
|
|
|
623fdc |
+ c = *(p-1);
|
|
|
623fdc |
+ else
|
|
|
623fdc |
+ {
|
|
|
623fdc |
+ uch cc = (cs ? (uch)*s : case_map((uch)*s));
|
|
|
623fdc |
+ uch uc = (uch) c;
|
|
|
623fdc |
+ if (*(p+1) != '-')
|
|
|
623fdc |
+ for (uc = uc ? uc : (uch)*p; uc <= (uch)*p; uc++)
|
|
|
623fdc |
+ /* compare range */
|
|
|
623fdc |
+ if ((cs ? uc : case_map(uc)) == cc)
|
|
|
623fdc |
+ return r ? 0 : recmatch(q + CLEN(q), s + CLEN(s), cs);
|
|
|
623fdc |
+ c = e = 0; /* clear range, escape flags */
|
|
|
623fdc |
+ }
|
|
|
623fdc |
+ }
|
|
|
623fdc |
+ return r ? recmatch(q + CLEN(q), s + CLEN(s), cs) : 0;
|
|
|
623fdc |
+ /* bracket match failed */
|
|
|
623fdc |
+ }
|
|
|
623fdc |
+#endif /* !VMS */
|
|
|
623fdc |
|
|
|
623fdc |
- /* just a character--compare it */
|
|
|
623fdc |
-#ifdef QDOS
|
|
|
623fdc |
- return QMatch(Case((uch)c), Case(*s)) ?
|
|
|
623fdc |
- recmatch(p, s + CLEN(s), ic __WDL) : 0;
|
|
|
623fdc |
-#else
|
|
|
623fdc |
- return Case((uch)c) == Case(*s) ?
|
|
|
623fdc |
- recmatch(p, s + CLEN(s), ic __WDL) : 0;
|
|
|
623fdc |
-#endif
|
|
|
623fdc |
+ /* If escape ('\'), just compare next character */
|
|
|
623fdc |
+ if (!no_wild && c == '\\')
|
|
|
623fdc |
+ if ((c = *p++) == '\0') /* if \ at end, then syntax error */
|
|
|
623fdc |
+ return 0;
|
|
|
623fdc |
+
|
|
|
623fdc |
+#ifdef VMS
|
|
|
623fdc |
+ /* 2005-11-06 SMS.
|
|
|
623fdc |
+ Handle "..." wildcard in p with "." or "]" in s.
|
|
|
623fdc |
+ */
|
|
|
623fdc |
+ if ((c == '.') && (*p == '.') && (*(p+ CLEN( p)) == '.') &&
|
|
|
623fdc |
+ ((*s == '.') || (*s == ']')))
|
|
|
623fdc |
+ {
|
|
|
623fdc |
+ /* Match "...]" with "]". Continue after "]" in both. */
|
|
|
623fdc |
+ if ((*(p+ 2* CLEN( p)) == ']') && (*s == ']'))
|
|
|
623fdc |
+ return recmatch( (p+ 3* CLEN( p)), (s+ CLEN( s)), cs);
|
|
|
623fdc |
+
|
|
|
623fdc |
+ /* Else, look for a reduced match in s, until "]" in or end of s. */
|
|
|
623fdc |
+ for (; *s && (*s != ']'); INCSTR(s))
|
|
|
623fdc |
+ if (*s == '.')
|
|
|
623fdc |
+ /* If reduced match, then continue after "..." in p, "." in s. */
|
|
|
623fdc |
+ if ((c = recmatch( (p+ CLEN( p)), s, cs)) != 0)
|
|
|
623fdc |
+ return (int)c;
|
|
|
623fdc |
+
|
|
|
623fdc |
+ /* Match "...]" with "]". Continue after "]" in both. */
|
|
|
623fdc |
+ if ((*(p+ 2* CLEN( p)) == ']') && (*s == ']'))
|
|
|
623fdc |
+ return recmatch( (p+ 3* CLEN( p)), (s+ CLEN( s)), cs);
|
|
|
623fdc |
+
|
|
|
623fdc |
+ /* No reduced match. Quit. */
|
|
|
623fdc |
+ return 2;
|
|
|
623fdc |
+ }
|
|
|
623fdc |
+
|
|
|
623fdc |
+#endif /* def VMS */
|
|
|
623fdc |
+
|
|
|
623fdc |
+ /* Just a character--compare it */
|
|
|
623fdc |
+ return (cs ? c == *s : case_map((uch)c) == case_map((uch)*s)) ?
|
|
|
623fdc |
+ recmatch(p, s + CLEN(s), cs) : 0;
|
|
|
623fdc |
+}
|
|
|
623fdc |
|
|
|
623fdc |
-} /* end function recmatch() */
|
|
|
623fdc |
|
|
|
623fdc |
|
|
|
623fdc |
|
|
|
623fdc |
+/*************************************************************************************************/
|
|
|
623fdc |
static char *isshexp(p)
|
|
|
623fdc |
ZCONST char *p;
|
|
|
623fdc |
/* If p is a sh expression, a pointer to the first special character is
|