From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from keithw-W2600CR.wrs.com (97-94-195-106.dhcp.ftwo.tx.charter.com [97.94.195.106]) by dpdk.org (Postfix) with ESMTP id B8E8558D2 for ; Sun, 2 Nov 2014 23:19:18 +0100 (CET) Received: from keithw-W2600CR.wrs.com (localhost.localdomain [127.0.0.1]) by keithw-W2600CR.wrs.com (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id sA2MSSpQ069570 for ; Sun, 2 Nov 2014 16:28:28 -0600 Received: (from keithw@localhost) by keithw-W2600CR.wrs.com (8.14.4/8.14.4/Submit) id sA2MSSEW069569 for dev@dpdk.org; Sun, 2 Nov 2014 16:28:28 -0600 From: Keith Wiles To: dev@dpdk.org Date: Sun, 2 Nov 2014 16:28:28 -0600 Message-Id: <1414967308-69530-1-git-send-email-keith.wiles@windriver.com> X-Mailer: git-send-email 2.1.0 Subject: [dpdk-dev] [PATCH] Add external parser support for unknown commands. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Nov 2014 22:19:19 -0000 Allow for a external parser to handle the command line if the command is not found and the developer has called the routine int cmdline_set_external_parser(struct cmdline * cl, cmdline_external_parser_t parser); function to set the function pointer. The function for the external parser function should return CMDLINE_PARSE_NOMATCH if not able to match the command requested or zero is handled. Prototype of external routine: int (*cmdline_external_parser_t)(struct cmdline * cl, const char * buy); Signed-off-by: Keith Wiles --- lib/librte_cmdline/cmdline.h | 4 ++++ lib/librte_cmdline/cmdline_parse.c | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/librte_cmdline/cmdline.h b/lib/librte_cmdline/cmdline.h index 4c28d37..f15d996 100644 --- a/lib/librte_cmdline/cmdline.h +++ b/lib/librte_cmdline/cmdline.h @@ -65,6 +65,8 @@ extern "C" { #endif +typedef int (*cmdline_external_parser_t)(struct cmdline * cl, const char * buf); + struct cmdline { int s_in; int s_out; @@ -74,6 +76,7 @@ struct cmdline { #ifdef RTE_EXEC_ENV_LINUXAPP struct termios oldterm; #endif + cmdline_external_parser_t external_parser; }; struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out); @@ -85,6 +88,7 @@ int cmdline_in(struct cmdline *cl, const char *buf, int size); int cmdline_write_char(struct rdline *rdl, char c); void cmdline_interact(struct cmdline *cl); void cmdline_quit(struct cmdline *cl); +void cmdline_set_external_parser(struct cmdline * cl, cmdline_external_parser_t parser); #ifdef __cplusplus } diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c index 940480d..a65ae70 100644 --- a/lib/librte_cmdline/cmdline_parse.c +++ b/lib/librte_cmdline/cmdline_parse.c @@ -212,6 +212,14 @@ match_inst(cmdline_parse_inst_t *inst, const char *buf, return i; } +/* Set or disable external parser */ +void +cmdline_set_external_parser(struct cmdline *cl, cmdline_external_parser_t parser) +{ + /* If parser is NULL it allows for disabling external parser */ + if ( cl ) + cl->external_parser = parser; +} int cmdline_parse(struct cmdline *cl, const char * buf) @@ -320,7 +328,9 @@ cmdline_parse(struct cmdline *cl, const char * buf) /* no match */ else { debug_printf("No match err=%d\n", err); - return err; + if ( cl->external_parser == NULL ) + return err; + return cl->external_parser(cl, buf); } return linelen; -- 2.1.0