| 1 |
#!/bin/sh |
| 2 |
# The next line is executed by /bin/sh, but not tcl \ |
| 3 |
exec tclsh "$0" ${1+"$@"} |
| 4 |
|
| 5 |
# |
| 6 |
# uniClass.tcl -- |
| 7 |
# |
| 8 |
# Generates the character ranges and singletons that are used in |
| 9 |
# generic/regc_locale.c for translation of character classes. |
| 10 |
# This file must be generated using a tclsh that contains the |
| 11 |
# correct corresponding tclUniData.c file (generated by uniParse.tcl) |
| 12 |
# in order for the class ranges to match. |
| 13 |
# |
| 14 |
|
| 15 |
proc emitRange {first last} { |
| 16 |
global ranges numranges chars numchars extchars extranges |
| 17 |
|
| 18 |
if {$first < ($last-1)} { |
| 19 |
if {!$extranges && ($first) > 0xFFFF} { |
| 20 |
set extranges 1 |
| 21 |
set numranges 0 |
| 22 |
set ranges [string trimright $ranges " \n\r\t,"] |
| 23 |
append ranges "\n#if CHRBITS > 16\n ," |
| 24 |
} |
| 25 |
append ranges [format "{0x%X, 0x%X}, " \ |
| 26 |
$first $last] |
| 27 |
if {[incr numranges] % 4 == 0} { |
| 28 |
set ranges [string trimright $ranges] |
| 29 |
append ranges "\n " |
| 30 |
} |
| 31 |
} else { |
| 32 |
if {!$extchars && ($first) > 0xFFFF} { |
| 33 |
set extchars 1 |
| 34 |
set numchars 0 |
| 35 |
set chars [string trimright $chars " \n\r\t,"] |
| 36 |
append chars "\n#if CHRBITS > 16\n ," |
| 37 |
} |
| 38 |
append chars [format "0x%X, " $first] |
| 39 |
incr numchars |
| 40 |
if {$numchars % 9 == 0} { |
| 41 |
set chars [string trimright $chars] |
| 42 |
append chars "\n " |
| 43 |
} |
| 44 |
if {$first != $last} { |
| 45 |
append chars [format "0x%X, " $last] |
| 46 |
incr numchars |
| 47 |
if {$numchars % 9 == 0} { |
| 48 |
append chars "\n " |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
proc genTable {type} { |
| 55 |
global first last ranges numranges chars numchars extchars extranges |
| 56 |
set first -2 |
| 57 |
set last -2 |
| 58 |
|
| 59 |
set ranges " " |
| 60 |
set numranges 0 |
| 61 |
set chars " " |
| 62 |
set numchars 0 |
| 63 |
set extchars 0 |
| 64 |
set extranges 0 |
| 65 |
|
| 66 |
for {set i 0} {$i <= 0xEFFFF} {incr i} { |
| 67 |
if {$i == 0xD800} { |
| 68 |
# Skip surrogates |
| 69 |
set i 0xE000 |
| 70 |
} |
| 71 |
if {$i == 0xE000} { |
| 72 |
# Skip private |
| 73 |
set i 0xF900 |
| 74 |
} |
| 75 |
if {[string is $type [format %c $i]]} { |
| 76 |
if {$i == ($last + 1)} { |
| 77 |
set last $i |
| 78 |
} else { |
| 79 |
if {$first >= 0} { |
| 80 |
emitRange $first $last |
| 81 |
} |
| 82 |
set first $i |
| 83 |
set last $i |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
emitRange $first $last |
| 88 |
|
| 89 |
set ranges [string trimright $ranges "\t\n ,"] |
| 90 |
if {$extranges} { |
| 91 |
append ranges "\n#endif" |
| 92 |
} |
| 93 |
set chars [string trimright $chars "\t\n ,"] |
| 94 |
if {$extchars} { |
| 95 |
append chars "\n#endif" |
| 96 |
} |
| 97 |
if {$ranges ne ""} { |
| 98 |
puts "static const crange ${type}RangeTable\[\] = {\n$ranges\n};\n" |
| 99 |
puts "#define NUM_[string toupper $type]_RANGE ((int)(sizeof(${type}RangeTable)/sizeof(crange)))\n" |
| 100 |
} else { |
| 101 |
puts "/* no contiguous ranges of $type characters */\n" |
| 102 |
} |
| 103 |
if {$chars ne ""} { |
| 104 |
puts "static const chr ${type}CharTable\[\] = {\n$chars\n};\n" |
| 105 |
puts "#define NUM_[string toupper $type]_CHAR ((int)(sizeof(${type}CharTable)/sizeof(chr)))\n" |
| 106 |
} else { |
| 107 |
puts "/*\n * no singletons of $type characters.\n */\n" |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
puts "/* |
| 112 |
* Declarations of Unicode character ranges. This code |
| 113 |
* is automatically generated by the tools/uniClass.tcl script |
| 114 |
* and used in generic/regc_locale.c. Do not modify by hand. |
| 115 |
*/ |
| 116 |
" |
| 117 |
|
| 118 |
foreach {type desc} { |
| 119 |
alpha "alphabetic characters" |
| 120 |
control "control characters" |
| 121 |
digit "decimal digit characters" |
| 122 |
punct "punctuation characters" |
| 123 |
space "white space characters" |
| 124 |
lower "lowercase characters" |
| 125 |
upper "uppercase characters" |
| 126 |
graph "unicode print characters excluding space" |
| 127 |
} { |
| 128 |
puts "/*\n * Unicode: $desc.\n */\n" |
| 129 |
genTable $type |
| 130 |
} |
| 131 |
|
| 132 |
puts "/* |
| 133 |
* End of auto-generated Unicode character ranges declarations. |
| 134 |
*/" |