aboutsummaryrefslogtreecommitdiff
path: root/locale/programs/localedef.c
diff options
context:
space:
mode:
authorCarlos O'Donell <carlos@systemhalted.org>2017-10-17 01:33:42 -0700
committerCarlos O'Donell <carlos@systemhalted.org>2017-10-25 13:36:54 -0700
commit02eec681676c5aabf2eb13b92b1124245d19112f (patch)
treeaf9a0a8e118957855af45b207c1441db3fa9cce9 /locale/programs/localedef.c
parent56fa555a834c1536bf8d58c1ac6097f18f0d92b6 (diff)
downloadglibc-02eec681676c5aabf2eb13b92b1124245d19112f.tar
glibc-02eec681676c5aabf2eb13b92b1124245d19112f.tar.gz
glibc-02eec681676c5aabf2eb13b92b1124245d19112f.tar.bz2
glibc-02eec681676c5aabf2eb13b92b1124245d19112f.zip
localedef: Add --no-warnings/--warnings option
From localedef --help: Output control: ... --no-warnings=<warnings> Comma-separated list of warnings to disable; supported warnings are: ascii, intcurrsym ... --warnings=<warnings> Comma-separated list of warnings to enable; supported warnings are: ascii, intcurrsym Locales using SHIFT_JIS and SHIFT_JISX0213 character maps are not ASCII compatible. In order to build locales using these character maps, and have localedef exit with a status of 0, we add new option to localedef to disable or enable specific warnings. The options are --no-warnings and --warnings, to disable and enable specific warnings respectively. The options take a comma-separated list of warning names. The warning names are taken directly from the generated warning. When a warning that can be disabled is issued it will print something like this: foo is not defined [--no-warnings=foo] For the initial implementation we add two controllable warnings; first 'ascii' which is used by the localedata installation makefile target to install SHIFT_JIS and SHIFT_JISX0213-using locales without error; second 'intcurrsym' which allows a program to use a non-standard international currency symbol without triggering a warning. The 'intcurrsym' is useful in the future if country codes are added that are not in our current ISO 4217 list, and the user wants to avoid the warning. Having at least two warnings to control gives an example for how the changes can be extended to more warnings if required in the future. These changes allow ja_JP.SHIFT_JIS and ja_JP.SHIFT_JISX0213 to be compiled without warnings using --no-warnings=ascii. The localedata/Makefile $(INSTALL-SUPPORTED-LOCALES) target is adjusted to automatically add `--no-warnings=ascii` for such charmaps, and likewise localedata/gen-locale.sh is adjusted with similar logic. v2: Bring verbose, be_quiet, and all warning control booleans into record-status.c, and compile this object file to be used by locale, iconv, and localedef. Any users include record-status.h. v3: Fix an instance of boolean coercion in set_warning(). Signed-off-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'locale/programs/localedef.c')
-rw-r--r--locale/programs/localedef.c67
1 files changed, 55 insertions, 12 deletions
diff --git a/locale/programs/localedef.c b/locale/programs/localedef.c
index 7d76154228..973bb55c1f 100644
--- a/locale/programs/localedef.c
+++ b/locale/programs/localedef.c
@@ -32,6 +32,7 @@
#include <error.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <ctype.h>
#include "localedef.h"
#include "charmap.h"
@@ -48,18 +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;
-
-/* Warnings recorded by record_warnings (see localedef.h). */
-int recorded_warning_count;
-
-/* Errors recorded by record_error (see localedef.h). */
-int recorded_error_count;
-
-/* If not zero suppress warnings and information messages. */
-int be_quiet;
-
/* If not zero force output even if warning were issued. */
static int force_output;
@@ -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[] =
@@ -134,6 +125,13 @@ static const struct argp_option options[] =
{ "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") },
@@ -309,6 +307,43 @@ no output file produced because errors were issued"));
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
@@ -346,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;