|
| 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 |
0 commit comments