Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / cmd.src / newcmdcl.h
1 /*
2  * Simulator of microcontrollers (cmd.src/newcmdcl.h)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
6  *
7  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
8  *
9  */
10
11 /* This file is part of microcontroller simulator: ucsim.
12
13 UCSIM is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 UCSIM is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with UCSIM; see the file COPYING.  If not, write to the Free
25 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 02111-1307, USA. */
27 /*@1@*/
28
29 #ifndef CMD_NEWCMDCL_HEADER
30 #define CMD_NEWCMDCL_HEADER
31
32
33 #include "ddconfig.h"
34
35 #include <stdio.h>
36 #include <stdarg.h>
37 #include <sys/types.h>
38
39 // prj
40 #include "pobjcl.h"
41
42 // sim.src
43 #include "appcl.h"
44
45 // local, cmd
46 #include "commandcl.h"
47
48
49 // Flags of consoles
50 #define CONS_NONE        0
51 #define CONS_DEBUG       0x01   // Print debug messages on this console
52 #define CONS_FROZEN      0x02   // Console is frozen (g command issued)
53 #define CONS_PROMPT      0x04   // Prompt is out, waiting for input
54 #define CONS_INTERACTIVE 0x08   // Interactive console
55 #define CONS_NOWELCOME   0x10   // Do not print welcome message
56 #define CONS_INACTIVE    0x20   // Do not do any action
57 #define CONS_ECHO        0x40   // Echo commands
58
59 #define SY_ADDR         'a'
60 #define ADDRESS         "a"
61 #define SY_NUMBER       'n'
62 #define NUMBER          "n"
63 #define SY_DATA         'd'
64 #define DATA            "d"
65 #define SY_STRING       's'
66 #define STRING          "s"
67 #define SY_MEMORY       'm'
68 #define MEMORY          "m"
69 #define SY_HW           'h'
70 #define HW              "h"
71 #define SY_DATALIST     'D'
72 #define DATALIST        "D"
73 #define SY_BIT          'b'
74 #define BIT             "b"
75
76
77 class cl_prompt_option: public cl_optref
78 {
79 protected:
80   class cl_console_base *con;
81 public:
82   cl_prompt_option(class cl_console_base *console);
83   virtual int init(void);
84   virtual void option_changed(void);
85 };
86
87 class cl_debug_option: public cl_prompt_option
88 {
89 public:
90   cl_debug_option(class cl_console_base *console);
91   virtual int init(void);
92   virtual void option_changed(void);
93 };
94
95 /*
96  * Command console
97  */
98
99 class cl_console_base: public cl_base
100 {
101 protected:
102   class cl_prompt_option *prompt_option;
103   class cl_optref *null_prompt_option;
104   class cl_debug_option *debug_option;
105   class cl_ustrings *lines_printed;
106   class cl_cmd *last_command;
107   class cl_cmdline *last_cmdline;
108
109 public:
110   cl_console_base(void): cl_base() { app = 0; flags = 0; prompt = 0; }
111
112   virtual class cl_console_base *clone_for_exec(char *fin) = 0;
113
114   virtual void redirect(char *fname, char *mode) = 0;
115   virtual void un_redirect(void) = 0;
116   virtual int cmd_do_print(const char *format, va_list ap) = 0;
117   virtual bool is_tty(void) const = 0;
118   virtual bool is_eof(void) const = 0;
119   virtual int input_avail(void) = 0;
120   virtual char *read_line(void) = 0;
121
122   virtual int init(void);
123   virtual void welcome(void);
124   virtual int proc_input(class cl_cmdset *cmdset);
125
126   void print_prompt(void);
127   int dd_printf(const char *format, ...);
128   int debug(const char *format, ...);
129   void print_bin(long data, int bits);
130   void print_char_octal(char c);
131
132   bool interpret(char *cmd);
133   int get_id(void) const { return(id); }
134   void set_id(int new_id);
135   void set_prompt(char *p);
136   
137   bool input_active(void) const;
138   bool accept_last(void) { return is_tty() ? DD_TRUE : DD_FALSE; }
139
140 public:
141   int flags; // See CONS_XXXX
142
143 protected:
144   class cl_app *app;
145   char *prompt;
146   int id;
147 };
148
149 /*
150  * Command interpreter
151  */
152
153 class cl_commander_base: public cl_base
154 {
155 public:
156   class cl_app *app;
157   class cl_list *cons;
158   class cl_console_base *actual_console, *frozen_console;
159   class cl_cmdset *cmdset;
160
161 public:
162   cl_commander_base(class cl_app *the_app, class cl_cmdset *acmdset);
163   virtual ~cl_commander_base(void);
164
165   void add_console(class cl_console_base *console);
166   void del_console(class cl_console_base *console);
167   void activate_console(class cl_console_base *console);
168   void deactivate_console(class cl_console_base *console);
169
170   void prompt(void);
171   int all_printf(const char *format, ...);        // print to all consoles
172   int dd_printf(const char *format, va_list ap);  // print to actual_console
173   int dd_printf(const char *format, ...);         // print to actual_console
174   int debug(const char *format, ...);             // print consoles with debug flag set
175   int debug(const char *format, va_list ap);      // print consoles with debug flag set
176   int flag_printf(int iflags, const char *format, ...);
177   int input_avail_on_frozen(void);
178   void exec_on(class cl_console_base *cons, char *file_name);
179
180   virtual int init(void) = 0;
181   virtual void set_fd_set(void) = 0;
182   virtual int proc_input(void) = 0;
183   virtual int input_avail(void) = 0;
184   virtual int wait_input(void) = 0;
185 };
186
187
188 #endif
189
190 /* End of cmd.src/newcmdcl.h */