aboutsummaryrefslogtreecommitdiff
path: root/gen/prop/na
blob: 2b80b3b68469dd4f467beee62b8b05ec21fc145a (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
#!/bin/sh

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

gawk '
BEGIN {
	FS = ";"

	print "/* This file is autogenerated by gen/prop/na; DO NOT EDIT. */"
	print ""
	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 u8view_t lookup[] = {"
}

$2 !~ /^</ {
	gsub(/./, "\x27&\x27, ", $2)
	sub(/, $/, "", $2)
	printf "\t[RUNE_C(0x%06X)] = _(%s),\n", strtonum("0X" $1), $2
}

END {
	print "};"
	print ""
	print "u8view_t"
	print "uprop_get_na(rune ch)"
	print "{"
	print "\treturn ch < lengthof(lookup) ? lookup[ch] : (u8view_t){};"
	print "}"
}
' data/UnicodeData