1#!/usr/bin/awk -f
2#
3# $Id$
4#
5# Description: a script to generate east asian width table.
6#
7
8BEGIN {
9	prev = -1
10	comma = 0
11	ORS = ""
12	FS = "[;.|# ]"
13	print "static const struct {\n\tint begin;\n\tint end;\n} " TABLE_NAME "[] = {\n\t"
14}
15
16/^#/ {
17}
18
19/^[0-9a-fA-F]+;/ {
20	if ($2 == "W" || $2 == "F") {
21
22		v = strtonum( "0x" $1 )
23		if (prev < 0) {
24			first = v
25		} else if (v - prev > 1) {
26			if (comma) {
27				print ",\n\t"
28			}
29			printf("{ 0x%04x, 0x%04x }", first, prev)
30			first = v
31			comma = 1
32		}
33		prev = v
34	} else {
35		if (prev >= 0) {
36			if (comma) {
37				print ",\n\t"
38			}
39			printf("{ 0x%04x, 0x%04x }", first, prev)
40			prev = -1
41			comma = 1
42		}
43	}
44}
45
46/^[0-9a-fA-F]+\.\./ {
47	if ($4 == "W" || $4 == "F") {
48		vs = strtonum( "0x" $1 )
49		ve = strtonum( "0x" $3 )
50		if (prev < 0) {
51			first = vs
52		} else if (vs - prev > 1) {
53			if (comma) {
54				print ",\n\t"
55			}
56			printf("{ 0x%04x, 0x%04x }", first, prev)
57			first = vs
58			comma = 1
59		}
60		prev = ve
61	} else {
62		if (prev >= 0) {
63			if (comma) {
64				print ",\n\t"
65			}
66			printf("{ 0x%04x, 0x%04x }", first, prev)
67			prev = -1
68			comma = 1
69		}
70	}
71}
72
73END {
74	if (prev >= 0) {
75		if (comma) {
76			print ",\n\t"
77		}
78		printf("{ 0x%04x, 0x%04x }", first, prev)
79	}
80	print "\n};\n"
81}
82