diff options
author | Carlos O'Donell <carlos@systemhalted.org> | 2017-10-13 09:54:03 -0700 |
---|---|---|
committer | Carlos O'Donell <carlos@systemhalted.org> | 2017-10-13 22:30:18 -0700 |
commit | f16491eb8ebbef402f3da6f4035ce70fe36dec97 (patch) | |
tree | 686168ada3db669666f891e44158e8a092cc2bd7 /locale/programs/ld-monetary.c | |
parent | 8dc8be75d2afb7ebaf55f7609b301e5c6b8692e5 (diff) |
locale: Fix localedef exit code (Bug 22292)
The error and warning handling in localedef, locale, and iconv
is a bit of a mess.
We use ugly constructs like this:
WITH_CUR_LOCALE (error (1, errno, gettext ("\
cannot read character map directory `%s'"), directory));
to issue errors, and read error_message_count directly from the
error API to detect errors. The problem with that is that the
code also uses error to print warnings, and informative messages.
All of this leads to problems where just having warnings will
produce an exit status as-if errors had been seen.
To fix this situation I have adopted the following high-level
changes:
* All errors are counted distinctly.
* All warnings are counted distinctly.
* All informative messages are not counted.
* Increasing verbosity cannot generate *more* errors, and
it previously did for errors conditional on verbose,
this is now fixed.
* Increasing verbosity *can* generate *more* warnings.
* Making the output quiet cannot generate *fewer* errors,
and it previously did for errors conditional on be_quiet,
this is now fixed.
* Each of error, warning, and informative message has it's
own function to call defined in record-status.h, and they
are: record_error, record_warning, and record_verbose.
* The record_error function always records an error, but
conditional on be_quiet may not print it.
* The record_warning function always records a warning,
but conditional on be_quiet may not print it.
* The record_verbose function only prints the verbose
message if verbose is true and be_quiet is false.
This has allowed the following fix:
* Previously any warnings were being treated as errors
because they incremented error_message_count, but now
we properly return an exit status of 1 if there are
warnings but output was generated.
All of this allows localedef to correctly decide if errors,
or warnings were present, and produce the correct exit code.
The locale and iconv programs now also use record-status.h
and we have removed the WITH_CUR_LOCALE hack, and instead
have internal push_locale/pop_locale functions centralized
in the record routines.
Signed-off-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'locale/programs/ld-monetary.c')
-rw-r--r-- | locale/programs/ld-monetary.c | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/locale/programs/ld-monetary.c b/locale/programs/ld-monetary.c index cd50541603..35d17490cb 100644 --- a/locale/programs/ld-monetary.c +++ b/locale/programs/ld-monetary.c @@ -185,13 +185,12 @@ monetary_finish (struct localedef_t *locale, const struct charmap_t *charmap) = from->categories[LC_MONETARY].monetary; } - /* If there is still no definition issue an warning and create an + /* If there is still no definition issue a warning and create an empty one. */ if (monetary == NULL) { - if (! be_quiet) - WITH_CUR_LOCALE (error (0, 0, _("\ -No definition for %s category found"), "LC_MONETARY")); + record_warning (_("\ +No definition for %s category found"), "LC_MONETARY"); monetary_startup (NULL, locale, 0); monetary = locale->categories[LC_MONETARY].monetary; nothing = 1; @@ -201,9 +200,9 @@ No definition for %s category found"), "LC_MONETARY")); #define TEST_ELEM(cat, initval) \ if (monetary->cat == NULL) \ { \ - if (! be_quiet && ! nothing) \ - WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \ - "LC_MONETARY", #cat)); \ + if (! nothing) \ + record_error (0, 0, _("%s: field `%s' not defined"), \ + "LC_MONETARY", #cat); \ monetary->cat = initval; \ } @@ -219,10 +218,10 @@ No definition for %s category found"), "LC_MONETARY")); { if (strlen (monetary->int_curr_symbol) != 4) { - if (! be_quiet && ! nothing) - WITH_CUR_LOCALE (error (0, 0, _("\ + if (! nothing) + record_error (0, 0, _("\ %s: value of field `int_curr_symbol' has wrong length"), - "LC_MONETARY")); + "LC_MONETARY"); } else { /* Check the first three characters against ISO 4217 */ @@ -231,12 +230,11 @@ No definition for %s category found"), "LC_MONETARY")); symbol[3] = '\0'; if (bsearch (symbol, valid_int_curr, NR_VALID_INT_CURR, sizeof (const char *), - (comparison_fn_t) curr_strcmp) == NULL - && !be_quiet) - WITH_CUR_LOCALE (error (0, 0, _("\ + (comparison_fn_t) curr_strcmp) == NULL) + record_warning (_("\ %s: value of field `int_curr_symbol' does \ not correspond to a valid name in ISO 4217"), - "LC_MONETARY")); + "LC_MONETARY"); } } @@ -245,25 +243,25 @@ not correspond to a valid name in ISO 4217"), != "". */ if (monetary->mon_decimal_point == NULL) { - if (! be_quiet && ! nothing) - WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), - "LC_MONETARY", "mon_decimal_point")); + if (! nothing) + record_error (0, 0, _("%s: field `%s' not defined"), + "LC_MONETARY", "mon_decimal_point"); monetary->mon_decimal_point = "."; } else if (monetary->mon_decimal_point[0] == '\0' && ! be_quiet && ! nothing) { - WITH_CUR_LOCALE (error (0, 0, _("\ + record_error (0, 0, _("\ %s: value for field `%s' must not be an empty string"), - "LC_MONETARY", "mon_decimal_point")); + "LC_MONETARY", "mon_decimal_point"); } if (monetary->mon_decimal_point_wc == L'\0') monetary->mon_decimal_point_wc = L'.'; if (monetary->mon_grouping_len == 0) { - if (! be_quiet && ! nothing) - WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), - "LC_MONETARY", "mon_grouping")); + if (! nothing) + record_error (0, 0, _("%s: field `%s' not defined"), + "LC_MONETARY", "mon_grouping"); monetary->mon_grouping = (char *) "\177"; monetary->mon_grouping_len = 1; @@ -273,17 +271,17 @@ not correspond to a valid name in ISO 4217"), #define TEST_ELEM(cat, min, max, initval) \ if (monetary->cat == -2) \ { \ - if (! be_quiet && ! nothing) \ - WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \ - "LC_MONETARY", #cat)); \ + if (! nothing) \ + record_error (0, 0, _("%s: field `%s' not defined"), \ + "LC_MONETARY", #cat); \ monetary->cat = initval; \ } \ else if ((monetary->cat < min || monetary->cat > max) \ && min < max \ && !be_quiet && !nothing) \ - WITH_CUR_LOCALE (error (0, 0, _("\ + record_error (0, 0, _("\ %s: value for field `%s' must be in range %d...%d"), \ - "LC_MONETARY", #cat, min, max)) + "LC_MONETARY", #cat, min, max) TEST_ELEM (int_frac_digits, 1, 0, -1); TEST_ELEM (frac_digits, 1, 0, -1); @@ -309,11 +307,10 @@ not correspond to a valid name in ISO 4217"), #define TEST_ELEM(cat, alt, min, max) \ if (monetary->cat == -2) \ monetary->cat = monetary->alt; \ - else if ((monetary->cat < min || monetary->cat > max) && !be_quiet \ - && ! nothing) \ - WITH_CUR_LOCALE (error (0, 0, _("\ + else if ((monetary->cat < min || monetary->cat > max) && ! nothing) \ + record_error (0, 0, _("\ %s: value for field `%s' must be in range %d...%d"), \ - "LC_MONETARY", #cat, min, max)) + "LC_MONETARY", #cat, min, max) TEST_ELEM (int_p_cs_precedes, p_cs_precedes, -1, 1); TEST_ELEM (int_p_sep_by_space, p_sep_by_space, -1, 2); |