#!/bin/awk -f
#
-# Copyright © 2021-2022 Nick Bowler
+# Copyright © 2021-2022, 2024 Nick Bowler
#
# Generate a mapping from a (random) integer to a list of type specifiers
# represented by struct cdecl_declspec. Used internally by declgen to
print "\tswitch (rngval) {"
for (i = 0; i < count; i++) {
- print "\tcase " i ":"
- $0 = specs[i]
+ print "\tcase " i ":";
- for (j = 1; j <= NF; j++) {
+ n = split(specs[i], parts);
+ for (j = 1; j <= n; j++) {
prefix = j == 1 ? "return" : "";
- printf "\t\t%6s gen_raw_typespec_(%s,\n", prefix, $j
+ printf "\t\t%6s gen_raw_typespec_(%s,\n", prefix, parts[j];
}
- printf "\t\t%25sNULL%s;\n", "", substr("))))))))", 1, NF);
+ printf "\t\t%25sNULL%s;\n", "", substr("))))))))", 1, n);
}
print "\tdefault:\n\t\tassert(0);\n\t}"
print "}\n"