summaryrefslogtreecommitdiff
path: root/locale/programs/localedef.c
diff options
context:
space:
mode:
Diffstat (limited to 'locale/programs/localedef.c')
-rw-r--r--locale/programs/localedef.c142
1 files changed, 91 insertions, 51 deletions
diff --git a/locale/programs/localedef.c b/locale/programs/localedef.c
index 6becd9aa2e..d718d2e9f4 100644
--- a/locale/programs/localedef.c
+++ b/locale/programs/localedef.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1995.
@@ -24,7 +24,6 @@
#include <fcntl.h>
#include <libintl.h>
#include <locale.h>
-#include <mcheck.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -33,6 +32,7 @@
#include <error.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <ctype.h>
#include "localedef.h"
#include "charmap.h"
@@ -49,16 +49,6 @@ struct copy_def_list_t *copy_list;
/* If this is defined be POSIX conform. */
int posix_conformance;
-/* If not zero give a lot more messages. */
-int verbose;
-
-/* If not zero suppress warnings and information messages. */
-int be_quiet;
-
-/* If not zero, produce old-style hash table instead of 3-level access
- tables. */
-int oldstyle_tables;
-
/* If not zero force output even if warning were issued. */
static int force_output;
@@ -105,7 +95,6 @@ void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
#define OPT_POSIX 301
#define OPT_QUIET 302
-#define OPT_OLDSTYLE 303
#define OPT_PREFIX 304
#define OPT_NO_ARCHIVE 305
#define OPT_ADD_TO_ARCHIVE 306
@@ -114,6 +103,8 @@ void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
#define OPT_LIST_ARCHIVE 309
#define OPT_LITTLE_ENDIAN 400
#define OPT_BIG_ENDIAN 401
+#define OPT_NO_WARN 402
+#define OPT_WARN 403
/* Definitions of arguments for argp functions. */
static const struct argp_option options[] =
@@ -129,12 +120,18 @@ static const struct argp_option options[] =
{ NULL, 0, NULL, 0, N_("Output control:") },
{ "force", 'c', NULL, 0,
N_("Create output even if warning messages were issued") },
- { "old-style", OPT_OLDSTYLE, NULL, 0, N_("Create old-style tables") },
{ "prefix", OPT_PREFIX, N_("PATH"), 0, N_("Optional output file prefix") },
{ "posix", OPT_POSIX, NULL, 0, N_("Strictly conform to POSIX") },
{ "quiet", OPT_QUIET, NULL, 0,
N_("Suppress warnings and information messages") },
{ "verbose", 'v', NULL, 0, N_("Print more messages") },
+ { "no-warnings", OPT_NO_WARN, N_("<warnings>"), 0,
+ N_("Comma-separated list of warnings to disable; "
+ "supported warnings are: ascii, intcurrsym") },
+ { "warnings", OPT_WARN, N_("<warnings>"), 0,
+ N_("Comma-separated list of warnings to enable; "
+ "supported warnings are: ascii, intcurrsym") },
+
{ NULL, 0, NULL, 0, N_("Archive control:") },
{ "no-archive", OPT_NO_ARCHIVE, NULL, 0,
N_("Don't add new data to archive") },
@@ -243,8 +240,8 @@ main (int argc, char *argv[])
defines error code 3 for this situation so I think it must be
a fatal error (see P1003.2 4.35.8). */
if (sysconf (_SC_2_LOCALEDEF) < 0)
- WITH_CUR_LOCALE (error (3, 0, _("\
-FATAL: system does not define `_POSIX2_LOCALEDEF'")));
+ record_error (3, 0, _("\
+FATAL: system does not define `_POSIX2_LOCALEDEF'"));
/* Process charmap file. */
charmap = charmap_read (charmap_file, verbose, 1, be_quiet, 1);
@@ -257,8 +254,8 @@ FATAL: system does not define `_POSIX2_LOCALEDEF'")));
/* Now read the locale file. */
if (locfile_read (&global, charmap) != 0)
- WITH_CUR_LOCALE (error (4, errno, _("\
-cannot open locale definition file `%s'"), input_file));
+ record_error (4, errno, _("\
+cannot open locale definition file `%s'"), input_file);
/* Perhaps we saw some `copy' instructions. */
while (1)
@@ -273,31 +270,80 @@ cannot open locale definition file `%s'"), input_file));
break;
if (locfile_read (runp, charmap) != 0)
- WITH_CUR_LOCALE (error (4, errno, _("\
-cannot open locale definition file `%s'"), runp->name));
+ record_error (4, errno, _("\
+cannot open locale definition file `%s'"), runp->name);
}
/* Check the categories we processed in source form. */
check_all_categories (locales, charmap);
- /* We are now able to write the data files. If warning were given we
- do it only if it is explicitly requested (--force). */
- if (error_message_count == 0 || force_output != 0)
+ /* What we do next depends on the number of errors and warnings we
+ have generated in processing the input files.
+
+ * No errors: Write the output file.
+
+ * Some warnings: Write the output file and exit with status 1 to
+ indicate there may be problems using the output file e.g. missing
+ data that makes it difficult to use
+
+ * Errors: We don't write the output file and we exit with status 4
+ to indicate no output files were written.
+
+ The use of -c|--force writes the output file even if errors were
+ seen. */
+ if (recorded_error_count == 0 || force_output != 0)
{
if (cannot_write_why != 0)
- WITH_CUR_LOCALE (error (4, cannot_write_why, _("\
-cannot write output files to `%s'"), output_path ? : argv[remaining]));
+ record_error (4, cannot_write_why, _("\
+cannot write output files to `%s'"), output_path ? : argv[remaining]);
else
write_all_categories (locales, charmap, argv[remaining], output_path);
}
else
- WITH_CUR_LOCALE (error (4, 0, _("\
-no output file produced because warnings were issued")));
+ record_error (4, 0, _("\
+no output file produced because errors were issued"));
/* This exit status is prescribed by POSIX.2 4.35.7. */
- exit (error_message_count != 0);
+ exit (recorded_warning_count != 0);
}
+/* Search warnings for matching warnings and if found enable those
+ warnings if ENABLED is true, otherwise disable the warnings. */
+static void
+set_warnings (char *warnings, bool enabled)
+{
+ char *tok = warnings;
+ char *copy = (char *) malloc (strlen (warnings) + 1);
+ char *save = copy;
+
+ /* As we make a copy of the warnings list we remove all spaces from
+ the warnings list to make the processing a more robust. We don't
+ support spaces in a warning name. */
+ do
+ {
+ while (isspace (*tok) != 0)
+ tok++;
+ }
+ while ((*save++ = *tok++) != '\0');
+
+ warnings = copy;
+
+ /* Tokenize the input list of warnings to set, compare them to
+ known warnings, and set the warning. We purposely ignore unknown
+ warnings, and are thus forward compatible, users can attempt to
+ disable whaterver new warnings they know about, but we will only
+ disable those *we* known about. */
+ while ((tok = strtok_r (warnings, ",", &save)) != NULL)
+ {
+ warnings = NULL;
+ if (strcmp (tok, "ascii") == 0)
+ warn_ascii = enabled;
+ else if (strcmp (tok, "intcurrsym") == 0)
+ warn_int_curr_symbol = enabled;
+ }
+
+ free (copy);
+}
/* Handle program arguments. */
static error_t
@@ -311,9 +357,6 @@ parse_opt (int key, char *arg, struct argp_state *state)
case OPT_POSIX:
posix_conformance = 1;
break;
- case OPT_OLDSTYLE:
- oldstyle_tables = 1;
- break;
case OPT_PREFIX:
output_prefix = arg;
break;
@@ -338,6 +381,14 @@ parse_opt (int key, char *arg, struct argp_state *state)
case OPT_BIG_ENDIAN:
set_big_endian (true);
break;
+ case OPT_NO_WARN:
+ /* Disable the warnings. */
+ set_warnings (arg, false);
+ break;
+ case OPT_WARN:
+ /* Enable the warnings. */
+ set_warnings (arg, true);
+ break;
case 'c':
force_output = 1;
break;
@@ -403,7 +454,7 @@ print_version (FILE *stream, struct argp_state *state)
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\
-"), "2016");
+"), "2018");
fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper");
}
@@ -577,14 +628,14 @@ add_to_readlist (int category, const char *name, const char *repertoire_name,
if (generate
&& (runp->needed & (1 << category)) != 0
&& (runp->avail & (1 << category)) == 0)
- WITH_CUR_LOCALE (error (5, 0, _("\
-circular dependencies between locale definitions")));
+ record_error (5, 0, _("\
+circular dependencies between locale definitions"));
if (copy_locale != NULL)
{
if (runp->categories[category].generic != NULL)
- WITH_CUR_LOCALE (error (5, 0, _("\
-cannot add already read locale `%s' a second time"), name));
+ record_error (5, 0, _("\
+cannot add already read locale `%s' a second time"), name);
else
runp->categories[category].generic =
copy_locale->categories[category].generic;
@@ -609,8 +660,8 @@ find_locale (int category, const char *name, const char *repertoire_name,
if ((result->avail & (1 << category)) == 0
&& locfile_read (result, charmap) != 0)
- WITH_CUR_LOCALE (error (4, errno, _("\
-cannot open locale definition file `%s'"), result->name));
+ record_error (4, errno, _("\
+cannot open locale definition file `%s'"), result->name);
return result;
}
@@ -629,19 +680,8 @@ load_locale (int category, const char *name, const char *repertoire_name,
if ((result->avail & (1 << category)) == 0
&& locfile_read (result, charmap) != 0)
- WITH_CUR_LOCALE (error (4, errno, _("\
-cannot open locale definition file `%s'"), result->name));
+ record_error (4, errno, _("\
+cannot open locale definition file `%s'"), result->name);
return result;
}
-
-static void
-turn_on_mcheck (void)
-{
- /* Enable `malloc' debugging. */
- mcheck (NULL);
- /* Use the following line for a more thorough but much slower testing. */
- /* mcheck_pedantic (NULL); */
-}
-
-void (*__malloc_initialize_hook) (void) = turn_on_mcheck;