6655260af40a8ca5998345ae1cf3efd6ba75c52b
[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  match(int fdnum);
142   virtual int  get_in_fd(void);
143   virtual int  input_avail(void);
144   virtual char *read_line(void);
145   virtual int  proc_input(class cl_cmdset *cmdset);
146   virtual bool interpret(char *cmd);
147   virtual void set_id(int new_id);
148   virtual int get_id(void) { return(id); }
149   virtual void set_prompt(char *p);
150 private:
151   FILE *get_out(void) { return(rout?rout:out); }
152 };
153
154 #ifdef SOCKET_AVAIL
155 class cl_listen_console: public cl_console
156 {
157 public:
158   int sock;
159 public:
160   cl_listen_console(int serverport, class cl_app *the_app);
161
162   virtual void welcome(void) {}
163
164   virtual int match(int fdnum);
165   virtual int get_in_fd(void);
166   virtual int proc_input(class cl_cmdset *cmdset);
167 };
168 #endif
169
170
171 class cl_sub_console: public cl_console
172 {
173   class cl_console *parent;
174 public:
175   cl_sub_console(class cl_console *the_parent,
176                  FILE *fin, FILE *fout, class cl_app *the_app);
177   virtual ~cl_sub_console(void);
178   virtual int init(void);
179 };
180
181
182 /*
183  * Command interpreter
184  */
185
186 class cl_commander: public cl_base
187 {
188 public:
189   class cl_app *app;
190   class cl_list *cons;
191   fd_set read_set, active_set;
192   UCSOCKET_T fd_num;
193   class cl_console *actual_console, *frozen_console;
194   class cl_cmdset *cmdset;
195
196 public:
197   cl_commander(class cl_app *the_app,
198                class cl_cmdset *acmdset/*, class cl_sim *asim*/);
199   virtual ~cl_commander(void);
200   virtual int init(void);
201
202   virtual class cl_console *mk_console(char *fin, char *fout);
203   virtual class cl_console *mk_console(FILE *fin, FILE *fout);
204 #ifdef SOCKET_AVAIL
205   virtual class cl_console *mk_console(int portnumber);
206 #endif
207   void add_console(class cl_console *console);
208   void del_console(class cl_console *console);
209   void activate_console(class cl_console *console);
210   void deactivate_console(class cl_console *console);
211   void set_fd_set(void);
212
213   void prompt(void);
214   int all_printf(char *format, ...);    // print to all consoles
215   int dd_printf(char *format, ...);     // print to actual_console
216   int debug(char *format, ...);         // print consoles with debug flag set
217   int debug(char *format, va_list ap);  // print consoles with debug flag set
218   int flag_printf(int iflags, char *format, ...);
219   int input_avail(void);
220   int input_avail_on_frozen(void);
221   int wait_input(void);
222   int proc_input(void);
223   void exec_on(class cl_console *cons, char *file_name);
224 };
225
226
227 #endif
228
229 /* End of cmd.src/cmdcl.h */