2 * Simulator of microcontrollers (cmd.src/cmdcl.h)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
10 /* This file is part of microcontroller simulator: ucsim.
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 #ifndef CMD_NEWCMDCL_HEADER
29 #define CMD_NEWCMDCL_HEADER
36 #include <sys/types.h>
48 #include "commandcl.h"
53 #define CONS_DEBUG 0x01 // Print debug messages on this console
54 #define CONS_FROZEN 0x02 // Console is frozen (g command issued)
55 #define CONS_PROMPT 0x04 // Prompt is out, waiting for input
56 #define CONS_INTERACTIVE 0x08 // Interactive console
57 #define CONS_NOWELCOME 0x10 // Do not print welcome message
58 #define CONS_INACTIVE 0x20 // Do not do any action
59 #define CONS_ECHO 0x40 // Echo commands
73 #define SY_DATALIST 'D'
79 class cl_prompt_option: public cl_optref
82 class cl_console *con;
84 cl_prompt_option(class cl_console *console);
85 virtual int init(void);
86 virtual void option_changed(void);
89 class cl_debug_option: public cl_prompt_option
92 cl_debug_option(class cl_console *console);
93 virtual int init(void);
94 virtual void option_changed(void);
101 class cl_console: public cl_base
103 friend class cl_commander;
105 FILE *in, *out, *rout/*redirected output*/;
107 class cl_prompt_option *prompt_option;
108 class cl_optref *null_prompt_option;
109 class cl_debug_option *debug_option;
110 class cl_ustrings *lines_printed;
111 class cl_cmd *last_command;
112 class cl_cmdline *last_cmdline;
115 int flags; // See CONS_XXXX
119 cl_console(void): cl_base() { app= 0; in= out= 0; flags= 0; }
120 cl_console(char *fin, char *fout, class cl_app *the_app);
121 cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
122 cl_console(char *fin, FILE *fout);
124 cl_console(int portnumber, class cl_app *the_app);
126 virtual ~cl_console(void);
127 virtual class cl_console *cl_console::clone_for_exec(char *fin);
128 virtual int init(void);
130 virtual bool accept_last(void);
132 virtual void welcome(void);
133 virtual void redirect(char *fname, char *mode);
134 virtual void un_redirect(void);
135 virtual FILE *get_out(void) { return(rout?rout:out); }
136 int cmd_do_print(FILE *f, char *format, va_list ap);
137 virtual void print_prompt(void);
138 virtual int dd_printf(char *format, ...);
139 virtual int debug(char *format, ...);
140 virtual void print_bin(long data, int bits);
141 virtual void print_char_octal(char c);
142 virtual int match(int fdnum);
143 virtual int get_in_fd(void);
144 virtual int input_avail(void);
145 virtual char *read_line(void);
146 virtual int proc_input(class cl_cmdset *cmdset);
147 virtual bool interpret(char *cmd);
148 virtual void set_id(int new_id);
149 virtual int get_id(void) { return(id); }
150 virtual void set_prompt(char *p);
154 class cl_listen_console: public cl_console
159 cl_listen_console(int serverport, class cl_app *the_app);
161 virtual void welcome(void) {}
162 virtual void prompt(void) {}
164 virtual int match(int fdnum);
165 virtual int get_in_fd(void);
166 virtual int proc_input(class cl_cmdset *cmdset);
171 class cl_sub_console: public cl_console
173 class cl_console *parent;
175 cl_sub_console(class cl_console *the_parent,
176 FILE *fin, FILE *fout, class cl_app *the_app);
177 virtual ~cl_sub_console(void);
178 virtual int init(void);
183 * Command interpreter
186 class cl_commander: public cl_base
191 fd_set read_set, active_set;
194 class cl_console *actual_console, *frozen_console;
195 class cl_cmdset *cmdset;
198 cl_commander(class cl_app *the_app,
199 class cl_cmdset *acmdset/*, class cl_sim *asim*/);
200 virtual ~cl_commander(void);
201 virtual int init(void);
203 virtual class cl_console *mk_console(char *fin, char *fout);
204 virtual class cl_console *mk_console(FILE *fin, FILE *fout);
206 virtual class cl_console *mk_console(int portnumber);
208 void add_console(class cl_console *console);
209 void del_console(class cl_console *console);
210 void activate_console(class cl_console *console);
211 void deactivate_console(class cl_console *console);
212 void set_fd_set(void);
216 int all_printf(char *format, ...); // print to all consoles
217 int all_print(char *string, int length);
218 int dd_printf(char *format, ...); // print to actual_console
219 int dd_printf(char *format, va_list ap);// print to actual_console
220 int debug(char *format, ...); // print consoles with debug flag set
221 int debug(char *format, va_list ap); // print consoles with debug flag set
222 int flag_printf(int iflags, char *format, ...);
223 int input_avail(void);
224 int input_avail_on_frozen(void);
225 int wait_input(void);
226 int proc_input(void);
227 void exec_on(class cl_console *cons, char *file_name);
233 /* End of cmd.src/cmdcl.h */