bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnulib] argmatch, backupfile sync from coreutils (API change)


From: Paul Eggert
Subject: [Bug-gnulib] argmatch, backupfile sync from coreutils (API change)
Date: Sun, 03 Oct 2004 21:35:42 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

I installed the following patch to sync with coreutils.

Warning: this patch changes the API for backupfile: it
renames enum constants (e.g., none -> no_backups) in order
to avoid some name clashes and shadowing problems.

2004-10-03  Paul Eggert  <address@hidden>

        * backupfile.h (enum backuptype): Rename none -> no_backups,
        simple -> simple_backups, numbered_existing ->
        numbered_existing_backups, numbered -> numbered_backups
        to avoid shadowing problems.  All uses changed.
        * argmatch.c (enum backuptype) [defined TEST]: Likewise.
        * backupfile.c (check_extension, numbered_backup):
        Rename locals to avoid shadowing 'basename'.
        * backupfile.h (VALID_BACKUP_TYPE): Don't evaluate arg more than
        once.

Index: lib/argmatch.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/argmatch.c,v
retrieving revision 1.34
diff -p -u -r1.34 argmatch.c
--- lib/argmatch.c      6 Aug 2004 23:04:38 -0000       1.34
+++ lib/argmatch.c      4 Oct 2004 04:16:27 -0000
@@ -216,17 +216,17 @@ char *program_name;
 enum backup_type
 {
   /* Never make backups.  */
-  none,
+  no_backups,
 
   /* Make simple backups of every file.  */
-  simple,
+  simple_backups,
 
   /* Make numbered backups of files that already have numbered backups,
      and simple backups of the others.  */
-  numbered_existing,
+  numbered_existing_backups,
 
   /* Make numbered backups of every file.  */
-  numbered
+  numbered_backups
 };
 
 /* Two tables describing arguments (keys) and their corresponding
@@ -242,17 +242,17 @@ static const char *const backup_args[] =
 
 static const enum backup_type backup_vals[] =
 {
-  none, none, none,
-  simple, simple,
-  numbered_existing, numbered_existing,
-  numbered, numbered
+  no_backups, no_backups, no_backups,
+  simple_backups, simple_backups,
+  numbered_existing_backups, numbered_existing_backups,
+  numbered_backups, numbered_backups
 };
 
 int
 main (int argc, const char *const *argv)
 {
   const char *cp;
-  enum backup_type backup_type = none;
+  enum backup_type backup_type = no_backups;
 
   program_name = (char *) argv[0];
 
Index: lib/backupfile.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/backupfile.c,v
retrieving revision 1.42
diff -p -u -r1.42 backupfile.c
--- lib/backupfile.c    6 Aug 2004 23:12:57 -0000       1.42
+++ lib/backupfile.c    4 Oct 2004 04:16:27 -0000
@@ -109,16 +109,16 @@
 char const *simple_backup_suffix = "~";
 
 
-/* If FILENAME (which was of length FILELEN before an extension was
+/* If FILE (which was of length FILELEN before an extension was
    appended to it) is too long, replace the extension with the single
    char E.  If the result is still too long, remove the char just
    before E.  */
 
 static void
-check_extension (char *filename, size_t filelen, char e)
+check_extension (char *file, size_t filelen, char e)
 {
-  char *basename = base_name (filename);
-  size_t baselen = base_len (basename);
+  char *base = base_name (file);
+  size_t baselen = base_len (base);
   size_t baselen_max = HAVE_LONG_FILE_NAMES ? 255 : NAME_MAX_MINIMUM;
 
   if (HAVE_DOS_FILE_NAMES || NAME_MAX_MINIMUM < baselen)
@@ -129,41 +129,41 @@ check_extension (char *filename, size_t 
       /* Temporarily modify the buffer into its parent directory name,
         invoke pathconf on the directory, and then restore the buffer.  */
       char tmp[sizeof "."];
-      memcpy (tmp, basename, sizeof ".");
-      strcpy (basename, ".");
+      memcpy (tmp, base, sizeof ".");
+      strcpy (base, ".");
       errno = 0;
-      name_max = pathconf (filename, _PC_NAME_MAX);
+      name_max = pathconf (file, _PC_NAME_MAX);
       if (0 <= name_max || errno == 0)
        {
          long size = baselen_max = name_max;
          if (name_max != size)
            baselen_max = SIZE_MAX;
        }
-      memcpy (basename, tmp, sizeof ".");
+      memcpy (base, tmp, sizeof ".");
     }
 
   if (HAVE_DOS_FILE_NAMES && baselen_max <= 12)
     {
       /* Live within DOS's 8.3 limit.  */
-      char *dot = strchr (basename, '.');
+      char *dot = strchr (base, '.');
       if (!dot)
        baselen_max = 8;
       else
        {
          char const *second_dot = strchr (dot + 1, '.');
          baselen_max = (second_dot
-                        ? second_dot - basename
-                        : dot + 1 - basename + 3);
+                        ? second_dot - base
+                        : dot + 1 - base + 3);
        }
     }
 
   if (baselen_max < baselen)
     {
-      baselen = filename + filelen - basename;
+      baselen = file + filelen - base;
       if (baselen_max <= baselen)
        baselen = baselen_max - 1;
-      basename[baselen] = e;
-      basename[baselen + 1] = '\0';
+      base[baselen] = e;
+      base[baselen + 1] = '\0';
     }
 }
 
@@ -204,18 +204,18 @@ numbered_backup (char **buffer, size_t b
   struct dirent *dp;
   char *buf = *buffer;
   size_t versionlenmax = 1;
-  char *basename = base_name (buf);
-  size_t basename_offset = basename - buf;
-  size_t baselen = base_len (basename);
+  char *base = base_name (buf);
+  size_t base_offset = base - buf;
+  size_t baselen = base_len (base);
 
   /* Temporarily modify the buffer into its parent directory name,
      open the directory, and then restore the buffer.  */
   char tmp[sizeof "."];
-  memcpy (tmp, basename, sizeof ".");
-  strcpy (basename, ".");
+  memcpy (tmp, base, sizeof ".");
+  strcpy (base, ".");
   dirp = opendir (buf);
-  memcpy (basename, tmp, sizeof ".");
-  strcpy (basename + baselen, ".~1~");
+  memcpy (base, tmp, sizeof ".");
+  strcpy (base + baselen, ".~1~");
 
   if (!dirp)
     return result;
@@ -231,7 +231,7 @@ numbered_backup (char **buffer, size_t b
       if (! REAL_DIR_ENTRY (dp) || NLENGTH (dp) < baselen + 4)
        continue;
 
-      if (memcmp (buf + basename_offset, dp->d_name, baselen + 2) != 0)
+      if (memcmp (buf + base_offset, dp->d_name, baselen + 2) != 0)
        continue;
 
       p = dp->d_name + baselen + 2;
@@ -270,7 +270,7 @@ numbered_backup (char **buffer, size_t b
       *q = '0';
       q += all_9s;
       memcpy (q, p, versionlen + 2);
-      
+
       /* Add 1 to the version number.  */
 
       q += versionlen;
@@ -287,7 +287,7 @@ numbered_backup (char **buffer, size_t b
 
 /* Return the name of the new backup file for the existing file FILE,
    allocated with malloc.  Report an error and fail if out of memory.
-   Do not call this function if backup_type == none. */
+   Do not call this function if backup_type == no_backups.  */
 
 char *
 find_backup_file_name (char const *file, enum backup_type backup_type)
@@ -310,7 +310,7 @@ find_backup_file_name (char const *file,
   memcpy (s, file, filelen + 1);
 
 #if HAVE_DIR
-  if (backup_type != simple)
+  if (backup_type != simple_backups)
     switch (numbered_backup (&s, ssize, filelen))
       {
       case BACKUP_IS_SAME_LENGTH:
@@ -321,7 +321,7 @@ find_backup_file_name (char const *file,
        break;
 
       case BACKUP_IS_NEW:
-       simple = (backup_type == numbered_existing);
+       simple = (backup_type == numbered_existing_backups);
        break;
       }
 #endif
@@ -345,14 +345,14 @@ static char const * const backup_args[] 
 
 static const enum backup_type backup_types[] =
 {
-  none, none,
-  simple, simple,
-  numbered_existing, numbered_existing,
-  numbered, numbered
+  no_backups, no_backups,
+  simple_backups, simple_backups,
+  numbered_existing_backups, numbered_existing_backups,
+  numbered_backups, numbered_backups
 };
 
 /* Return the type of backup specified by VERSION.
-   If VERSION is NULL or the empty string, return numbered_existing.
+   If VERSION is NULL or the empty string, return numbered_existing_backups.
    If VERSION is invalid or ambiguous, fail with a diagnostic appropriate
    for the specified CONTEXT.  Unambiguous abbreviations are accepted.  */
 
@@ -360,7 +360,7 @@ enum backup_type
 get_version (char const *context, char const *version)
 {
   if (version == 0 || *version == 0)
-    return numbered_existing;
+    return numbered_existing_backups;
   else
     return XARGMATCH (context, version, backup_args, backup_types);
 }
Index: lib/backupfile.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/backupfile.h,v
retrieving revision 1.13
diff -p -u -r1.13 backupfile.h
--- lib/backupfile.h    16 Jul 2004 16:28:48 -0000      1.13
+++ lib/backupfile.h    4 Oct 2004 04:16:27 -0000
@@ -30,24 +30,21 @@ extern "C" {
 enum backup_type
 {
   /* Never make backups. */
-  none,
+  no_backups,
 
   /* Make simple backups of every file. */
-  simple,
+  simple_backups,
 
   /* Make numbered backups of files that already have numbered backups,
      and simple backups of the others. */
-  numbered_existing,
+  numbered_existing_backups,
 
   /* Make numbered backups of every file. */
-  numbered
+  numbered_backups
 };
 
 # define VALID_BACKUP_TYPE(Type)       \
-  ((Type) == none                      \
-   || (Type) == simple                 \
-   || (Type) == numbered_existing      \
-   || (Type) == numbered)
+  ((unsigned int) (Type) <= numbered_backups)
 
 extern char const *simple_backup_suffix;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]