From: Benno Schulenberg Date: Wed, 28 May 2025 09:37:01 +0000 (+0200) Subject: lib/colors: call gettext() only when the argument of --color is invalid X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=42b60bce24536266869e512e43ad5be460dad399;p=thirdparty%2Futil-linux.git lib/colors: call gettext() only when the argument of --color is invalid 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 --- diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index fdd74fbf9..e4e16001e 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -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; diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index 6493e2767..727178da4 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -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; diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 41b5558ea..7f2f3deea 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -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; diff --git a/include/colors.h b/include/colors.h index 770161ae0..c02f61a57 100644 --- a/include/colors.h +++ b/include/colors.h @@ -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); diff --git a/lib/colors.c b/lib/colors.c index 4852a87cc..47d69cabc 100644 --- a/lib/colors.c +++ b/lib/colors.c @@ -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; diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 8c0eb3638..09622165a 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -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); diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 8dcf67c94..6584613c7 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -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; diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c index 36744554e..60bf6f94b 100644 --- a/text-utils/hexdump.c +++ b/text-utils/hexdump.c @@ -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"));