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 *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; 63 64 public: 65 cl_cmdline(class cl_app *the_app, char *acmd, class cl_console_base *acon); 66 virtual ~cl_cmdline(void); 67 virtual int init(void); 68 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 split_out_bit(char *dot, char *param_str); 73 virtual void split_out_array(char *dot, char *param_str); 74 public: 75 virtual int split(void); 76 virtual int shift(void); 77 virtual int repeat(void); 78 virtual class cl_cmd_arg *param(int num); 79 virtual void insert_param(int pos, class cl_cmd_arg *param); 80 virtual bool syntax_match(class cl_uc *uc, const char *syntax); 81 virtual bool set_data_list(class cl_cmd_arg *parm, int *iparm); nuof_params(void)82 virtual int nuof_params(void) { return(params->get_count()); } 83 virtual bool restart_at_rest(void); 84 private: 85 char *skip_delims(char *start); 86 }; 87 88 89 /* 90 * Command and container 91 */ 92 93 class cl_cmdset; 94 95 // simple command 96 class cl_cmd: public cl_base 97 { 98 public: 99 enum cmd_operate_on operate_on; 100 class cl_strings *names; 101 int can_repeat; 102 chars usage_help; 103 chars short_help; 104 chars long_help; 105 106 public: 107 cl_cmd(enum cmd_operate_on opon, 108 const char *aname, 109 int can_rep); 110 virtual ~cl_cmd(void); 111 init(void)112 virtual int init(void) { set_help(); return 0; } set_help(void)113 virtual void set_help(void) {} 114 virtual void set_help(const char *usage_hlp, const char *short_hlp, const char *long_hlp); get_subcommands(void)115 virtual class cl_cmdset *get_subcommands(void) { return(0); } 116 virtual void add_name(const char *nam); 117 virtual int name_match(const char *aname, int strict); 118 virtual int name_match(class cl_cmdline *cmdline, int strict); 119 virtual int syntax_ok(class cl_cmdline *cmdline); 120 virtual int work(class cl_app *app, 121 class cl_cmdline *cmdline, class cl_console_base *con); 122 virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con); 123 virtual int do_work(class cl_app *app, 124 class cl_cmdline *cmdline, class cl_console_base *con); 125 virtual int do_work(class cl_sim *sim, 126 class cl_cmdline *cmdline, class cl_console_base *con); 127 virtual int do_work(class cl_uc *uc, 128 class cl_cmdline *cmdline, class cl_console_base *con); 129 virtual void print_short(class cl_console_base *con); 130 virtual void syntax_error(class cl_console_base *con); 131 }; 132 133 #define COMMAND_HEAD(CLASS_NAME) \ 134 class CLASS_NAME : public cl_cmd\ 135 { 136 #define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \ 137 class CLASS_NAME : public ANCESTOR \ 138 { 139 140 #define COMMAND_METHODS(CLASS_NAME) \ 141 public:\ 142 CLASS_NAME (const char *aname,\ 143 int can_rep):\ 144 cl_cmd(operate_on_none, aname, can_rep) {} \ 145 virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);\ 146 virtual void set_help(void); 147 148 #define COMMAND_METHODS_ON(ON,CLASS_NAME) \ 149 public:\ 150 CLASS_NAME (const char *aname,\ 151 int can_rep):\ 152 cl_cmd(operate_on_ ## ON, aname, can_rep) {} \ 153 virtual int do_work(class cl_ ## ON * ON ,\ 154 class cl_cmdline *cmdline, class cl_console_base *con);\ 155 virtual void set_help(void); 156 157 #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \ 158 public:\ 159 CLASS_NAME (const char *aname, int can_rep):\ 160 ANCESTOR (aname, can_rep) {} \ 161 virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);\ 162 virtual void set_help(void); 163 164 #define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \ 165 public:\ 166 CLASS_NAME (const char *aname, int can_rep):\ 167 ANCESTOR (aname, can_rep) {} \ 168 virtual int do_work(class cl_ ## ON * ON ,\ 169 class cl_cmdline *cmdline, class cl_console_base *con);\ 170 virtual void set_help(void); \ 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_base *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_base *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_base *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_base *con) 229 230 #define CMDHELP(CLASS_NAME,USAGE_HLP,SHORT_HLP,LONG_HLP) \ 231 void \ 232 CLASS_NAME::set_help(void) \ 233 { \ 234 usage_help=(char*)USAGE_HLP; \ 235 short_help=(char*)SHORT_HLP; \ 236 long_help=(char*)LONG_HLP; \ 237 } 238 239 // Command set is list of cl_cmd objects 240 class cl_cmdset: public cl_list 241 { 242 public: 243 //class cl_sim *sim; 244 //class cl_cmd *last_command; 245 246 public: 247 cl_cmdset(void); 248 //cl_cmdset(class cl_sim *asim); 249 250 virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline, bool accept_last); 251 virtual class cl_cmd *get_cmd(const char *cmd_name); 252 virtual void del(char *nam); 253 virtual void replace(char *nam, class cl_cmd *cmd); 254 }; 255 256 // subset of commands 257 class cl_super_cmd: public cl_cmd 258 { 259 public: 260 class cl_cmdset *commands; 261 262 public: 263 cl_super_cmd(const char *aname, 264 int can_rep, 265 class cl_cmdset *acommands); 266 virtual ~cl_super_cmd(void); 267 get_subcommands(void)268 virtual class cl_cmdset *get_subcommands(void) { return(commands); } 269 virtual int work(class cl_app *app, 270 class cl_cmdline *cmdline, class cl_console_base *con); 271 }; 272 273 274 #endif 275 276 /* End of cmd.src/commandcl.h */ 277