4 # Convert cppucnid.tab to cppucnid.h. We use two arrays of length
5 # 65536 to represent the table, since this is nice and simple. The
6 # first array holds the tags indicating which ranges are valid in
7 # which contexts. The second array holds the language name associated
12 @names = ("") x
65536;
15 # Array mapping tag numbers to standard #defines
18 # Current standard and language
19 our($curstd, $curlang);
21 # First block of the file is a template to be saved for later.
30 # Second block of the file is the UCN tables.
31 # The format looks like this:
36 # xxxx-xxxx xxxx xxxx-xxxx ....
38 # with comment lines starting with #.
56 # Print out the template, inserting as requested.
59 print("/* Automatically generated from cppucnid.tab, do not edit */"),
60 next if $_ eq "[dne]";
61 print_table
(), next if $_ eq "[table]";
69 for ($lo = 0; $lo <= $#tags; $lo = $hi) {
71 $hi++ while $hi <= $#tags
72 && $tags[$hi] eq $tags[$lo]
73 && $names[$hi] eq $names[$lo];
75 # Range from $lo to $hi-1.
76 # Don't make entries for ranges that are not valid idchars.
77 next if ($tags[$lo] eq "");
79 $tag = " ".$tag if $tag =~ /^C99/;
81 if ($names[$lo] eq $prevname) {
82 printf(" { 0x%04x, 0x%04x, %-11s },\n",
85 printf(" { 0x%04x, 0x%04x, %-11s }, /* %s */\n",
86 $lo, $hi-1, $tag, $names[$lo]);
88 $prevname = $names[$lo];
92 # The line is a list of four-digit hexadecimal numbers or
93 # pairs of such numbers. Each is a valid identifier character
94 # from the given language, under the given standard.
97 if ($range =~ /^[0-9a-f]{4}$/) {
99 if ($tags[$i] eq "") {
102 $tags[$i] = $curstd . "|" . $tags[$i];
104 if ($names[$i] ne "" && $names[$i] ne $curlang) {
105 warn sprintf ("language overlap: %s/%s at %x (tag %d)",
106 $names[$i], $curlang, $i, $tags[$i]);
109 $names[$i] = $curlang;
110 } elsif ($range =~ /^ ([0-9a-f]{4}) - ([0-9a-f]{4}) $/x) {
111 my ($start, $end) = (hex($1), hex($2));
113 for ($i = $start; $i <= $end; $i++) {
114 if ($tags[$i] eq "") {
117 $tags[$i] = $curstd . "|" . $tags[$i];
119 if ($names[$i] ne "" && $names[$i] ne $curlang) {
120 warn sprintf ("language overlap: %s/%s at %x (tag %d)",
121 $names[$i], $curlang, $i, $tags[$i]);
124 $names[$i] = $curlang;
127 warn "malformed range expression $range";