if (PyRun_AnyFile(fp, pyfile)) {
if (PyErr_Occurred())
PyErr_Print();
- else
- printf("unknown python failure (?)\n");
return 1;
}
Py_Finalize();
return rv;
}
-static PyObject *get_args(void)
+static PyObject *get_args(const char *filename, int lineno)
{
PyObject *pyObj = PyList_New(0);
PyObject *pyArg = NULL;
free(tval);
continue;
}
+ if (token == PREPROC) {
+ free(tval);
+ Py_DECREF(pyObj);
+ return PyErr_Format(PyExc_ValueError,
+ "%s:%d: cannot process CPP directive within argument list",
+ filename, lineno);
+ }
if (token == SPECIAL) {
if (depth == 1 && (tval[0] == ',' || tval[0] == ')')) {
if (pyArg)
case DEFUNNY:
case INSTALL:
case AUXILIARY:
- pyArgs = get_args();
+ pyArgs = get_args(filename, lineno);
+ if (!pyArgs) {
+ free(tval);
+ Py_DECREF(pyCont);
+ return NULL;
+ }
pyItem = PyDict_New();
PyDict_SetItemString(pyItem, "type", PyUnicode_FromString(tval));
PyDict_SetItemString(pyItem, "args", pyArgs);
pyItem = PyDict_New();
PyDict_SetItemString(pyItem, "type", PyUnicode_FromString("PREPROC"));
PyDict_SetItemString(pyItem, "line", PyUnicode_FromString(tval));
+ lineno--;
break;
}
if (pyItem) {
#if HAVE_BFDD > 0
DEFUN_HIDDEN(
+ ip_pim_bfd_param,
+ ip_pim_bfd_param_cmd,
+ "ip pim bfd (2-255) (50-60000) (50-60000)",
+ IP_STR
+ PIM_STR
+ "Enables BFD support\n"
+ "Detect Multiplier\n"
+ "Required min receive interval\n"
+ "Desired min transmit interval\n")
#else
DEFUN(
-#endif /* HAVE_BFDD */
ip_pim_bfd_param,
ip_pim_bfd_param_cmd,
"ip pim bfd (2-255) (50-60000) (50-60000)",
"Detect Multiplier\n"
"Required min receive interval\n"
"Desired min transmit interval\n")
+#endif /* HAVE_BFDD */
{
VTY_DECLVAR_CONTEXT(interface, ifp);
int idx_number = 3;
}''')
def process_file(fn, ofd, dumpfd, all_defun):
+ errors = 0
filedata = clippy.parse(fn)
for entry in filedata['data']:
if entry['type'].startswith('DEFPY') or (all_defun and entry['type'].startswith('DEFUN')):
+ if len(entry['args'][0]) != 1:
+ sys.stderr.write('%s:%d: DEFPY function name not parseable (%r)\n' % (fn, entry['lineno'], entry['args'][0]))
+ errors += 1
+ continue
+
cmddef = entry['args'][2]
+ 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:
+ continue
cmddef = ''.join([i[1:-1] for i in cmddef])
graph = clippy.Graph(cmddef)
params['nonempty'] = len(argblocks)
ofd.write(templ.substitute(params))
+ return errors
+
if __name__ == '__main__':
import argparse
if args.show:
dumpfd = sys.stderr
- process_file(args.cfile, ofd, dumpfd, args.all_defun)
+ errors = process_file(args.cfile, ofd, dumpfd, args.all_defun)
+ if errors != 0:
+ sys.exit(1)
if args.o is not None:
clippy.wrdiff(args.o, ofd, [args.cfile, os.path.realpath(__file__), sys.executable])