]> rtime.felk.cvut.cz Git - sysless.git/commitdiff
Add support for parsing of space separated parameters
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 31 Jul 2013 07:38:22 +0000 (09:38 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 31 Jul 2013 08:02:39 +0000 (10:02 +0200)
libs4c/cmdproc/cmd_proc.c
libs4c/cmdproc/cmd_proc.h

index fe667b733d1c0578029c7137ed9d82af4a8e8ead..7b1dd843a86625e28f75a60be62c8e0432fb6f67 100644 (file)
@@ -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);
index 18e2a21c55d1faade10578295deaa3fb38472bce..6a95bbf3bb7ad988dcad922c3f904c86fa56a69f 100644 (file)
@@ -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{