GNU file utilities FILEUTILS-3_4_1
authorJim Meyering <jim@meyering.net>
Sun, 28 Mar 1993 19:25:12 +0000 (19:25 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 28 Mar 1993 19:25:12 +0000 (19:25 +0000)
12 files changed:
lib/backupfile.c
lib/dirname.c
lib/fnmatch.c
lib/fnmatch.h
lib/idcache.c
lib/makepath.c
lib/mountlist.c
lib/savedir.c
lib/strdup.c
lib/stripslash.c
lib/userspec.c
lib/xstrdup.c

index c6d7914..94bb55a 100644 (file)
    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. */
@@ -138,7 +135,7 @@ max_backup_version (file, dir)
      char *file, *dir;
 {
   DIR *dirp;
-  struct direct *dp;
+  struct dirent *dp;
   int highest_version;
   int this_version;
   int file_name_length;
index 82deea7..5a92ce5 100644 (file)
 #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
index 525e6a8..be662d9 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
@@ -16,16 +16,13 @@ not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 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
@@ -37,40 +34,42 @@ fnmatch (pattern, string, flags)
   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;
 
@@ -78,9 +77,9 @@ fnmatch (pattern, string, flags)
            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;
@@ -95,7 +94,7 @@ fnmatch (pattern, string, flags)
              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 == '^');
@@ -110,13 +109,16 @@ fnmatch (pattern, string, flags)
                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;
 
@@ -127,10 +129,12 @@ fnmatch (pattern, string, flags)
                      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 == ']')
@@ -150,7 +154,7 @@ fnmatch (pattern, string, flags)
 
                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)
@@ -159,14 +163,18 @@ fnmatch (pattern, string, flags)
          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;
index 0b3588a..2289f63 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
@@ -20,8 +20,7 @@ Cambridge, MA 02139, USA.  */
 #define        _FNMATCH_H      1
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 #if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
@@ -35,14 +34,14 @@ extern "C"
 #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.  */
@@ -50,12 +49,11 @@ extern "C"
 
 /* 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 */
index 3e5f134..dd9c366 100644 (file)
@@ -20,7 +20,7 @@
 #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>
index 5c61124..12da458 100644 (file)
@@ -49,7 +49,7 @@ char *alloca ();
 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
@@ -127,7 +127,7 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string)
       slash = dirpath;
       while (*slash == '/')
        slash++;
-      while (slash = index (slash, '/'))
+      while ((slash = index (slash, '/')))
        {
          *slash = '\0';
          if (stat (dirpath, &stats))
index 78955f7..88fda7a 100644 (file)
@@ -24,7 +24,7 @@
 #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>
index fce61da..d89adc0 100644 (file)
    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. */
@@ -71,7 +73,7 @@ savedir (dir, name_size)
      unsigned name_size;
 {
   DIR *dirp;
-  struct direct *dp;
+  struct dirent *dp;
   char *name_space;
   char *namep;
 
index 078c69b..b137db2 100644 (file)
@@ -23,10 +23,6 @@ char *malloc ();
 char *strcpy ();
 #endif
 
-#if !__STDC__
-#define const
-#endif
-
 /* Return a newly allocated copy of STR,
    or 0 if out of memory. */
 
index 802204f..2971d4c 100644 (file)
@@ -15,7 +15,7 @@
    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>
index 60c6ecc..a417cca 100644 (file)
@@ -22,7 +22,7 @@
 #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
index da39db3..9588bc7 100644 (file)
@@ -15,7 +15,7 @@
    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>