aboutsummaryrefslogtreecommitdiff
path: root/gen/prop/nt
blob: a55ea4513d9d30737c3dc0b21fbfe8c0bb0df043 (plain) (blame)
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
62
63
64
65
66
67
68
69
#!/bin/sh

set -e
cd "${0%/*}/../.."
exec >lib/unicode/prop/uprop_get_nt.c

gawk '
BEGIN {
	FS = "( *#.*| +; +)"

	map["Decimal"] = "DE"
	map["Digit"]   = "DI"
	map["Numeric"] = "NU"

	print "/* This file is autogenerated by gen/prop/nt; DO NOT EDIT. */"
	print ""
	print "#include \"__bsearch.h\""
	print "#include \"macros.h\""
	print "#include \"rune.h\""
	print "#include \"unicode/prop.h\""
	print ""
}

/^[^#]/ {
	n = split($1, a, /\.\./)
	lo = strtonum("0X" a[1])
	hi = strtonum("0X" a[n])

	for (i = lo; i <= hi; i++) {
		gsub(/^; /, "", $2)
		props[i] = "NT_" map[$2]
	}
}

END {
	print "static constexpr enum uprop_nt lookup_lat1[] = {"
	for (i = 0; i < 0x100; i++) {
		if (i % 8 == 0)
			printf "\t"
		printf "%-8s%s", (props[i] ? props[i] : "NT_NONE") ",", \
			i % 8 == 7 ? "\n" : " "
	}
	print "};"
	print ""
	print "static const struct {"
	print "\trune lo, hi;"
	print "\tenum uprop_nt val;"
	print "} lookup[] = {"

	for (i = 0x100; i <= 0x10FFFF; i++) {
		if (!props[i])
			continue
		lo = i
		while (props[lo] == props[i + 1])
			i++
		printf "\t{RUNE_C(0x%06X), RUNE_C(0x%06X), %s},\n", lo, i, props[i]
	}

	print "};"
	print ""
	print "__MLIB_DEFINE_BSEARCH(enum uprop_nt, lookup, NT_NONE)"
	print ""
	print "enum uprop_nt"
	print "uprop_get_nt(rune ch)"
	print "{"
	print "\treturn ch < lengthof(lookup_lat1) ? lookup_lat1[ch] : mlib_lookup(ch);"
	print "}"
}
' data/DerivedNumericType.txt | sed 's/\s*$//'