OSDN Git Service

2820ba44193661ac536b4f9acea6a9f95cfc0a8c
[pf3gnuchains/sourceware.git] / tcl / tools / uniClass.tcl
1 proc emitRange {first last} {
2     global ranges numranges chars numchars
3
4     if {$first < ($last-1)} {
5         append ranges [format "{0x%04x, 0x%04x}, " \
6                 $first $last]
7         if {[incr numranges] % 4 == 0} {
8             append ranges "\n    "
9         }
10     } else {
11         append chars [format "0x%04x, " $first]
12         incr numchars
13         if {$numchars % 9 == 0} {
14             append chars "\n    "
15         }
16         if {$first != $last} {
17             append chars [format "0x%04x, " $last]
18             incr numchars
19             if {$numchars % 9 == 0} {
20                 append chars "\n    "
21             }
22         }
23     }
24 }
25
26 proc genTable {type} {
27     global first last ranges numranges chars numchars
28     set first -2
29     set last -2
30
31     set ranges "    "
32     set numranges 0
33     set chars "    "
34     set numchars 0
35
36     for {set i 0} {$i < 0x10000} {incr i} {
37         if {[string is $type [format %c $i]]} {
38             if {$i == ($last + 1)} {
39                 set last $i
40             } else {
41                 if {$first > 0} {
42                     emitRange $first $last
43                 }
44                 set first $i
45                 set last $i
46             }
47         }
48     }
49     emitRange $first $last
50     
51     puts "static crange ${type}RangeTable\[\] = {\n$ranges\n};\n"
52     puts "#define NUM_[string toupper $type]_RANGE (sizeof(${type}RangeTable)/sizeof(crange))\n"
53     puts "static chr ${type}CharTable\[\] = {\n$chars\n};\n"
54     puts "#define NUM_[string toupper $type]_CHAR (sizeof(${type}CharTable)/sizeof(chr))\n"
55 }
56
57
58 foreach type {alpha digit punct space lower upper graph } {
59     genTable $type
60 }
61