1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
/*
* Simulator of microcontrollers (cmd.src/commandcl.h)
*
* Copyright (C) 2002,02 Drotos Daniel, Talker Bt.
*
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
/* This file is part of microcontroller simulator: ucsim.
UCSIM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
UCSIM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UCSIM; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/*@1@*/
#ifndef CMD_COMMAND_HEADER
#define CMD_COMMAND_HEADER
#include "ddconfig.h"
// prj
#include "pobjcl.h"
// local, cmd
#include "newcmdcl.h"
enum cmd_operate_on {
operate_on_none,
operate_on_app,
operate_on_sim,
operate_on_uc
};
/*
* Command line with parameters
*/
class cl_cmdline: public cl_base
{
public:
class cl_app *app;
char *cmd;
char *rest;
//char *name;
class cl_list *params;
class cl_ustrings *tokens;
const char *matched_syntax;
class cl_console_base *con;
public:
cl_cmdline(class cl_app *the_app, char *acmd, class cl_console_base *acon);
virtual ~cl_cmdline(void);
virtual int init(void);
private:
virtual void split_out_string(char **_start, char **_end);
virtual void split_out_output_redirection(char **_start, char **_end);
virtual void split_out_bit(char *dot, char *param_str);
virtual void split_out_array(char *dot, char *param_str);
public:
virtual int split(void);
virtual int shift(void);
virtual int repeat(void);
virtual class cl_cmd_arg *param(int num);
virtual void insert_param(int pos, class cl_cmd_arg *param);
virtual bool syntax_match(class cl_uc *uc, const char *syntax);
virtual bool set_data_list(class cl_cmd_arg *parm, int *iparm);
virtual int nuof_params(void) { return(params->get_count()); }
virtual bool restart_at_rest(void);
private:
char *skip_delims(char *start);
};
/*
* Command and container
*/
class cl_cmdset;
// simple command
class cl_cmd: public cl_base
{
public:
enum cmd_operate_on operate_on;
class cl_strings *names;
int can_repeat;
const char *short_help;
const char *long_help;
public:
cl_cmd(enum cmd_operate_on opon,
const char *aname,
int can_rep,
const char *short_hlp,
const char *long_hlp);
virtual ~cl_cmd(void);
virtual class cl_cmdset *get_subcommands(void) { return(0); }
virtual void add_name(const char *nam);
virtual int name_match(const char *aname, int strict);
virtual int name_match(class cl_cmdline *cmdline, int strict);
virtual int syntax_ok(class cl_cmdline *cmdline);
virtual int work(class cl_app *app,
class cl_cmdline *cmdline, class cl_console_base *con);
virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);
virtual int do_work(class cl_app *app,
class cl_cmdline *cmdline, class cl_console_base *con);
virtual int do_work(class cl_sim *sim,
class cl_cmdline *cmdline, class cl_console_base *con);
virtual int do_work(class cl_uc *uc,
class cl_cmdline *cmdline, class cl_console_base *con);
};
#define COMMAND_HEAD(CLASS_NAME) \
class CLASS_NAME : public cl_cmd\
{
#define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
class CLASS_NAME : public ANCESTOR \
{
#define COMMAND_METHODS(CLASS_NAME) \
public:\
CLASS_NAME (const char *aname,\
int can_rep,\
const char *short_help,\
const char *long_help):\
cl_cmd(operate_on_none, aname, can_rep, short_help, long_help) {}\
virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);
#define COMMAND_METHODS_ON(ON,CLASS_NAME) \
public:\
CLASS_NAME (const char *aname,\
int can_rep,\
const char *short_help,\
const char *long_help):\
cl_cmd(operate_on_ ## ON, aname, can_rep, short_help, long_help) {}\
virtual int do_work(class cl_ ## ON * ON ,\
class cl_cmdline *cmdline, class cl_console_base *con);
#define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
public:\
CLASS_NAME (const char *aname,\
int can_rep,\
const char *short_help,\
const char *long_help):\
ANCESTOR (aname, can_rep, short_help, long_help) {}\
virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);
#define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
public:\
CLASS_NAME (const char *aname,\
int can_rep,\
const char *short_help,\
const char *long_help):\
ANCESTOR (aname, can_rep, short_help, long_help) {}\
virtual int do_work(class cl_ ## ON * ON ,\
class cl_cmdline *cmdline, class cl_console_base *con); \
#define COMMAND_TAIL }
#define COMMAND(CLASS_NAME) \
COMMAND_HEAD(CLASS_NAME) \
COMMAND_METHODS(CLASS_NAME) \
COMMAND_TAIL
#define COMMAND_ON(ON,CLASS_NAME) \
COMMAND_HEAD(CLASS_NAME) \
COMMAND_METHODS_ON(ON,CLASS_NAME) \
COMMAND_TAIL
#define COMMAND_DATA(CLASS_NAME,DATA) \
COMMAND_HEAD(CLASS_NAME) \
public: DATA ; \
COMMAND_METHODS(CLASS_NAME)\
COMMAND_TAIL
#define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
COMMAND_HEAD(CLASS_NAME) \
public: DATA ; \
COMMAND_METHODS_ON(ON,CLASS_NAME)\
COMMAND_TAIL
#define COMMAND_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
COMMAND_TAIL
#define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
public: DATA ; \
COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
COMMAND_TAIL
#define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
public: DATA ; \
COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
COMMAND_TAIL
#define COMMAND_DO_WORK(CLASS_NAME) \
int \
CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console_base *con)
#define COMMAND_DO_WORK_APP(CLASS_NAME) \
int \
CLASS_NAME::do_work(class cl_app *app,\
class cl_cmdline *cmdline, class cl_console_base *con)
#define COMMAND_DO_WORK_SIM(CLASS_NAME) \
int \
CLASS_NAME::do_work(class cl_sim *sim,\
class cl_cmdline *cmdline, class cl_console_base *con)
#define COMMAND_DO_WORK_UC(CLASS_NAME) \
int \
CLASS_NAME::do_work(class cl_uc *uc,\
class cl_cmdline *cmdline, class cl_console_base *con)
// Command set is list of cl_cmd objects
class cl_cmdset: public cl_list
{
public:
//class cl_sim *sim;
//class cl_cmd *last_command;
public:
cl_cmdset(void);
//cl_cmdset(class cl_sim *asim);
virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline, bool accept_last);
virtual class cl_cmd *get_cmd(const char *cmd_name);
virtual void del(char *nam);
virtual void replace(char *nam, class cl_cmd *cmd);
};
// subset of commands
class cl_super_cmd: public cl_cmd
{
public:
class cl_cmdset *commands;
public:
cl_super_cmd(const char *aname,
int can_rep,
const char *short_hlp,
const char *long_hlp,
class cl_cmdset *acommands);
virtual ~cl_super_cmd(void);
virtual class cl_cmdset *get_subcommands(void) { return(commands); }
virtual int work(class cl_app *app,
class cl_cmdline *cmdline, class cl_console_base *con);
};
#endif
/* End of cmd.src/commandcl.h */
|