]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
Update cmdproc from sysless
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 31 Jul 2013 14:29:26 +0000 (16:29 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 31 Jul 2013 14:29:26 +0000 (16:29 +0200)
- whitespace
- backspace handling
- more comments

cmdproc/include/cmdproc.h
cmdproc/src/cmdproc.c
cmdproc/src/cmdproc_io_line.c
cmdproc/src/cmdproc_run.c

index 51819168142b7273171a8e5a4f9978fb055a546d..302e4f3c4b07924777a8378597a4e0562f3d7ec4 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************
   Components for embedded applications builded for
-  laboratory and medical instruments firmware  
+  laboratory and medical instruments firmware
+
   cmd_proc.h - text line command processor
                designed for instruments control and setup
               over RS-232 line
+
   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>
@@ -28,7 +28,9 @@
 
 #define FL_ELB_ECHO   0x10      /* Read characters are echoed back */
 #define FL_ELB_INSEND 0x20      /* The line is currently being sent */
-#define FL_ELB_NOCRLF 0x40      /* CR and/or LF will not start the new line */
+#define FL_ELB_NOCRLF 0x40      /* CR and/or LF will not start a new
+                                * line (used for out buffers to store
+                                * more than a single line) */
 #define CMD_DES_CONTINUE_AT_ID ((cmd_des_t*)1)
 #define CMD_DES_INCLUDE_SUBLIST_ID ((cmd_des_t*)2)
 #define CMD_DES_CONTINUE_AT(list)     CMD_DES_CONTINUE_AT_ID,((cmd_des_t*)list)
@@ -58,8 +60,11 @@ typedef struct cmd_io{
   int (*read)(struct cmd_io *cmd_io,void *buf,int count);
   union {
     struct {
-      ed_line_buf_t *in;
-      ed_line_buf_t *out;
+      ed_line_buf_t *in;  /* Buffer for storing the read command line */
+      ed_line_buf_t *out; /* Temporarily stores characters to be sent
+                          * out (until the send operation is
+                          * finished). This is not used for echo
+                          * handling. */
       struct cmd_io *io_stack;
     } ed_line;
     struct {
@@ -203,4 +208,4 @@ int cmd_processor_run(cmd_io_t *cmd_io, cmd_des_t const **commands);
 
 /* Local Variables: */
 /* c-basic-offset: 2 */
-/* End */
+/* End: */
index ba839e45525c2aa48e05f7ce7fa1bf4cc10ff2f2..b2cdec3e949b04eaa6a28461825d27feb2995601 100644 (file)
@@ -1,12 +1,12 @@
 /*******************************************************************
   Components for embedded applications builded for
-  laboratory and medical instruments firmware  
+  laboratory and medical instruments firmware
+
   cmd_proc.c - text command processor
                enables to define multilevel tables of commands
               which can be received from more inputs and send reply
               to respective I/O stream output
+
   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>
@@ -39,7 +39,7 @@ char *skip_white(char *p)
  * @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
  * command is executed, then the return value of the command function
@@ -53,7 +53,7 @@ int proc_cmd_line(cmd_io_t *cmd_io, cmd_des_t const **des_arr, char *line)
   int arr_stack_sp=0;
   char *param[10];
   short cmd_len;
-  int res, i, parcnt; 
+  int res, i, parcnt;
   param[0]=p=skip_white(p);
   if(!*p) return 0;
   /* Determine the name of the command */
@@ -65,7 +65,7 @@ int proc_cmd_line(cmd_io_t *cmd_io, cmd_des_t const **des_arr, char *line)
     cmd_len=p-param[0];
   }
   param[1]=param[2]=skip_white(p);
-  
+
   /* Find the command in des_arr */
   while(1){
     des=*(des_arr++);
@@ -111,7 +111,7 @@ int proc_cmd_line(cmd_io_t *cmd_io, cmd_des_t const **des_arr, char *line)
        break;
       }
       i=1;                     /* Signal no match */
-      break;      
+      break;
     }
     if(i!=0) continue; /* Try next command */
     /* Setup parameters */
@@ -160,7 +160,7 @@ int proc_cmd_line(cmd_io_t *cmd_io, cmd_des_t const **des_arr, char *line)
  * if the opchar is not ':' or '?'.
  */
 int cmd_opchar_check(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{ 
+{
   int opchar=*param[2];
   if(opchar==':'){
     if(!(des->mode&CDESM_WR)){
@@ -192,7 +192,7 @@ int cmd_num_suffix(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[], u
     p++;
   }while(*p && !strchr(" :?=",*p));
   *pval=val;
-  return 0;  
+  return 0;
 }
 
 
@@ -202,7 +202,7 @@ int cmd_do_stamp(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
   cmd_io_write(cmd_io,param[0],param[2]-param[0]);
   cmd_io_putc(cmd_io,'=');
   cmd_io_write(cmd_io,param[3],strlen(param[3]));
-  return 0; 
+  return 0;
 }
 
 /**
@@ -222,7 +222,7 @@ int cmd_do_rw_short(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
   }else{
     return cmd_opchar_replong(cmd_io, param, (long)*ptr, 0, 0);
   }
-  return 0; 
+  return 0;
 }
 
 /**
@@ -242,7 +242,7 @@ int cmd_do_rw_int(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
   }else{
     return cmd_opchar_replong(cmd_io, param, (long)*ptr, 0, 0);
   }
-  return 0; 
+  return 0;
 }
 
 
@@ -263,7 +263,7 @@ int cmd_do_rw_long(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
   }else{
     return cmd_opchar_replong(cmd_io, param, (long)*ptr, 0, 0);
   }
-  return 0; 
+  return 0;
 }
 
 /**
@@ -367,4 +367,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: */
index 4c30445aef89db019d8eea5c4e46cc016703c8c3..1763123857384eef2a012876c9376fa14600655c 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************
   Components for embedded applications builded for
-  laboratory and medical instruments firmware  
+  laboratory and medical instruments firmware
+
   cmd_proc.h - text line command processor
                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
             (C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
 
 /* cmd_io line editor */
 
-/** 
+/**
  * Adds new characters to an edit line buffer.
- * 
+ *
  * @param elb Edit line buffer.
  * @param ch character to add.
- * 
- * @return 1 in case of end of line, 0 otherwise.
+ *
+ * @return 1 in case of end of line, -1 if called at inaproprate time, 0 otherwise.
  */
 int cmd_ed_line_buf(ed_line_buf_t *elb, int ch)
 {
@@ -40,6 +40,11 @@ int cmd_ed_line_buf(ed_line_buf_t *elb, int ch)
   if(!lastch){
     elb->inbuf=0;               /* Start new line */
   }
+  if(ch == '\b') {             /* backspace */
+    if (elb->inbuf > 0)
+      elb->inbuf--;
+    return 0;
+  }
   if((!(elb->flg&FL_ELB_NOCRLF))&&((ch=='\n')||(ch=='\r'))){
     if((lastch=='\n')&&(ch=='\r')) /* Empty line, ignore it. */
       return 0;
@@ -47,11 +52,11 @@ int cmd_ed_line_buf(ed_line_buf_t *elb, int ch)
     elb->buf[elb->inbuf]=0;
     return 1;
   }
-  if(elb->inbuf>=elb->alloc-1){ 
+  if(elb->inbuf>=elb->alloc-1){
     /* try to reallocate buffer len not implemented */
     return 0;
   }
-  elb->buf[elb->inbuf++]=ch;  
+  elb->buf[elb->inbuf++]=ch;
   return 0;
 }
 
@@ -65,11 +70,11 @@ int cmd_io_line_out(cmd_io_t *cmd_io)
 {
   cmd_io_t* io_stack=cmd_io->priv.ed_line.io_stack;
   ed_line_buf_t* ed_line_out=cmd_io->priv.ed_line.out;
-  
+
   if(!ed_line_out->inbuf) return 0;
   if(!io_stack)
     return -1;
-  
+
   if(!(ed_line_out->flg&FL_ELB_INSEND)){
     ed_line_out->flg|=FL_ELB_INSEND;
     ed_line_out->lastch=0;
@@ -85,7 +90,7 @@ int cmd_io_line_out(cmd_io_t *cmd_io)
   return 1;
 }
 
-/* process input */
+/* process input & perform echo if requested */
 int cmd_io_line_in(cmd_io_t *cmd_io)
 {
   int ch;
@@ -98,6 +103,8 @@ int cmd_io_line_in(cmd_io_t *cmd_io)
   while((ch=cmd_io_getc(io_stack))>=0){
 //    DPRINT("Added %c (%d)\n", ch, ch);
     int eol = cmd_ed_line_buf(ed_line_in,ch);
+    if (eol == -1)
+      return -1;
     if(eol){
       if(ed_line_in->flg&FL_ELB_ECHO){
         while(cmd_io_putc(io_stack,'\r')<0);
@@ -105,7 +112,7 @@ int cmd_io_line_in(cmd_io_t *cmd_io)
       }
       return 1;
     }
-    else 
+    else
       if(ed_line_in->flg&FL_ELB_ECHO) {
         while(cmd_io_putc(io_stack,ch)<0);
       }
@@ -126,4 +133,4 @@ char *cmd_io_line_rdline(cmd_io_t *cmd_io, int mode)
 
 /* Local Variables: */
 /* c-basic-offset: 2 */
-/* End */
+/* End: */
index 72aa81731f670d587e3235aecb9bb055e03a15c3..643ca59bd15c4164b6c78638680b07e3c41261f8 100644 (file)
@@ -1,12 +1,12 @@
 /*******************************************************************
   Components for embedded applications builded for
-  laboratory and medical instruments firmware  
+  laboratory and medical instruments firmware
+
   cmd_proc.c - text command processor
                enables to define multilevel tables of commands
               which can be received from more inputs and send reply
               to respective I/O stream output
+
   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>
@@ -59,4 +59,4 @@ int cmd_processor_run(cmd_io_t *cmd_io, cmd_des_t const **commands)
 
 /* Local Variables: */
 /* c-basic-offset: 2 */
-/* End */
+/* End: */