]> rtime.felk.cvut.cz Git - sysless.git/blobdiff - libs4c/cmdproc/cmdproc_test.c
Add tests for space separated parameters
[sysless.git] / libs4c / cmdproc / cmdproc_test.c
index 0db4bd00fdc5cc95a85749b3c71eb2fe70f55939..ea85d0c9f3f6c6ffdb2a937774986aff11d44ace 100644 (file)
@@ -20,6 +20,21 @@ int cmd_do_testopchar(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]
   return 0;
 }
 
+int cmd_do_spacesep(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  if (des->mode & CDESM_OPCHR) {
+    int opchar;
+    opchar=cmd_opchar_check(cmd_io,des,param);
+    if(opchar<0) return opchar;
+  }
+
+  int i;
+  for (i = 0; param[i] || (des->mode & CDESM_OPCHR && i == 1); i++)
+    printf("param[%d]=%s\n", i, param[i]);
+
+  return 0;
+}
+
 int cmd_do_testparam(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
   printf(
@@ -27,7 +42,7 @@ int cmd_do_testparam(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
       "param[0]=%s\n"
       "param[1]=%s\n"
       "param[2]=%s\n",
-      param[0], param[1], param[2]);
+      param[0], param[1], param[1] == NULL ? "!!unset!!" : param[2]);
 
   return 0;
 }
@@ -55,80 +70,95 @@ cmd_des_t const **cmd_list;
 
 cmd_des_t const cmd_des_help={
     0, 0,
-    "HELP","prints help for commands",
+    "help","prints help for commands",
     cmd_do_help,{(char*)&cmd_list}};
 
 int val;
 cmd_des_t const cmd_des_val={
     0, CDESM_OPCHR|CDESM_RW,
-    "VAL","use ':' or '?' to store/read value of an integer variable",
+    "val","use ':' or '?' to store/read value of an integer variable",
     cmd_do_rw_int, {(char*)&val}};
 
 cmd_des_t const cmd_des_valro={
     0, CDESM_OPCHR|CDESM_RD,
-    "VALRO","read only access to an integer variable",
+    "valro","read only access to an integer variable",
     cmd_do_rw_int, {(char*)&val}};
 
 cmd_des_t const cmd_des_valwo={
     0, CDESM_OPCHR|CDESM_WR,
-    "VALWO","write only access to an integer variable",
+    "valwo","write only access to an integer variable",
     cmd_do_rw_int, {(char*)&val}};
 
 cmd_des_t const cmd_des_opchar_test={
     0, CDESM_OPCHR|CDESM_RW,
-    "OPCHAR","opchar test (use ':' or '?' as suffix)",
+    "opchar","opchar test (use ':' or '?' as suffix)",
     cmd_do_testopchar};
 
 cmd_des_t const cmd_des_opchar_testro={
     0, CDESM_OPCHR|CDESM_RD,
-    "OPCHARRO","opchar test (only '?' is allowed)",
+    "opcharro","opchar test (only '?' is allowed)",
     cmd_do_testopchar};
 
 cmd_des_t const cmd_des_test={
     0, 0,
-    "TEST","the simplest command",
+    "test","the simplest command",
     cmd_do_test};
 
 cmd_des_t const cmd_des_testio={
     0, 0,
-    "TESTIO","test of cmd_io inside functions (universal way to print results)",
+    "testio","test of cmd_io inside functions (universal way to print results)",
     cmd_do_testcmdio};
 
 cmd_des_t const cmd_des_param={
     0, 0,
-    "PARAM","test of parameters",
+    "param","test of parameters",
     cmd_do_testparam};
 
 cmd_des_t const cmd_des_prefix={
     0, 0,
-    "PREFIX*","suffix of the command is supplied as a parametr",
+    "prefix*","suffix of the command is supplied as a parametr",
     cmd_do_testparam};
 
 cmd_des_t const cmd_des_num={
     0, 0,
-    "NUM##","suffix of the command (two digits) is supplied as a parametr",
+    "num##","suffix of the command (two digits) is supplied as a parametr",
     cmd_do_testparam};
 
 cmd_des_t const cmd_des_char={
     0, 0,
-    "CHAR?","suffix of the command (one character) is supplied as a parametr",
+    "char?","suffix of the command (one character) is supplied as a parametr",
     cmd_do_testparam};
 
 cmd_des_t const cmd_des_charmid={
     0, 0,
-    "CHAR?MID","middle character of the command is supplied as a parametr",
+    "char?mid","middle character of the command is supplied as a parametr",
     cmd_do_testparam};
 
 cmd_des_t const cmd_des_hiddedn={
     0, 0,
-    "HIDDEN","should not be available",
+    "hidden","should not be available",
     cmd_do_test};
 
 cmd_des_t const cmd_des_error={
     0, 0,
-    "TESTERROR","should produce an error",
+    "testerror","should produce an error",
     cmd_do_testerror};
 
+cmd_des_t const cmd_des_spacesep={
+    0, CDESM_SPACE_SEP,
+    "spacesep","Test for space separated parameters",
+    cmd_do_spacesep};
+
+cmd_des_t const cmd_des_spacesepop={
+    0, CDESM_SPACE_SEP|CDESM_OPCHR|CDESM_RW,
+    "spacesepop","Test for space separated parameters and an opchar",
+    cmd_do_spacesep};
+
+cmd_des_t const cmd_des_spacesepwild={
+    0, CDESM_SPACE_SEP,
+    "spacesep#","Test for space separated parameters and a wildcard",
+    cmd_do_spacesep};
+
 /* Command lists */
 
 cmd_des_t const *cmd_list_1[]={
@@ -148,6 +178,9 @@ cmd_des_t const *cmd_list_2[]={
     &cmd_des_num,
     &cmd_des_char,
     &cmd_des_charmid,
+    &cmd_des_spacesep,
+    &cmd_des_spacesepop,
+    &cmd_des_spacesepwild,
     NULL
     };