From ff752029df033c16591f6a1556f03d2ce4bf7229 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 29 Sep 2009 21:14:34 +0000 Subject: Add some debugging machinery - we can now dump set flags in a convenient form. --- devtools/maskaudit | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'devtools') diff --git a/devtools/maskaudit b/devtools/maskaudit index 24c0b9f6..8adb1918 100755 --- a/devtools/maskaudit +++ b/devtools/maskaudit @@ -4,6 +4,8 @@ # client-side library. # # With -p, dump a Python status mask list translated from the C one. +# +# With -c, generare C code to dump masks for debugging purposes. import sys, commands, glob, getopt @@ -11,10 +13,13 @@ class SourceExtractor: def __init__(self): self.daemonfiles = ["gpsd.c", "libgpsd_core.c", "pseudonmea.c"] + glob.glob("driver_*.c") self.masks = [] + self.primitive_masks = [] for line in file("gps.h"): if line.startswith("#define") and "_SET" in line: fields = line.split() self.masks.append((fields[1], fields[2])) + if fields[2].endswith("u"): + self.primitive_masks.append((fields[1], fields[2])) def in_library(self, flag): (status, output) = commands.getstatusoutput("grep %s libgps.c libgps_json.c" % flag) @@ -26,17 +31,19 @@ class SourceExtractor: if __name__ == '__main__': try: - (options, arguments) = getopt.getopt(sys.argv[1:], "pt") + (options, arguments) = getopt.getopt(sys.argv[1:], "ptc") tabulate = False pythonize = False + codegen = False for (switch, val) in options: if (switch == '-t'): tabulate = True if (switch == '-p'): pythonize = True + if (switch == '-c'): + codegen = True source = SourceExtractor() - print source.daemonfiles if tabulate: print "%-14s %8s %8s" % (" ", "Library", "Daemon") @@ -47,6 +54,42 @@ if __name__ == '__main__': if v[-1] == 'u': v = v[:-1] print "%-15s\t= %s" % (d, v) + if codegen: + maxout = 0 + for (d, v) in source.primitive_masks: + if source.in_daemon(d): + maxout += len(d) - len("_SET") + 1 + print """/* This code is generated. Do not hand-hack it! */ +#include +#include + +#include \"gpsd_config.h\" /* for strlcat() */ +#include \"gpsd.h\" + +const char *gpsd_maskdump(gps_mask_t set) +{ + static char buf[%d]; + const struct { + gps_mask_t mask; + const char *name; + } *sp, names[] = {""" % (maxout + 1,) + for (flag, value) in source.primitive_masks: + print " {%s,\t\"%s\"}," % (flag, flag[:-4]) + print '''\ + }; + + buf[0] = '\\0'; + for (sp = names; sp < names + sizeof(names)/sizeof(names[0]); sp++) + if ((set & sp->mask)!=0) { + (void)strlcat(buf, sp->name, sizeof(buf)); + (void)strlcat(buf, "|", sizeof(buf)); + } + if (buf[0] != \'\\0\') + buf[strlen(buf)-1] = \'\\0\'; + return buf; +} +''' + except KeyboardInterrupt: pass -- cgit v1.2.1