Skip to content

Commit 4110b0c

Browse files
committed
Automatically regenerate locale_table.h
I got tired of editing each entry when something new comes along. Doing this opens up new possibilities of simplification, but this commit tries to keep the generated header as close to the original as possible.
1 parent 975f9cc commit 4110b0c

File tree

6 files changed

+139
-4
lines changed

6 files changed

+139
-4
lines changed

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -5917,6 +5917,7 @@ regen/genpacksizetables.pl Generate the size tables for pack/unpack
59175917
regen/HeaderParser.pm Module used to parse header files
59185918
regen/keywords.pl Program to write keywords.h
59195919
regen/lib_cleanup.pl Generate lib/.gitignore from MANIFEST
5920+
regen/locale.pl Program to write locale_table.h
59205921
regen/mg_vtable.pl generate mg_vtable.h
59215922
regen/miniperlmain.pl generate miniperlmain.c
59225923
regen/mk_invlists.pl Generates charclass_invlists.h

Makefile.SH

+1
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,7 @@ CHMOD_W = chmod +w
12621262
# regcomp.pl: regnodes.h
12631263
# warnings.pl: warnings.h lib/warnings.pm
12641264
# feature.pl: feature.h lib/feature.pm
1265+
# locale.pl: locale_table.h
12651266
# The correct versions should be already supplied with the perl kit,
12661267
# in case you don't have perl available.
12671268
# To force them to be regenerated, run

locale_table.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
/* locale_entry.h
1+
/* -*- mode: C; buffer-read-only: t -*-
22
*
3-
* Copyright (C) 2023 by Larry Wall and others
3+
* locale_table.h
4+
*
5+
* Copyright (C) 2023, 2024 by Larry Wall and others
46
*
57
* You may distribute under the terms of either the GNU General Public
68
* License or the Artistic License, as specified in the README file.
79
*
8-
* This defines a macro for each individual locale category used on the this
10+
* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
11+
* This file is built by regen/locale.pl from data in regen/locale.pl.
12+
* Any changes made here will be lost!
13+
*/
14+
15+
/* This defines a macro for each individual locale category used on the this
916
* system. (The congomerate category LC_ALL is not included.) This
1017
* file will be #included as the interior of various parallel arrays and in
1118
* other constructs; each usage will re-#define the macro to generate its
@@ -203,3 +210,5 @@
203210
# define USE_LOCALE_TOD
204211
# endif
205212
#endif
213+
214+
/* ex: set ro ft=c: */

regen.pl

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
scope_types.pl
3434
tidy_embed.pl
3535
warnings.pl
36+
locale.pl

regen/locale.pl

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/perl -w
2+
#
3+
# Regenerate (overwriting only if changed):
4+
#
5+
# locale_table.h
6+
#
7+
# Also accepts the standard regen_lib -q and -v args.
8+
#
9+
# This script is normally invoked from regen.pl.
10+
11+
BEGIN {
12+
require './regen/regen_lib.pl';
13+
}
14+
15+
use strict;
16+
use warnings;
17+
18+
sub open_print_header {
19+
my ($file, $quote) = @_;
20+
return open_new($file, '>',
21+
{ by => 'regen/locale.pl',
22+
from => 'data in regen/locale.pl',
23+
file => $file, style => '*',
24+
copyright => [2023..2024],
25+
quote => $quote });
26+
}
27+
28+
my $l = open_print_header('locale_table.h');
29+
print $l <<EOF;
30+
/* This defines a macro for each individual locale category used on the this
31+
* system. (The congomerate category LC_ALL is not included.) This
32+
* file will be #included as the interior of various parallel arrays and in
33+
* other constructs; each usage will re-#define the macro to generate its
34+
* appropriate data.
35+
*
36+
* This guarantees the arrays will be parallel, and populated in the order
37+
* given here. That order is mostly arbitrary. LC_CTYPE is first because when
38+
* we are setting multiple categories, CTYPE often needs to match the other(s),
39+
* and the way the code is constructed, if we set the other category first, we
40+
* might otherwise have to set CTYPE twice.
41+
*
42+
* Each entry takes the token giving the category name, and either the name of
43+
* a function to call that does specialized set up for this category when it is
44+
* changed into, or NULL if no such set up is needed
45+
*/
46+
47+
EOF
48+
49+
# It's not worth generalizing these further.
50+
my %comment = ( COLLATE => <<EOF
51+
52+
/* Perl outsources all its collation efforts to the libc strxfrm(), so
53+
* if it isn't available on the system, default "C" locale collation
54+
* gets used */
55+
EOF
56+
);
57+
my %extra_conditional = (
58+
COLLATE => " || ! defined(HAS_STRXFRM)",
59+
);
60+
61+
62+
while (<DATA>) { # Read in the categories
63+
chomp;
64+
my ($name, $function) = split /\s*\|\s*/, $_;
65+
66+
my $macro_arg = $function ? $function : "NULL";
67+
my $macro_with_func = "PERL_LOCALE_TABLE_ENTRY($name, $macro_arg)";
68+
my $macro_sans_func = "PERL_LOCALE_TABLE_ENTRY($name, NULL)";
69+
my ($common_macro, $macro_if_name, $macro_unless_name);
70+
if ($macro_with_func eq $macro_sans_func) {
71+
$common_macro = $macro_with_func;
72+
$macro_if_name = "";
73+
$macro_unless_name = "";
74+
}
75+
else {
76+
$common_macro = "";
77+
$macro_if_name = $macro_with_func;
78+
$macro_unless_name = $macro_sans_func;
79+
}
80+
81+
print $l "#ifdef LC_${name}\n";
82+
print $l $comment{$name} if defined $comment{$name};
83+
print $l "\n $common_macro\n\n" if $common_macro;
84+
85+
my $extra = "";
86+
$extra = $extra_conditional{$name} if defined $extra_conditional{$name};
87+
print $l "# if defined(NO_LOCALE) || defined(NO_LOCALE_${name})$extra\n";
88+
89+
print $l "\n $macro_unless_name\n\n" if $macro_unless_name;
90+
print $l <<~EOF;
91+
# define HAS_IGNORED_LOCALE_CATEGORIES_
92+
# define LC_${name}_AVAIL_ 0
93+
# else
94+
EOF
95+
print $l "\n $macro_if_name\n\n" if $macro_if_name;
96+
print $l <<~EOF;
97+
# define LC_${name}_AVAIL_ 1
98+
# define USE_LOCALE_${name}
99+
# endif
100+
#endif
101+
EOF
102+
}
103+
104+
close DATA;
105+
106+
read_only_bottom_close_and_rename($l);
107+
108+
# category | update function
109+
__DATA__
110+
CTYPE | S_new_ctype
111+
NUMERIC | S_new_numeric
112+
COLLATE | S_new_collate
113+
TIME
114+
MESSAGES
115+
MONETARY
116+
ADDRESS
117+
IDENTIFICATION
118+
MEASUREMENT
119+
PAPER
120+
TELEPHONE
121+
NAME
122+
SYNTAX
123+
TOD

t/porting/regen.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if ( $Config{usecrosscompile} ) {
2727
skip_all( "Not all files are available during cross-compilation" );
2828
}
2929

30-
my $tests = 27; # I can't see a clean way to calculate this automatically.
30+
my $tests = 28; # I can't see a clean way to calculate this automatically.
3131

3232
my %skip = ("regen_perly.pl" => [qw(perly.act perly.h perly.tab)],
3333
"regen/keywords.pl" => [qw(keywords.c keywords.h)],

0 commit comments

Comments
 (0)