]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - locale/programs/ld-monetary.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / locale / programs / ld-monetary.c
index c88275f1cc85600736d948794c0bf1350af4ca7e..0a7a6b5d1cceb49a7efb145fb663ddeb83127252 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-2013 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
 
@@ -13,7 +13,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, see <http://www.gnu.org/licenses/>.  */
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -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;                                               \
     }
 
@@ -217,26 +216,36 @@ No definition for %s category found"), "LC_MONETARY"));
   /* The international currency symbol must come from ISO 4217.  */
   if (monetary->int_curr_symbol != NULL)
     {
-      if (strlen (monetary->int_curr_symbol) != 4)
+      /* POSIX says this should be a 3-character symbol from ISO 4217
+        along with a 4th character that is a divider, but the POSIX
+        locale is documented as having a special case of "", and we
+        support that also, so allow other locales to be created with
+        a blank int_curr_symbol.  */
+      int ics_len = strlen (monetary->int_curr_symbol);
+      if (ics_len != 4 && ics_len != 0)
        {
-         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
+      else if (ics_len == 4)
        { /* Check the first three characters against ISO 4217 */
          char symbol[4];
          strncpy (symbol, monetary->int_curr_symbol, 3);
          symbol[3] = '\0';
+         /* A user may disable this waning for testing purposes or
+            for building a locale with a 3 letter country code that
+            was not yet supported in our ISO 4217 list.
+            See the use of --no-warnings=intcurrsym.  */
          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, _("\
+             && warn_int_curr_symbol)
+           record_warning (_("\
 %s: value of field `int_curr_symbol' does \
-not correspond to a valid name in ISO 4217"),
-                               "LC_MONETARY"));
+not correspond to a valid name in ISO 4217 [--no-warnings=intcurrsym]"),
+                           "LC_MONETARY");
        }
     }
 
@@ -245,25 +254,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 +282,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 +318,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);