]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - iconv/iconvconfig.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / iconv / iconvconfig.c
index dc3f00845799d48b70c608227e9e6d4840423472..da6855fd6d05c9fb24ddc304b06b90e957270b18 100644 (file)
@@ -1,11 +1,12 @@
 /* Generate fastloading iconv module configuration files.
-   Copyright (C) 2000-2004, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2000-2020 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
 
    This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License version 2 as
-   published by the Free Software Foundation.
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +14,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
 
 #include <argp.h>
 #include <assert.h>
@@ -123,8 +123,9 @@ static char *more_help (int key, const char *text, void *input);
 #define OPT_NOSTDLIB 301
 static const struct argp_option options[] =
 {
-  { "prefix", OPT_PREFIX, "PATH", 0, N_("Prefix used for all file accesses") },
-  { "output", 'o', "FILE", 0, N_("\
+  { "prefix", OPT_PREFIX, N_("PATH"), 0,
+    N_("Prefix used for all file accesses") },
+  { "output", 'o', N_("FILE"), 0, N_("\
 Put output in FILE instead of installed location\
  (--prefix does not apply to FILE)") },
   { "nostdlib", OPT_NOSTDLIB, NULL, 0,
@@ -247,9 +248,7 @@ static struct
 static const char gconv_module_ext[] = MODULE_EXT;
 
 
-extern void *xmalloc (size_t n) __attribute_malloc__;
-extern void *xcalloc (size_t n, size_t m) __attribute_malloc__;
-extern void *xrealloc (void *p, size_t n);
+#include <programs/xmalloc.h>
 
 
 /* C string table handling.  */
@@ -372,13 +371,16 @@ parse_opt (int key, char *arg, struct argp_state *state)
 static char *
 more_help (int key, const char *text, void *input)
 {
+  char *tp = NULL;
   switch (key)
     {
     case ARGP_KEY_HELP_EXTRA:
       /* We print some extra information.  */
-      return strdup (gettext ("\
+      if (asprintf (&tp, gettext ("\
 For bug reporting instructions, please see:\n\
-<http://www.gnu.org/software/libc/bugs.html>.\n"));
+%s.\n"), REPORT_BUGS_TO) < 0)
+       return NULL;
+      return tp;
     default:
       break;
     }
@@ -390,12 +392,12 @@ For bug reporting instructions, please see:\n\
 static void
 print_version (FILE *stream, struct argp_state *state)
 {
-  fprintf (stream, "iconvconfig (GNU %s) %s\n", PACKAGE, VERSION);
+  fprintf (stream, "iconvconfig %s%s\n", PKGVERSION, VERSION);
   fprintf (stream, gettext ("\
 Copyright (C) %s Free Software Foundation, Inc.\n\
 This is free software; see the source for copying conditions.  There is NO\n\
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "2006");
+"), "2019");
   fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper");
 }
 
@@ -564,7 +566,6 @@ new_module (const char *fromname, size_t fromlen, const char *toname,
 
 /* Add new module.  */
 static void
-internal_function
 add_module (char *rp, const char *directory)
 {
   /* We expect now
@@ -992,25 +993,53 @@ next_prime (uint32_t seed)
    stoff    ???          String table
 
    hoff     8*hsize      Array of tuples
-                            string table offset
-                            module index
+                           string table offset
+                           module index
 
    moff     ???          Array of tuples
-                            canonical name offset
-                            from-internal module dir name offset
-                            from-internal module name off
-                            to-internal module dir name offset
-                            to-internal module name offset
-                            offset into other conversion table
+                           canonical name offset
+                           from-internal module dir name offset
+                           from-internal module name off
+                           to-internal module dir name offset
+                           to-internal module name offset
+                           offset into other conversion table
 
    ooff     ???          One or more of
-                            number of steps/modules
-                            one or more of tuple
-                              canonical name offset for output
-                              module dir name offset
-                              module name offset
-                         (following last entry with step count 0)
+                           number of steps/modules
+                           one or more of tuple
+                             canonical name offset for output
+                             module dir name offset
+                             module name offset
+                        (following last entry with step count 0)
 */
+
+static struct hash_entry *hash_table;
+static size_t hash_size;
+
+/* Function to insert the names.  */
+static void name_insert (const void *nodep, VISIT value, int level)
+{
+  struct name *name;
+  unsigned int idx;
+  unsigned int hval2;
+
+  if (value != leaf && value != postorder)
+    return;
+
+  name = *(struct name **) nodep;
+  idx = name->hashval % hash_size;
+  hval2 = 1 + name->hashval % (hash_size - 2);
+
+  while (hash_table[idx].string_offset != 0)
+    if ((idx += hval2) >= hash_size)
+      idx -= hash_size;
+
+  hash_table[idx].string_offset = strtaboffset (name->strent);
+
+  assert (name->module_idx != -1);
+  hash_table[idx].module_idx = name->module_idx;
+}
+
 static int
 write_output (void)
 {
@@ -1018,8 +1047,6 @@ write_output (void)
   char *string_table;
   size_t string_table_size;
   struct gconvcache_header header;
-  struct hash_entry *hash_table;
-  size_t hash_size;
   struct module_entry *module_table;
   char *extra_table;
   char *cur_extra_table;
@@ -1032,31 +1059,6 @@ write_output (void)
   char tmpfname[(output_file == NULL ? sizeof finalname : output_file_len + 1)
                + strlen (".XXXXXX")];
 
-  /* Function to insert the names.  */
-  auto void
-  name_insert (const void *nodep, VISIT value, int level)
-    {
-      struct name *name;
-      unsigned int idx;
-      unsigned int hval2;
-
-      if (value != leaf && value != postorder)
-       return;
-
-      name = *(struct name **) nodep;
-      idx = name->hashval % hash_size;
-      hval2 = 1 + name->hashval % (hash_size - 2);
-
-      while (hash_table[idx].string_offset != 0)
-       if ((idx += hval2) >= hash_size)
-         idx -= hash_size;
-
-      hash_table[idx].string_offset = strtaboffset (name->strent);
-
-      assert (name->module_idx != -1);
-      hash_table[idx].module_idx = name->module_idx;
-    }
-
   /* Open the output file.  */
   if (output_file == NULL)
     {
@@ -1077,9 +1079,9 @@ write_output (void)
 
   /* Create the hashing table.  We know how many strings we have.
      Creating a perfect hash table is not reasonable here.  Therefore
-     we use open hashing and a table size which is the next prime 40%
+     we use open hashing and a table size which is the next prime 50%
      larger than the number of strings.  */
-  hash_size = next_prime (nnames * 1.4);
+  hash_size = next_prime (nnames + (nnames >> 1));
   hash_table = (struct hash_entry *) xcalloc (hash_size,
                                              sizeof (struct hash_entry));
   /* Fill the hash table.  */