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
35 #include <sys/types.h> // to define fd_set
59 #define SY_DATALIST 'D'
73 * Command line with parameters
76 class cl_cmdline: cl_base
82 class cl_list *params;
83 class cl_ustrings *tokens;
85 class cl_console *con;
88 cl_cmdline(class cl_app *the_app, char *acmd, class cl_console *acon);
89 virtual ~cl_cmdline(void);
90 virtual int init(void);
92 virtual int split(void);
93 virtual int shift(void);
94 virtual int repeat(void);
95 virtual class cl_cmd_arg *param(int num);
96 virtual void insert_param(int pos, class cl_cmd_arg *param);
97 virtual bool syntax_match(class cl_uc *uc, char *syntax);
98 virtual bool set_data_list(class cl_cmd_arg *parm, int *iparm);
100 char *skip_delims(char *start);
105 * Command and container
109 class cl_cmd: public cl_base
112 enum cmd_operate_on operate_on;
113 class cl_strings *names;
119 cl_cmd(enum cmd_operate_on opon,
126 virtual void add_name(char *name);
127 virtual int name_match(char *aname, int strict);
128 virtual int name_match(class cl_cmdline *cmdline, int strict);
129 virtual int syntax_ok(class cl_cmdline *cmdline);
130 virtual int work(class cl_app *app,
131 class cl_cmdline *cmdline, class cl_console *con);
132 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
133 virtual int do_work(class cl_app *app,
134 class cl_cmdline *cmdline, class cl_console *con);
135 virtual int do_work(class cl_sim *sim,
136 class cl_cmdline *cmdline, class cl_console *con);
137 virtual int do_work(class cl_uc *uc,
138 class cl_cmdline *cmdline, class cl_console *con);
141 #define COMMAND_HEAD(CLASS_NAME) \
142 class CLASS_NAME : public cl_cmd\
144 #define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
145 class CLASS_NAME : public ANCESTOR \
148 #define COMMAND_METHODS(CLASS_NAME) \
150 CLASS_NAME (char *aname,\
154 cl_cmd(operate_on_none, aname, can_rep, short_help, long_help) {}\
155 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
157 #define COMMAND_METHODS_ON(ON,CLASS_NAME) \
159 CLASS_NAME (char *aname,\
163 cl_cmd(operate_on_ ## ON, aname, can_rep, short_help, long_help) {}\
164 virtual int do_work(class cl_ ## ON * ON ,\
165 class cl_cmdline *cmdline, class cl_console *con);
167 #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
169 CLASS_NAME (char *aname,\
173 ANCESTOR (aname, can_rep, short_help, long_help) {}\
174 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
176 #define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
178 CLASS_NAME (char *aname,\
182 ANCESTOR (aname, can_rep, short_help, long_help) {}\
183 virtual int do_work(class cl_ ## ON * ON ,\
184 class cl_cmdline *cmdline, class cl_console *con); \
187 #define COMMAND_TAIL }
189 #define COMMAND(CLASS_NAME) \
190 COMMAND_HEAD(CLASS_NAME) \
191 COMMAND_METHODS(CLASS_NAME) \
194 #define COMMAND_ON(ON,CLASS_NAME) \
195 COMMAND_HEAD(CLASS_NAME) \
196 COMMAND_METHODS_ON(ON,CLASS_NAME) \
199 #define COMMAND_DATA(CLASS_NAME,DATA) \
200 COMMAND_HEAD(CLASS_NAME) \
202 COMMAND_METHODS(CLASS_NAME)\
205 #define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
206 COMMAND_HEAD(CLASS_NAME) \
208 COMMAND_METHODS_ON(ON,CLASS_NAME)\
211 #define COMMAND_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
212 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
213 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
216 #define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
217 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
219 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
222 #define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
223 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
225 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
228 #define COMMAND_DO_WORK(CLASS_NAME) \
230 CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console *con)
231 #define COMMAND_DO_WORK_APP(CLASS_NAME) \
233 CLASS_NAME::do_work(class cl_app *app,\
234 class cl_cmdline *cmdline, class cl_console *con)
235 #define COMMAND_DO_WORK_SIM(CLASS_NAME) \
237 CLASS_NAME::do_work(class cl_sim *sim,\
238 class cl_cmdline *cmdline, class cl_console *con)
239 #define COMMAND_DO_WORK_UC(CLASS_NAME) \
241 CLASS_NAME::do_work(class cl_uc *uc,\
242 class cl_cmdline *cmdline, class cl_console *con)
244 // Command set is list of cl_cmd objects
245 class cl_cmdset: public cl_list
249 class cl_cmd *last_command;
253 //cl_cmdset(class cl_sim *asim);
255 virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline);
256 virtual class cl_cmd *get_cmd(char *cmd_name);
257 virtual void del(char *name);
258 virtual void replace(char *name, class cl_cmd *cmd);
261 // subset of commands
262 class cl_super_cmd: public cl_cmd
265 class cl_cmdset *commands;
268 cl_super_cmd(char *aname,
272 class cl_cmdset *acommands);
275 virtual int work(class cl_app *app,
276 class cl_cmdline *cmdline, class cl_console *con);
284 class cl_console: public cl_base
286 friend class cl_commander;
292 int flags; // See CONS_XXXX
296 cl_console(void): cl_base() { app= 0; in= out= 0; flags= 0; }
297 cl_console(char *fin, char *fout, class cl_app *the_app);
298 cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
300 cl_console(int portnumber, class cl_app *the_app);
303 virtual int init(void);
305 virtual void welcome(void);
306 virtual void print_prompt(void);
307 virtual int dd_printf(char *format, ...);
308 virtual void print_bin(long data, int bits);
309 virtual int match(int fdnum);
310 virtual int get_in_fd(void);
311 virtual int input_avail(void);
312 virtual char *read_line(void);
313 virtual int proc_input(class cl_cmdset *cmdset);
314 virtual bool interpret(char *cmd);
318 class cl_listen_console: public cl_console
323 cl_listen_console(int serverport, class cl_app *the_app);
325 virtual void welcome(void) {}
326 virtual void prompt(void) {}
328 virtual int match(int fdnum);
329 virtual int get_in_fd(void);
330 virtual int proc_input(class cl_cmdset *cmdset);
336 * Command interpreter
339 class cl_commander: public cl_base
344 fd_set read_set, active_set;
347 class cl_console *actual_console, *frozen_console;
348 class cl_cmdset *cmdset;
351 cl_commander(class cl_app *the_app,
352 class cl_cmdset *acmdset/*, class cl_sim *asim*/);
354 virtual int init(void);
356 virtual class cl_console *mk_console(char *fin, char *fout);
357 virtual class cl_console *mk_console(FILE *fin, FILE *fout);
359 virtual class cl_console *mk_console(int portnumber);
361 void add_console(class cl_console *console);
362 void del_console(class cl_console *console);
363 void set_fd_set(void);
365 int all_printf(char *format, ...); // print to all consoles
366 int all_print(char *string, int length);
367 int dd_printf(char *format, ...); // print to actual_console
368 int debug(char *format, ...); // print consoles with debug flag set
369 int flag_printf(int iflags, char *format, ...);
370 int input_avail(void);
371 int input_avail_on_frozen(void);
372 int wait_input(void);
373 int proc_input(void);
379 /* End of cmd.src/cmdcl.h */