]> rtime.felk.cvut.cz Git - sysless.git/blobdiff - libs4c/cmdproc/cmd_proc.c
Fix missing ':' in Emacs setup
[sysless.git] / libs4c / cmdproc / cmd_proc.c
index 86cfbe2e0b8b5ae5668ddfba78fb156ea1b05162..0b255f5f4ed3b0ff67249467c1d66deff0c3a2d5 100644 (file)
@@ -18,7 +18,7 @@
    - other license provided by project originators
  *******************************************************************/
 
-#include <inttypes.h>
+#include <stdint.h>
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
@@ -35,6 +35,11 @@ char *skip_white(char *p)
 }
 
 /**
+ * Process a command line
+ *
+ * @param cmd_io I/O stack
+ * @param des_arr Pointer to the command descriptors.
+ * @param line Command line to process.
  *
  * @return Zero if no command was given in line, -CMDERR_BADCMD if
  * command is not known or has no function assigned to it. If a
@@ -90,26 +95,27 @@ int proc_cmd_line(cmd_io_t *cmd_io, cmd_des_t const **des_arr, char *line)
     var=NULL;
     while(*r){
       while((*p==*r)&&i){i--;r++;p++;};
-      if((i==0)&&!*r) break;    /* We've found the command */
-      if((*r=='?')&&i){
+      if((i==0)&&!*r) break;    /* We've found the command (full match) */
+      if((*r=='?')&&i){                /* '?' stands for an arbitrary character */
         if(!var) var=p;
        p++; r++; i--;
        continue;
       }
-      if((*r=='#')&&i&&isdigit((uint8_t)*p)){
+      if((*r=='#')&&i&&isdigit((uint8_t)*p)){ /* '#' stands for a digit */
        if(!var) var=p;
        p++; r++; i--;
        continue;
       }
-      if(*r=='*'){
+      if(*r=='*'){             /* '*' stands for any number of any characters */
        if(!var) var=p;
        i=0;
        break;
       }
-      i=1;
+      i=1;                     /* Signal no match */
       break;      
     }
     if(i!=0) continue; /* Try next command */
+    /* Setup parameters */
     if(des->mode&CDESM_OPCHR){
       if(!param[2])continue;
       if(!*param[2])continue;
@@ -122,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);
@@ -344,4 +366,4 @@ int cmd_do_help(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 
 /* Local Variables: */
 /* c-basic-offset: 2 */
-/* End */
+/* End: */