2 * Simulator of microcontrollers (cmd.src/newcmdwin32cl.h)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5 * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
7 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
11 /* This file is part of microcontroller simulator: ucsim.
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.
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.
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
29 #ifndef CMD_NEWCMDFDCL_HEADER
30 #define CMD_NEWCMDFDCL_HEADER
39 cl_channel(void) { set(); }
40 cl_channel(HANDLE _handle, e_handle_type _type = CH_UNDEF) { set(_handle, _type); }
41 cl_channel(FILE *_fp, e_handle_type _type = CH_UNDEF) { set(_fp, _type); }
44 void set(HANDLE _handle, e_handle_type _type = CH_UNDEF);
45 void set(FILE *_fp, e_handle_type _type = CH_UNDEF);
48 bool input_avail(void) const { return ::input_avail(handle, type); }
49 enum e_handle_type get_type(void) const { return type; }
50 HANDLE get_handle(void) const { return handle; }
51 FILE *get_fp(void) const { return fp; }
52 bool is_tty(void) const { return CH_FILE != type; }
53 bool is_eof(void) const { return get_fp() ? feof(get_fp()) : true; }
56 e_handle_type guess_type(void) { return get_handle_type(handle); }
65 * Command socket console
68 class cl_console: public cl_console_base
70 friend class cl_commander;
73 cl_channel in, out, rout/*redirected output*/;
76 cl_console(void) { in = cl_channel(); out = cl_channel(); rout = cl_channel(); }
77 cl_console(char *fin, char *fout, class cl_app *the_app);
78 cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
79 cl_console(cl_channel _in, cl_channel _out, class cl_app *the_app);
81 int cmd_do_print(char *format, va_list ap);
83 virtual ~cl_console(void);
84 virtual class cl_console *clone_for_exec(char *fin);
86 virtual void redirect(char *fname, char *mode);
87 virtual void un_redirect(void);
88 virtual bool is_tty(void) const { return CH_FILE != in.get_type(); }
89 virtual bool is_eof(void) const { return in.is_eof(); }
90 virtual HANDLE get_in_fd(void) { return in.get_handle(); }
91 virtual bool input_avail(void) { return input_active() ? in.input_avail() : false; }
92 virtual char *read_line(void);
95 class cl_channel *get_out(void) { return (CH_UNDEF != rout.get_type()) ? &rout : &out; }
98 class cl_listen_console: public cl_console
101 cl_listen_console(int serverport, class cl_app *the_app);
103 virtual void welcome(void) {}
104 virtual int proc_input(class cl_cmdset *cmdset);
107 class cl_sub_console: public cl_console
110 class cl_console_base *parent;
113 cl_sub_console(class cl_console_base *the_parent,
114 cl_channel _in, cl_channel _out, class cl_app *the_app);
115 virtual ~cl_sub_console(void);
116 virtual int init(void);
121 * Command interpreter
124 class cl_commander: public cl_commander_base
127 fd_set read_set, active_set, console_active_set;
130 cl_commander(class cl_app *the_app, class cl_cmdset *acmdset)
131 : cl_commander_base(the_app, acmdset)
135 virtual int init(void);
136 virtual void set_fd_set(void);
137 virtual int input_avail(void) { return input_avail_timeout(0); }
138 virtual int wait_input(void);
139 virtual int proc_input(void);
142 int console_count(void);
143 int console_input_avail(void);
144 int socket_input_avail(long timeout, bool sleep);
145 int input_avail_timeout(long timeout);
150 /* End of cmd.src/newcmdwin32cl.h */