version 0.5.2
[fw/sdcc] / sim / ucsim / cmd.src / commandcl.h
1 /*
2  * Simulator of microcontrollers (cmd.src/commandcl.h)
3  *
4  * Copyright (C) 2002,02 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
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.
16
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.
21
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@*/
27
28 #ifndef CMD_COMMAND_HEADER
29 #define CMD_COMMAND_HEADER
30
31 #include "ddconfig.h"
32
33 // prj
34 #include "pobjcl.h"
35
36 // local, cmd
37 #include "newcmdcl.h"
38
39
40 enum cmd_operate_on {
41   operate_on_none,
42   operate_on_app,
43   operate_on_sim,
44   operate_on_uc
45 };
46
47
48 /*
49  * Command line with parameters
50  */
51
52 class cl_cmdline: public cl_base
53 {
54 public:
55   class cl_app *app;
56   char *cmd;
57   //char *name;
58   class cl_list *params;
59   class cl_ustrings *tokens;
60   char *matched_syntax;
61   class cl_console *con;
62
63 public:
64   cl_cmdline(class cl_app *the_app, char *acmd, class cl_console *acon);
65   virtual ~cl_cmdline(void);
66   virtual int init(void);
67
68 private:
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);
73 public:
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()); }
82 private:
83   char *skip_delims(char *start);
84 };
85
86
87 /*
88  * Command and container
89  */
90
91 class cl_cmdset;
92
93 // simple command
94 class cl_cmd: public cl_base
95 {
96 public:
97   enum cmd_operate_on operate_on;
98   class cl_strings *names;
99   int  can_repeat;
100   char *short_help;
101   char *long_help;
102
103 public:
104   cl_cmd(enum cmd_operate_on opon,
105          char *aname,
106          int  can_rep,
107          char *short_hlp,
108          char *long_hlp);
109   virtual ~cl_cmd(void);
110
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);
125 };
126
127 #define COMMAND_HEAD(CLASS_NAME) \
128 class CLASS_NAME : public cl_cmd\
129 {
130 #define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
131 class CLASS_NAME : public ANCESTOR \
132 {
133
134 #define COMMAND_METHODS(CLASS_NAME) \
135 public:\
136   CLASS_NAME (char *aname,\
137               int  can_rep,\
138               char *short_help,\
139               char *long_help):\
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);
142
143 #define COMMAND_METHODS_ON(ON,CLASS_NAME) \
144 public:\
145   CLASS_NAME (char *aname,\
146               int  can_rep,\
147               char *short_help,\
148               char *long_help):\
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);
152
153 #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
154 public:\
155   CLASS_NAME (char *aname,\
156               int  can_rep,\
157               char *short_help,\
158               char *long_help):\
159     ANCESTOR (aname, can_rep, short_help, long_help) {}\
160   virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
161
162 #define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
163 public:\
164   CLASS_NAME (char *aname,\
165               int  can_rep,\
166               char *short_help,\
167               char *long_help):\
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); \
171
172
173 #define COMMAND_TAIL }
174
175 #define COMMAND(CLASS_NAME) \
176 COMMAND_HEAD(CLASS_NAME) \
177 COMMAND_METHODS(CLASS_NAME) \
178 COMMAND_TAIL
179
180 #define COMMAND_ON(ON,CLASS_NAME) \
181 COMMAND_HEAD(CLASS_NAME) \
182 COMMAND_METHODS_ON(ON,CLASS_NAME) \
183 COMMAND_TAIL
184
185 #define COMMAND_DATA(CLASS_NAME,DATA) \
186 COMMAND_HEAD(CLASS_NAME) \
187 public: DATA ; \
188 COMMAND_METHODS(CLASS_NAME)\
189 COMMAND_TAIL
190
191 #define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
192 COMMAND_HEAD(CLASS_NAME) \
193 public: DATA ; \
194 COMMAND_METHODS_ON(ON,CLASS_NAME)\
195 COMMAND_TAIL
196
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) \
200 COMMAND_TAIL
201
202 #define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
203 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
204 public: DATA ; \
205 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
206 COMMAND_TAIL
207
208 #define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
209 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
210 public: DATA ; \
211 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
212 COMMAND_TAIL
213
214 #define COMMAND_DO_WORK(CLASS_NAME) \
215 int \
216 CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console *con)
217 #define COMMAND_DO_WORK_APP(CLASS_NAME) \
218 int \
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) \
222 int \
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) \
226 int \
227 CLASS_NAME::do_work(class cl_uc *uc,\
228                     class cl_cmdline *cmdline, class cl_console *con)
229
230 // Command set is list of cl_cmd objects
231 class cl_cmdset: public cl_list
232 {
233 public:
234   //class cl_sim *sim;
235   //class cl_cmd *last_command;
236
237 public:
238   cl_cmdset(void);
239   //cl_cmdset(class cl_sim *asim);
240
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);
245 };
246
247 // subset of commands
248 class cl_super_cmd: public cl_cmd
249 {
250 public:
251   class cl_cmdset *commands;
252
253 public:
254   cl_super_cmd(char *aname,
255                int  can_rep,
256                char *short_hlp,
257                char *long_hlp,
258                class cl_cmdset *acommands);
259   virtual ~cl_super_cmd(void);
260
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);
264 };
265
266
267 #endif
268
269 /* End of cmd.src/commandcl.h */