]> Dogcows Code - chaz/tar/commitdiff
(struct fmttab.name): Now char const *. All uses changed.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 3 Sep 2003 06:19:00 +0000 (06:19 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 3 Sep 2003 06:19:00 +0000 (06:19 +0000)
(fmttab): Now const.  All uses changed.  Avoid GCC warning by
not eliding initializers.
(set_archive_format): Report an error if no format name matches,
instead of returning an undefined value.
(set_archive_format): Now static.

src/tar.c

index 004a13d30108f9f1ba9b482e8cc1db2c6c8377f4..91c4104eeed148708cdd6d14cfe417bbdbf62e99 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -113,13 +113,13 @@ confirm (const char *message_action, const char *message_name)
   }
 }
 
-void
-set_archive_format (char *name)
+static void
+set_archive_format (char const *name)
 {
   static struct fmttab {
-    char *name;
+    char const *name;
     enum archive_format fmt;
-  } fmttab[] = {
+  } const fmttab[] = {
     { "v7",      V7_FORMAT },
     { "oldgnu",  OLDGNU_FORMAT },      
     { "posix",   POSIX_FORMAT },
@@ -127,24 +127,19 @@ set_archive_format (char *name)
     { "star",    STAR_FORMAT },
 #endif
     { "gnu",     GNU_FORMAT },
-    NULL
+    { NULL,     0 }
   };
-  struct fmttab *p;
-  enum archive_format fmt;
-  
-  for (p = fmttab; p->name; p++)
-    {
-      if (strcmp (p->name, name) == 0)
-       {
-         fmt = p->fmt;
-         break;
-       }
-    }
+  struct fmttab const *p;
+
+  for (p = fmttab; strcmp (p->name, name) != 0; )
+    if (! (++p)->name)
+      USAGE_ERROR ((0, 0, _("%s: Invalid archive format"),
+                   quotearg_colon (name)));
 
-  if (archive_format != DEFAULT_FORMAT && archive_format != fmt)
+  if (archive_format != DEFAULT_FORMAT && archive_format != p->fmt)
     USAGE_ERROR ((0, 0, _("Conflicting archive format options")));
   
-  archive_format = fmt;
+  archive_format = p->fmt;
 }
 \f
 /* Options.  */
This page took 0.026404 seconds and 4 git commands to generate.