From 9cba9c3ecf3cde43971fd9943193de2a124f1286 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 31 Jul 2013 09:38:22 +0200 Subject: [PATCH] Add support for parsing of space separated parameters --- libs4c/cmdproc/cmd_proc.c | 16 ++++++++++++++++ libs4c/cmdproc/cmd_proc.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/libs4c/cmdproc/cmd_proc.c b/libs4c/cmdproc/cmd_proc.c index fe667b7..7b1dd84 100644 --- a/libs4c/cmdproc/cmd_proc.c +++ b/libs4c/cmdproc/cmd_proc.c @@ -128,6 +128,22 @@ int proc_cmd_line(cmd_io_t *cmd_io, cmd_des_t const **des_arr, char *line) if(param[parcnt]) if(*param[parcnt]) parcnt++; } + if(des->mode&CDESM_SPACE_SEP){ + while (*param[parcnt-1] && parcnt > (var ? 2 : 1) && parcnt < 9) { + p = param[parcnt-1]; + while (*p && !isspace(*p)) p++; + if (*p) { + *p = '\0'; + p = skip_white(p+1); + if (*p) { + parcnt++; + param[parcnt-1] = p; + continue; + } + } + break; /* No more parameters */ + } + } param[parcnt]=0; if(!des->fnc) return -CMDERR_BADCMD; res=des->fnc(cmd_io,des,param); diff --git a/libs4c/cmdproc/cmd_proc.h b/libs4c/cmdproc/cmd_proc.h index 18e2a21..6a95bbf 100644 --- a/libs4c/cmdproc/cmd_proc.h +++ b/libs4c/cmdproc/cmd_proc.h @@ -112,6 +112,7 @@ int cmd_io_read_bychar(cmd_io_t *cmd_io,void *buf,int count); #define CDESM_RD 0x01 /* Value read is possible */ #define CDESM_WR 0x02 /* Value write is possible */ #define CDESM_RW (CDESM_RD|CDESM_WR) /* Both */ +#define CDESM_SPACE_SEP 0x20 /* Whitespace separated params - replaces space with '\0' */ /** * Command descriptor. @@ -135,6 +136,11 @@ int cmd_io_read_bychar(cmd_io_t *cmd_io,void *buf,int count); * points to the beginning of those parameters (after skipping * whitespace) * + * If CDESM_SPACE_SEP is specified in the command descriptor, then + * the command arguments are split at whitespace by '\0' + * characters and stored in the next unused param elements. Param + * array can contain up to 9 elements. + * * The param elements are always terminated by NULL element. */ typedef struct cmd_des{ -- 2.39.2