* sim/ucsim/cmd.src/newcmd.cc, sim/ucsim/cmd.src/newcmdcl.h:
[fw/sdcc] / sim / ucsim / cmd.src / newcmdcl.h
1 /*
2  * Simulator of microcontrollers (cmd.src/cmdcl.h)
3  *
4  * Copyright (C) 1999,99 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_NEWCMDCL_HEADER
29 #define CMD_NEWCMDCL_HEADER
30
31
32 #include "ddconfig.h"
33
34 #include <stdio.h>
35 #include <stdarg.h>
36 #include <sys/types.h>
37 #if FD_HEADER_OK
38 # include HEADER_FD
39 #endif
40
41 // prj
42 #include "pobjcl.h"
43
44 // sim.src
45 #include "appcl.h"
46
47 // local, cmd
48 #include "commandcl.h"
49
50
51 // Flags of consoles
52 #define CONS_NONE        0
53 #define CONS_DEBUG       0x01   // Print debug messages on this console
54 #define CONS_FROZEN      0x02   // Console is frozen (g command issued)
55 #define CONS_PROMPT      0x04   // Prompt is out, waiting for input
56 #define CONS_INTERACTIVE 0x08   // Interactive console
57 #define CONS_NOWELCOME   0x10   // Do not print welcome message
58 #define CONS_INACTIVE    0x20   // Do not do any action
59 #define CONS_ECHO        0x40   // Echo commands
60
61 #define SY_ADDR         'a'
62 #define ADDRESS         "a"
63 #define SY_NUMBER       'n'
64 #define NUMBER          "n"
65 #define SY_DATA         'd'
66 #define DATA            "d"
67 #define SY_STRING       's'
68 #define STRING          "s"
69 #define SY_MEMORY       'm'
70 #define MEMORY          "m"
71 #define SY_HW           'h'
72 #define HW              "h"
73 #define SY_DATALIST     'D'
74 #define DATALIST        "D"
75 #define SY_BIT          'b'
76 #define BIT             "b"
77
78
79 class cl_prompt_option: public cl_optref
80 {
81 protected:
82   class cl_console *con;
83 public:
84   cl_prompt_option(class cl_console *console);
85   virtual int init(void);
86   virtual void option_changed(void);
87 };
88
89 class cl_debug_option: public cl_prompt_option
90 {
91 public:
92   cl_debug_option(class cl_console *console);
93   virtual int init(void);
94   virtual void option_changed(void);
95 };
96
97 /*
98  * Command console
99  */
100
101 class cl_console: public cl_base
102 {
103   friend class cl_commander;
104 protected:
105   FILE *in, *out, *rout/*redirected output*/;
106   int id;
107   class cl_prompt_option *prompt_option;
108   class cl_optref *null_prompt_option;
109   class cl_debug_option *debug_option;
110   class cl_ustrings *lines_printed;
111   class cl_cmd *last_command;
112   class cl_cmdline *last_cmdline;
113 public:
114   class cl_app *app;
115   int flags; // See CONS_XXXX
116   char *prompt;
117
118 public:
119   cl_console(void): cl_base() { app= 0; in= out= 0; flags= 0; }
120   cl_console(char *fin, char *fout, class cl_app *the_app);
121   cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
122   cl_console(char *fin, FILE *fout);
123 #ifdef SOCKET_AVAIL
124   cl_console(int portnumber, class cl_app *the_app);
125 #endif
126   virtual ~cl_console(void);
127   virtual class cl_console *clone_for_exec(char *fin);
128   virtual int init(void);
129
130   virtual bool accept_last(void);
131
132   virtual void welcome(void);
133   virtual void redirect(char *fname, char *mode);
134   virtual void un_redirect(void);
135   int cmd_do_print(char *format, va_list ap);
136   virtual void print_prompt(void);
137   virtual int  dd_printf(char *format, ...);
138   virtual int  debug(char *format, ...);
139   virtual void print_bin(long data, int bits);
140   virtual void print_char_octal(char c);
141   virtual int  get_in_fd(void);
142   virtual int  input_avail(void);
143   virtual char *read_line(void);
144   virtual int  proc_input(class cl_cmdset *cmdset);
145   virtual bool interpret(char *cmd);
146   virtual void set_id(int new_id);
147   virtual int get_id(void) { return(id); }
148   virtual void set_prompt(char *p);
149 private:
150   FILE *get_out(void) { return(rout?rout:out); }
151 };
152
153 #ifdef SOCKET_AVAIL
154 class cl_listen_console: public cl_console
155 {
156 public:
157   int sock;
158 public:
159   cl_listen_console(int serverport, class cl_app *the_app);
160
161   virtual void welcome(void) {}
162
163   virtual int get_in_fd(void);
164   virtual int proc_input(class cl_cmdset *cmdset);
165 };
166 #endif
167
168
169 class cl_sub_console: public cl_console
170 {
171   class cl_console *parent;
172 public:
173   cl_sub_console(class cl_console *the_parent,
174                  FILE *fin, FILE *fout, class cl_app *the_app);
175   virtual ~cl_sub_console(void);
176   virtual int init(void);
177 };
178
179
180 /*
181  * Command interpreter
182  */
183
184 class cl_commander: public cl_base
185 {
186 public:
187   class cl_app *app;
188   class cl_list *cons;
189   fd_set read_set, active_set;
190   UCSOCKET_T fd_num;
191   class cl_console *actual_console, *frozen_console;
192   class cl_cmdset *cmdset;
193
194 public:
195   cl_commander(class cl_app *the_app,
196                class cl_cmdset *acmdset/*, class cl_sim *asim*/);
197   virtual ~cl_commander(void);
198   virtual int init(void);
199
200   virtual class cl_console *mk_console(char *fin, char *fout);
201   virtual class cl_console *mk_console(FILE *fin, FILE *fout);
202 #ifdef SOCKET_AVAIL
203   virtual class cl_console *mk_console(int portnumber);
204 #endif
205   void add_console(class cl_console *console);
206   void del_console(class cl_console *console);
207   void activate_console(class cl_console *console);
208   void deactivate_console(class cl_console *console);
209   void set_fd_set(void);
210
211   void prompt(void);
212   int all_printf(char *format, ...);        // print to all consoles
213   int dd_printf(char *format, va_list ap);  // print to actual_console
214   int dd_printf(char *format, ...);         // print to actual_console
215   int debug(char *format, ...);             // print consoles with debug flag set
216   int debug(char *format, va_list ap);      // print consoles with debug flag set
217   int flag_printf(int iflags, char *format, ...);
218   int input_avail(void);
219   int input_avail_on_frozen(void);
220   int wait_input(void);
221   int proc_input(void);
222   void exec_on(class cl_console *cons, char *file_name);
223 };
224
225
226 #endif
227
228 /* End of cmd.src/cmdcl.h */