diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-10-05 23:17:27 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-10-05 23:17:27 -0400 |
commit | 532a53921ea7c696262e24ff5b60d209165b65ec (patch) | |
tree | eec0f5daa0c7b5a99802f7b35f84e7c60944b7f4 /devtools/tablegen.py | |
parent | dbd353352d8d6dff23ac1a87601a7c0eac688ad4 (diff) | |
download | gpsd-532a53921ea7c696262e24ff5b60d209165b65ec.tar.gz |
Correctly generate JSON dumping code for trailing arrays.
Diffstat (limited to 'devtools/tablegen.py')
-rwxr-xr-x | devtools/tablegen.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/devtools/tablegen.py b/devtools/tablegen.py index 78632599..ad48af08 100755 --- a/devtools/tablegen.py +++ b/devtools/tablegen.py @@ -280,10 +280,9 @@ def make_json_dumper(wfp): # At end of tuples, or if scaled flag changes, or if next op is array, # flush out dump code for a span of fields. if i+1 == len(tuples): - if not inarray: - endit = '}",\n' + endit = '}",' elif tuples[i+1][1] == None: - endit = r',\"%s\":[",' + endit = r',\"%s\":[",' % tuples[i+1][0] elif scaled(i) != scaled(i+1): endit = ',",' else: @@ -291,7 +290,11 @@ def make_json_dumper(wfp): if endit: if not scaled(i): print >>wfp, base + header - print >>wfp, base + step + '"'+','.join(tslice(i,1)) + endit + if inarray: + prefix = '{"' + else: + prefix = '"' + print >>wfp, base + step + prefix +','.join(tslice(i,1)) + endit for (j, t) in enumerate(tuples[startspan:i+1]): if inarray: ref = structname + "." + inarray + "[i]." + t[0] @@ -334,7 +337,7 @@ def make_json_dumper(wfp): if inarray: base = " " * 8 print >>wfp, base + "}" - print >>wfp, base + "if (buf[strlen(buf) - 1] == ',')" + print >>wfp, base + "if (buf[strlen(buf)-1] == ',')" print >>wfp, base + step + r"buf[strlen(buf)-1] = '\0';" print >>wfp, base + "(void)strlcat(buf, \"]}\", buflen - strlen(buf));" |