# common form, without requiring a more advanced template engine (e.g.
# jinja2)
templ = Template(
- """/* $fnname => "$cmddef" */
+ """$cond_begin/* $fnname => "$cmddef" */
DEFUN_CMD_FUNC_DECL($fnname)
#define funcdecl_$fnname static int ${fnname}_magic(\\
const struct cmd_element *self __attribute__ ((unused)),\\
$argassert
return ${fnname}_magic(self, vty, argc, argv$arglist);
}
-
+$cond_end
"""
)
errors = 0
filedata = clippy.parse(fn)
+ cond_stack = []
+
for entry in filedata["data"]:
+ if entry["type"] == "PREPROC":
+ line = entry["line"].lstrip()
+ tokens = line.split(maxsplit=1)
+ line = "#" + line + "\n"
+
+ if not tokens:
+ continue
+
+ if tokens[0] in ["if", "ifdef", "ifndef"]:
+ cond_stack.append(line)
+ elif tokens[0] in ["elif", "else"]:
+ prev_line = cond_stack.pop(-1)
+ cond_stack.append(prev_line + line)
+ elif tokens[0] in ["endif"]:
+ cond_stack.pop(-1)
+ continue
if entry["type"].startswith("DEFPY") or (
all_defun and entry["type"].startswith("DEFUN")
):
else:
dumpfd.write('"%s":\n\t---- no magic arguments ----\n\n' % (cmddef))
+ params["cond_begin"] = "".join(cond_stack)
+ params["cond_end"] = "".join(["#endif\n"] * len(cond_stack))
params["argdefs"] = "".join(argdefs)
params["argdecls"] = "".join(argdecls)
params["arglist"] = "".join(arglist)