]> rtime.felk.cvut.cz Git - sysless.git/blobdiff - libs4c/cmdproc/cmd_proc.h
Add support for parsing of space separated parameters
[sysless.git] / libs4c / cmdproc / cmd_proc.h
index f4533f8f6f478a1e6489a24e97cfbbc0ba4795df..6a95bbf3bb7ad988dcad922c3f904c86fa56a69f 100644 (file)
@@ -6,8 +6,8 @@
                designed for instruments control and setup
               over RS-232 line
  
-  Copyright (C) 2001 by Pavel Pisa pisa@cmp.felk.cvut.cz
-            (C) 2002 by PiKRON Ltd. http://www.pikron.com
+  Copyright (C) 2001-2009 by Pavel Pisa pisa@cmp.felk.cvut.cz
+            (C) 2002-2009 by PiKRON Ltd. http://www.pikron.com
             (C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
 
   This file can be used and copied according to next
@@ -112,11 +112,41 @@ 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.
+ *
+ * Command name may contain the following wildcards:
+ * - '?' stands for one arbitrary character
+ * - '#' stands for one digit
+ * - '*' stands for any number of arbitrary characters at the end of the command
+ *
+ * The fnc() function is passed the following information as the param array:
+ *   - param[0] points to the command (the longest sequence of alphanumeric characters)
+ *   If CDESM_OPCHR is specified in the command descriptor then
+ *   - param[1] points to the first wildcard in the command or is NULL for commands without wildcard in the name
+ *   - param[2] points to the operation character (':' or '?') and
+ *   - param[3] points to the string after the operation character (after skipping whitespace)
+ *   If CDESM_OPCHR is not specified then
+ *     If the command name contains a wildcard,
+ *     - param[1] points to the first wildcard in the command and
+ *     If the command has any parameters
+ *     - param[1] or param[2] (depending on the presence of a wildcard)
+ *       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{
-  int code;
-  int mode;
-  char *name;
+  int code;                    /* Application specific code */
+  int mode;                    /* CDESM_* constants */
+  char *name;                  /* Name of the command with possible wildcards */
   char *help;
   int (*fnc)(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
   char *info[];