#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <stdbool.h>
#include <rte_string_fns.h>
}
-int
-cmdline_parse(struct cmdline *cl, const char * buf)
+static inline int
+__cmdline_parse(struct cmdline *cl, const char *buf, bool call_fn)
{
unsigned int inst_num=0;
cmdline_parse_inst_t *inst;
inst = ctx[inst_num];
}
- /* call func */
- if (f) {
- f(result.buf, cl, data);
- }
-
/* no match */
- else {
+ if (f == NULL) {
debug_printf("No match err=%d\n", err);
return err;
}
+ /* call func if requested */
+ if (call_fn)
+ f(result.buf, cl, data);
+
return linelen;
}
+int
+cmdline_parse(struct cmdline *cl, const char *buf)
+{
+ return __cmdline_parse(cl, buf, true);
+}
+
+int
+cmdline_parse_check(struct cmdline *cl, const char *buf)
+{
+ return __cmdline_parse(cl, buf, false);
+}
+
int
cmdline_complete(struct cmdline *cl, const char *buf, int *state,
char *dst, unsigned int size)
#ifndef _CMDLINE_PARSE_H_
#define _CMDLINE_PARSE_H_
+#include <rte_compat.h>
+
#ifdef __cplusplus
extern "C" {
#endif
* argument buf must ends with "\n\0". The function returns
* CMDLINE_PARSE_AMBIGUOUS, CMDLINE_PARSE_NOMATCH or
* CMDLINE_PARSE_BAD_ARGS on error. Else it calls the associated
- * function (defined in the context) and returns 0
- * (CMDLINE_PARSE_SUCCESS).
+ * function (defined in the context) and returns the parsed line length (>= 0).
*/
int cmdline_parse(struct cmdline *cl, const char *buf);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Try to parse a buffer according to the specified context, but do not
+ * perform any function calls if parse is successful.
+ *
+ * The argument buf must ends with "\n\0".
+ * The function returns CMDLINE_PARSE_AMBIGUOUS, CMDLINE_PARSE_NOMATCH or
+ * CMDLINE_PARSE_BAD_ARGS on error and returns the parsed line length (>=0)
+ * on successful parse.
+ */
+__rte_experimental
+int cmdline_parse_check(struct cmdline *cl, const char *buf);
+
/**
* complete() must be called with *state==0 (try to complete) or
* with *state==-1 (just display choices), then called without