]> Dogcows Code - chaz/tar/blobdiff - src/names.c
Remove some lint, found by gcc -W etc.
[chaz/tar] / src / names.c
index 16566bb57aeee8f4ce5700f14f6a653eb98f20bf..f1e5ab1bee33a8c5af3ea1f7c0482d9dbcdf1cf2 100644 (file)
 \f
 /* User and group names.  */
 
-struct group *getgrnam ();
-struct passwd *getpwnam ();
-#if ! HAVE_DECL_GETPWUID
-struct passwd *getpwuid ();
-#endif
-#if ! HAVE_DECL_GETGRGID
-struct group *getgrgid ();
-#endif
-
 /* Make sure you link with the proper libraries if you are running the
    Yellow Peril (thanks for the good laugh, Ian J.!), or, euh... NIS.
    This code should also be modified for non-UNIX systems to do something
@@ -179,7 +170,7 @@ gname_to_gid (char const *gname, gid_t *gidp)
 }
 
 \f
-struct name *
+static struct name *
 make_name (const char *file_name)
 {
   struct name *p = xzalloc (sizeof (*p));
@@ -190,7 +181,7 @@ make_name (const char *file_name)
   return p;
 }
 
-void
+static void
 free_name (struct name *p)
 {
   if (p)
@@ -205,9 +196,9 @@ free_name (struct name *p)
 /* Names from the command call.  */
 
 static struct name *namelist;  /* first name in list, if any */
-static struct name **nametail = &namelist;     /* end of name list */
+static struct name *nametail;  /* end of name list */
 
-/* File name arguments are processed in two stages: first a 
+/* File name arguments are processed in two stages: first a
    name_array (see below) is filled, then the names from it
    are moved into the namelist.
 
@@ -215,7 +206,7 @@ static struct name **nametail = &namelist;  /* end of name list */
    which is meant to help process large archives on machines with
    limited memory.  With this option on, namelist contains at most one
    entry, which diminishes the memory consumption.
-   
+
    However, I very much doubt if we still need this -- Sergey */
 
 /* A name_array element contains entries of three types: */
@@ -230,7 +221,7 @@ struct name_elt        /* A name_array element. */
   union
   {
     const char *name;  /* File or directory name */
-    int matching_flags;/* fnmatch options if type == NELT_FMASK */ 
+    int matching_flags;/* fnmatch options if type == NELT_FMASK */
   } v;
 };
 
@@ -241,7 +232,7 @@ static size_t name_index;    /* how many of the entries have we scanned? */
 
 /* Check the size of name_array, reallocating it as necessary.  */
 static void
-check_name_alloc ()
+check_name_alloc (void)
 {
   if (names == allocated_names)
     {
@@ -282,7 +273,7 @@ name_add_dir (const char *name)
   ep = &name_array[names++];
   ep->type = NELT_CHDIR;
   ep->v.name = name;
-}  
+}
 
 \f
 /* Names from external name file.  */
@@ -313,10 +304,10 @@ static int matching_flags; /* exclude_fnmatch options */
 
    If CHANGE_DIRS is true, treat any entries of type NELT_CHDIR as
    the request to change to the given directory.
-   
+
    Entries of type NELT_FMASK cause updates of the matching_flags
    value. */
-struct name_elt *
+static struct name_elt *
 name_next_elt (int change_dirs)
 {
   static struct name_elt entry;
@@ -327,14 +318,14 @@ name_next_elt (int change_dirs)
     {
       struct name_elt *ep;
       size_t source_len;
-      
+
       ep = &name_array[name_index++];
       if (ep->type == NELT_FMASK)
        {
          matching_flags = ep->v.matching_flags;
          continue;
        }
-      
+
       source = ep->v.name;
       source_len = strlen (source);
       if (name_buffer_length < source_len)
@@ -421,9 +412,8 @@ name_gather (void)
          buffer->directory = NULL;
          buffer->parent = NULL;
          buffer->cmdline = true;
-         
-         namelist = buffer;
-         nametail = &namelist->next;
+
+         namelist = nametail = buffer;
        }
       else if (change_dir)
        addname (0, change_dir, false, NULL);
@@ -457,7 +447,7 @@ addname (char const *string, int change_dir, bool cmdline, struct name *parent)
 {
   struct name *name = make_name (string);
 
-  name->prev = *nametail;
+  name->prev = nametail;
   name->next = NULL;
   name->found_count = 0;
   name->matching_flags = matching_flags;
@@ -465,9 +455,12 @@ addname (char const *string, int change_dir, bool cmdline, struct name *parent)
   name->directory = NULL;
   name->parent = parent;
   name->cmdline = cmdline;
-  
-  *nametail = name;
-  nametail = &name->next;
+
+  if (nametail)
+    nametail->next = name;
+  else
+    namelist = name;
+  nametail = name;
   return name;
 }
 
@@ -501,7 +494,7 @@ remname (struct name *name)
   if ((p = name->next) != NULL)
     p->prev = name->prev;
   else
-    nametail = &name->prev;
+    nametail = name->prev;
 }
 
 /* Return true if and only if name FILE_NAME (from an archive) matches any
@@ -517,12 +510,12 @@ name_match (const char *file_name)
 
       if (!cursor)
        return true;
-      
+
       if (cursor->name[0] == 0)
        {
          chdir_do (cursor->change_dir);
-         namelist = 0;
-         nametail = &namelist;
+         namelist = NULL;
+         nametail = NULL;
          return true;
        }
 
@@ -535,8 +528,8 @@ name_match (const char *file_name)
          if (starting_file_option)
            {
              free (namelist);
-             namelist = 0;
-             nametail = &namelist;
+             namelist = NULL;
+             nametail = NULL;
            }
          chdir_do (cursor->change_dir);
 
@@ -575,8 +568,6 @@ all_names_found (struct tar_stat_info *p)
   struct name const *cursor;
   size_t len;
 
-  if (test_label_option)
-    return true;
   if (!p->file_name || occurrence_option == 0 || p->had_trailing_slash)
     return false;
   len = strlen (p->file_name);
@@ -589,29 +580,21 @@ all_names_found (struct tar_stat_info *p)
   return true;
 }
 
-static inline int
-is_pattern (const char *string)
-{
-  return strchr (string, '*') || strchr (string, '[') || strchr (string, '?');
-}
-
-static void
+static int
 regex_usage_warning (const char *name)
 {
   static int warned_once = 0;
 
-  if (warn_regex_usage && is_pattern (name))
+  if (warn_regex_usage && fnmatch_pattern_has_wildcards (name, 0))
     {
       warned_once = 1;
       WARN ((0, 0,
-            /* TRANSLATORS: The following three msgids form a single sentence.
-             */
-            _("Pattern matching characters used in file names. Please,")));
-      WARN ((0, 0,
-            _("use --wildcards to enable pattern matching, or --no-wildcards to")));
+            _("Pattern matching characters used in file names")));
       WARN ((0, 0,
-            _("suppress this warning.")));
+            _("Use --wildcards to enable pattern matching,"
+              " or --no-wildcards to suppress this warning")));
     }
+  return warned_once;
 }
 
 /* Print the names of things in the namelist that were not matched.  */
@@ -624,17 +607,16 @@ names_notfound (void)
     if (!WASFOUND (cursor) && cursor->name[0])
       {
        regex_usage_warning (cursor->name);
-       if (cursor->found_count == 0)
-         ERROR ((0, 0, _("%s: Not found in archive"),
-                 quotearg_colon (cursor->name)));
-       else
-         ERROR ((0, 0, _("%s: Required occurrence not found in archive"),
-                 quotearg_colon (cursor->name)));  
+       ERROR ((0, 0,
+               (cursor->found_count == 0) ?
+                    _("%s: Not found in archive") :
+                    _("%s: Required occurrence not found in archive"),
+               quotearg_colon (cursor->name)));
       }
 
   /* Don't bother freeing the name list; we're about to exit.  */
-  namelist = 0;
-  nametail = &namelist;
+  namelist = NULL;
+  nametail = NULL;
 
   if (same_order_option)
     {
@@ -648,13 +630,49 @@ names_notfound (void)
        }
     }
 }
+
+void
+label_notfound (void)
+{
+  struct name const *cursor;
+
+  if (!namelist)
+    return;
+
+  for (cursor = namelist; cursor; cursor = cursor->next)
+    if (WASFOUND (cursor))
+      return;
+
+  if (verbose_option)
+    error (0, 0, _("Archive label mismatch"));
+  set_exit_status (TAREXIT_DIFFERS);
+
+  for (cursor = namelist; cursor; cursor = cursor->next)
+    {
+      if (regex_usage_warning (cursor->name))
+       break;
+    }
+
+  /* Don't bother freeing the name list; we're about to exit.  */
+  namelist = NULL;
+  nametail = NULL;
+
+  if (same_order_option)
+    {
+      const char *name;
+
+      while ((name = name_next (1)) != NULL
+            && regex_usage_warning (name) == 0)
+       ;
+    }
+}
 \f
 /* Sorting name lists.  */
 
 /* Sort *singly* linked LIST of names, of given LENGTH, using COMPARE
    to order names.  Return the sorted list.  Note that after calling
    this function, the `prev' links in list elements are messed up.
-   
+
    Apart from the type `struct name' and the definition of SUCCESSOR,
    this is a generic list-sorting function, but it's too painful to
    make it both generic and portable
@@ -770,7 +788,7 @@ static void
 add_hierarchy_to_namelist (struct name *name, dev_t device, bool cmdline)
 {
   const char *buffer;
-  
+
   name_fill_directory (name, device, cmdline);
   buffer = directory_contents (name->directory);
   if (buffer)
@@ -855,7 +873,7 @@ rebase_child_list (struct name *child, struct name *parent)
   size_t old_prefix_len = child->parent->length;
   size_t new_prefix_len = parent->length;
   char *new_prefix = parent->name;
-  
+
   for (; child; child = child->sibling)
     {
       size_t size = child->length - old_prefix_len + new_prefix_len;
@@ -867,7 +885,7 @@ rebase_child_list (struct name *child, struct name *parent)
       child->length = size;
 
       rebase_directory (child->directory,
-                       child->parent->name, old_prefix_len, 
+                       child->parent->name, old_prefix_len,
                        new_prefix, new_prefix_len);
     }
 }
@@ -880,11 +898,11 @@ void
 collect_and_sort_names (void)
 {
   struct name *name;
-  struct name *next_name, *prev_name;
+  struct name *next_name, *prev_name = NULL;
   int num_names;
   struct stat statbuf;
   Hash_table *nametab;
-  
+
   name_gather ();
 
   if (!namelist)
@@ -909,10 +927,10 @@ collect_and_sort_names (void)
                        _("Only one -C option is allowed with "
                          "--listed-incremental")));
        }
-      chdir_do (namelist->change_dir);
+
       read_directory_file ();
     }
-  
+
   num_names = 0;
   for (name = namelist; name; name = name->next, num_names++)
     {
@@ -959,6 +977,7 @@ collect_and_sort_names (void)
                {
                  if (p->child)
                    rebase_child_list (p->child, name);
+                 hash_delete (nametab, name);
                  /* FIXME: remove_directory (p->caname); ? */
                  remname (p);
                  free_name (p);
@@ -981,7 +1000,7 @@ collect_and_sort_names (void)
       prev_name = name;
       num_names++;
     }
-  nametail = &prev_name;
+  nametail = prev_name;
   hash_free (nametab);
 
   namelist = merge_sort (namelist, num_names, compare_names_found);
@@ -1080,24 +1099,6 @@ excluded_name (char const *name)
 {
   return excluded_file_name (excluded, name + FILE_SYSTEM_PREFIX_LEN (name));
 }
-\f
-/* Names to avoid dumping.  */
-static Hash_table *avoided_name_table;
-
-/* Remember to not archive NAME.  */
-void
-add_avoided_name (char const *name)
-{
-  hash_string_insert (&avoided_name_table, name);
-}
-
-/* Should NAME be avoided when archiving?  */
-bool
-is_avoided_name (char const *name)
-{
-  return hash_string_lookup (avoided_name_table, name);
-}
-
 \f
 static Hash_table *individual_file_table;
 
@@ -1105,12 +1106,12 @@ static void
 register_individual_file (char const *name)
 {
   struct stat st;
-  
+
   if (deref_stat (dereference_option, name, &st) != 0)
     return; /* Will be complained about later */
   if (S_ISDIR (st.st_mode))
     return;
-  
+
   hash_string_insert (&individual_file_table, name);
 }
 
This page took 0.031497 seconds and 4 git commands to generate.