summaryrefslogtreecommitdiff
path: root/devtools
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-10-06 07:44:52 -0400
committerEric S. Raymond <esr@thyrsus.com>2013-10-06 07:44:52 -0400
commitb1f2606203d8a13888246f7046b1cfcb6b5e02b5 (patch)
treeb9342b09ce292bb107c46e5f8dca7e3a40db49f4 /devtools
parentee5fab0fb9e7694bede1074246379dfead4255f5 (diff)
downloadgpsd-b1f2606203d8a13888246f7046b1cfcb6b5e02b5.tar.gz
Make vocabulary references in dump code.
Diffstat (limited to 'devtools')
-rwxr-xr-xdevtools/tablegen.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/devtools/tablegen.py b/devtools/tablegen.py
index c9be5d68..f96edf88 100755
--- a/devtools/tablegen.py
+++ b/devtools/tablegen.py
@@ -192,7 +192,19 @@ def make_structure(wfp):
print >>wfp, tabify(baseindent) + "} %s;" % structname
def make_json_dumper(wfp):
- # Write the skeleton of a JSON dump corresponding to the table
+ # Write the skeleton of a JSON dump corresponding to the table.
+ # Also, if there are subtables, some initializers
+ if subtables:
+ for (name, lines) in subtables:
+ wfp.write(" const char %s_vocabulary[] = {\n" % name)
+ for line in lines:
+ value = line[1]
+ if value.endswith(" (default)"):
+ value = value[:-10]
+ wfp.write(' "%s",\n' % value)
+ wfp.write(" }\n")
+ wfp.write('#define %s_DISPLAY(n) (((n) < (unsigned int)NITEMS(%s_vocabulary)) ? %s_vocabulary[n] : "INVALID %s")\n' % (name.upper(), name, name, name.upper()))
+ wfp.write("\n")
record = after is None
# Elements of each tuple type except 'a':
# 1. variable name,
@@ -207,6 +219,7 @@ def make_json_dumper(wfp):
# 4. None
# 5. Name of length field
tuples = []
+ vocabularies = [x[0] for x in subtables]
for (i, t) in enumerate(table):
if '|' in t:
fields = map(lambda s: s.strip(), t.split('|'))
@@ -230,8 +243,13 @@ def make_json_dumper(wfp):
tuples.append((name,
fmt+"%u", "%s",
None, None))
+ if vocabularies:
+ this = vocabularies.pop(0)
+ ref = "DISPLAY_%s(%%s)" % (this.upper())
+ else:
+ ref = 'FOO[%s]'
tuples.append((name,
- fmt_text+r"\"%s\"", 'FOO[%s]',
+ fmt_text+r"\"%s\"", ref,
None, None))
elif ftype == 'i':
tuples.append((name,