commit: 7c8f67102e9e013ecb85d60feb3a5969717a2f1b
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Jan 8 03:47:21 2026 +0000
Commit: Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Thu Jan 8 03:49:18 2026 +0000
URL: https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=7c8f6710
Tidy up the UTF8 warning code in parse_config()
Presently, the parse_config() subroutine issues warnings where either
field contains "UTF8" (because it is a misnomer). Tidy the code up a
little by introducing a helper routine to issue such warnings.
The resulting diagnostics are more consistent. The term, charmap, is
consistently used, which better aligns with the language of the revised
locale.gen(5) man page. Also, the offending field number is mentioned.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
locale-gen | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/locale-gen b/locale-gen
index a3d718e..d79d3a8 100644
--- a/locale-gen
+++ b/locale-gen
@@ -355,6 +355,13 @@ sub parse_config ($fh, $path, $supported_by, $be_strict) {
}
};
+ # Set up a helper routine to issue warnings regarding the UTF8 misnomer.
+ my $utf8_warner = sub ($i) {
+ print_warning(sprintf
+ 'WARNING! Charmap specified as UTF8 in field #%d
(should be UTF-8) at %s[%d]: %s',
+ $i, $path, $., render_printable($line));
+ };
+
# Select an appropriate adjective for errors of validation.
my $adjective = $be_strict ? 'Invalid' : 'Unsupported';
@@ -382,22 +389,12 @@ sub parse_config ($fh, $path, $supported_by, $be_strict) {
# Handle "UTF8" as a special case. Though glibc tolerates it,
# locale-gen would otherwise not because there is no charmap
- # file by that name. The intention is to encourage users to
- # amend their config files before eventually dropping support
- # for "UTF8" altogether.
- my @warnings;
+ # file by that name. This code will eventually be removed.
if ($locale =~ s/\.UTF\K8(?=@|\z)/-8/) {
- push @warnings,
- sprintf "Codeset specified as UTF8 (should be
UTF-8) at %s[%d]: %s",
- $path, $., render_printable($line);
+ $utf8_warner->(1);
}
if ($charmap =~ s/^UTF\K8\z/-8/) {
- push @warnings,
- sprintf "Charmap specified as UTF8 (should be
UTF-8) at %s[%d]: %s",
- $path, $., render_printable($line);
- }
- for my $warning (@warnings) {
- print_warning("WARNING! $warning\n");
+ $utf8_warner->(2);
}
# Validate both locale and character map before accepting.