]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib/clippy: expand some macros
authorDavid Lamparter <equinox@diac24.net>
Tue, 11 Jun 2019 13:35:28 +0000 (15:35 +0200)
committerDavid Lamparter <equinox@diac24.net>
Wed, 12 Jun 2019 17:23:00 +0000 (19:23 +0200)
At least the "easy" cases of macros work.

Signed-off-by: David Lamparter <equinox@diac24.net>
python/clidef.py
zebra/zebra_vty.c

index be6800131043a5ae184645a0f77b6783f67865ab..85464a62d475f1360204b86177fcfd6a0c98b32e 100644 (file)
@@ -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)
 
index 257fb168d2f926746cb9c661a6670355d6a133bd..1f8eec9cad1491c2cc901239eda85cadf6bb6c1c 100644 (file)
@@ -2172,7 +2172,7 @@ DEFPY (show_evpn_mac_vni_all_dad,
 
 DEFPY (show_evpn_mac_vni_dad,
        show_evpn_mac_vni_dad_cmd,
-       "show evpn mac vni " CMD_VNI_RANGE " duplicate" "[json]",
+       "show evpn mac vni " CMD_VNI_RANGE " duplicate [json]",
        SHOW_STR
        "EVPN\n"
        "MAC addresses\n"
@@ -2182,10 +2182,8 @@ DEFPY (show_evpn_mac_vni_dad,
        JSON_STR)
 {
        struct zebra_vrf *zvrf;
-       vni_t vni;
        bool uj = use_json(argc, argv);
 
-       vni = strtoul(argv[4]->arg, NULL, 10);
        zvrf = zebra_vrf_get_evpn();
 
        zebra_vxlan_print_macs_vni_dad(vty, zvrf, vni, uj);
@@ -2195,7 +2193,7 @@ DEFPY (show_evpn_mac_vni_dad,
 
 DEFPY (show_evpn_neigh_vni_dad,
        show_evpn_neigh_vni_dad_cmd,
-       "show evpn arp-cache vni " CMD_VNI_RANGE "duplicate" "[json]",
+       "show evpn arp-cache vni " CMD_VNI_RANGE "duplicate [json]",
        SHOW_STR
        "EVPN\n"
        "ARP and ND cache\n"
@@ -2205,10 +2203,8 @@ DEFPY (show_evpn_neigh_vni_dad,
        JSON_STR)
 {
        struct zebra_vrf *zvrf;
-       vni_t vni;
        bool uj = use_json(argc, argv);
 
-       vni = strtoul(argv[4]->arg, NULL, 10);
        zvrf = zebra_vrf_get_evpn();
        zebra_vxlan_print_neigh_vni_dad(vty, zvrf, vni, uj);
        return CMD_SUCCESS;
@@ -2387,7 +2383,7 @@ DEFUN (show_pbr_iptable,
 
 DEFPY (clear_evpn_dup_addr,
        clear_evpn_dup_addr_cmd,
-       "clear evpn dup-addr vni <all$vni_all |" CMD_VNI_RANGE"$vni_val [mac M:A:C$mac_val | ip <A.B.C.D|X:X::X:X>]>",
+       "clear evpn dup-addr vni <all$vni_all |" CMD_VNI_RANGE"$vni [mac M:A:C$mac_val | ip <A.B.C.D|X:X::X:X>]>",
        CLEAR_STR
        "EVPN\n"
        "Duplicate address \n"
@@ -2401,15 +2397,12 @@ DEFPY (clear_evpn_dup_addr,
        "IPv6 address\n")
 {
        struct zebra_vrf *zvrf;
-       vni_t vni = 0;
        struct ipaddr host_ip = {.ipa_type = IPADDR_NONE };
        struct ethaddr mac_addr;
        int ret = CMD_SUCCESS;
 
        zvrf = zebra_vrf_get_evpn();
-       if (vni_val) {
-               vni = strtoul(vni_val, NULL, 10);
-
+       if (vni_str) {
                if (mac_val) {
                        prefix_str2mac(mac_val, &mac_addr);
                        ret = zebra_vxlan_clear_dup_detect_vni_mac(vty, zvrf,