2 * Simulator of microcontrollers (cmd.src/commandcl.h)
4 * Copyright (C) 2002,02 Drotos Daniel
6 * To contact author send email to dr.dkdb@gmail.com
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
59 class cl_list
*params
;
60 class cl_ustrings
*tokens
;
61 const char *matched_syntax
;
62 class cl_console_base
*con
;
65 cl_cmdline(class cl_app
*the_app
, const char *acmd
, class cl_console_base
*acon
);
66 virtual ~cl_cmdline(void);
67 virtual int init(void);
70 virtual void split_out_string(char **_start
, char **_end
);
71 virtual void split_out_output_redirection(char **_start
, char **_end
);
72 virtual void add_bit(char *dot
, char *colon
, class cl_cmd_arg
*sfr
);
73 virtual void split_out_bit(char *dot
, char *param_str
);
74 virtual void split_out_array(char *dot
, char *param_str
);
75 virtual int token_length(char *start
);
76 virtual chars
get_token(char *start
);
77 virtual bool expand_commands(chars
*params
);
79 virtual int split(void);
80 virtual int shift(void);
81 virtual int repeat(void);
82 virtual class cl_cmd_arg
*param(int num
);
83 virtual void insert_param(int pos
, class cl_cmd_arg
*param
);
84 virtual bool syntax_match(class cl_uc
*uc
, const char *syntax
);
85 virtual bool set_data_list(class cl_cmd_arg
*parm
, int *iparm
);
86 virtual int nuof_params(void) { return(params
->get_count()); }
87 virtual bool restart_at_rest(void);
89 char *skip_delims(char *start
);
94 * Command and container
100 class cl_cmd
: public cl_base
103 enum cmd_operate_on operate_on
;
104 class cl_strings
*names
;
111 cl_cmd(enum cmd_operate_on opon
,
114 virtual ~cl_cmd(void);
116 virtual int init(void) { set_help(); return 0; }
117 virtual void set_help(void) {}
118 virtual void set_help(const char *usage_hlp
, const char *short_hlp
, const char *long_hlp
);
119 virtual class cl_cmdset
*get_subcommands(void) { return(0); }
120 virtual void add_name(const char *nam
);
121 virtual int name_match(const char *aname
, int strict
);
122 virtual int name_match(class cl_cmdline
*cmdline
, int strict
);
123 virtual int syntax_ok(class cl_cmdline
*cmdline
);
124 virtual int work(class cl_app
*app
,
125 class cl_cmdline
*cmdline
, class cl_console_base
*con
);
126 virtual int do_work(class cl_cmdline
*cmdline
, class cl_console_base
*con
);
127 virtual int do_work(class cl_app
*app
,
128 class cl_cmdline
*cmdline
, class cl_console_base
*con
);
129 virtual int do_work(class cl_sim
*sim
,
130 class cl_cmdline
*cmdline
, class cl_console_base
*con
);
131 virtual int do_work(class cl_uc
*uc
,
132 class cl_cmdline
*cmdline
, class cl_console_base
*con
);
133 virtual void print_short(class cl_console_base
*con
);
134 virtual void syntax_error(class cl_console_base
*con
);
137 #define COMMAND_HEAD(CLASS_NAME) \
138 class CLASS_NAME : public cl_cmd\
140 #define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
141 class CLASS_NAME : public ANCESTOR \
144 #define COMMAND_METHODS(CLASS_NAME) \
146 CLASS_NAME (const char *aname,\
148 cl_cmd(operate_on_none, aname, can_rep) {} \
149 virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);\
150 virtual void set_help(void);
152 #define COMMAND_METHODS_ON(ON,CLASS_NAME) \
154 CLASS_NAME (const char *aname,\
156 cl_cmd(operate_on_ ## ON, aname, can_rep) {} \
157 virtual int do_work(class cl_ ## ON * ON ,\
158 class cl_cmdline *cmdline, class cl_console_base *con);\
159 virtual void set_help(void);
161 #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
163 CLASS_NAME (const char *aname, int can_rep):\
164 ANCESTOR (aname, can_rep) {} \
165 virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);\
166 virtual void set_help(void);
168 #define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
170 CLASS_NAME (const char *aname, int can_rep):\
171 ANCESTOR (aname, can_rep) {} \
172 virtual int do_work(class cl_ ## ON * ON ,\
173 class cl_cmdline *cmdline, class cl_console_base *con);\
174 virtual void set_help(void); \
177 #define COMMAND_TAIL }
179 #define COMMAND(CLASS_NAME) \
180 COMMAND_HEAD(CLASS_NAME) \
181 COMMAND_METHODS(CLASS_NAME) \
184 #define COMMAND_ON(ON,CLASS_NAME) \
185 COMMAND_HEAD(CLASS_NAME) \
186 COMMAND_METHODS_ON(ON,CLASS_NAME) \
189 #define COMMAND_DATA(CLASS_NAME,DATA) \
190 COMMAND_HEAD(CLASS_NAME) \
192 COMMAND_METHODS(CLASS_NAME)\
195 #define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
196 COMMAND_HEAD(CLASS_NAME) \
198 COMMAND_METHODS_ON(ON,CLASS_NAME)\
201 #define COMMAND_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
202 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
203 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
206 #define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
207 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
209 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
212 #define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
213 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
215 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
218 #define COMMAND_DO_WORK(CLASS_NAME) \
220 CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console_base *con)
221 #define COMMAND_DO_WORK_APP(CLASS_NAME) \
223 CLASS_NAME::do_work(class cl_app *app,\
224 class cl_cmdline *cmdline, class cl_console_base *con)
225 #define COMMAND_DO_WORK_SIM(CLASS_NAME) \
227 CLASS_NAME::do_work(class cl_sim *sim,\
228 class cl_cmdline *cmdline, class cl_console_base *con)
229 #define COMMAND_DO_WORK_UC(CLASS_NAME) \
231 CLASS_NAME::do_work(class cl_uc *uc,\
232 class cl_cmdline *cmdline, class cl_console_base *con)
234 #define CMDHELP(CLASS_NAME,USAGE_HLP,SHORT_HLP,LONG_HLP) \
236 CLASS_NAME::set_help(void) \
238 usage_help=USAGE_HLP; \
239 short_help=SHORT_HLP; \
240 long_help=LONG_HLP; \
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
, bool accept_last
);
255 virtual class cl_cmd
*get_cmd(const char *cmd_name
);
256 virtual void del(char *nam
);
257 virtual void replace(char *nam
, 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(const char *aname
,
269 class cl_cmdset
*acommands
);
270 virtual ~cl_super_cmd(void);
272 virtual class cl_cmdset
*get_subcommands(void) { return(commands
); }
273 virtual int work(class cl_app
*app
,
274 class cl_cmdline
*cmdline
, class cl_console_base
*con
);
280 /* End of cmd.src/commandcl.h */