Imported from ../bash-2.05a.tar.gz.

This commit is contained in:
Jari Aalto
2009-09-12 16:46:54 +00:00
parent 28ef6c316f
commit f73dda092b
303 changed files with 37057 additions and 28800 deletions
-13
View File
@@ -1,13 +0,0 @@
Thu Oct 29 08:58:12 1992 Brian Fox (bfox@cubit)
* glob.c (glob_filename): Fix tiny memory leak. Rework some
comments.
Mon Jul 20 10:57:36 1992 Brian Fox (bfox@cubit)
* glob.c: (glob_filename) Change use of rindex () to strrchr ().
Thu Jul 9 10:02:47 1992 Brian Fox (bfox@cubit)
* fnmatch.c: (fnmatch) Only process `[' as the start of a bracket
expression if there is a closing `]' present in the string.
+8 -7
View File
@@ -62,12 +62,12 @@ CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(CPPFLAGS) ${INCLUDES} $(LOCAL_CFLAGS) $(CFLAGS
LIBRARY_NAME = libglob.a
# The C code source files for this library.
CSOURCES = $(srcdir)/glob.c $(srcdir)/fnmatch.c
CSOURCES = $(srcdir)/glob.c $(srcdir)/strmatch.c
# The header files for this library.
HSOURCES = $(srcdir)/fnmatch.h
HSOURCES = $(srcdir)/strmatch.h
OBJECTS = glob.o fnmatch.o
OBJECTS = glob.o strmatch.o
# The texinfo files which document this library.
DOCSOURCE = doc/glob.texi
@@ -121,14 +121,15 @@ mostlyclean: clean
# #
######################################################################
fnmatch.o: fnmatch.h
fnmatch.o: $(BUILD_DIR)/config.h
strmatch.o: strmatch.h
strmatch.o: $(BUILD_DIR)/config.h
strmatch.o: $(BASHINCDIR)/chartypes.h
glob.o: $(BUILD_DIR)/config.h
glob.o: $(topdir)/bashtypes.h $(BASHINCDIR)/ansi_stdlib.h $(topdir)/bashansi.h
glob.o: $(BASHINCDIR)/posixstat.h $(BASHINCDIR)/memalloc.h
glob.o: fnmatch.h
glob.o: strmatch.h
# Rules for deficient makes, like SunOS and Solaris
fnmatch.o: fnmatch.c
strmatch.o: strmatch.c
glob.o: glob.c
+99 -87
View File
@@ -34,96 +34,108 @@ typedef struct _collsym {
static COLLSYM posix_collsyms[] =
{
"NUL", '\0',
"SOH", '\001',
"STX", '\002',
"ETX", '\003',
"EOT", '\004',
"ENQ", '\005',
"ACK", '\006',
{ "NUL", '\0' },
{ "SOH", '\001' },
{ "STX", '\002' },
{ "ETX", '\003' },
{ "EOT", '\004' },
{ "ENQ", '\005' },
{ "ACK", '\006' },
#ifdef __STDC__
"alert", '\a',
{ "alert", '\a' },
#else
"alert", '\007',
{ "alert", '\007' },
#endif
"backspace", '\b',
"tab", '\t',
"newline", '\n',
"vertical-tab", '\v',
"form-feed", '\f',
"carriage-return", '\r',
"SO", '\016',
"SI", '\017',
"DLE", '\020',
"DC1", '\021',
"DC2", '\022',
"DC3", '\023',
"DC4", '\024',
"NAK", '\025',
"SYN", '\026',
"ETB", '\027',
"CAN", '\030',
"EM", '\031',
"SUB", '\032',
"ESC", '\033',
"IS4", '\034',
"IS3", '\035',
"IS2", '\036',
"IS1", '\037',
"space", ' ',
"exclamation-mark", '!',
"quotation-mark", '"',
"number-sign", '#',
"dollar-sign", '$',
"percent-sign", '%',
"ampersand", '&',
"apostrophe", '\'',
"left-parenthesis", '(',
"right-parenthesis", ')',
"asterisk", '*',
"plus-sign", '+',
"comma", ',',
"hyphen", '-',
"minus", '-', /* extension from POSIX.2 */
"dash", '-', /* extension from POSIX.2 */
"period", '.',
"slash", '/',
"solidus", '/', /* extension from POSIX.2 */
"zero", '0',
"one", '1',
"two", '2',
"three", '3',
"four", '4',
"five", '5',
"six", '6',
"seven", '7',
"eight", '8',
"nine", '9',
"colon", ':',
"semicolon", ';',
"less-than-sign", '<',
"equals-sign", '=',
"greater-than-sign", '>',
"question-mark", '?',
"commercial-at", '@',
/* upper-case letters omitted */
"left-square-bracket",'[',
"backslash", '\\',
"reverse-solidus", '\\',
"right-square-bracket", ']',
"circumflex", '^',
"circumflex-accent", '^', /* extension from POSIX.2 */
"underscore", '_',
"grave-accent", '`',
/* lower-case letters omitted */
"left-brace", '{', /* extension from POSIX.2 */
"left-curly-bracket", '{',
"vertical-line", '|',
"right-brace", '}', /* extension from POSIX.2 */
"right-curly-bracket", '}',
"tilde", '~',
"DEL", '\177',
0, 0,
{ "BS", '\010' },
{ "backspace", '\b' },
{ "HT", '\011' },
{ "tab", '\t' },
{ "LF", '\012' },
{ "newline", '\n' },
{ "VT", '\013' },
{ "vertical-tab", '\v' },
{ "FF", '\014' },
{ "form-feed", '\f' },
{ "CR", '\015' },
{ "carriage-return", '\r' },
{ "SO", '\016' },
{ "SI", '\017' },
{ "DLE", '\020' },
{ "DC1", '\021' },
{ "DC2", '\022' },
{ "DC3", '\023' },
{ "DC4", '\024' },
{ "NAK", '\025' },
{ "SYN", '\026' },
{ "ETB", '\027' },
{ "CAN", '\030' },
{ "EM", '\031' },
{ "SUB", '\032' },
{ "ESC", '\033' },
{ "IS4", '\034' },
{ "FS", '\034' },
{ "IS3", '\035' },
{ "GS", '\035' },
{ "IS2", '\036' },
{ "RS", '\036' },
{ "IS1", '\037' },
{ "US", '\037' },
{ "space", ' ' },
{ "exclamation-mark", '!' },
{ "quotation-mark", '"' },
{ "number-sign", '#' },
{ "dollar-sign", '$' },
{ "percent-sign", '%' },
{ "ampersand", '&' },
{ "apostrophe", '\'' },
{ "left-parenthesis", '(' },
{ "right-parenthesis", ')' },
{ "asterisk", '*' },
{ "plus-sign", '+' },
{ "comma", ',' },
{ "hyphen", '-' },
{ "hyphen-minus", '-' },
{ "minus", '-' }, /* extension from POSIX.2 */
{ "dash", '-' }, /* extension from POSIX.2 */
{ "period", '.' },
{ "full-stop", '.' },
{ "slash", '/' },
{ "solidus", '/' }, /* extension from POSIX.2 */
{ "zero", '0' },
{ "one", '1' },
{ "two", '2' },
{ "three", '3' },
{ "four", '4' },
{ "five", '5' },
{ "six", '6' },
{ "seven", '7' },
{ "eight", '8' },
{ "nine", '9' },
{ "colon", ':' },
{ "semicolon", ';' },
{ "less-than-sign", '<' },
{ "equals-sign", '=' },
{ "greater-than-sign", '>' },
{ "question-mark", '?' },
{ "commercial-at", '@' },
/* upper-case letters omitted */
{ "left-square-bracket",'[' },
{ "backslash", '\\' },
{ "reverse-solidus", '\\' },
{ "right-square-bracket",']' },
{ "circumflex", '^' },
{ "circumflex-accent", '^' }, /* extension from POSIX.2 */
{ "underscore", '_' },
{ "grave-accent", '`' },
/* lower-case letters omitted */
{ "left-brace", '{' }, /* extension from POSIX.2 */
{ "left-curly-bracket",'{' },
{ "vertical-line", '|' },
{ "right-brace", '}' }, /* extension from POSIX.2 */
{ "right-curly-bracket",'}' },
{ "tilde", '~' },
{ "DEL", '\177' },
{ 0, 0 },
};
#endif
+7 -7
View File
@@ -67,7 +67,7 @@
# endif
#endif /* !HAVE_DIRENT_H */
#if defined (_POSIX_SOURCE) && !defined (STRUCT_DIRENT_HAS_D_INO)
#if defined (_POSIX_SOURCE) && !defined (STRUCT_DIRENT_HAS_D_INO) || defined (BROKEN_DIRENT_D_INO)
/* Posix does not require that the d_ino field be present, and some
systems do not provide it. */
# define REAL_DIR_ENTRY(dp) 1
@@ -94,7 +94,7 @@
# include "memalloc.h"
#endif
#include "fnmatch.h"
#include "strmatch.h"
#if !defined (HAVE_STDLIB_H) && !defined (SHELL)
extern char *malloc (), *realloc ();
@@ -131,9 +131,9 @@ char *glob_error_return;
/* Return nonzero if PATTERN has any special globbing chars in it. */
int
glob_pattern_p (pattern)
char *pattern;
const char *pattern;
{
register char *p;
register const char *p;
register char c;
int bopen;
@@ -256,7 +256,7 @@ glob_vector (pat, dir)
int lose, skip;
register char **name_vector;
register unsigned int i;
int flags; /* Flags passed to fnmatch (). */
int flags; /* Flags passed to strmatch (). */
lastlink = 0;
count = lose = skip = 0;
@@ -342,7 +342,7 @@ glob_vector (pat, dir)
if (d == NULL)
return ((char **) &glob_error_return);
/* Compute the flags that will be passed to fnmatch(). We don't
/* Compute the flags that will be passed to strmatch(). We don't
need to do this every time through the loop. */
flags = (noglob_dot_filenames ? FNM_PERIOD : 0) | FNM_PATHNAME;
@@ -394,7 +394,7 @@ glob_vector (pat, dir)
(pat[0] != '\\' || pat[1] != '.'))
continue;
if (fnmatch (pat, dp->d_name, flags) != FNM_NOMATCH)
if (strmatch (pat, dp->d_name, flags) != FNM_NOMATCH)
{
nextlink = (struct globval *) alloca (sizeof (struct globval));
nextlink->next = lastlink;
+1 -1
View File
@@ -20,7 +20,7 @@
#include "stdc.h"
extern int glob_pattern_p __P((char *));
extern int glob_pattern_p __P((const char *));
extern char **glob_vector __P((char *, char *));
extern char **glob_filename __P((char *));
+40 -37
View File
@@ -1,4 +1,4 @@
/* fnmatch.c -- ksh-like extended pattern matching for the shell and filename
/* strmatch.c -- ksh-like extended pattern matching for the shell and filename
globbing. */
/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
@@ -23,9 +23,9 @@
#include <stdio.h> /* for debugging */
#include "fnmatch.h"
#include "strmatch.h"
#include "collsyms.h"
#include <ctype.h>
#include <chartypes.h>
#if defined (HAVE_STRING_H)
# include <string.h>
@@ -40,27 +40,13 @@ static int extmatch ();
static char *patscan ();
#endif
#if !defined (isascii)
#if !defined (isascii) && !defined (HAVE_ISASCII)
# define isascii(c) ((unsigned int)(c) <= 0177)
#endif
/* Note that these evaluate C many times. */
#ifndef isblank
# define isblank(c) ((c) == ' ' || (c) == '\t')
#endif
#ifndef isgraph
# define isgraph(c) ((c) != ' ' && isprint((c)))
#endif
#ifndef isxdigit
# define isxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
#endif
/* The result of FOLD is an `unsigned char' */
# define FOLD(c) ((flags & FNM_CASEFOLD) && isupper ((unsigned char)c) \
? tolower ((unsigned char)c) \
# define FOLD(c) ((flags & FNM_CASEFOLD) \
? TOLOWER ((unsigned char)c) \
: ((unsigned char)c))
#ifndef STREQ
@@ -127,8 +113,23 @@ collsym (s, len)
return -1;
}
#ifdef HAVE_LIBC_FNM_EXTMATCH
int
fnmatch (pattern, string, flags)
strmatch (pattern, string, flags)
char *pattern;
char *string;
int flags;
{
char *se, *pe;
if (string == 0 || pattern == 0)
return FNM_NOMATCH;
return (fnmatch (pattern, string, flags));
}
#else /* !HAVE_LIBC_FNM_EXTMATCH */
int
strmatch (pattern, string, flags)
char *pattern;
char *string;
int flags;
@@ -143,6 +144,7 @@ fnmatch (pattern, string, flags)
return (gmatch (string, se, pattern, pe, flags));
}
#endif /* !HAVE_LIBC_FNM_EXTMATCH */
/* Match STRING against the filename pattern PATTERN, returning zero if
it matches, FNM_NOMATCH if not. */
@@ -231,7 +233,7 @@ fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
we are matching a pathname. */
return FNM_NOMATCH;
/* Collapse multiple consecutive, `*' and `?', but make sure that
/* Collapse multiple consecutive `*' and `?', but make sure that
one character of the string is consumed for each `?'. */
for (c = *p++; (c == '?' || c == '*'); c = *p++)
{
@@ -267,7 +269,8 @@ fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
We need to skip the glob pattern and see if we
match the rest of the string. */
newn = patscan (p + 1, pe, 0);
p = newn;
/* If NEWN is 0, we have an ill-formed pattern. */
p = newn ? newn : pe;
}
#endif
if (p == pe)
@@ -288,7 +291,7 @@ fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
c1 = FOLD (c1);
for (--p; n < se; ++n)
{
/* Only call fnmatch if the first character indicates a
/* Only call strmatch if the first character indicates a
possible match. We can check the first character if
we're not doing an extended glob match. */
if ((flags & FNM_EXTMATCH) == 0 && c != '[' && FOLD (*n) != c1) /*]*/
@@ -426,29 +429,29 @@ brackmatch (p, test, flags)
{
pc = 0; /* make sure invalid char classes don't match. */
if (STREQN (p+1, "alnum:]", 7))
{ pc = isalnum (test); p += 8; }
{ pc = ISALNUM (test); p += 8; }
else if (STREQN (p+1, "alpha:]", 7))
{ pc = isalpha (test); p += 8; }
{ pc = ISALPHA (test); p += 8; }
else if (STREQN (p+1, "blank:]", 7))
{ pc = isblank (test); p += 8; }
{ pc = ISBLANK (test); p += 8; }
else if (STREQN (p+1, "cntrl:]", 7))
{ pc = iscntrl (test); p += 8; }
{ pc = ISCNTRL (test); p += 8; }
else if (STREQN (p+1, "digit:]", 7))
{ pc = isdigit (test); p += 8; }
{ pc = ISDIGIT (test); p += 8; }
else if (STREQN (p+1, "graph:]", 7))
{ pc = isgraph (test); p += 8; }
{ pc = ISGRAPH (test); p += 8; }
else if (STREQN (p+1, "lower:]", 7))
{ pc = islower (test); p += 8; }
{ pc = ISLOWER (test); p += 8; }
else if (STREQN (p+1, "print:]", 7))
{ pc = isprint (test); p += 8; }
{ pc = ISPRINT (test); p += 8; }
else if (STREQN (p+1, "punct:]", 7))
{ pc = ispunct (test); p += 8; }
{ pc = ISPUNCT (test); p += 8; }
else if (STREQN (p+1, "space:]", 7))
{ pc = isspace (test); p += 8; }
{ pc = ISSPACE (test); p += 8; }
else if (STREQN (p+1, "upper:]", 7))
{ pc = isupper (test); p += 8; }
{ pc = ISUPPER (test); p += 8; }
else if (STREQN (p+1, "xdigit:]", 8))
{ pc = isxdigit (test); p += 9; }
{ pc = ISXDIGIT (test); p += 9; }
else if (STREQN (p+1, "ascii:]", 7))
{ pc = isascii (test); p += 8; }
if (pc)
@@ -828,7 +831,7 @@ main (c, v)
string = v[1];
pat = v[2];
if (fnmatch (pat, string, 0) == 0)
if (strmatch (pat, string, 0) == 0)
{
printf ("%s matches %s\n", string, pat);
exit (0);
+24 -8
View File
@@ -16,8 +16,14 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#ifndef _FNMATCH_H
#define _FNMATCH_H 1
#ifndef _STRMATCH_H
#define _STRMATCH_H 1
#ifdef HAVE_LIBC_FNM_EXTMATCH
#include <fnmatch.h>
#else /* !HAVE_LIBC_FNM_EXTMATCH */
#include "stdc.h"
@@ -27,22 +33,32 @@ not, write to the Free Software Foundation, Inc.,
#undef FNM_NOESCAPE
#undef FNM_PERIOD
/* Bits set in the FLAGS argument to `fnmatch'. */
/* standard flags */
/* Bits set in the FLAGS argument to `strmatch'. */
/* standard flags are like fnmatch(3). */
#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
#define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
/* extended flags */
/* extended flags not available in most libc fnmatch versions, but we undef
them to avoid any possible warnings. */
#undef FNM_LEADING_DIR
#undef FNM_CASEFOLD
#undef FNM_EXTMATCH
#define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */
#define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */
#define FNM_EXTMATCH (1 << 5) /* Use ksh-like extended matching. */
/* Value returned by `fnmatch' if STRING does not match PATTERN. */
/* Value returned by `strmatch' if STRING does not match PATTERN. */
#undef FNM_NOMATCH
#define FNM_NOMATCH 1
/* Match STRING against the filename pattern PATTERN,
returning zero if it matches, FNM_NOMATCH if not. */
extern int fnmatch __P((char *, char *, int));
extern int strmatch __P((char *, char *, int));
#endif /* _FNMATCH_H */
#endif /* !HAVE_LIBC_FNM_EXTMATCH */
#endif /* _STRMATCH_H */