diff --git a/sdk/tools/mkisofs/schilytools/libschily/fnmatch.c b/sdk/tools/mkisofs/schilytools/libschily/fnmatch.c index deae7b5..53a44ab 100644 --- a/sdk/tools/mkisofs/schilytools/libschily/fnmatch.c +++ b/sdk/tools/mkisofs/schilytools/libschily/fnmatch.c @@ -1,8 +1,8 @@ -/* @(#)fnmatch.c 8.24 17/08/30 2005-2017 J. Schilling from 8.2 (Berkeley) */ +/* @(#)fnmatch.c 8.20 15/07/06 2005-2015 J. Schilling from 8.2 (Berkeley) */ #include #ifndef lint static UConst char sccsid[] = - "@(#)fnmatch.c 8.24 17/08/30 2005-2017 J. Schilling from 8.2 (Berkeley)"; + "@(#)fnmatch.c 8.20 15/07/06 2005-2015 J. Schilling from 8.2 (Berkeley)"; #endif /* * Copyright (c) 1989, 1993, 1994 @@ -11,12 +11,6 @@ static UConst char sccsid[] = * This code is derived from software contributed to Berkeley by * Guido van Rossum. * - * Copyright (c) 2005-2017 J. Schilling - * Copyright (c) 2011 The FreeBSD Foundation - * All rights reserved. - * Portions of this software were developed by David Chisnall - * under sponsorship from the FreeBSD Foundation. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -43,7 +37,7 @@ static UConst char sccsid[] = */ #if defined(LIBC_SCCS) && !defined(lint) -static UConst char sccsid[] = "@(#)fnmatch.c 8.24 (Berkeley) 08/30/17"; +static UConst char sccsid[] = "@(#)fnmatch.c 8.20 (Berkeley) 07/06/15"; #endif /* LIBC_SCCS and not lint */ /* "FBSD src/lib/libc/gen/fnmatch.c,v 1.19 2010/04/16 22:29:24 jilles Exp $" */ @@ -77,8 +71,6 @@ static UConst char sccsid[] = "@(#)fnmatch.c 8.24 (Berkeley) 08/30/17"; #define RANGE_NOMATCH 0 #define RANGE_ERROR (-1) -#define CL_SIZE 32 /* Max size for '[: :]' */ - static int rangematch __PR((const char *, wchar_t, int, char **, mbstate_t *)); static int fnmatch1 __PR((const char *, const char *, const char *, int, mbstate_t, mbstate_t)); @@ -135,14 +127,11 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs) mbstate_t patmbs; mbstate_t strmbs; { - const char *bt_pattern, *bt_string; - mbstate_t bt_patmbs, bt_strmbs; char *newp; char c; wchar_t pc, sc; size_t pclen, sclen; - bt_pattern = bt_string = NULL; for (;;) { pclen = mbrtowc(&pc, pattern, MB_LEN_MAX, &patmbs); if (pclen == (size_t)-1 || pclen == (size_t)-2) @@ -158,18 +147,16 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs) case EOS: if ((flags & FNM_LEADING_DIR) && sc == '/') return (0); - if (sc == EOS) - return (0); - goto backtrack; + return (sc == EOS ? 0 : FNM_NOMATCH); case '?': if (sc == EOS) return (FNM_NOMATCH); if (sc == '/' && (flags & FNM_PATHNAME)) - goto backtrack; + return (FNM_NOMATCH); if (sc == '.' && (flags & FNM_PERIOD) && (string == stringstart || ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - goto backtrack; + return (FNM_NOMATCH); string += sclen; break; case '*': @@ -181,7 +168,7 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs) if (sc == '.' && (flags & FNM_PERIOD) && (string == stringstart || ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - goto backtrack; + return (FNM_NOMATCH); /* Optimize for pattern with * at end or before /. */ if (c == EOS) { @@ -197,34 +184,43 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs) break; } - /* - * First try the shortest match for the '*' that - * could work. We can forget any earlier '*' since - * there is no way having it match more characters - * can help us, given that we are already here. - */ - bt_pattern = pattern, bt_patmbs = patmbs; - bt_string = string, bt_strmbs = strmbs; - break; + /* General case, use recursion. */ + while (sc != EOS) { + if (!fnmatch1(pattern, string, stringstart, + flags, patmbs, strmbs)) + return (0); + sclen = mbrtowc(&sc, string, MB_LEN_MAX, + &strmbs); + if (sclen == (size_t)-1 || + sclen == (size_t)-2) { + sc = (unsigned char)*string; + sclen = 1; + memset(&strmbs, 0, sizeof (strmbs)); + } + if (sc == '/' && (flags & FNM_PATHNAME)) + break; + string += sclen; + } + return (FNM_NOMATCH); case '[': if (sc == EOS) return (FNM_NOMATCH); if (sc == '/' && (flags & FNM_PATHNAME)) - goto backtrack; + return (FNM_NOMATCH); if (sc == '.' && (flags & FNM_PERIOD) && (string == stringstart || ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - goto backtrack; + return (FNM_NOMATCH); switch (rangematch(pattern, sc, flags, &newp, - &patmbs)) { + &patmbs)) { case RANGE_ERROR: goto norm; case RANGE_MATCH: pattern = newp; break; case RANGE_NOMATCH: - goto backtrack; + return (FNM_NOMATCH); } string += sclen; break; @@ -235,45 +231,20 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs) if (pclen == (size_t)-1 || pclen == (size_t)-2) return (FNM_NOMATCH); if (pclen == 0) - return (FNM_NOMATCH); + pc = '\\'; pattern += pclen; } /* FALLTHROUGH */ default: norm: - string += sclen; - if (pc == sc) { + if (pc == sc) ; - } else if ((flags & FNM_CASEFOLD) && - (towlower(pc) == towlower(sc))) { + else if ((flags & FNM_CASEFOLD) && + (towlower(pc) == towlower(sc))) ; - } else { - backtrack: - /* - * If we have a mismatch (other than hitting - * the end of the string), go back to the last - * '*' seen and have it match one additional - * character. - */ - if (bt_pattern == NULL) - return (FNM_NOMATCH); - sclen = mbrtowc(&sc, bt_string, MB_LEN_MAX, - &bt_strmbs); - if (sclen == (size_t)-1 || - sclen == (size_t)-2) { - sc = (unsigned char)*bt_string; - sclen = 1; - memset(&bt_strmbs, 0, - sizeof (bt_strmbs)); - } - if (sc == EOS) - return (FNM_NOMATCH); - if (sc == '/' && flags & FNM_PATHNAME) - return (FNM_NOMATCH); - bt_string += sclen; - pattern = bt_pattern, patmbs = bt_patmbs; - string = bt_string, strmbs = bt_strmbs; - } + else + return (FNM_NOMATCH); + string += sclen; break; } } @@ -282,8 +253,7 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs) #ifdef PROTOTYPES static int -rangematch(const char *pattern, wchar_t test, int flags, char **newp, - mbstate_t *patmbs) +rangematch(const char *pattern, wchar_t test, int flags, char **newp, mbstate_t *patmbs) #else static int rangematch(pattern, test, flags, newp, patmbs) @@ -296,13 +266,8 @@ rangematch(pattern, test, flags, newp, patmbs) { int negate, ok; wchar_t c, c2; - wchar_t otest = test; size_t pclen; const char *origpat; -#ifdef XXX_COLLATE - struct xlocale_collate *table = (struct xlocale_collate *) - __get_locale()->components[XLC_COLLATE]; -#endif /* * A bracket expression starting with an unquoted circumflex @@ -325,8 +290,6 @@ rangematch(pattern, test, flags, newp, patmbs) ok = 0; origpat = pattern; for (;;) { - int quoted = 0; - if (*pattern == ']' && pattern > origpat) { pattern++; break; @@ -334,54 +297,13 @@ rangematch(pattern, test, flags, newp, patmbs) return (RANGE_ERROR); } else if (*pattern == '/' && (flags & FNM_PATHNAME)) { return (RANGE_NOMATCH); - } else if (*pattern == '\\' && !(flags & FNM_NOESCAPE)) { + } else if (*pattern == '\\' && !(flags & FNM_NOESCAPE)) pattern++; - quoted++; - } pclen = mbrtowc(&c, pattern, MB_LEN_MAX, patmbs); if (pclen == (size_t)-1 || pclen == (size_t)-2) return (RANGE_NOMATCH); pattern += pclen; - if (!quoted && c == '[') { - if (pattern[0] == ':') { - char class[CL_SIZE+1]; - char *pc = class; - const char *p; - - p = pattern + 1; /* Eat ':' */ - for (;;) { - if (*p == '\0') - return (RANGE_ERROR); - if (*p == ':' && p[1] == ']') - break; - if (pc >= &class[CL_SIZE]) - return (RANGE_ERROR); - *pc++ = *p++; - } - if (pc == class) - return (RANGE_ERROR); - *pc = '\0'; - pattern = p + 2; /* Skip ":]" */ - if (iswctype(otest, wctype(class))) { - ok = 1; - } else if (flags & FNM_CASEFOLD) { - /* - * Convert to the other case - */ - if (strcmp(class, "upper") == 0) - if (iswctype(otest, - wctype("lower"))) - ok = 1; - else if (strcmp(class, "lower") == 0) - if (iswctype(otest, - wctype("upper"))) - ok = 1; - } - continue; - } - } - if (flags & FNM_CASEFOLD) c = towlower(c); @@ -401,10 +323,10 @@ rangematch(pattern, test, flags, newp, patmbs) c2 = towlower(c2); #ifdef XXX_COLLATE - if (table->__collate_load_error ? + if (__collate_load_error ? c <= test && test <= c2 : - __wcollate_range_cmp(c, test) <= 0 && - __wcollate_range_cmp(test, c2) <= 0) + __collate_range_cmp(c, test) <= 0 && + __collate_range_cmp(test, c2) <= 0) ok = 1; #else if (c <= test && test <= c2) diff --git a/sdk/tools/mkisofs/schilytools/libschily/match.c b/sdk/tools/mkisofs/schilytools/libschily/match.c index b0b28e8..addba2d 100644 --- a/sdk/tools/mkisofs/schilytools/libschily/match.c +++ b/sdk/tools/mkisofs/schilytools/libschily/match.c @@ -1,18 +1,10 @@ -/* @(#)match.c 1.27 17/08/13 Copyright 1985, 1995-2017 J. Schilling */ +/* @(#)match.c 1.24 10/08/21 Copyright 1985, 1995-2010 J. Schilling */ #include #include -#define POSIX_CLASS /* Support [[:alpha:]] by default */ -#ifdef NO_POSIX_CLASS /* Allow to disable [[:alpha:]] */ -#undef POSIX_CLASS -#endif -#ifdef POSIX_CLASS -#include /* With [[:alpha:]], we need wctype() */ -#include /* and thus wchar.h and wctype.h */ -#endif /* * Pattern matching functions * - * Copyright (c) 1985, 1995-2017 J. Schilling + * Copyright (c) 1985, 1995-2010 J. Schilling */ /* * The contents of this file are subject to the terms of the @@ -21,8 +13,6 @@ * with the License. * * See the file CDDL.Schily.txt in this distribution for details. - * A copy of the CDDL is also available via the Internet at - * http://www.opensource.org/licenses/cddl1.txt * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file CDDL.Schily.txt from this distribution. @@ -43,7 +33,6 @@ * * Character classes have been added to allow "[]" * to be used. - * POSIX features like [[:alpha:]] have been added. * Start of line '^' and end of line '$' have been added. */ @@ -64,36 +53,15 @@ #define patmatch patwmatch #endif #define CHAR wchar_t -#define PCHAR wchar_t -#endif - -#ifdef __MB_CHAR -#undef patmatch -#ifdef __LINE_MATCH -#define patmatch patmblmatch -#else -#define patmatch patmbmatch -#endif -#define PCHAR wchar_t #endif #ifndef CHAR typedef unsigned char Uchar; -#define DID_UCHAR_TYPE #define CHAR Uchar #endif -#ifndef PCHAR -#ifndef DID_UCHAR_TYPE -typedef unsigned char Uchar; -#endif -#define PCHAR Uchar -#endif - #define ENDSTATE (-1) -#define CL_SIZE 32 /* Max size for '[: :]' */ - /* * The Interpreter */ @@ -123,63 +91,22 @@ typedef unsigned char Uchar; /* * match a character in class - * - * Syntax errors do not appear here, they are handled by the compiler, - * so in theory we could remove the "return (0)" statements from the - * the POSIX class code. */ -#ifdef POSIX_CLASS -#define CHK_POSIX_CLASS \ - else if (*lpat == LCLASS) { \ - if (lpat[1] == ':') { \ - char class[CL_SIZE+1]; \ - char *pc = class; \ - \ - lpat += 2; /* Eat ':' */ \ - for (;;) { \ - if (*lpat == '\0') { \ - ok = FALSE; \ - goto out; \ - } \ - if (*lpat == ':' && lpat[1] == RCLASS) \ - break; \ - if (pc >= &class[CL_SIZE]) { \ - ok = FALSE; \ - goto out; \ - } \ - *pc++ = *lpat++; \ - } \ - if (pc == class) { \ - ok = FALSE; \ - goto out; \ - } \ - *pc = '\0'; \ - lpat += 2; /* Skip ":]" */ \ - if (iswctype(lc, wctype(class))) { \ - ok = !ok; \ - goto out; \ - } \ - continue; \ - } \ - } -#else -#define CHK_POSIX_CLASS -#endif #define in_class(found, pat, c) { \ - register const PCHAR *lpat = pat; \ + register const CHAR *lpat = pat; \ register int lc = c; \ int lo_bound; \ int hi_bound; \ - BOOL ok = FALSE; \ + \ + found = FALSE; \ \ if (*lpat == NOT) { \ lpat++; \ - ok = TRUE; \ + found = TRUE; \ } \ while (*lpat != RCLASS) { \ if (*lpat == QUOTE) \ lpat++; \ - CHK_POSIX_CLASS \ lo_bound = *lpat++; \ if (*lpat == RANGE) { \ lpat++; \ @@ -190,12 +117,10 @@ typedef unsigned char Uchar; hi_bound = lo_bound; \ } \ if (lo_bound <= lc && lc <= hi_bound) { \ - ok = !ok; \ - goto out; \ + found = !found; \ + break; \ } \ } \ -out: \ - found = ok; \ } /* @@ -204,10 +129,10 @@ out: \ * Trys to match a string beginning at offset * against the compiled pattern. */ -#if !defined(__WIDE_CHAR) && !defined(__MB_CHAR) +#ifndef __WIDE_CHAR EXPORT CHAR *opatmatch(pat, aux, str, soff, slen, alt) - const PCHAR *pat; + const CHAR *pat; const int *aux; const CHAR *str; int soff; @@ -228,7 +153,7 @@ EXPORT CHAR */ EXPORT CHAR * patmatch(pat, aux, str, soff, slen, alt, state) - const PCHAR *pat; + const CHAR *pat; const int *aux; const CHAR *str; int soff; @@ -241,12 +166,7 @@ patmatch(pat, aux, str, soff, slen, alt, state) register int *i; register int p; register int q, s, k; -#ifdef __MB_CHAR - wchar_t c; - int mlen = 1; -#else int c; -#endif const CHAR *lastp = (CHAR *)NULL; #ifdef __LINE_MATCH @@ -258,29 +178,14 @@ for (; soff <= slen; soff++) { if (alt != ENDSTATE) put(sp, state, sp, alt); -#ifdef __MB_CHAR - mbtowc(NULL, NULL, 0); - for (s = soff; ; s += mlen) { -#else for (s = soff; ; s++) { -#endif /* * next char from input string */ - if (s >= slen) { + if (s >= slen) c = 0; - } else { -#ifdef __MB_CHAR - mlen = mbtowc(&c, (char *)str, slen - s); - if (mlen < 0) { - mbtowc(NULL, NULL, 0); - c = str[s]; - mlen = 1; - } -#else + else c = str[s]; -#endif - } /* * first complete the closure */ @@ -382,17 +287,17 @@ return ((CHAR *)lastp); } -#if !defined(__LINE_MATCH) && !defined(__MB_CHAR) +#ifndef __LINE_MATCH /* * The Compiler */ typedef struct args { - const PCHAR *pattern; + const CHAR *pattern; int *aux; int patp; int length; - PCHAR Ch; + CHAR Ch; } arg_t; LOCAL void nextitem __PR((arg_t *)); @@ -413,15 +318,6 @@ LOCAL int join __PR((int *, int, int)); } /* - * 'peek' the next character from pattern - */ -#define pch(ap) \ - ((((ap)->patp + 1) >= (ap)->length) ? \ - 0 \ - : \ - (ap)->pattern[(ap)->patp+1]) \ - -/* * get the next item from pattern */ LOCAL void @@ -452,39 +348,8 @@ prim(ap) case RBRACK: return (ENDSTATE); case LCLASS: - while (ap->Ch != RCLASS && ap->Ch != '\0') { -#ifdef POSIX_CLASS - if (ap->Ch == LCLASS) { - if (pch(ap) == ':') { /* [:alpha:] */ - char class[CL_SIZE+1]; - char *pc = class; - - nextitem(ap); - nextitem(ap); - while (ap->Ch != ':' && - ap->Ch != '\0') { - if (pc > &class[CL_SIZE]) - return (ENDSTATE); - *pc = ap->Ch; - if (*pc++ != ap->Ch) - return (ENDSTATE); - nextitem(ap); - } - if (pc == class) - return (ENDSTATE); - *pc = '\0'; - if (ap->Ch == '\0') - return (ENDSTATE); - if (wctype(class) == 0) - return (ENDSTATE); - nextitem(ap); - } - if (ap->Ch != RCLASS) - return (ENDSTATE); - } -#endif + while (ap->Ch != RCLASS && ap->Ch != '\0') nextitem(ap); - } if (ap->Ch == '\0') return (ENDSTATE); nextitem(ap); @@ -516,12 +381,10 @@ expr(ap, altp) int exits = ENDSTATE; int a; int *aux = ap->aux; - PCHAR Ch; + CHAR Ch; for (;;) { a = prim(ap); - if (a == ENDSTATE) - return (ENDSTATE); Ch = ap->Ch; if (Ch == ALT || Ch == RBRACK || Ch == '\0') { exits = join(aux, exits, a); @@ -582,7 +445,7 @@ join(aux, a, b) */ EXPORT int patcompile(pat, len, aux) - const PCHAR *pat; + const CHAR *pat; int len; int *aux; { @@ -604,4 +467,4 @@ patcompile(pat, len, aux) setexits(aux, i, ENDSTATE); return (alt); } -#endif /* !defined(__LINE_MATCH) && !defined(__MB_CHAR) */ +#endif /* LMATCH */