2 * Simulator of microcontrollers (cmd.src/commandcl.h)
4 * Copyright (C) 2002,02 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_COMMAND_HEADER
29 #define CMD_COMMAND_HEADER
49 * Command line with parameters
52 class cl_cmdline: public cl_base
58 class cl_list *params;
59 class cl_ustrings *tokens;
61 class cl_console *con;
64 cl_cmdline(class cl_app *the_app, char *acmd, class cl_console *acon);
65 virtual ~cl_cmdline(void);
66 virtual int init(void);
69 virtual void split_out_string(char **_start, char **_end);
70 virtual void split_out_output_redirection(char **_start, char **_end);
71 virtual void split_out_bit(char *dot, char *param_str);
72 virtual void split_out_array(char *dot, char *param_str);
74 virtual int split(void);
75 virtual int shift(void);
76 virtual int repeat(void);
77 virtual class cl_cmd_arg *param(int num);
78 virtual void insert_param(int pos, class cl_cmd_arg *param);
79 virtual bool syntax_match(class cl_uc *uc, char *syntax);
80 virtual bool set_data_list(class cl_cmd_arg *parm, int *iparm);
81 virtual int nuof_params(void) { return(params->get_count()); }
83 char *skip_delims(char *start);
88 * Command and container
94 class cl_cmd: public cl_base
97 enum cmd_operate_on operate_on;
98 class cl_strings *names;
104 cl_cmd(enum cmd_operate_on opon,
109 virtual ~cl_cmd(void);
111 virtual class cl_cmdset *get_subcommands(void) { return(0); }
112 virtual void add_name(char *nam);
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_app *app,
117 class cl_cmdline *cmdline, class cl_console *con);
118 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
119 virtual int do_work(class cl_app *app,
120 class cl_cmdline *cmdline, class cl_console *con);
121 virtual int do_work(class cl_sim *sim,
122 class cl_cmdline *cmdline, class cl_console *con);
123 virtual int do_work(class cl_uc *uc,
124 class cl_cmdline *cmdline, class cl_console *con);
127 #define COMMAND_HEAD(CLASS_NAME) \
128 class CLASS_NAME : public cl_cmd\
130 #define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
131 class CLASS_NAME : public ANCESTOR \
134 #define COMMAND_METHODS(CLASS_NAME) \
136 CLASS_NAME (char *aname,\
140 cl_cmd(operate_on_none, aname, can_rep, short_help, long_help) {}\
141 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
143 #define COMMAND_METHODS_ON(ON,CLASS_NAME) \
145 CLASS_NAME (char *aname,\
149 cl_cmd(operate_on_ ## ON, aname, can_rep, short_help, long_help) {}\
150 virtual int do_work(class cl_ ## ON * ON ,\
151 class cl_cmdline *cmdline, class cl_console *con);
153 #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
155 CLASS_NAME (char *aname,\
159 ANCESTOR (aname, can_rep, short_help, long_help) {}\
160 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
162 #define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
164 CLASS_NAME (char *aname,\
168 ANCESTOR (aname, can_rep, short_help, long_help) {}\
169 virtual int do_work(class cl_ ## ON * ON ,\
170 class cl_cmdline *cmdline, class cl_console *con); \
173 #define COMMAND_TAIL }
175 #define COMMAND(CLASS_NAME) \
176 COMMAND_HEAD(CLASS_NAME) \
177 COMMAND_METHODS(CLASS_NAME) \
180 #define COMMAND_ON(ON,CLASS_NAME) \
181 COMMAND_HEAD(CLASS_NAME) \
182 COMMAND_METHODS_ON(ON,CLASS_NAME) \
185 #define COMMAND_DATA(CLASS_NAME,DATA) \
186 COMMAND_HEAD(CLASS_NAME) \
188 COMMAND_METHODS(CLASS_NAME)\
191 #define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
192 COMMAND_HEAD(CLASS_NAME) \
194 COMMAND_METHODS_ON(ON,CLASS_NAME)\
197 #define COMMAND_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
198 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
199 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
202 #define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
203 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
205 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
208 #define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
209 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
211 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
214 #define COMMAND_DO_WORK(CLASS_NAME) \
216 CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console *con)
217 #define COMMAND_DO_WORK_APP(CLASS_NAME) \
219 CLASS_NAME::do_work(class cl_app *app,\
220 class cl_cmdline *cmdline, class cl_console *con)
221 #define COMMAND_DO_WORK_SIM(CLASS_NAME) \
223 CLASS_NAME::do_work(class cl_sim *sim,\
224 class cl_cmdline *cmdline, class cl_console *con)
225 #define COMMAND_DO_WORK_UC(CLASS_NAME) \
227 CLASS_NAME::do_work(class cl_uc *uc,\
228 class cl_cmdline *cmdline, class cl_console *con)
230 // Command set is list of cl_cmd objects
231 class cl_cmdset: public cl_list
235 //class cl_cmd *last_command;
239 //cl_cmdset(class cl_sim *asim);
241 virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline, bool accept_last);
242 virtual class cl_cmd *get_cmd(char *cmd_name);
243 virtual void del(char *nam);
244 virtual void replace(char *nam, class cl_cmd *cmd);
247 // subset of commands
248 class cl_super_cmd: public cl_cmd
251 class cl_cmdset *commands;
254 cl_super_cmd(char *aname,
258 class cl_cmdset *acommands);
259 virtual ~cl_super_cmd(void);
261 virtual class cl_cmdset *get_subcommands(void) { return(commands); }
262 virtual int work(class cl_app *app,
263 class cl_cmdline *cmdline, class cl_console *con);
269 /* End of cmd.src/commandcl.h */