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		v = ( "0x" $1 ) + 0
22		if (prev < 0) {
23			first = v
24		} else if (v - prev > 1) {
25			if (comma) {
26				print ",\n\t"
27			}
28			printf("{ 0x%04x, 0x%04x }", first, prev)
29			first = v
30			comma = 1
31		}
32		prev = v
33	} else {
34		if (prev >= 0) {
35			if (comma) {
36				print ",\n\t"
37			}
38			printf("{ 0x%04x, 0x%04x }", first, prev)
39			prev = -1
40			comma = 1
41		}
42	}
43}
44
45/^[0-9a-fA-F]+\.\./ {
46	if ($4 == "W" || $4 == "F") {
47		vs = ( "0x" $1 ) + 0
48		ve = ( "0x" $3 ) + 0
49		if (prev < 0) {
50			first = vs
51		} else if (vs - prev > 1) {
52			if (comma) {
53				print ",\n\t"
54			}
55			printf("{ 0x%04x, 0x%04x }", first, prev)
56			first = vs
57			comma = 1
58		}
59		prev = ve
60	} else {
61		if (prev >= 0) {
62			if (comma) {
63				print ",\n\t"
64			}
65			printf("{ 0x%04x, 0x%04x }", first, prev)
66			prev = -1
67			comma = 1
68		}
69	}
70}
71
72END {
73	if (prev >= 0) {
74		if (comma) {
75			print ",\n\t"
76		}
77		printf("{ 0x%04x, 0x%04x }", first, prev)
78	}
79	print "\n};\n"
80}
81