]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/colors: call gettext() only when the argument of --color is invalid
authorBenno Schulenberg <bensberg@telfort.nl>
Wed, 28 May 2025 09:37:01 +0000 (11:37 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 29 May 2025 10:04:28 +0000 (12:04 +0200)
Instead of calling gettext() before starting to interpret the argument
of option -L/--color, call it only when it's needed: when the argument
is not recognized.

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
disk-utils/cfdisk.c
disk-utils/fdisk.c
disk-utils/sfdisk.c
include/colors.h
lib/colors.c
misc-utils/cal.c
sys-utils/dmesg.c
text-utils/hexdump.c

index fdd74fbf949804fc78373936f03993e54586b1bf..e4e16001ea9f1630b8dc7b206fdcd49edf8e1400 100644 (file)
@@ -2781,8 +2781,7 @@ int main(int argc, char *argv[])
                case 'L':
                        colormode = UL_COLORMODE_AUTO;
                        if (optarg)
-                               colormode = colormode_or_err(optarg,
-                                               _("unsupported color mode"));
+                               colormode = colormode_or_err(optarg);
                        break;
                 case 'r':
                         read_only = 1;
index 6493e27672b67843c20e9850f87502214a3d6862..727178da4ab709cb772ccbb971c065c009a5b1fa 100644 (file)
@@ -1239,8 +1239,7 @@ int main(int argc, char **argv)
                case 'L':
                        colormode = UL_COLORMODE_AUTO;
                        if (optarg)
-                               colormode = colormode_or_err(optarg,
-                                               _("unsupported color mode"));
+                               colormode = colormode_or_err(optarg);
                        break;
                case 'n':
                        noauto_pt = 1;
index 41b5558ead7e864bfdd9b6cd330e42ca03c02d97..7f2f3deea2b0fcedb2acbacb98361a7873afdee1 100644 (file)
@@ -2437,8 +2437,7 @@ int main(int argc, char *argv[])
                case OPT_COLOR:
                        colormode = UL_COLORMODE_AUTO;
                        if (optarg)
-                               colormode = colormode_or_err(optarg,
-                                               _("unsupported color mode"));
+                               colormode = colormode_or_err(optarg);
                        break;
                case OPT_MOVEDATA:
                        sf->movedata = 1;
index 770161ae07cb3c157689f46e4c69c04cfd706b4f..c02f61a570bf1e422e954d289f0427ba4beb00d9 100644 (file)
@@ -33,7 +33,7 @@ enum colortmode {
 #endif
 
 extern int colormode_from_string(const char *str);
-extern int colormode_or_err(const char *str, const char *errmsg);
+extern int colormode_or_err(const char *str);
 
 /* Initialize the global variable UL_COLOR_TERM_OK */
 extern int colors_init(int mode, const char *util_name);
index 4852a87cccb66079c0b6cb4369eedef4b7210c82..47d69cabc527f9928649c3879554786cebc7364d 100644 (file)
@@ -34,6 +34,7 @@
 #include "c.h"
 #include "cctype.h"
 #include "colors.h"
+#include "nls.h"
 #include "pathnames.h"
 #include "strutils.h"
 
@@ -755,14 +756,14 @@ int colormode_from_string(const char *str)
 /*
  * Parses @str and exit(EXIT_FAILURE) on error
  */
-int colormode_or_err(const char *str, const char *errmsg)
+int colormode_or_err(const char *str)
 {
        const char *p = str && *str == '=' ? str + 1 : str;
        int colormode;
 
        colormode = colormode_from_string(p);
        if (colormode < 0)
-               errx(EXIT_FAILURE, "%s: '%s'", errmsg, p);
+               errx(EXIT_FAILURE, _("unsupported color mode: %s"), p);
 
        return colormode;
 }
@@ -791,7 +792,7 @@ int main(int argc, char *argv[])
                        color_scheme = optarg;
                        break;
                case 'm':
-                       mode = colormode_or_err(optarg, "unsupported color mode");
+                       mode = colormode_or_err(optarg);
                        break;
                case 'n':
                        name = optarg;
index 8c0eb36384e6ba18a34e2a32417303252ab5ab5c..09622165a4d1a67bba57ffd7dac72c8c6f32d6aa 100644 (file)
@@ -421,8 +421,7 @@ int main(int argc, char **argv)
                case OPT_COLOR:
                        ctl.colormode = UL_COLORMODE_AUTO;
                        if (optarg)
-                               ctl.colormode = colormode_or_err(optarg,
-                                               _("unsupported color mode"));
+                               ctl.colormode = colormode_or_err(optarg);
                        break;
                case OPT_REFORM:
                        ctl.reform_year = parse_reform_year(optarg);
index 8dcf67c9425dfb870a95b8e2ee22dd84f86325b1..6584613c772164fd6d7e6464a00c149db62610b3 100644 (file)
@@ -1756,8 +1756,7 @@ int main(int argc, char *argv[])
                case 'L':
                        colormode = UL_COLORMODE_AUTO;
                        if (optarg)
-                               colormode = colormode_or_err(optarg,
-                                               _("unsupported color mode"));
+                               colormode = colormode_or_err(optarg);
                        break;
                case 'l':
                        ctl.fltr_lev= 1;
index 36744554edf2972c12c27e2c5d67a9d38c4339b5..60bf6f94ba9487fe1add4336993ebe74992e624f 100644 (file)
@@ -115,8 +115,7 @@ parse_args(int argc, char **argv, struct hexdump *hex)
                case 'L':
                        colormode = UL_COLORMODE_AUTO;
                        if (optarg)
-                               colormode = colormode_or_err(optarg,
-                                               _("unsupported color mode"));
+                               colormode = colormode_or_err(optarg);
                         break;
                case 'n':
                        hex->length = strtosize_or_err(optarg, _("failed to parse length"));