]> rtime.felk.cvut.cz Git - sysless.git/blob - libs4c/cmdproc/cmd_proc_run.c
Fix missing ':' in Emacs setup
[sysless.git] / libs4c / cmdproc / cmd_proc_run.c
1 /*******************************************************************
2   Components for embedded applications builded for
3   laboratory and medical instruments firmware  
4  
5   cmd_proc.c - text command processor
6                enables to define multilevel tables of commands
7                which can be received from more inputs and send reply
8                to respective I/O stream output
9  
10   Copyright (C) 2001-2009 by Pavel Pisa pisa@cmp.felk.cvut.cz
11             (C) 2002-2009 by PiKRON Ltd. http://www.pikron.com
12             (C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
13
14   This file can be used and copied according to next
15   license alternatives
16    - MPL - Mozilla Public License
17    - GPL - GNU Public License
18    - other license provided by project originators
19  *******************************************************************/
20
21 #include <cmd_proc.h>
22 #include "cmd_proc_priv.h"
23
24 /**
25  * Executes command processor. This function is usually called from
26  * application's main loop.
27  */
28 int cmd_processor_run(cmd_io_t *cmd_io, cmd_des_t const **commands)
29 {
30   int val;
31
32   if(cmd_io_line_out(cmd_io))
33     return 1; /* Not all the output has been sent. */
34         
35   if(cmd_io_line_in(cmd_io)<=0)
36     return 0; /* Input line not finished or error. */
37
38   if(commands){
39     val=proc_cmd_line(cmd_io, commands, cmd_io->priv.ed_line.in->buf);
40   }else{
41     val=-CMDERR_BADCMD;
42   }
43
44   if(cmd_io->priv.ed_line.out->inbuf){
45     cmd_io_putc(cmd_io,'\r');
46     cmd_io_putc(cmd_io,'\n');
47   }else if(val<0){
48     char s[20];
49     cmd_io_puts(cmd_io,"ERROR ");
50     i2str(s,-val,0,0);
51     cmd_io_puts(cmd_io,s);
52     cmd_io_putc(cmd_io,'\r');
53     cmd_io_putc(cmd_io,'\n');
54   }
55   return 1; /* Command line processed */
56 }
57
58
59 /* Local Variables: */
60 /* c-basic-offset: 2 */
61 /* End: */