diff options
| author | David Lamparter <equinox@diac24.net> | 2019-06-11 15:35:28 +0200 | 
|---|---|---|
| committer | David Lamparter <equinox@diac24.net> | 2019-06-12 19:23:00 +0200 | 
| commit | b41b3f7bf1dee6e7c2817a63452e725d764a38a1 (patch) | |
| tree | 238c21bef7b3befafec120201b1192b05543d866 /python | |
| parent | 4381a59be0d5122c732cc9831af9d82e6fa87c4a (diff) | |
lib/clippy: expand some macros
At least the "easy" cases of macros work.
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'python')
| -rw-r--r-- | python/clidef.py | 50 | 
1 files changed, 41 insertions, 9 deletions
diff --git a/python/clidef.py b/python/clidef.py index be68001310..85464a62d4 100644 --- a/python/clidef.py +++ b/python/clidef.py @@ -201,7 +201,27 @@ def get_always_args(token, always_args, args = [], stack = []):      for nexttkn in token.next():          get_always_args(nexttkn, always_args, args, stack) -def process_file(fn, ofd, dumpfd, all_defun): +class Macros(dict): +    def load(self, filename): +        filedata = clippy.parse(filename) +        for entry in filedata['data']: +            if entry['type'] != 'PREPROC': +                continue +            ppdir = entry['line'].lstrip().split(None, 1) +            if ppdir[0] != 'define' or len(ppdir) != 2: +                continue +            ppdef = ppdir[1].split(None, 1) +            name = ppdef[0] +            if '(' in name: +                continue +            val = ppdef[1] if len(ppdef) == 2 else '' + +            val = val.strip(' \t\n\\') +            if name in self: +                sys.stderr.write('warning: macro %s redefined!\n' % (name)) +            self[name] = val + +def process_file(fn, ofd, dumpfd, all_defun, macros):      errors = 0      filedata = clippy.parse(fn) @@ -213,15 +233,21 @@ def process_file(fn, ofd, dumpfd, all_defun):                  continue              cmddef = entry['args'][2] +            cmddefx = []              for i in cmddef: -                if not (i.startswith('"') and i.endswith('"')): -                    sys.stderr.write('%s:%d: DEFPY command string not parseable (%r)\n' % (fn, entry['lineno'], cmddef)) -                    errors += 1 -                    cmddef = None -                    break -            if cmddef is None: +                while i in macros: +                    i = macros[i] +                if i.startswith('"') and i.endswith('"'): +                    cmddefx.append(i[1:-1]) +                    continue + +                sys.stderr.write('%s:%d: DEFPY command string not parseable (%r)\n' % (fn, entry['lineno'], cmddef)) +                errors += 1 +                cmddefx = None +                break +            if cmddefx is None:                  continue -            cmddef = ''.join([i[1:-1] for i in cmddef]) +            cmddef = ''.join([i for i in cmddefx])              graph = clippy.Graph(cmddef)              args = OrderedDict() @@ -320,7 +346,13 @@ if __name__ == '__main__':          if args.show:              dumpfd = sys.stderr -    errors = process_file(args.cfile, ofd, dumpfd, args.all_defun) +    macros = Macros() +    macros.load('lib/route_types.h') +    macros.load('lib/command.h') +    # sigh :( +    macros['PROTO_REDIST_STR'] = 'FRR_REDIST_STR_ISISD' + +    errors = process_file(args.cfile, ofd, dumpfd, args.all_defun, macros)      if errors != 0:          sys.exit(1)  | 
