diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-10-06 05:53:15 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-10-06 05:53:15 -0400 |
commit | 0e0bd294363e486b7e6c39bf104685c07524e2a4 (patch) | |
tree | 996605bb8318d4a521ee9e174fad15cdef17cbd6 /devtools/tablegen.py | |
parent | 810c626eb036368bcb2bd20b681e050054552485 (diff) | |
download | gpsd-0e0bd294363e486b7e6c39bf104685c07524e2a4.tar.gz |
Modified table parsing - a step towards parsing vocabulary tables.
Diffstat (limited to 'devtools/tablegen.py')
-rwxr-xr-x | devtools/tablegen.py | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/devtools/tablegen.py b/devtools/tablegen.py index ad48af08..fe284d48 100755 --- a/devtools/tablegen.py +++ b/devtools/tablegen.py @@ -6,7 +6,7 @@ # correct offsets in the tables themselves. # # Requires the AIVDM.txt file on standard input. Takes a single argument, -# the line number of a table start. Things you can generate: +# which must match a string in a //: Type comment. Things you can generate: # # * -t: A corrected version of the table. It will redo all the offsets to be # in conformance with the bit widths. (The other options rely only on the @@ -474,23 +474,26 @@ if __name__ == '__main__': # widths - array of table widths # ranges - array of table offsets # trailing - bit length of the table or trailing array element - startline = int(arguments[0]) + tablename = arguments[0] table = [] ranges = [] keep = False i = 0 + state = 0 for line in sys.stdin: i += 1 - if i == startline: + if state == 0 and line.startswith("//: Type") and tablename in line: + state = 1 + continue + elif state == 1: # Found table tag if line.startswith("|="): - keep = True - else: - print >>sys.stderr, "Bad table start" - sys.exit(1) - elif line.startswith("|="): - keep = False - if keep: - if line[0] == '|': + state = 2 + continue + elif state == 2: # Found table header + if line.startswith("|="): + state = 3 + continue + elif line[0] == '|': fields = line.split("|") trailing = fields[1] ranges.append(fields[1].strip()) @@ -499,8 +502,17 @@ if __name__ == '__main__': else: ranges.append('') table.append(line) - table = table[2:] - ranges = ranges[2:] + continue + elif state == 3: # Found table end + break + if state == 0: + print >>sys.stderr, "Can't find named table." + sys.exit(1) + elif state < 3: + print >>sys.stderr, "Ill-formed table (in state %d)." % state + sys.exit(1) + table = table[1:] + ranges = ranges[1:] widths = [] for line in table: fields = line.split('|') |