summaryrefslogtreecommitdiff
path: root/jsongen.py.in
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-05-31 08:24:37 -0400
committerEric S. Raymond <esr@thyrsus.com>2011-05-31 08:24:37 -0400
commit57273f9c51a1e03227e27d5c5b30835ab412ac4b (patch)
treefe898687bfeb8fc4a4ecfde3a6b7d3315407bd20 /jsongen.py.in
parent4e4ac8884e5469d3843f4a775559f22ff7c8d292 (diff)
downloadgpsd-57273f9c51a1e03227e27d5c5b30835ab412ac4b.tar.gz
Closing in on generating correct code for union subtypes.
Diffstat (limited to 'jsongen.py.in')
-rw-r--r--jsongen.py.in9
1 files changed, 6 insertions, 3 deletions
diff --git a/jsongen.py.in b/jsongen.py.in
index 67392baf..0e2603bb 100644
--- a/jsongen.py.in
+++ b/jsongen.py.in
@@ -727,7 +727,7 @@ def generate(spec):
report += " char %s[JSON_VAL_MAX+1];\n" % attr
outboard.append(attr)
structname = spec["structname"]
- # If there are structarrays describing array sobobjects, we need
+ # If there are structarrays describing array subobjects, we need
# to make a separate parse control initializer for each one. The
# attribute name is the name of the array; substructure and length
# fieldnames must be given in the defaults part.
@@ -739,8 +739,11 @@ def generate(spec):
report += " const struct json_attr_t %s_%s_subtype[] = {\n" % (initname, attr)
for (subattr, subitype, default) in elements:
report += '\t{"%s",%st_%s,%sSTRUCTOBJECT(struct %s, %s),\n' % \
- (subattr, " "*(14-len(subattr)), subitype, " "*(8-len(itype)), innerstruct, subattr)
- report += leader + ".dflt.%s = %s},\n" % (subitype, default)
+ (subattr, " "*(14-len(subattr)), subitype, " "*(8-len(subitype)), innerstruct, subattr)
+ if subitype == "string":
+ report += leader + ".len = sizeof(%s.%s)},\n" % (structname,subattr)
+ else:
+ report += leader + ".dflt.%s = %s},\n" % (subitype, default)
report += " };\n"
# Generate the main structure definition describing this parse.
# It may have object subarrays.