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
58 #define SY_DATALIST 'D'
72 * Command line with parameters
75 class cl_cmdline: cl_base
81 class cl_list *params;
82 class cl_ustrings *tokens;
84 class cl_console *con;
87 cl_cmdline(class cl_app *the_app, char *acmd, class cl_console *acon);
88 virtual ~cl_cmdline(void);
89 virtual int init(void);
91 virtual int split(void);
92 virtual int shift(void);
93 virtual int repeat(void);
94 virtual class cl_cmd_arg *param(int num);
95 virtual void insert_param(int pos, class cl_cmd_arg *param);
96 virtual bool syntax_match(class cl_uc *uc, char *syntax);
97 virtual bool set_data_list(class cl_cmd_arg *parm, int *iparm);
99 char *skip_delims(char *start);
104 * Command and container
108 class cl_cmd: public cl_base
111 enum cmd_operate_on operate_on;
112 class cl_strings *names;
118 cl_cmd(enum cmd_operate_on opon,
125 virtual void add_name(char *name);
126 virtual int name_match(char *aname, int strict);
127 virtual int name_match(class cl_cmdline *cmdline, int strict);
128 virtual int syntax_ok(class cl_cmdline *cmdline);
129 virtual int work(class cl_app *app,
130 class cl_cmdline *cmdline, class cl_console *con);
131 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
132 virtual int do_work(class cl_app *app,
133 class cl_cmdline *cmdline, class cl_console *con);
134 virtual int do_work(class cl_sim *sim,
135 class cl_cmdline *cmdline, class cl_console *con);
136 virtual int do_work(class cl_uc *uc,
137 class cl_cmdline *cmdline, class cl_console *con);
140 #define COMMAND_HEAD(CLASS_NAME) \
141 class CLASS_NAME : public cl_cmd\
143 #define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
144 class CLASS_NAME : public ANCESTOR \
147 #define COMMAND_METHODS(CLASS_NAME) \
149 CLASS_NAME (char *aname,\
153 cl_cmd(operate_on_none, aname, can_rep, short_help, long_help) {}\
154 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
156 #define COMMAND_METHODS_ON(ON,CLASS_NAME) \
158 CLASS_NAME (char *aname,\
162 cl_cmd(operate_on_ ## ON, aname, can_rep, short_help, long_help) {}\
163 virtual int do_work(class cl_ ## ON * ON ,\
164 class cl_cmdline *cmdline, class cl_console *con);
166 #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
168 CLASS_NAME (char *aname,\
172 ANCESTOR (aname, can_rep, short_help, long_help) {}\
173 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
175 #define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
177 CLASS_NAME (char *aname,\
181 ANCESTOR (aname, can_rep, short_help, long_help) {}\
182 virtual int do_work(class cl_ ## ON * ON ,\
183 class cl_cmdline *cmdline, class cl_console *con); \
186 #define COMMAND_TAIL }
188 #define COMMAND(CLASS_NAME) \
189 COMMAND_HEAD(CLASS_NAME) \
190 COMMAND_METHODS(CLASS_NAME) \
193 #define COMMAND_ON(ON,CLASS_NAME) \
194 COMMAND_HEAD(CLASS_NAME) \
195 COMMAND_METHODS_ON(ON,CLASS_NAME) \
198 #define COMMAND_DATA(CLASS_NAME,DATA) \
199 COMMAND_HEAD(CLASS_NAME) \
201 COMMAND_METHODS(CLASS_NAME)\
204 #define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
205 COMMAND_HEAD(CLASS_NAME) \
207 COMMAND_METHODS_ON(ON,CLASS_NAME)\
210 #define COMMAND_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
211 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
212 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
215 #define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
216 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
218 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
221 #define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
222 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
224 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
227 #define COMMAND_DO_WORK(CLASS_NAME) \
229 CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console *con)
230 #define COMMAND_DO_WORK_APP(CLASS_NAME) \
232 CLASS_NAME::do_work(class cl_app *app,\
233 class cl_cmdline *cmdline, class cl_console *con)
234 #define COMMAND_DO_WORK_SIM(CLASS_NAME) \
236 CLASS_NAME::do_work(class cl_sim *sim,\
237 class cl_cmdline *cmdline, class cl_console *con)
238 #define COMMAND_DO_WORK_UC(CLASS_NAME) \
240 CLASS_NAME::do_work(class cl_uc *uc,\
241 class cl_cmdline *cmdline, class cl_console *con)
243 // Command set is list of cl_cmd objects
244 class cl_cmdset: public cl_list
248 class cl_cmd *last_command;
252 //cl_cmdset(class cl_sim *asim);
254 virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline);
255 virtual class cl_cmd *get_cmd(char *cmd_name);
256 virtual void del(char *name);
257 virtual void replace(char *name, class cl_cmd *cmd);
260 // subset of commands
261 class cl_super_cmd: public cl_cmd
264 class cl_cmdset *commands;
267 cl_super_cmd(char *aname,
271 class cl_cmdset *acommands);
274 virtual int work(class cl_app *app,
275 class cl_cmdline *cmdline, class cl_console *con);
283 class cl_console: public cl_base
285 friend class cl_commander;
291 int flags; // See CONS_XXXX
295 cl_console(void): cl_base() { app= 0; in= out= 0; flags= 0; }
296 cl_console(char *fin, char *fout, class cl_app *the_app);
297 cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
299 cl_console(int portnumber, class cl_app *the_app);
302 virtual int init(void);
304 virtual void welcome(void);
305 virtual void print_prompt(void);
306 virtual int printf(char *format, ...);
307 virtual void print_bin(long data, int bits);
308 virtual int match(int fdnum);
309 virtual int get_in_fd(void);
310 virtual int input_avail(void);
311 virtual char *read_line(void);
312 virtual int proc_input(class cl_cmdset *cmdset);
313 virtual bool interpret(char *cmd);
317 class cl_listen_console: public cl_console
322 cl_listen_console(int serverport, class cl_app *the_app);
324 virtual void welcome(void) {}
325 virtual void prompt(void) {}
327 virtual int match(int fdnum);
328 virtual int get_in_fd(void);
329 virtual int proc_input(class cl_cmdset *cmdset);
335 * Command interpreter
338 class cl_commander: public cl_base
343 fd_set read_set, active_set;
346 class cl_console *actual_console, *frozen_console;
347 class cl_cmdset *cmdset;
350 cl_commander(class cl_app *the_app,
351 class cl_cmdset *acmdset/*, class cl_sim *asim*/);
353 virtual int init(void);
355 virtual class cl_console *mk_console(char *fin, char *fout);
356 virtual class cl_console *mk_console(FILE *fin, FILE *fout);
358 virtual class cl_console *mk_console(int portnumber);
360 void add_console(class cl_console *console);
361 void del_console(class cl_console *console);
362 void set_fd_set(void);
364 int all_printf(char *format, ...); // print to all consoles
365 int all_print(char *string, int length);
366 int printf(char *format, ...); // print to actual_console
367 int debug(char *format, ...); // print consoles with debug flag set
368 int flag_printf(int iflags, char *format, ...);
369 int input_avail(void);
370 int input_avail_on_frozen(void);
371 int wait_input(void);
372 int proc_input(void);
378 /* End of cmd.src/cmdcl.h */