along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-/* David MacKenzie <djm@ai.mit.edu>.
+/* David MacKenzie <djm@gnu.ai.mit.edu>.
Some algorithms adapted from GNU Emacs. */
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include "backupfile.h"
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#define index strchr
#define rindex strrchr
#include <strings.h>
#endif
-#ifdef DIRENT
+#if defined(DIRENT) || defined(_POSIX_VERSION)
#include <dirent.h>
-#ifdef direct
-#undef direct
-#endif
-#define direct dirent
#define NLENGTH(direct) (strlen((direct)->d_name))
-#else /* !DIRENT */
+#else /* not (DIRENT or _POSIX_VERSION) */
+#define dirent direct
#define NLENGTH(direct) ((direct)->d_namlen)
-#ifdef USG
#ifdef SYSNDIR
#include <sys/ndir.h>
-#else /* !SYSNDIR */
-#include <ndir.h>
-#endif /* !SYSNDIR */
-#else /* !USG */
+#endif /* SYSNDIR */
+#ifdef SYSDIR
#include <sys/dir.h>
-#endif /* !USG */
-#endif /* !DIRENT */
+#endif /* SYSDIR */
+#ifdef NDIR
+#include <ndir.h>
+#endif /* NDIR */
+#endif /* DIRENT or _POSIX_VERSION */
#ifdef VOID_CLOSEDIR
/* Fake a return value. */
char *file, *dir;
{
DIR *dirp;
- struct direct *dp;
+ struct dirent *dp;
int highest_version;
int this_version;
int file_name_length;
#else
char *malloc ();
#endif
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
+#ifndef rindex
#define rindex strrchr
+#endif
#else
#include <strings.h>
#endif
-/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
Cambridge, MA 02139, USA. */
#include <errno.h>
-#include "fnmatch.h"
+#include <fnmatch.h>
+#include <ctype.h>
#if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
extern int errno;
#endif
-#if !__STDC__
-#define const
-#endif
-
/* Match STRING against the filename pattern PATTERN, returning zero if
it matches, nonzero if not. */
int
register const char *p = pattern, *n = string;
register char c;
- if ((flags & ~__FNM_FLAGS) != 0)
- {
- errno = EINVAL;
- return -1;
- }
+/* Note that this evalutes C many times. */
+#define FOLD(c) ((flags & FNM_CASEFOLD) && isupper (c) ? tolower (c) : (c))
while ((c = *p++) != '\0')
{
+ c = FOLD (c);
+
switch (c)
{
case '?':
if (*n == '\0')
return FNM_NOMATCH;
- else if ((flags & FNM_PATHNAME) && *n == '/')
+ else if ((flags & FNM_FILE_NAME) && *n == '/')
return FNM_NOMATCH;
else if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
break;
case '\\':
if (!(flags & FNM_NOESCAPE))
- c = *p++;
- if (*n != c)
+ {
+ c = *p++;
+ c = FOLD (c);
+ }
+ if (FOLD (*n) != c)
return FNM_NOMATCH;
break;
case '*':
if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
for (c = *p++; c == '?' || c == '*'; c = *p++, ++n)
- if (((flags & FNM_PATHNAME) && *n == '/') ||
+ if (((flags & FNM_FILE_NAME) && *n == '/') ||
(c == '?' && *n == '\0'))
return FNM_NOMATCH;
return 0;
{
- char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
+ char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? FOLD (*p) : c;
for (--p; *n != '\0'; ++n)
- if ((c == '[' || *n == c1) &&
+ if ((c == '[' || FOLD (*n) == c1) &&
fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
return 0;
return FNM_NOMATCH;
return FNM_NOMATCH;
if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
not = (*p == '!' || *p == '^');
if (!(flags & FNM_NOESCAPE) && c == '\\')
cstart = cend = *p++;
+ cstart = cend = FOLD (cstart);
+
if (c == '\0')
/* [ (unterminated) loses. */
return FNM_NOMATCH;
c = *p++;
+ c = FOLD (c);
- if ((flags & FNM_PATHNAME) && c == '/')
+ if ((flags & FNM_FILE_NAME) && c == '/')
/* [/] can never match. */
return FNM_NOMATCH;
cend = *p++;
if (cend == '\0')
return FNM_NOMATCH;
+ cend = FOLD (cend);
+
c = *p++;
}
- if (*n >= cstart && *n <= cend)
+ if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
goto matched;
if (c == ']')
c = *p++;
if (!(flags & FNM_NOESCAPE) && c == '\\')
- /* 1003.2d11 is unclear if this is right. %%% */
+ /* XXX 1003.2d11 is unclear if this is right. */
++p;
}
if (not)
break;
default:
- if (c != *n)
+ if (c != FOLD (*n))
return FNM_NOMATCH;
}
++n;
}
- if (*n == '\0' || ((flags & FNM_TARPATH) && *n == '/'))
+ if (*n == '\0')
+ return 0;
+
+ if ((flags & FNM_LEADING_DIR) && *n == '/')
+ /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
return 0;
return FNM_NOMATCH;
-/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
#define _FNMATCH_H 1
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
#endif /* C++ or ANSI C. */
/* Bits set in the FLAGS argument to `fnmatch'. */
-#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. */
-#define FNM_TARPATH (1 << 4)/* Ignore `/...' after a match. */
-#define __FNM_FLAGS (FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD|FNM_TARPATH)
-
-#if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_BSD_SOURCE)
-#define FNM_FILE_NAME FNM_PATHNAME
+#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. */
+
+#if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_GNU_SOURCE)
+#define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */
+#define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */
+#define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */
#endif
/* Value returned by `fnmatch' if STRING does not match PATTERN. */
/* Match STRING against the filename pattern PATTERN,
returning zero if it matches, FNM_NOMATCH if not. */
- extern int fnmatch __P ((const char *__pattern, const char *__string,
- int __flags));
+extern int fnmatch __P ((const char *__pattern, const char *__string,
+ int __flags));
#ifdef __cplusplus
}
-
#endif
#endif /* fnmatch.h */
#include <pwd.h>
#include <grp.h>
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>
extern int errno;
#endif
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#define index strchr
#else
slash = dirpath;
while (*slash == '/')
slash++;
- while (slash = index (slash, '/'))
+ while ((slash = index (slash, '/')))
{
*slash = '\0';
if (stat (dirpath, &stats))
#else
void free ();
#endif
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-/* Written by David MacKenzie <djm@ai.mit.edu>. */
+/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#include <sys/types.h>
-#ifdef DIRENT
-#include <dirent.h>
-#ifdef direct
-#undef direct
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
#endif
-#define direct dirent
+
+#if defined(DIRENT) || defined(_POSIX_VERSION)
+#include <dirent.h>
#define NLENGTH(direct) (strlen((direct)->d_name))
-#else
+#else /* not (DIRENT or _POSIX_VERSION) */
+#define dirent direct
#define NLENGTH(direct) ((direct)->d_namlen)
-#ifdef USG
#ifdef SYSNDIR
#include <sys/ndir.h>
-#else
-#include <ndir.h>
-#endif
-#else
+#endif /* SYSNDIR */
+#ifdef SYSDIR
#include <sys/dir.h>
-#endif
-#endif
+#endif /* SYSDIR */
+#ifdef NDIR
+#include <ndir.h>
+#endif /* NDIR */
+#endif /* DIRENT or _POSIX_VERSION */
#ifdef VOID_CLOSEDIR
/* Fake a return value. */
unsigned name_size;
{
DIR *dirp;
- struct direct *dp;
+ struct dirent *dp;
char *name_space;
char *namep;
char *strcpy ();
#endif
-#if !__STDC__
-#define const
-#endif
-
/* Return a newly allocated copy of STR,
or 0 if out of memory. */
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#if defined(STDC_HEADERS) || defined(USG)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>
#include <pwd.h>
#include <grp.h>
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#define index strchr
#else
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>