aboutsummaryrefslogtreecommitdiff
path: root/gen/prop/na1
blob: 855f1de045516e4397c34e23dea5ae82f63d4dc8 (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
#!/bin/sh

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

gawk '
BEGIN {
	FS = ";"

	print "/* This file is autogenerated by gen/prop/na1; DO NOT EDIT. */"
	print ""
	print "#include \"__bsearch.h\""
	print "#include \"macros.h\""
	print "#include \"rune.h\""
	print "#include \"unicode/prop.h\""
	print ""
	print "#define _(...) \\"
	print "\t{(const char8_t []){__VA_ARGS__}, sizeof((const char8_t []){__VA_ARGS__})}"
	print ""
	print "static const struct {"
	print "\trune k;"
	print "\tstruct u8view v;"
	print "} lookup[] = {"
}

length($11) > 0 {
	gsub(/./, "\x27&\x27, ", $11)
	sub(/, $/, "", $11)
	printf "\t{RUNE_C(0x%06X), _(%s)},\n", strtonum("0X" $1), $11
}

END {
	print "};"
	print ""
	print "__MLIB_DEFINE_BSEARCH_KV(struct u8view, lookup, (struct u8view){})"
	print ""
	print "struct u8view"
	print "uprop_get_na1(rune ch)"
	print "{"
	print "\treturn mlib_lookup_kv(ch);"
	print "}"
}
' data/UnicodeData