[ucsim] Update email and file info, fix stm8 flash controller
[sdcc.git] / sdcc / sim / ucsim / src / core / cmd.src / commandcl.h
blob08a247172a4c83545f74459e315f67f52bf95293
1 /*
2 * Simulator of microcontrollers (cmd.src/commandcl.h)
4 * Copyright (C) 2002,02 Drotos Daniel
5 *
6 * To contact author send email to dr.dkdb@gmail.com
8 */
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
25 02111-1307, USA. */
26 /*@1@*/
28 #ifndef CMD_COMMAND_HEADER
29 #define CMD_COMMAND_HEADER
31 #include "ddconfig.h"
33 // prj
34 #include "pobjcl.h"
36 // local, cmd
37 #include "newcmdcl.h"
40 enum cmd_operate_on {
41 operate_on_none,
42 operate_on_app,
43 operate_on_sim,
44 operate_on_uc
49 * Command line with parameters
52 class cl_cmdline: public cl_base
54 public:
55 class cl_app *app;
56 char *cmd;
57 char *rest;
58 //char *name;
59 class cl_list *params;
60 class cl_ustrings *tokens;
61 const char *matched_syntax;
62 class cl_console_base *con;
64 public:
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);
69 private:
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);
78 public:
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);
88 private:
89 char *skip_delims(char *start);
94 * Command and container
97 class cl_cmdset;
99 // simple command
100 class cl_cmd: public cl_base
102 public:
103 enum cmd_operate_on operate_on;
104 class cl_strings *names;
105 int can_repeat;
106 chars usage_help;
107 chars short_help;
108 chars long_help;
110 public:
111 cl_cmd(enum cmd_operate_on opon,
112 const char *aname,
113 int can_rep);
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) \
145 public:\
146 CLASS_NAME (const char *aname,\
147 int can_rep):\
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) \
153 public:\
154 CLASS_NAME (const char *aname,\
155 int can_rep):\
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) \
162 public:\
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) \
169 public:\
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) \
182 COMMAND_TAIL
184 #define COMMAND_ON(ON,CLASS_NAME) \
185 COMMAND_HEAD(CLASS_NAME) \
186 COMMAND_METHODS_ON(ON,CLASS_NAME) \
187 COMMAND_TAIL
189 #define COMMAND_DATA(CLASS_NAME,DATA) \
190 COMMAND_HEAD(CLASS_NAME) \
191 public: DATA ; \
192 COMMAND_METHODS(CLASS_NAME)\
193 COMMAND_TAIL
195 #define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
196 COMMAND_HEAD(CLASS_NAME) \
197 public: DATA ; \
198 COMMAND_METHODS_ON(ON,CLASS_NAME)\
199 COMMAND_TAIL
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) \
204 COMMAND_TAIL
206 #define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
207 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
208 public: DATA ; \
209 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
210 COMMAND_TAIL
212 #define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
213 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
214 public: DATA ; \
215 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
216 COMMAND_TAIL
218 #define COMMAND_DO_WORK(CLASS_NAME) \
219 int \
220 CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console_base *con)
221 #define COMMAND_DO_WORK_APP(CLASS_NAME) \
222 int \
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) \
226 int \
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) \
230 int \
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) \
235 void \
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
246 public:
247 //class cl_sim *sim;
248 //class cl_cmd *last_command;
250 public:
251 cl_cmdset(void);
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
263 public:
264 class cl_cmdset *commands;
266 public:
267 cl_super_cmd(const char *aname,
268 int can_rep,
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);
278 #endif
280 /* End of cmd.src/commandcl.h */