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);
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);
76 char *skip_delims(char *start);
81 * Command and container
85 class cl_cmd: public cl_base
88 enum cmd_operate_on operate_on;
89 class cl_strings *names;
95 cl_cmd(enum cmd_operate_on opon,
100 virtual ~cl_cmd(void);
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);
117 #define COMMAND_HEAD(CLASS_NAME) \
118 class CLASS_NAME : public cl_cmd\
120 #define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
121 class CLASS_NAME : public ANCESTOR \
124 #define COMMAND_METHODS(CLASS_NAME) \
126 CLASS_NAME (char *aname,\
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);
133 #define COMMAND_METHODS_ON(ON,CLASS_NAME) \
135 CLASS_NAME (char *aname,\
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);
143 #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
145 CLASS_NAME (char *aname,\
149 ANCESTOR (aname, can_rep, short_help, long_help) {}\
150 virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
152 #define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
154 CLASS_NAME (char *aname,\
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); \
163 #define COMMAND_TAIL }
165 #define COMMAND(CLASS_NAME) \
166 COMMAND_HEAD(CLASS_NAME) \
167 COMMAND_METHODS(CLASS_NAME) \
170 #define COMMAND_ON(ON,CLASS_NAME) \
171 COMMAND_HEAD(CLASS_NAME) \
172 COMMAND_METHODS_ON(ON,CLASS_NAME) \
175 #define COMMAND_DATA(CLASS_NAME,DATA) \
176 COMMAND_HEAD(CLASS_NAME) \
178 COMMAND_METHODS(CLASS_NAME)\
181 #define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
182 COMMAND_HEAD(CLASS_NAME) \
184 COMMAND_METHODS_ON(ON,CLASS_NAME)\
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) \
192 #define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
193 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
195 COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
198 #define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
199 COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
201 COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
204 #define COMMAND_DO_WORK(CLASS_NAME) \
206 CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console *con)
207 #define COMMAND_DO_WORK_APP(CLASS_NAME) \
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) \
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) \
217 CLASS_NAME::do_work(class cl_uc *uc,\
218 class cl_cmdline *cmdline, class cl_console *con)
220 // Command set is list of cl_cmd objects
221 class cl_cmdset: public cl_list
225 class cl_cmd *last_command;
229 //cl_cmdset(class cl_sim *asim);
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);
237 // subset of commands
238 class cl_super_cmd: public cl_cmd
241 class cl_cmdset *commands;
244 cl_super_cmd(char *aname,
248 class cl_cmdset *acommands);
249 virtual ~cl_super_cmd(void);
251 virtual int work(class cl_app *app,
252 class cl_cmdline *cmdline, class cl_console *con);
258 /* End of cmd.src/commandcl.h */