use strict;
use warnings;
require 'regen/regen_lib.pl';
+require 'regen/charset_translations.pl';
use charnames qw(:loose);
my $out_fh = open_new('unicode_constants.h', '>',
- {style => '*', by => $0,
+ {style => '*', by => $0,
from => "Unicode data"});
print $out_fh <<END;
# of UTF-8, and to generate proper EBCDIC as well as ASCII without manually
# having to figure things out.
-while ( <DATA> ) {
+my @data = <DATA>;
+
+foreach my $charset (get_supported_code_pages()) {
+ print $out_fh "\n" . get_conditional_compile_line_start($charset);
+
+ my @a2n = get_a2n($charset);
+
+for ( @data ) {
chomp;
# Convert any '#' comments to /* ... */; empty lines and comments are
die "Unknown code point '$name_or_cp' at line $.: $_\n" unless $undef_ok;
$name = "";
}
- $cp = utf8::unicode_to_native($U_cp);
}
else {
$name = $name_or_cp;
- $cp = charnames::vianame($name =~ s/_/ /gr);
- $U_cp = utf8::native_to_unicode($cp);
die "Unknown name '$name' at line $.: $_\n" unless defined $name;
+ $U_cp = charnames::vianame($name =~ s/_/ /gr);
}
+ $cp = ($U_cp < 256)
+ ? $a2n[$U_cp]
+ : $U_cp;
+
$name = $desired_name if $name eq "" && $desired_name;
$name =~ s/[- ]/_/g; # The macro name can have no blanks nor dashes
$str = sprintf "0x%02X", $cp; # Is a numeric constant
}
else {
- $str = join "", map { sprintf "\\x%02X", $_ }
- unpack("U0C*", pack("U", $cp));
+ $str = join "", map { sprintf "\\x%02X", ord $_ } split //, cp_2_utfbytes($U_cp, $charset);
$suffix = '_UTF8';
if (! defined $flag || $flag =~ /^ string (_skip_if_undef)? $/x) {
die "Unknown flag at line $.: $_\n";
}
}
- printf $out_fh "#define %s%s %s /* U+%04X */\n", $name, $suffix, $str, $U_cp;
+ printf $out_fh "# define %s%s %s /* U+%04X */\n", $name, $suffix, $str, $U_cp;
+}
+ print $out_fh "\n" . get_conditional_compile_line_end();
}
print $out_fh "\n#endif /* H_UNICODE_CONSTANTS */\n";
* "_TAIL" if instead it represents all but the first byte. This, and
* with no additional suffix are both string constants */
-#define LATIN_SMALL_LETTER_LONG_S_UTF8 "\xC5\xBF" /* U+017F */
-#define COMBINING_GRAVE_ACCENT_UTF8 "\xCC\x80" /* U+0300 */
+#if 'A' == 65 /* ASCII/Latin1 */
+# define LATIN_SMALL_LETTER_LONG_S_UTF8 "\xC5\xBF" /* U+017F */
-#define GREEK_CAPITAL_LETTER_IOTA_UTF8 "\xCE\x99" /* U+0399 */
-#define GREEK_SMALL_LETTER_MU_UTF8 "\xCE\xBC" /* U+03BC */
+# define COMBINING_GRAVE_ACCENT_UTF8 "\xCC\x80" /* U+0300 */
-#define LATIN_CAPITAL_LETTER_SHARP_S_UTF8 "\xE1\xBA\x9E" /* U+1E9E */
+# define GREEK_CAPITAL_LETTER_IOTA_UTF8 "\xCE\x99" /* U+0399 */
+# define GREEK_SMALL_LETTER_MU_UTF8 "\xCE\xBC" /* U+03BC */
-#define LATIN_SMALL_LIGATURE_LONG_S_T_UTF8 "\xEF\xAC\x85" /* U+FB05 */
-#define LATIN_SMALL_LIGATURE_ST_UTF8 "\xEF\xAC\x86" /* U+FB06 */
+# define LATIN_CAPITAL_LETTER_SHARP_S_UTF8 "\xE1\xBA\x9E" /* U+1E9E */
-#define HYPHEN_UTF8 "\xE2\x80\x90" /* U+2010 */
-#define FIRST_SURROGATE_UTF8_FIRST_BYTE 0xED /* U+D800 */
-#define BOM_UTF8_FIRST_BYTE 0xEF /* U+FEFF */
-#define BOM_UTF8_TAIL "\xBB\xBF" /* U+FEFF */
+# define LATIN_SMALL_LIGATURE_LONG_S_T_UTF8 "\xEF\xAC\x85" /* U+FB05 */
+# define LATIN_SMALL_LIGATURE_ST_UTF8 "\xEF\xAC\x86" /* U+FB06 */
-#define NBSP_NATIVE 0xA0 /* U+00A0 */
-#define NBSP_UTF8 "\xC2\xA0" /* U+00A0 */
+# define HYPHEN_UTF8 "\xE2\x80\x90" /* U+2010 */
+# define FIRST_SURROGATE_UTF8_FIRST_BYTE 0xED /* U+D800 */
+# define BOM_UTF8_FIRST_BYTE 0xEF /* U+FEFF */
+# define BOM_UTF8_TAIL "\xBB\xBF" /* U+FEFF */
-#define DEL_NATIVE 0x7F /* U+007F */
-#define CR_NATIVE 0x0D /* U+000D */
-#define LF_NATIVE 0x0A /* U+000A */
-#define LATIN_SMALL_LETTER_SHARP_S_NATIVE 0xDF /* U+00DF */
-#define LATIN_SMALL_LETTER_A_WITH_RING_ABOVE_NATIVE 0xE5 /* U+00E5 */
-#define LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE_NATIVE 0xC5 /* U+00C5 */
-#define LATIN_SMALL_LETTER_Y_WITH_DIAERESIS_NATIVE 0xFF /* U+00FF */
-#define MICRO_SIGN_NATIVE 0xB5 /* U+00B5 */
+# define NBSP_NATIVE 0xA0 /* U+00A0 */
+# define NBSP_UTF8 "\xC2\xA0" /* U+00A0 */
+
+# define DEL_NATIVE 0x7F /* U+007F */
+# define CR_NATIVE 0x0D /* U+000D */
+# define LF_NATIVE 0x0A /* U+000A */
+# define LATIN_SMALL_LETTER_SHARP_S_NATIVE 0xDF /* U+00DF */
+# define LATIN_SMALL_LETTER_A_WITH_RING_ABOVE_NATIVE 0xE5 /* U+00E5 */
+# define LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE_NATIVE 0xC5 /* U+00C5 */
+# define LATIN_SMALL_LETTER_Y_WITH_DIAERESIS_NATIVE 0xFF /* U+00FF */
+# define MICRO_SIGN_NATIVE 0xB5 /* U+00B5 */
+
+#endif /* ASCII/Latin1 */
+
+#if 'A' == 193 /* EBCDIC 1047 */ \
+ && '\\' == 224 && '[' == 173 && ']' == 189 && '{' == 192 && '}' == 208 \
+ && '^' == 95 && '~' == 161 && '!' == 90 && '#' == 123 && '|' == 79 \
+ && '$' == 91 && '@' == 124 && '`' == 121
+# define LATIN_SMALL_LETTER_LONG_S_UTF8 "\x8F\x73" /* U+017F */
+
+# define COMBINING_GRAVE_ACCENT_UTF8 "\xAF\x41" /* U+0300 */
+
+# define GREEK_CAPITAL_LETTER_IOTA_UTF8 "\xB3\x68" /* U+0399 */
+# define GREEK_SMALL_LETTER_MU_UTF8 "\xB4\x70" /* U+03BC */
+
+# define LATIN_CAPITAL_LETTER_SHARP_S_UTF8 "\xBF\x63\x72" /* U+1E9E */
+
+# define LATIN_SMALL_LIGATURE_LONG_S_T_UTF8 "\xDD\x72\x67\x46" /* U+FB05 */
+# define LATIN_SMALL_LIGATURE_ST_UTF8 "\xDD\x72\x67\x47" /* U+FB06 */
+
+# define HYPHEN_UTF8 "\xCA\x41\x57" /* U+2010 */
+# define FIRST_SURROGATE_UTF8_FIRST_BYTE 0xDD /* U+D800 */
+# define BOM_UTF8_FIRST_BYTE 0xDD /* U+FEFF */
+# define BOM_UTF8_TAIL "\x73\x66\x73" /* U+FEFF */
+
+# define NBSP_NATIVE 0x41 /* U+00A0 */
+# define NBSP_UTF8 "\x80\x41" /* U+00A0 */
+
+# define DEL_NATIVE 0x07 /* U+007F */
+# define CR_NATIVE 0x0D /* U+000D */
+# define LF_NATIVE 0x15 /* U+000A */
+# define LATIN_SMALL_LETTER_SHARP_S_NATIVE 0x59 /* U+00DF */
+# define LATIN_SMALL_LETTER_A_WITH_RING_ABOVE_NATIVE 0x47 /* U+00E5 */
+# define LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE_NATIVE 0x67 /* U+00C5 */
+# define LATIN_SMALL_LETTER_Y_WITH_DIAERESIS_NATIVE 0xDF /* U+00FF */
+# define MICRO_SIGN_NATIVE 0xA0 /* U+00B5 */
+
+#endif /* EBCDIC 1047 */
+
+#if 'A' == 193 /* EBCDIC 037 */ \
+ && '\\' == 224 && '[' == 186 && ']' == 187 && '{' == 192 && '}' == 208 \
+ && '^' == 176 && '~' == 161 && '!' == 90 && '#' == 123 && '|' == 79 \
+ && '$' == 91 && '@' == 124 && '`' == 121
+# define LATIN_SMALL_LETTER_LONG_S_UTF8 "\x8E\x72" /* U+017F */
+
+# define COMBINING_GRAVE_ACCENT_UTF8 "\xAD\x41" /* U+0300 */
+
+# define GREEK_CAPITAL_LETTER_IOTA_UTF8 "\xB2\x67" /* U+0399 */
+# define GREEK_SMALL_LETTER_MU_UTF8 "\xB3\x6A" /* U+03BC */
+
+# define LATIN_CAPITAL_LETTER_SHARP_S_UTF8 "\xBF\x62\x71" /* U+1E9E */
+
+# define LATIN_SMALL_LIGATURE_LONG_S_T_UTF8 "\xDD\x71\x66\x46" /* U+FB05 */
+# define LATIN_SMALL_LIGATURE_ST_UTF8 "\xDD\x71\x66\x47" /* U+FB06 */
+
+# define HYPHEN_UTF8 "\xCA\x41\x57" /* U+2010 */
+# define FIRST_SURROGATE_UTF8_FIRST_BYTE 0xDD /* U+D800 */
+# define BOM_UTF8_FIRST_BYTE 0xDD /* U+FEFF */
+# define BOM_UTF8_TAIL "\x72\x65\x72" /* U+FEFF */
+
+# define NBSP_NATIVE 0x41 /* U+00A0 */
+# define NBSP_UTF8 "\x78\x41" /* U+00A0 */
+
+# define DEL_NATIVE 0x07 /* U+007F */
+# define CR_NATIVE 0x0D /* U+000D */
+# define LF_NATIVE 0x25 /* U+000A */
+# define LATIN_SMALL_LETTER_SHARP_S_NATIVE 0x59 /* U+00DF */
+# define LATIN_SMALL_LETTER_A_WITH_RING_ABOVE_NATIVE 0x47 /* U+00E5 */
+# define LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE_NATIVE 0x67 /* U+00C5 */
+# define LATIN_SMALL_LETTER_Y_WITH_DIAERESIS_NATIVE 0xDF /* U+00FF */
+# define MICRO_SIGN_NATIVE 0xA0 /* U+00B5 */
+
+#endif /* EBCDIC 037 */
+
+#if 'A' == 193 /* EBCDIC POSIX-BC */ \
+ && '\\' == 188 && '[' == 187 && ']' == 189 && '{' == 251 && '}' == 253 \
+ && '^' == 106 && '~' == 255 && '!' == 90 && '#' == 123 && '|' == 79 \
+ && '$' == 91 && '@' == 124 && '`' == 74
+# define LATIN_SMALL_LETTER_LONG_S_UTF8 "\x90\x75" /* U+017F */
+
+# define COMBINING_GRAVE_ACCENT_UTF8 "\xAE\x41" /* U+0300 */
+
+# define GREEK_CAPITAL_LETTER_IOTA_UTF8 "\xB2\x69" /* U+0399 */
+# define GREEK_SMALL_LETTER_MU_UTF8 "\xB3\x72" /* U+03BC */
+
+# define LATIN_CAPITAL_LETTER_SHARP_S_UTF8 "\xC0\x64\x74" /* U+1E9E */
+
+# define LATIN_SMALL_LIGATURE_LONG_S_T_UTF8 "\xDC\x74\x68\x46" /* U+FB05 */
+# define LATIN_SMALL_LIGATURE_ST_UTF8 "\xDC\x74\x68\x47" /* U+FB06 */
+
+# define HYPHEN_UTF8 "\xCA\x41\x58" /* U+2010 */
+# define FIRST_SURROGATE_UTF8_FIRST_BYTE 0xDC /* U+D800 */
+# define BOM_UTF8_FIRST_BYTE 0xDC /* U+FEFF */
+# define BOM_UTF8_TAIL "\x75\x67\x75" /* U+FEFF */
+
+# define NBSP_NATIVE 0x41 /* U+00A0 */
+# define NBSP_UTF8 "\x8A\x41" /* U+00A0 */
+
+# define DEL_NATIVE 0x07 /* U+007F */
+# define CR_NATIVE 0x0D /* U+000D */
+# define LF_NATIVE 0x15 /* U+000A */
+# define LATIN_SMALL_LETTER_SHARP_S_NATIVE 0x59 /* U+00DF */
+# define LATIN_SMALL_LETTER_A_WITH_RING_ABOVE_NATIVE 0x47 /* U+00E5 */
+# define LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE_NATIVE 0x67 /* U+00C5 */
+# define LATIN_SMALL_LETTER_Y_WITH_DIAERESIS_NATIVE 0xDF /* U+00FF */
+# define MICRO_SIGN_NATIVE 0xA0 /* U+00B5 */
+
+#endif /* EBCDIC POSIX-BC */
#endif /* H_UNICODE_CONSTANTS */