1 /*******************************************************************
2 Components for embedded applications builded for
3 laboratory and medical instruments firmware
5 cmdio_std_file.c - interconnection of text command processor
6 with generic file interface
8 Copyright (C) 2001-2009 by Pavel Pisa pisa@cmp.felk.cvut.cz
9 (C) 2002-2009 by PiKRON Ltd. http://www.pikron.com
10 (C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
12 This file can be used and copied according to next
14 - MPL - Mozilla Public License
15 - GPL - GNU Public License
16 - other license provided by project originators
18 *******************************************************************/
26 cmd_des_t const **cmd_forshell;
28 static int cmd_io_putc_forfile(struct cmd_io *cmd_io,int ch)
30 int res=fputc(ch,cmd_io->priv.file.out);
35 static int cmd_io_getc_forfile(struct cmd_io *cmd_io)
37 int ch=fgetc(cmd_io->priv.file.in);
42 static int cmd_io_write_forfile(struct cmd_io *cmd_io,const void *buf,int count)
44 int res=fwrite(buf, 1, count, cmd_io->priv.file.out);
48 static int cmd_io_read_forfile(struct cmd_io *cmd_io,void *buf,int count)
50 int res=fread(buf, 1, count, cmd_io->priv.file.in);
54 int cmd_proc_forfile(FILE * in,FILE * out, cmd_des_t const **des_arr, char *line)
58 cmd_io.putc=cmd_io_putc_forfile;
59 cmd_io.getc=cmd_io_getc_forfile;
60 cmd_io.write=cmd_io_write_forfile;
61 cmd_io.read=cmd_io_read_forfile;
62 cmd_io.priv.file.in=in;
63 cmd_io.priv.file.out=out;
65 return proc_cmd_line(&cmd_io, des_arr, line);
68 int cmd_proc_forshell (int argc, char **argv)
76 cmd_proc_forfile(stdin, stdout, cmd_forshell, "help");
81 for(len=0, i=1; i<argc; i++)
82 len+=strlen(argv[i])+1;
88 for(p=line, i=1; i<argc; i++) {
90 memcpy(p,argv[i],len);
96 res=cmd_proc_forfile(stdin, stdout, cmd_forshell, line);
100 printf("cmdproc \"%s\" failed with error %d\n",line,res);