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
54 #define SY_DATALIST 'D'
60 * Command line with parameters
63 class cl_cmdline: cl_base
68 class cl_list *params;
69 class cl_ustrings *tokens;
71 class cl_console *con;
74 cl_cmdline(char *acmd, class cl_console *acon);
75 virtual ~cl_cmdline(void);
76 virtual int init(void);
78 virtual int split(void);
79 virtual int shift(void);
80 virtual int repeat(void);
81 virtual class cl_cmd_arg *param(int num);
82 virtual void insert_param(int pos, class cl_cmd_arg *param);
83 virtual bool syntax_match(class cl_sim *sim, char *syntax);
84 virtual bool set_data_list(class cl_cmd_arg *parm, int *iparm);
86 char *skip_delims(char *start);
91 * Command and container
95 class cl_cmd: public cl_base
99 class cl_strings *names;
105 cl_cmd(//class cl_sim *asim,
112 virtual void add_name(char *name);
113 virtual int name_match(char *aname, int strict);
114 virtual int name_match(class cl_cmdline *cmdline, int strict);
115 virtual int syntax_ok(class cl_cmdline *cmdline);
116 virtual int work(class cl_sim *sim,
117 class cl_cmdline *cmdline, class cl_console *con);
118 virtual int do_work(class cl_sim *sim,
119 class cl_cmdline *cmdline, class cl_console *con);
122 #define COMMAND_HEAD(CLASS_NAME) \
123 class CLASS_NAME : public cl_cmd\
125 #define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
126 class CLASS_NAME : public ANCESTOR \
129 #define COMMAND_METHODS(CLASS_NAME) \
131 CLASS_NAME (char *aname,\
135 cl_cmd(aname, can_rep, short_help, long_help) {}\
136 virtual int do_work(class cl_sim *sim,\
137 class cl_cmdline *cmdline, class cl_console *con);
138 #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
140 CLASS_NAME (char *aname,\
144 ANCESTOR (aname, can_rep, short_help, long_help) {}\
145 virtual int do_work(class cl_sim *sim,\
146 class cl_cmdline *cmdline, class cl_console *con);
148 #define COMMAND_TAIL \
151 #define COMMAND(CLASS_NAME) \
152 COMMAND_HEAD(CLASS_NAME) \
153 COMMAND_METHODS(CLASS_NAME) \
156 #define COMMAND_DATA(CLASS_NAME,DATA) \
157 COMMAND_HEAD(CLASS_NAME) \
159 COMMAND_METHODS(CLASS_NAME)\
162 #define COMMAND_ANCESTOR(CLASS_NAME,ANCESTOR) \
163 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
164 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
167 #define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
168 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
170 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
174 // Command set is list of cl_cmd objects
175 class cl_cmdset: public cl_list
179 class cl_cmd *last_command;
182 cl_cmdset(class cl_sim *asim);
184 virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline);
185 virtual class cl_cmd *get_cmd(char *cmd_name);
186 virtual void del(char *name);
187 virtual void replace(char *name, class cl_cmd *cmd);
190 // subset of commands
191 class cl_super_cmd: public cl_cmd
194 class cl_cmdset *commands;
197 cl_super_cmd(//class cl_sim *asim,
202 class cl_cmdset *acommands);
205 virtual int work(class cl_sim *sim,
206 class cl_cmdline *cmdline, class cl_console *con);
214 class cl_console: public cl_base
216 friend class cl_commander;
222 int flags; // See CONS_XXXX
226 cl_console(): cl_base() {}
227 cl_console(char *fin, char *fout, class cl_sim *asim);
228 cl_console(FILE *fin, FILE *fout, class cl_sim *asim);
230 cl_console(int portnumber, class cl_sim *asim);
233 virtual int init(void);
235 virtual void welcome(void);
236 virtual void print_prompt(void);
237 virtual int printf(char *format, ...);
238 virtual void print_bin(long data, int bits);
239 virtual int match(int fdnum);
240 virtual int get_in_fd(void);
241 virtual int input_avail(void);
242 virtual char *read_line(void);
243 virtual int proc_input(class cl_app *app, class cl_cmdset *cmdset);
244 virtual bool interpret(char *cmd);
248 class cl_listen_console: public cl_console
253 cl_listen_console(int serverport, class cl_sim *asim);
255 virtual void welcome(void) {}
256 virtual void prompt(void) {}
258 virtual int match(int fdnum);
259 virtual int get_in_fd(void);
260 virtual int proc_input(class cl_cmdset *cmdset);
266 * Command interpreter
269 class cl_commander: public cl_base
274 fd_set read_set, active_set;
277 class cl_console *actual_console, *frozen_console;
278 class cl_cmdset *cmdset;
281 cl_commander(class cl_app *the_app,
282 class cl_cmdset *acmdset, class cl_sim *asim);
284 virtual int init(void);
286 virtual class cl_console *mk_console(char *fin, char *fout,
288 virtual class cl_console *mk_console(FILE *fin, FILE *fout,
291 virtual class cl_console *mk_console(int portnumber, class cl_sim *asim);
293 void add_console(class cl_console *console);
294 void del_console(class cl_console *console);
295 void set_fd_set(void);
297 int all_printf(char *format, ...); // print to all consoles
298 int all_print(char *string, int length);
299 int printf(char *format, ...); // print to actual_console
300 int debug(char *format, ...); // print consoles with debug flag set
301 int flag_printf(int iflags, char *format, ...);
302 int input_avail(void);
303 int input_avail_on_frozen(void);
304 int wait_input(void);
305 int proc_input(void);
311 /* End of cmd.src/cmdcl.h */