diff --git a/MANIFEST b/MANIFEST index 23e55126f355..7759b182f086 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5917,6 +5917,7 @@ regen/genpacksizetables.pl Generate the size tables for pack/unpack regen/HeaderParser.pm Module used to parse header files regen/keywords.pl Program to write keywords.h regen/lib_cleanup.pl Generate lib/.gitignore from MANIFEST +regen/locale.pl Program to write locale_table.h regen/mg_vtable.pl generate mg_vtable.h regen/miniperlmain.pl generate miniperlmain.c regen/mk_invlists.pl Generates charclass_invlists.h diff --git a/Makefile.SH b/Makefile.SH index 0833a1b9971c..d5206fdc33af 100755 --- a/Makefile.SH +++ b/Makefile.SH @@ -1262,6 +1262,7 @@ CHMOD_W = chmod +w # regcomp.pl: regnodes.h # warnings.pl: warnings.h lib/warnings.pm # feature.pl: feature.h lib/feature.pm +# locale.pl: locale_table.h # The correct versions should be already supplied with the perl kit, # in case you don't have perl available. # To force them to be regenerated, run diff --git a/locale_table.h b/locale_table.h index 326009956bb7..7c50b69119ce 100644 --- a/locale_table.h +++ b/locale_table.h @@ -1,11 +1,18 @@ -/* locale_entry.h +/* -*- mode: C; buffer-read-only: t -*- * - * Copyright (C) 2023 by Larry Wall and others + * locale_table.h + * + * Copyright (C) 2023, 2024 by Larry Wall and others * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. * - * This defines a macro for each individual locale category used on the this + * !!!!!!! DO NOT EDIT THIS FILE !!!!!!! + * This file is built by regen/locale.pl from data in regen/locale.pl. + * Any changes made here will be lost! + */ + +/* This defines a macro for each individual locale category used on the this * system. (The congomerate category LC_ALL is not included.) This * file will be #included as the interior of various parallel arrays and in * other constructs; each usage will re-#define the macro to generate its @@ -203,3 +210,5 @@ # define USE_LOCALE_TOD # endif #endif + +/* ex: set ro ft=c: */ diff --git a/regen.pl b/regen.pl index 5ea59e0f5ca7..31299b90c65c 100644 --- a/regen.pl +++ b/regen.pl @@ -33,3 +33,4 @@ scope_types.pl tidy_embed.pl warnings.pl +locale.pl diff --git a/regen/locale.pl b/regen/locale.pl new file mode 100644 index 000000000000..70676dac7693 --- /dev/null +++ b/regen/locale.pl @@ -0,0 +1,123 @@ +#!/usr/bin/perl -w +# +# Regenerate (overwriting only if changed): +# +# locale_table.h +# +# Also accepts the standard regen_lib -q and -v args. +# +# This script is normally invoked from regen.pl. + +BEGIN { + require './regen/regen_lib.pl'; +} + +use strict; +use warnings; + +sub open_print_header { + my ($file, $quote) = @_; + return open_new($file, '>', + { by => 'regen/locale.pl', + from => 'data in regen/locale.pl', + file => $file, style => '*', + copyright => [2023..2024], + quote => $quote }); +} + +my $l = open_print_header('locale_table.h'); +print $l < < " || ! defined(HAS_STRXFRM)", + ); + + +while () { # Read in the categories + chomp; + my ($name, $function) = split /\s*\|\s*/, $_; + + my $macro_arg = $function ? $function : "NULL"; + my $macro_with_func = "PERL_LOCALE_TABLE_ENTRY($name, $macro_arg)"; + my $macro_sans_func = "PERL_LOCALE_TABLE_ENTRY($name, NULL)"; + my ($common_macro, $macro_if_name, $macro_unless_name); + if ($macro_with_func eq $macro_sans_func) { + $common_macro = $macro_with_func; + $macro_if_name = ""; + $macro_unless_name = ""; + } + else { + $common_macro = ""; + $macro_if_name = $macro_with_func; + $macro_unless_name = $macro_sans_func; + } + + print $l "#ifdef LC_${name}\n"; + print $l $comment{$name} if defined $comment{$name}; + print $l "\n $common_macro\n\n" if $common_macro; + + my $extra = ""; + $extra = $extra_conditional{$name} if defined $extra_conditional{$name}; + print $l "# if defined(NO_LOCALE) || defined(NO_LOCALE_${name})$extra\n"; + + print $l "\n $macro_unless_name\n\n" if $macro_unless_name; + print $l <<~EOF; + # define HAS_IGNORED_LOCALE_CATEGORIES_ + # define LC_${name}_AVAIL_ 0 + # else + EOF + print $l "\n $macro_if_name\n\n" if $macro_if_name; + print $l <<~EOF; + # define LC_${name}_AVAIL_ 1 + # define USE_LOCALE_${name} + # endif + #endif + EOF +} + +close DATA; + +read_only_bottom_close_and_rename($l); + +# category | update function +__DATA__ +CTYPE | S_new_ctype +NUMERIC | S_new_numeric +COLLATE | S_new_collate +TIME +MESSAGES +MONETARY +ADDRESS +IDENTIFICATION +MEASUREMENT +PAPER +TELEPHONE +NAME +SYNTAX +TOD diff --git a/t/porting/regen.t b/t/porting/regen.t index f6eb24743b9b..e5c8bcad8470 100644 --- a/t/porting/regen.t +++ b/t/porting/regen.t @@ -27,7 +27,7 @@ if ( $Config{usecrosscompile} ) { skip_all( "Not all files are available during cross-compilation" ); } -my $tests = 27; # I can't see a clean way to calculate this automatically. +my $tests = 28; # I can't see a clean way to calculate this automatically. my %skip = ("regen_perly.pl" => [qw(perly.act perly.h perly.tab)], "regen/keywords.pl" => [qw(keywords.c keywords.h)],