Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / cmd.src / newcmdposixcl.h
1 /*
2  * Simulator of microcontrollers (cmd.src/newcmdposixcl.h)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
6  *
7  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
8  *
9  */
10
11 /* This file is part of microcontroller simulator: ucsim.
12
13 UCSIM is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 UCSIM is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with UCSIM; see the file COPYING.  If not, write to the Free
25 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 02111-1307, USA. */
27 /*@1@*/
28
29 #ifndef CMD_NEWCMDFDCL_HEADER
30 #define CMD_NEWCMDFDCL_HEADER
31
32 #include "newcmdcl.h"
33 #include "cmdutil.h"
34
35
36 /*
37  * Command fd console
38  */
39
40 class cl_console: public cl_console_base
41 {
42 protected:
43   FILE *in, *out, *rout/*redirected output*/;
44
45 public:
46   cl_console(void) { in = out = rout = 0; }
47   cl_console(const char *fin, const char *fout, class cl_app *the_app);
48   cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
49   int cmd_do_print(const char *format, va_list ap);
50
51   virtual ~cl_console(void);
52   virtual class cl_console *clone_for_exec(char *fin);
53
54   virtual void redirect(char *fname, char *mode);
55   virtual void un_redirect(void);
56   virtual UCSOCKET_T get_in_fd(void) { return(in ? fileno(in) : -1); }
57   virtual bool is_tty(void) const { return in && isatty(fileno(in)); }
58   virtual bool is_eof(void) const { return in ? feof(in) : true; }
59   virtual bool input_avail(void) { return input_active() ? ::input_avail(fileno(in)) : false; };
60   virtual char *read_line(void);
61
62 private:
63   FILE *get_out(void) { return rout ? rout : out; }
64 };
65
66 #ifdef SOCKET_AVAIL
67 class cl_listen_console: public cl_console
68 {
69 private:
70   int sock;
71
72 public:
73   cl_listen_console(int serverport, class cl_app *the_app);
74
75   virtual void welcome(void) {}
76
77   virtual UCSOCKET_T get_in_fd(void) { return(sock); }
78   virtual int proc_input(class cl_cmdset *cmdset);
79 };
80 #endif
81
82
83 class cl_sub_console: public cl_console
84 {
85 private:
86   class cl_console_base *parent;
87
88 public:
89   cl_sub_console(class cl_console_base *the_parent,
90                  FILE *fin, FILE *fout, class cl_app *the_app);
91   virtual ~cl_sub_console(void);
92   virtual int init(void);
93 };
94
95
96 /*
97  * Command interpreter
98  */
99
100 class cl_commander: public cl_commander_base
101 {
102 private:
103   fd_set read_set, active_set;
104   UCSOCKET_T fd_num;
105
106 public:
107   cl_commander(class cl_app *the_app, class cl_cmdset *acmdset)
108     : cl_commander_base(the_app, acmdset)
109   {
110   }
111
112   virtual int init(void);
113   virtual void set_fd_set(void);
114   virtual int input_avail(void);
115   virtual int wait_input(void);
116   virtual int proc_input(void);
117 };
118
119 #endif
120
121 /* End of cmd.src/newcmdposixcl.h */