summaryrefslogtreecommitdiffstats
path: root/tools/uniClass.tcl
blob: 2820ba44193661ac536b4f9acea6a9f95cfc0a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
proc emitRange {first last} {
    global ranges numranges chars numchars

    if {$first < ($last-1)} {
	append ranges [format "{0x%04x, 0x%04x}, " \
		$first $last]
	if {[incr numranges] % 4 == 0} {
	    append ranges "\n    "
	}
    } else {
	append chars [format "0x%04x, " $first]
	incr numchars
	if {$numchars % 9 == 0} {
	    append chars "\n    "
	}
	if {$first != $last} {
	    append chars [format "0x%04x, " $last]
	    incr numchars
	    if {$numchars % 9 == 0} {
		append chars "\n    "
	    }
	}
    }
}

proc genTable {type} {
    global first last ranges numranges chars numchars
    set first -2
    set last -2

    set ranges "    "
    set numranges 0
    set chars "    "
    set numchars 0

    for {set i 0} {$i < 0x10000} {incr i} {
	if {[string is $type [format %c $i]]} {
	    if {$i == ($last + 1)} {
		set last $i
	    } else {
		if {$first > 0} {
		    emitRange $first $last
		}
		set first $i
		set last $i
	    }
	}
    }
    emitRange $first $last
    
    puts "static crange ${type}RangeTable\[\] = {\n$ranges\n};\n"
    puts "#define NUM_[string toupper $type]_RANGE (sizeof(${type}RangeTable)/sizeof(crange))\n"
    puts "static chr ${type}CharTable\[\] = {\n$chars\n};\n"
    puts "#define NUM_[string toupper $type]_CHAR (sizeof(${type}CharTable)/sizeof(chr))\n"
}


foreach type {alpha digit punct space lower upper graph } {
    genTable $type
}