0.2.38-pre1 implements AVR instructions
[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 #if FD_HEADER_OK
36 # include HEADER_FD
37 #endif
38
39 #include "pobjcl.h"
40
41
42 /*
43  * Command line with parameters
44  */
45
46 class cl_cmdline: cl_base
47 {
48 public:
49   char *cmd;
50   char *name;
51   class cl_list *params;
52   class cl_ustrings *tokens;
53
54 public:
55   cl_cmdline(char *cmd);
56   virtual ~cl_cmdline(void);
57   virtual int init(void);
58
59   virtual int split(void);
60   virtual int shift(void);
61   virtual int repeat(void);
62   virtual class cl_cmd_arg *param(int num);
63   virtual void insert_param(int pos, class cl_cmd_arg *param);
64 private:
65   char *skip_delims(char *start);
66 };
67
68
69 /*
70  * Command and container
71  */
72
73 // simple command
74 class cl_cmd: public cl_base
75 {
76 public:
77   class cl_sim *sim;
78   class cl_strings *names;
79   int  can_repeat;
80   char *short_help;
81   char *long_help;
82
83 public:
84   cl_cmd(class cl_sim *asim,
85          char *aname,
86          int  can_rep,
87          char *short_hlp,
88          char *long_hlp);
89   ~cl_cmd(void);
90
91   virtual void add_name(char *name);
92   virtual int name_match(char *aname, int strict);
93   virtual int name_match(class cl_cmdline *cmdline, int strict);
94   virtual int syntax_ok(class cl_cmdline *cmdline);
95   virtual int work(class cl_cmdline *cmdline, class cl_console *con);
96   virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
97 };
98
99 // Command set is list of cl_cmd objects
100 class cl_cmdset: public cl_list
101 {
102 public:
103   class cl_sim *sim;
104   class cl_cmd *last_command;
105
106 public:
107   cl_cmdset(class cl_sim *asim);
108
109   virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline);
110   virtual void del(char *name);
111   virtual void replace(char *name, class cl_cmd *cmd);
112 };
113
114 // subset of commands
115 class cl_super_cmd: public cl_cmd
116 {
117 public:
118   class cl_cmdset *commands;
119
120 public:
121   cl_super_cmd(class cl_sim *asim,
122                char *aname,
123                int  can_rep,
124                char *short_hlp,
125                char *long_hlp,
126                class cl_cmdset *acommands);
127   ~cl_super_cmd(void);
128
129   virtual int work(class cl_cmdline *cmdline, class cl_console *con);
130 };
131
132
133 /*
134  * Command console
135  */
136
137 class cl_console: public cl_base
138 {
139   friend class cl_commander;
140 protected:
141   FILE *in, *out;
142 public:
143   class cl_sim *sim;
144   char *last_command;
145   int flags; // See CONS_XXXX
146   char *prompt;
147
148 public:
149   cl_console(): cl_base() {}
150   cl_console(char *fin, char *fout, class cl_sim *asim);
151   cl_console(FILE *fin, FILE *fout, class cl_sim *asim);
152 #ifdef SOCKET_AVAIL
153   cl_console(int portnumber, class cl_sim *asim);
154 #endif
155   ~cl_console(void);
156   virtual int init(void);
157
158   virtual void welcome(void);
159   virtual void print_prompt(void);
160   virtual int  printf(char *format, ...);
161   virtual void print_bin(long data, int bits);
162   virtual int  match(int fdnum);
163   virtual int  get_in_fd(void);
164   virtual int  input_avail(void);
165   virtual char *read_line(void);
166   virtual int  proc_input(void);
167   virtual bool interpret(char *cmd);
168   virtual bool old_command(class cl_cmdline *cmdline) { return(DD_FALSE); }
169 };
170
171 #ifdef SOCKET_AVAIL
172 class cl_listen_console: public cl_console
173 {
174 public:
175   int sock;
176 public:
177   cl_listen_console(int serverport, class cl_sim *asim);
178
179   virtual void welcome(void) {}
180   virtual void prompt(void) {}
181
182   virtual int match(int fdnum);
183   virtual int get_in_fd(void);
184   virtual int proc_input(void);
185 };
186 #endif
187
188
189 /*
190  * Command interpreter
191  */
192
193 class cl_commander: public cl_base
194 {
195 public:
196   class cl_list *cons;
197   fd_set read_set, active_set;
198   int fd_num;
199   class cl_sim *sim;
200   class cl_console *actual_console, *frozen_console;
201
202 public:
203   cl_commander(class cl_sim *asim);
204   ~cl_commander(void);
205   virtual int init(void);
206
207   virtual class cl_console *mk_console(char *fin, char *fout,
208                                        class cl_sim *asim);
209   virtual class cl_console *mk_console(FILE *fin, FILE *fout,
210                                        class cl_sim *asim);
211 #ifdef SOCKET_AVAIL
212   virtual class cl_console *mk_console(int portnumber, class cl_sim *asim);
213 #endif
214   void add_console(class cl_console *console);
215   void del_console(class cl_console *console);
216   void set_fd_set(void);
217
218   int all_printf(char *format, ...);    // print to all consoles
219   int all_print(char *string, int length);
220   int printf(char *format, ...);        // print to actual_console
221   int debug(char *format, ...);         // print consoles with debug flag set
222   int flag_printf(int iflags, char *format, ...);
223   int input_avail(void);
224   int input_avail_on_frozen(void);
225   int wait_input(void);
226   int proc_input(void);
227 };
228
229
230 #endif
231
232 /* End of cmd.src/cmdcl.h */