Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | # |
| 3 | # Reads the Unicode 2.0 "unidata2.txt" file and selects encodings |
| 4 | # for case pairs, then builds an include file "casemap.h" for the |
| 5 | # case conversion routines. |
| 6 | |
| 7 | use integer |
| 8 | |
| 9 | $INFILE = "unidata2.txt"; |
| 10 | $OUT = ">casemap.h"; |
| 11 | $TEST = ">allcodes"; |
| 12 | |
| 13 | # Open the data file ... |
| 14 | open INFILE or die "Can't open input file $INFILE!\n"; |
| 15 | open OUT or die "Can't open output file $OUT!\n"; |
| 16 | open TEST or die "Can't open output file $OUT!\n"; |
| 17 | |
| 18 | #Initialize the upper and lower hashes |
| 19 | %lwrtable = (); |
| 20 | %uprtable = (); |
| 21 | @low = ("0") x 256; |
| 22 | @upr = ("0") x 256; |
| 23 | |
| 24 | while ($line = <INFILE> ) |
| 25 | { |
| 26 | # Decode the fields ... |
| 27 | ($code, $name, $cat, $comb, $bidi, |
| 28 | $decomp, $dec, $dig, $num, $mirror, |
| 29 | $oldname, $comment, $upper, $lower, $title) = split /;/, $line; |
| 30 | |
| 31 | #Get the high byte of the code |
| 32 | $high = substr $code, 0, 2; |
| 33 | if ($lower ne "") { |
| 34 | $low[hex $high] = "lblk" . $high; |
| 35 | $lwrtable{$code} = $lower; |
| 36 | } |
| 37 | if ($upper ne "") { |
| 38 | $upr[hex $high] = "ublk" . $high; |
| 39 | $uprtable{$code} = $upper; |
| 40 | } |
| 41 | #Write everything to the test file |
| 42 | printf TEST "%s %s %s\n", $code, |
| 43 | $upper ne "" ? $upper : "0000", |
| 44 | $lower ne "" ? $lower : "0000"; |
| 45 | |
| 46 | } |
| 47 | close(FILE); |
| 48 | close TEST; |
| 49 | |
| 50 | #Generate the header file |
| 51 | print OUT "/*\n"; |
| 52 | print OUT " * Automatically generated file -- do not edit!\n"; |
| 53 | print OUT " * (Use tools/unimap.pl for generation)\n"; |
| 54 | print OUT " *\n"; |
| 55 | print OUT " * Mapping tables for Unicode case conversion\n"; |
Patrik Stridvall | 857eb39 | 1999-06-12 18:36:54 +0000 | [diff] [blame] | 56 | print OUT " */\n"; |
| 57 | print OUT "\n"; |
| 58 | print OUT "#ifndef __WINE_CASEMAP_H\n"; |
| 59 | print OUT "#define __WINE_CASEMAP_H\n"; |
| 60 | print OUT "\n"; |
| 61 | print OUT "#include \"windef.h\"\n"; |
| 62 | print OUT "\n"; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 63 | |
| 64 | #Write out the non-trivial mappings |
| 65 | for ($high = 0; $high < 256; $high++) { |
| 66 | #Check whether the table is needed |
| 67 | if (length $low[$high] < 6) { |
| 68 | next; |
| 69 | } |
| 70 | printf OUT "/* Lowercase mappings %02X00 - %02XFF */\n", |
| 71 | $high, $high; |
| 72 | printf OUT "static const WCHAR lblk%02X[256] = {\n", $high; |
| 73 | for ($low = 0; $low < 256; $low += 8) { |
| 74 | @patch = (); |
| 75 | for ($i = 0; $i < 8; $i++) { |
| 76 | $code = sprintf "%02X%02X", $high, $low + $i; |
| 77 | $map = $lwrtable{$code}; |
| 78 | if ($map eq "") { |
| 79 | $map = $code; |
| 80 | } |
| 81 | $patch[$i] = "0x" . $map; |
| 82 | } |
| 83 | printf OUT "\t%s, %s, %s, %s, %s, %s, %s, %s,\n", |
| 84 | @patch; |
| 85 | } |
| 86 | print OUT "};\n\n"; |
| 87 | } |
| 88 | print OUT "static const WCHAR * const lwrtable[256] = {\n"; |
| 89 | for ($i = 0; $i < 256; $i += 8) { |
| 90 | @patch = @low[$i+0 .. $i+7]; |
| 91 | printf OUT "\t%06s, %06s, %06s, %06s, %06s, %06s, %06s, %06s,\n", |
| 92 | @patch; |
| 93 | } |
| 94 | print OUT "};\n\n"; |
| 95 | |
| 96 | for ($high = 0; $high < 256; $high++) { |
| 97 | #Check whether the table is needed |
| 98 | if (length $upr[$high] < 6) { |
| 99 | next; |
| 100 | } |
| 101 | printf OUT "/* Uppercase mappings %02X00 - %02XFF */\n", |
| 102 | $high, $high; |
| 103 | printf OUT "static const WCHAR ublk%02X[256] = {\n", $high; |
| 104 | for ($low = 0; $low < 256; $low += 8) { |
| 105 | @patch = (); |
| 106 | for ($i = 0; $i < 8; $i++) { |
| 107 | $code = sprintf "%02X%02X", $high, $low + $i; |
| 108 | $map = $uprtable{$code}; |
| 109 | if ($map eq "") { |
| 110 | $map = $code; |
| 111 | } |
| 112 | $patch[$i] = "0x" . $map; |
| 113 | } |
| 114 | printf OUT "\t%s, %s, %s, %s, %s, %s, %s, %s,\n", |
| 115 | @patch; |
| 116 | } |
| 117 | print OUT "};\n\n"; |
| 118 | } |
| 119 | print OUT "static const WCHAR * const uprtable[256] = {\n"; |
| 120 | for ($i = 0; $i < 256; $i += 8) { |
| 121 | @patch = @upr[$i+0 .. $i+7]; |
| 122 | printf OUT "\t%06s, %06s, %06s, %06s, %06s, %06s, %06s, %06s,\n", |
| 123 | @patch; |
| 124 | } |
Patrik Stridvall | 857eb39 | 1999-06-12 18:36:54 +0000 | [diff] [blame] | 125 | print OUT "};\n"; |
| 126 | print OUT "\n"; |
| 127 | print OUT "#endif /* !defined(__WINE_CASEMAP_H) */\n"; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 128 | |
| 129 | close(OUT); |