Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / cmd.src / show.cc
1 /*
2  * Simulator of microcontrollers (cmd.src/show.cc)
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 #include "ddconfig.h"
29
30 #include <stdlib.h>
31 #include "i_string.h"
32
33 // prj
34 #include "globals.h"
35 #include "utils.h"
36 #include "errorcl.h"
37
38 // sim
39 #include "simcl.h"
40
41 // local
42 #include "showcl.h"
43
44
45 /*
46  * Command: show copying
47  *----------------------------------------------------------------------------
48  */
49
50 //int
51 //cl_show_copying_cmd::do_work(class cl_sim *sim,
52 //                           class cl_cmdline *cmdline, class cl_console_base *con)
53 COMMAND_DO_WORK(cl_show_copying_cmd)
54 {
55   con->dd_printf("%s\n", copying);
56   return(DD_FALSE);;
57 }
58
59
60 /*
61  * Command: show warranty
62  *----------------------------------------------------------------------------
63  */
64
65 //int
66 //cl_show_warranty_cmd::do_work(class cl_sim *sim,
67 //                            class cl_cmdline *cmdline, class cl_console_base *con)
68 COMMAND_DO_WORK(cl_show_warranty_cmd)
69 {
70   con->dd_printf("%s\n", warranty);
71   return(DD_FALSE);;
72 }
73
74
75 /*
76  * Command: show option
77  *----------------------------------------------------------------------------
78  */
79 COMMAND_DO_WORK_APP(cl_show_option_cmd)
80 {
81   class cl_cmd_arg *parm= cmdline->param(0);
82   char *s= 0;
83
84   if (!parm)
85     ;
86   else if (cmdline->syntax_match(0/*app->get_uc()*/, STRING)) {
87     s= parm->value.string.string;
88   }
89   else
90     con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
91
92   int i;
93   for (i= 0; i < app->options->count; i++)
94     {
95       class cl_option *o= (class cl_option *)(/*uc*/app->options->at(i));
96       if (!s ||
97           !strcmp(s, o->get_name()))
98         {
99           int j;
100           con->dd_printf("%d. %s: ", i, object_name(o));
101           o->print(con);
102           con->dd_printf(" - %s\n", o->help);
103           con->dd_printf("  Type: %s\n", o->get_type_name());
104           /*union option_value *val= o->get_value();
105           con->dd_printf("  Value: \"");
106           unsigned int uj;
107           TYPE_UBYTE *d= (TYPE_UBYTE*)val;
108           for (uj= 0; uj < sizeof(*val); uj++)
109           con->print_char_octal(d[uj]);
110           con->dd_printf("\"\n");*/
111           con->dd_printf("  Hidden: %s\n", (o->hidden)?"True":"False");
112           con->dd_printf("  Creator: \"%s\"\n  %d Users:\n",
113                          object_name(o->get_creator()),
114                          o->users->count);
115           for (j= 0; j < o->users->count; j++)
116             {
117               class cl_optref *r= (class cl_optref *)(o->users->at(j));
118               con->dd_printf("    %2d. owner(s)=\"%s\"\n", j,
119                              object_name(r->get_owner()));
120             }
121           if (i >= 0 &&
122               i < app->options->count-1)
123             con->dd_printf("\n");
124         }
125     }
126   
127   return(DD_FALSE);
128 }
129
130
131 // prj
132 #include "errorcl.h"
133
134 static void
135 show_error_cmd_print_node(class cl_console_base *con,
136                           int indent, class cl_base *node)
137 {
138   if (!node)
139     return;
140   int i;
141   for (i= 0; i < indent; i++)
142     con->dd_printf(" ");
143   const char *name= node->get_name("unknown");
144   class cl_error_class *ec= dynamic_cast<class cl_error_class *>(node);
145   char *str;
146   con->dd_printf("%s: %s [%s/%s]\n",
147                  str= case_string(case_case, ec->get_type_name()),
148                  name, get_id_string(error_on_off_names,
149                                      ec->get_on()),
150                  (ec->is_on())?"ON":"OFF");
151   free(str);
152   class cl_base *c= node->first_child();
153   while (c)
154     {
155       show_error_cmd_print_node(con, indent+2, c);
156       c= node->next_child(c);
157     }
158 }
159
160 /*
161  * Command: show error
162  *----------------------------------------------------------------------------
163  */
164 COMMAND_DO_WORK_APP(cl_show_error_cmd)
165 {
166   /*class cl_cmd_arg *parm= cmdline->param(0);
167   char *s= 0;
168
169   if (!parm)
170     ;
171   else if (cmdline->syntax_match(0, STRING)) {
172     s= parm->value.string.string;
173   }
174   else
175     con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
176   */
177   class cl_list *registered_errors = cl_error_registry::get_list();
178   int i;
179   for (i= 0; i < registered_errors->count; i++)
180     {
181       class cl_error_class *ec;
182       ec= dynamic_cast<class cl_error_class*>(registered_errors->object_at(i));
183       if (!ec->get_parent())
184         show_error_cmd_print_node(con, 0, ec);
185     }
186   return(DD_FALSE);
187 }
188
189
190 /* End of cmd.src/show.cc */