3bec252d34d639420b9cb5f121199221946907d3
[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   virtual int split(void);
69   virtual int shift(void);
70   virtual int repeat(void);
71   virtual class cl_cmd_arg *param(int num);
72   virtual void insert_param(int pos, class cl_cmd_arg *param);
73   virtual bool syntax_match(class cl_uc *uc, char *syntax);
74   virtual bool set_data_list(class cl_cmd_arg *parm, int *iparm);
75 private:
76   char *skip_delims(char *start);
77 };
78
79
80 /*
81  * Command and container
82  */
83
84 // simple command
85 class cl_cmd: public cl_base
86 {
87 public:
88   enum cmd_operate_on operate_on;
89   class cl_strings *names;
90   int  can_repeat;
91   char *short_help;
92   char *long_help;
93
94 public:
95   cl_cmd(enum cmd_operate_on opon,
96          char *aname,
97          int  can_rep,
98          char *short_hlp,
99          char *long_hlp);
100   virtual ~cl_cmd(void);
101
102   virtual void add_name(char *nam);
103   virtual int name_match(char *aname, int strict);
104   virtual int name_match(class cl_cmdline *cmdline, int strict);
105   virtual int syntax_ok(class cl_cmdline *cmdline);
106   virtual int work(class cl_app *app,
107                    class cl_cmdline *cmdline, class cl_console *con);
108   virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
109   virtual int do_work(class cl_app *app,
110                       class cl_cmdline *cmdline, class cl_console *con);
111   virtual int do_work(class cl_sim *sim,
112                       class cl_cmdline *cmdline, class cl_console *con);
113   virtual int do_work(class cl_uc *uc,
114                       class cl_cmdline *cmdline, class cl_console *con);
115 };
116
117 #define COMMAND_HEAD(CLASS_NAME) \
118 class CLASS_NAME : public cl_cmd\
119 {
120 #define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
121 class CLASS_NAME : public ANCESTOR \
122 {
123
124 #define COMMAND_METHODS(CLASS_NAME) \
125 public:\
126   CLASS_NAME (char *aname,\
127               int  can_rep,\
128               char *short_help,\
129               char *long_help):\
130     cl_cmd(operate_on_none, aname, can_rep, short_help, long_help) {}\
131   virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
132
133 #define COMMAND_METHODS_ON(ON,CLASS_NAME) \
134 public:\
135   CLASS_NAME (char *aname,\
136               int  can_rep,\
137               char *short_help,\
138               char *long_help):\
139     cl_cmd(operate_on_ ## ON, aname, can_rep, short_help, long_help) {}\
140   virtual int do_work(class cl_ ## ON * ON ,\
141                       class cl_cmdline *cmdline, class cl_console *con);
142
143 #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
144 public:\
145   CLASS_NAME (char *aname,\
146               int  can_rep,\
147               char *short_help,\
148               char *long_help):\
149     ANCESTOR (aname, can_rep, short_help, long_help) {}\
150   virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
151
152 #define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
153 public:\
154   CLASS_NAME (char *aname,\
155               int  can_rep,\
156               char *short_help,\
157               char *long_help):\
158     ANCESTOR (aname, can_rep, short_help, long_help) {}\
159   virtual int do_work(class cl_ ## ON * ON ,\
160                       class cl_cmdline *cmdline, class cl_console *con); \
161
162
163 #define COMMAND_TAIL }
164
165 #define COMMAND(CLASS_NAME) \
166 COMMAND_HEAD(CLASS_NAME) \
167 COMMAND_METHODS(CLASS_NAME) \
168 COMMAND_TAIL
169
170 #define COMMAND_ON(ON,CLASS_NAME) \
171 COMMAND_HEAD(CLASS_NAME) \
172 COMMAND_METHODS_ON(ON,CLASS_NAME) \
173 COMMAND_TAIL
174
175 #define COMMAND_DATA(CLASS_NAME,DATA) \
176 COMMAND_HEAD(CLASS_NAME) \
177 public: DATA ; \
178 COMMAND_METHODS(CLASS_NAME)\
179 COMMAND_TAIL
180
181 #define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
182 COMMAND_HEAD(CLASS_NAME) \
183 public: DATA ; \
184 COMMAND_METHODS_ON(ON,CLASS_NAME)\
185 COMMAND_TAIL
186
187 #define COMMAND_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
188 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
189 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
190 COMMAND_TAIL
191
192 #define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
193 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
194 public: DATA ; \
195 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
196 COMMAND_TAIL
197
198 #define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
199 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
200 public: DATA ; \
201 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
202 COMMAND_TAIL
203
204 #define COMMAND_DO_WORK(CLASS_NAME) \
205 int \
206 CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console *con)
207 #define COMMAND_DO_WORK_APP(CLASS_NAME) \
208 int \
209 CLASS_NAME::do_work(class cl_app *app,\
210                     class cl_cmdline *cmdline, class cl_console *con)
211 #define COMMAND_DO_WORK_SIM(CLASS_NAME) \
212 int \
213 CLASS_NAME::do_work(class cl_sim *sim,\
214                     class cl_cmdline *cmdline, class cl_console *con)
215 #define COMMAND_DO_WORK_UC(CLASS_NAME) \
216 int \
217 CLASS_NAME::do_work(class cl_uc *uc,\
218                     class cl_cmdline *cmdline, class cl_console *con)
219
220 // Command set is list of cl_cmd objects
221 class cl_cmdset: public cl_list
222 {
223 public:
224   //class cl_sim *sim;
225   class cl_cmd *last_command;
226
227 public:
228   cl_cmdset(void);
229   //cl_cmdset(class cl_sim *asim);
230
231   virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline);
232   virtual class cl_cmd *get_cmd(char *cmd_name);
233   virtual void del(char *nam);
234   virtual void replace(char *nam, class cl_cmd *cmd);
235 };
236
237 // subset of commands
238 class cl_super_cmd: public cl_cmd
239 {
240 public:
241   class cl_cmdset *commands;
242
243 public:
244   cl_super_cmd(char *aname,
245                int  can_rep,
246                char *short_hlp,
247                char *long_hlp,
248                class cl_cmdset *acommands);
249   virtual ~cl_super_cmd(void);
250
251   virtual int work(class cl_app *app,
252                    class cl_cmdline *cmdline, class cl_console *con);
253 };
254
255
256 #endif
257
258 /* End of cmd.src/commandcl.h */