dev.dpdk.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add external parser support for unknown commands.
@ 2014-11-02 22:28 Keith Wiles
       [not found] ` <1414967308-69530-1-git-send-email-keith.wiles-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
  0 siblings, 1 reply; 15+ messages in thread
From: Keith Wiles @ 2014-11-02 22:28 UTC (permalink / raw)
  To: dev-VfR2kkLFssw

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 <keith.wiles-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
---
 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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-11-05 15:11 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-02 22:28 [PATCH] Add external parser support for unknown commands Keith Wiles
     [not found] ` <1414967308-69530-1-git-send-email-keith.wiles-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2014-11-03 10:41   ` Bruce Richardson
2014-11-03 14:08     ` Wiles, Roger Keith
     [not found]       ` <307F2C60-7638-40C8-A9BC-DC3EE3D59F8C-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2014-11-03 14:16         ` Bruce Richardson
2014-11-03 14:25           ` Wiles, Roger Keith
     [not found]             ` <7D39110F-D305-4C48-8BD6-37F6DCD2E434-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2014-11-03 16:06               ` Neil Horman
     [not found]                 ` <20141103160602.GA6625-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2014-11-03 16:50                   ` Wiles, Roger Keith
     [not found]                     ` <6F166021-567F-4B30-8EAE-EDB68A86C6CC-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2014-11-03 23:26                       ` Stephen Hemminger
2014-11-03 23:42                         ` Neil Horman
     [not found]                           ` <20141103234230.GA2660-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2014-11-04  4:52                             ` Wiles, Roger Keith
     [not found]                               ` <35090085-66D7-4F23-9867-A0DCC09E7DDD-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2014-11-04 11:27                                 ` Neil Horman
     [not found]                                   ` <20141104112742.GB9995-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2014-11-04 14:44                                     ` Wiles, Roger Keith
     [not found]                                       ` <6F5C8CE3-5882-4222-BF8F-B8A29A3EB1BD-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2014-11-04 19:29                                         ` Neil Horman
     [not found]                                           ` <20141104192904.GD9995-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2014-11-04 20:45                                             ` Wiles, Roger Keith
     [not found]                                               ` <394E147B-5A0E-4557-8FD0-496BA25A4CB6-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2014-11-05 15:11                                                 ` Neil Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).