X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=sim%2Fucsim%2Fcmd.src%2Fnewcmdcl.h;h=49ae8cf4363f2f9cf376e95dd70d556761cec96c;hb=90f4aedaef8a2310573eef905f95c671f84e5cde;hp=9b6bba0e7aab3dcde14c2baa1387e3681a3bb92a;hpb=8c8f34ff4281a55d2f535335c02999246e9e12f2;p=fw%2Fsdcc diff --git a/sim/ucsim/cmd.src/newcmdcl.h b/sim/ucsim/cmd.src/newcmdcl.h index 9b6bba0e..49ae8cf4 100644 --- a/sim/ucsim/cmd.src/newcmdcl.h +++ b/sim/ucsim/cmd.src/newcmdcl.h @@ -1,8 +1,9 @@ /* - * Simulator of microcontrollers (cmd.src/cmdcl.h) + * Simulator of microcontrollers (cmd.src/newcmdcl.h) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * Copyright (C) 2006, Borut Razem - borut.razem@siol.net + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -32,10 +33,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "ddconfig.h" #include +#include #include -#if FD_HEADER_OK -# include HEADER_FD -#endif // prj #include "pobjcl.h" @@ -43,337 +42,149 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA // sim.src #include "appcl.h" - -#define SY_ADDR 'a' -#define ADDRESS "a" -#define SY_NUMBER 'n' -#define NUMBER "n" -#define SY_DATA 'd' -#define DATA "d" -#define SY_STRING 's' -#define STRING "s" -#define SY_MEMORY 'm' -#define MEMORY "m" -#define SY_HW 'h' -#define HW "h" -#define SY_DATALIST 'D' -#define DATALIST "D" -#define SY_BIT 'b' -#define BIT "b" - -enum cmd_operate_on { - operate_on_none, - operate_on_app, - operate_on_sim, - operate_on_uc -}; - - -/* - * Command line with parameters - */ - -class cl_cmdline: cl_base +// local, cmd +#include "commandcl.h" + + +// Flags of consoles +#define CONS_NONE 0 +#define CONS_DEBUG 0x01 // Print debug messages on this console +#define CONS_FROZEN 0x02 // Console is frozen (g command issued) +#define CONS_PROMPT 0x04 // Prompt is out, waiting for input +#define CONS_INTERACTIVE 0x08 // Interactive console +#define CONS_NOWELCOME 0x10 // Do not print welcome message +#define CONS_INACTIVE 0x20 // Do not do any action +#define CONS_ECHO 0x40 // Echo commands + +#define SY_ADDR 'a' +#define ADDRESS "a" +#define SY_NUMBER 'n' +#define NUMBER "n" +#define SY_DATA 'd' +#define DATA "d" +#define SY_STRING 's' +#define STRING "s" +#define SY_MEMORY 'm' +#define MEMORY "m" +#define SY_HW 'h' +#define HW "h" +#define SY_DATALIST 'D' +#define DATALIST "D" +#define SY_BIT 'b' +#define BIT "b" + + +class cl_prompt_option: public cl_optref { +protected: + class cl_console_base *con; public: - class cl_app *app; - char *cmd; - char *name; - class cl_list *params; - class cl_ustrings *tokens; - char *matched_syntax; - class cl_console *con; + cl_prompt_option(class cl_console_base *console); + virtual int init(void); + virtual void option_changed(void); +}; +class cl_debug_option: public cl_prompt_option +{ public: - cl_cmdline(class cl_app *the_app, char *acmd, class cl_console *acon); - virtual ~cl_cmdline(void); + cl_debug_option(class cl_console_base *console); virtual int init(void); - - 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, char *syntax); - virtual bool set_data_list(class cl_cmd_arg *parm, int *iparm); -private: - char *skip_delims(char *start); + virtual void option_changed(void); }; - /* - * Command and container + * Command console */ -// simple command -class cl_cmd: public cl_base +class cl_console_base: public cl_base { -public: - enum cmd_operate_on operate_on; - class cl_strings *names; - int can_repeat; - char *short_help; - char *long_help; +protected: + class cl_prompt_option *prompt_option; + class cl_optref *null_prompt_option; + class cl_debug_option *debug_option; + class cl_ustrings *lines_printed; + class cl_cmd *last_command; + class cl_cmdline *last_cmdline; public: - cl_cmd(enum cmd_operate_on opon, - char *aname, - int can_rep, - char *short_hlp, - char *long_hlp); - virtual ~cl_cmd(void); - - virtual void add_name(char *name); - virtual int name_match(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 *con); - virtual int do_work(class cl_cmdline *cmdline, class cl_console *con); - virtual int do_work(class cl_app *app, - class cl_cmdline *cmdline, class cl_console *con); - virtual int do_work(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con); - virtual int do_work(class cl_uc *uc, - class cl_cmdline *cmdline, class cl_console *con); -}; + cl_console_base(void): cl_base() { app = 0; flags = 0; prompt = 0; } -#define COMMAND_HEAD(CLASS_NAME) \ -class CLASS_NAME : public cl_cmd\ -{ -#define COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \ -class CLASS_NAME : public ANCESTOR \ -{ + virtual class cl_console_base *clone_for_exec(char *fin) = 0; -#define COMMAND_METHODS(CLASS_NAME) \ -public:\ - CLASS_NAME (char *aname,\ - int can_rep,\ - char *short_help,\ - 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 *con); - -#define COMMAND_METHODS_ON(ON,CLASS_NAME) \ -public:\ - CLASS_NAME (char *aname,\ - int can_rep,\ - char *short_help,\ - 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 *con); - -#define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \ -public:\ - CLASS_NAME (char *aname,\ - int can_rep,\ - char *short_help,\ - char *long_help):\ - ANCESTOR (aname, can_rep, short_help, long_help) {}\ - virtual int do_work(class cl_cmdline *cmdline, class cl_console *con); - -#define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \ -public:\ - CLASS_NAME (char *aname,\ - int can_rep,\ - char *short_help,\ - 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 *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 *con) -#define COMMAND_DO_WORK_APP(CLASS_NAME) \ -int \ -CLASS_NAME::do_work(class cl_app *app,\ - class cl_cmdline *cmdline, class cl_console *con) -#define COMMAND_DO_WORK_SIM(CLASS_NAME) \ -int \ -CLASS_NAME::do_work(class cl_sim *sim,\ - class cl_cmdline *cmdline, class cl_console *con) -#define COMMAND_DO_WORK_UC(CLASS_NAME) \ -int \ -CLASS_NAME::do_work(class cl_uc *uc,\ - class cl_cmdline *cmdline, class cl_console *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; + virtual void redirect(char *fname, char *mode) = 0; + virtual void un_redirect(void) = 0; + virtual int cmd_do_print(char *format, va_list ap) = 0; + virtual bool is_tty(void) const = 0; + virtual bool is_eof(void) const = 0; + virtual int input_avail(void) = 0; + virtual char *read_line(void) = 0; -public: - cl_cmdset(void); - //cl_cmdset(class cl_sim *asim); + virtual int init(void); + virtual void welcome(void); + virtual int proc_input(class cl_cmdset *cmdset); - virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline); - virtual class cl_cmd *get_cmd(char *cmd_name); - virtual void del(char *name); - virtual void replace(char *name, class cl_cmd *cmd); -}; + void print_prompt(void); + int dd_printf(char *format, ...); + int debug(char *format, ...); + void print_bin(long data, int bits); + void print_char_octal(char c); -// subset of commands -class cl_super_cmd: public cl_cmd -{ -public: - class cl_cmdset *commands; + bool interpret(char *cmd); + int get_id(void) const { return(id); } + void set_id(int new_id); + void set_prompt(char *p); + + bool input_active(void) const; + bool accept_last(void) { return is_tty() ? DD_TRUE : DD_FALSE; } public: - cl_super_cmd(char *aname, - int can_rep, - char *short_hlp, - char *long_hlp, - class cl_cmdset *acommands); - virtual ~cl_super_cmd(void); - - virtual int work(class cl_app *app, - class cl_cmdline *cmdline, class cl_console *con); -}; - - -/* - * Command console - */ + int flags; // See CONS_XXXX -class cl_console: public cl_base -{ - friend class cl_commander; protected: - FILE *in, *out; -public: class cl_app *app; - char *last_command; - int flags; // See CONS_XXXX char *prompt; - -public: - cl_console(void): cl_base() { app= 0; in= out= 0; flags= 0; } - cl_console(char *fin, char *fout, class cl_app *the_app); - cl_console(FILE *fin, FILE *fout, class cl_app *the_app); -#ifdef SOCKET_AVAIL - cl_console(int portnumber, class cl_app *the_app); -#endif - virtual ~cl_console(void); - virtual int init(void); - - virtual void welcome(void); - virtual void print_prompt(void); - virtual int dd_printf(char *format, ...); - virtual void print_bin(long data, int bits); - virtual int match(int fdnum); - virtual int get_in_fd(void); - virtual int input_avail(void); - virtual char *read_line(void); - virtual int proc_input(class cl_cmdset *cmdset); - virtual bool interpret(char *cmd); + int id; }; -#ifdef SOCKET_AVAIL -class cl_listen_console: public cl_console -{ -public: - int sock; -public: - cl_listen_console(int serverport, class cl_app *the_app); - - virtual void welcome(void) {} - virtual void prompt(void) {} - - virtual int match(int fdnum); - virtual int get_in_fd(void); - virtual int proc_input(class cl_cmdset *cmdset); -}; -#endif - - /* * Command interpreter */ -class cl_commander: public cl_base +class cl_commander_base: public cl_base { public: class cl_app *app; class cl_list *cons; - fd_set read_set, active_set; - int fd_num; - //class cl_sim *sim; - class cl_console *actual_console, *frozen_console; + class cl_console_base *actual_console, *frozen_console; class cl_cmdset *cmdset; public: - cl_commander(class cl_app *the_app, - class cl_cmdset *acmdset/*, class cl_sim *asim*/); - virtual ~cl_commander(void); - virtual int init(void); - - virtual class cl_console *mk_console(char *fin, char *fout); - virtual class cl_console *mk_console(FILE *fin, FILE *fout); -#ifdef SOCKET_AVAIL - virtual class cl_console *mk_console(int portnumber); -#endif - void add_console(class cl_console *console); - void del_console(class cl_console *console); - void set_fd_set(void); - - int all_printf(char *format, ...); // print to all consoles - int all_print(char *string, int length); - int dd_printf(char *format, ...); // print to actual_console - int debug(char *format, ...); // print consoles with debug flag set + cl_commander_base(class cl_app *the_app, class cl_cmdset *acmdset); + virtual ~cl_commander_base(void); + + void add_console(class cl_console_base *console); + void del_console(class cl_console_base *console); + void activate_console(class cl_console_base *console); + void deactivate_console(class cl_console_base *console); + + void prompt(void); + int all_printf(char *format, ...); // print to all consoles + int dd_printf(char *format, va_list ap); // print to actual_console + int dd_printf(char *format, ...); // print to actual_console + int debug(char *format, ...); // print consoles with debug flag set + int debug(char *format, va_list ap); // print consoles with debug flag set int flag_printf(int iflags, char *format, ...); - int input_avail(void); int input_avail_on_frozen(void); - int wait_input(void); - int proc_input(void); + void exec_on(class cl_console_base *cons, char *file_name); + + virtual int init(void) = 0; + virtual void set_fd_set(void) = 0; + virtual int proc_input(void) = 0; + virtual int input_avail(void) = 0; + virtual int wait_input(void) = 0; }; #endif -/* End of cmd.src/cmdcl.h */ +/* End of cmd.src/newcmdcl.h */