2 * Simulator of microcontrollers (cmd.src/newcmd.cc)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5 * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
7 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
11 /* This file is part of microcontroller simulator: ucsim.
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.
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.
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
58 cl_prompt_option::cl_prompt_option(class cl_console_base *console):
65 cl_prompt_option::init(void)
68 help= format_string("Prompt string of console%d", con->get_id());
69 create(con, string_opt, "prompt", help);
70 //fprintf(stderr," **new prompt option %p\"%s\", value=%p str=%p\n",option,object_name(option),option->get_value(),option->get_value()->sval);
72 default_option("prompt");
73 //fprintf(stderr,"opt=%p\"%s\" value after default set=%p str=%p\n",option,object_name(option),option->get_value(),option->get_value()->sval);
78 cl_prompt_option::option_changed(void)
83 option->get_value(&s);
88 cl_debug_option::cl_debug_option(class cl_console_base *console):
89 cl_prompt_option(console)
93 cl_debug_option::init(void)
96 help= format_string("Debug messages to console%d", con->get_id());
97 create(con, bool_opt, "debug", help);
99 default_option("debug");
104 cl_debug_option::option_changed(void)
109 option->get_value(&b);
111 con->flags|= CONS_DEBUG;
113 con->flags&= ~CONS_DEBUG;
119 *____________________________________________________________________________
123 cl_console_base::init(void)
126 prompt_option= new cl_prompt_option(this);
127 prompt_option->init();
128 null_prompt_option= new cl_optref(this);
129 null_prompt_option->init();
130 null_prompt_option->use("null_prompt");
131 debug_option= new cl_debug_option(this);
132 debug_option->init();
134 flags&= ~CONS_PROMPT;
142 cl_console_base::welcome(void)
144 if (!(flags & CONS_NOWELCOME))
146 dd_printf("uCsim %s, Copyright (C) 1997 Daniel Drotos, Talker Bt.\n"
147 "uCsim comes with ABSOLUTELY NO WARRANTY; for details type "
149 "This is free software, and you are welcome to redistribute it\n"
150 "under certain conditions; type `show c' for details.\n",
156 cl_console_base::print_prompt(void)
158 if (flags & (CONS_PROMPT | CONS_FROZEN | CONS_INACTIVE))
161 flags |= CONS_PROMPT;
162 if (/*app->args->arg_avail('P')*/null_prompt_option->get_value(bool(0)))
168 dd_printf("%d%s", id, (prompt && prompt[0]) ? prompt : "> ");
169 // ((p= app->args->get_sarg(0, "prompt"))?p:"> "));
174 cl_console_base::dd_printf(char *format, ...)
179 va_start(ap, format);
180 ret= cmd_do_print(format, ap);
187 cl_console_base::debug(char *format, ...)
189 if ((flags & CONS_DEBUG) == 0)
195 va_start(ap, format);
196 ret= cmd_do_print(format, ap);
203 * Printing out an integer in binary format
207 cl_console_base::print_bin(long data, int bits)
211 mask= mask << ((bits >= 1)?(bits-1):0);
214 dd_printf("%c", (data&mask)?'1':'0');
220 cl_console_base::print_char_octal(char c)
222 if (strchr("\a\b\f\n\r\t\v\"", c))
225 case '\a': dd_printf("\a"); break;
226 case '\b': dd_printf("\b"); break;
227 case '\f': dd_printf("\f"); break;
228 case '\n': dd_printf("\n"); break;
229 case '\r': dd_printf("\r"); break;
230 case '\t': dd_printf("\t"); break;
231 case '\v': dd_printf("\v"); break;
232 case '\"': dd_printf("\""); break;
237 dd_printf("\\%03hho", c);
241 cl_console_base::interpret(char *cmd)
243 dd_printf("Unknown command\n");
248 cl_console_base::set_id(int new_id)
253 set_name(s= format_string("console%d", id));
258 cl_console_base::set_prompt(char *p)
269 cl_console_base::input_active(void) const
271 if (((flags & CONS_FROZEN) == 0 ||
272 (flags & CONS_INTERACTIVE) != 0) &&
273 (flags & CONS_INACTIVE) == 0)
282 cl_console_base::proc_input(class cl_cmdset *cmdset)
292 char *cmdstr = read_line();
295 if (flags & CONS_FROZEN)
297 app->get_sim()->stop(resUSER);
298 flags&= ~CONS_FROZEN;
303 if (cmdstr && *cmdstr == '\004')
307 class cl_cmdline *cmdline= 0;
308 class cl_cmd *cm = 0;
309 if (flags & CONS_ECHO)
310 dd_printf("%s\n", cmdstr);
311 cmdline= new cl_cmdline(app, cmdstr, this);
313 if (cmdline->repeat() &&
319 cmdline = last_cmdline;
323 cm= cmdset->get_cmd(cmdline, accept_last());
333 retval= cm->work(app, cmdline, this);
337 last_cmdline = cmdline;
344 class YY_cl_ucsim_parser_CLASS *pars;
345 class cl_ucsim_lexer *lexer;
346 lexer = new cl_ucsim_lexer(cmdstr);
347 pars = new YY_cl_ucsim_parser_CLASS(lexer);
353 retval= interpret(cmdstr);*/
356 //retval= sim->do_cmd(cmd, this);
366 * Command interpreter
367 *____________________________________________________________________________
370 cl_commander_base::cl_commander_base(class cl_app *the_app, class cl_cmdset *acmdset):
374 cons= new cl_list(1, 1, "consoles");
375 actual_console= frozen_console= 0;
379 cl_commander_base::~cl_commander_base(void)
386 cl_commander_base::add_console(class cl_console_base *console)
390 int i=cons->add(console);
397 cl_commander_base::del_console(class cl_console_base *console)
399 cons->disconn(console);
404 cl_commander_base::activate_console(class cl_console_base *console)
406 console->flags&= ~CONS_INACTIVE;
407 //console->print_prompt();
412 cl_commander_base::deactivate_console(class cl_console_base *console)
414 console->flags|= CONS_INACTIVE;
419 * Printing to all consoles
423 cl_commander_base::all_printf(char *format, ...)
428 for (i= 0; i < cons->count; i++)
430 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
432 va_start(ap, format);
433 ret= c->cmd_do_print(format, ap);
440 cl_commander_base::prompt(void)
444 for (i= 0; i < cons->count; i++)
446 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
452 * Printing to actual_console
456 cl_commander_base::dd_printf(char *format, va_list ap)
459 class cl_console_base *con;
465 else if (frozen_console)
475 ret= con->cmd_do_print(format, ap);
481 cl_commander_base::dd_printf(char *format, ...)
486 va_start(ap, format);
487 ret= dd_printf(format, ap);
494 * Printing to consoles which have CONS_DEBUG flag set
498 cl_commander_base::debug(char *format, ...)
503 for (i= 0; i < cons->count; i++)
505 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
506 if (c->flags & CONS_DEBUG)
508 va_start(ap, format);
509 ret= c->cmd_do_print(format, ap);
517 cl_commander_base::debug(char *format, va_list ap)
521 for (i= 0; i < cons->count; i++)
523 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
524 if (c->flags & CONS_DEBUG)
526 ret= c->cmd_do_print(format, ap);
533 cl_commander_base::flag_printf(int iflags, char *format, ...)
538 for (i= 0; i < cons->count; i++)
540 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
541 if ((c->flags & iflags) == iflags)
543 va_start(ap, format);
544 ret= c->cmd_do_print(format, ap);
552 cl_commander_base::input_avail_on_frozen(void)
554 if (!frozen_console || frozen_console->is_tty())
556 return(frozen_console->input_avail());
560 cl_commander_base::exec_on(class cl_console_base *cons, char *file_name)
562 if (!cons || !file_name || !fopen(file_name, "r"))
565 class cl_console_base *subcon = cons->clone_for_exec(file_name);
566 subcon->flags |= CONS_NOWELCOME;
571 /* End of cmd.src/newcmd.cc */