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
59 cl_prompt_option::cl_prompt_option(class cl_console_base *console):
66 cl_prompt_option::init(void)
69 help= format_string("Prompt string of console%d", con->get_id());
70 create(con, string_opt, "prompt", help);
71 //fprintf(stderr," **new prompt option %p\"%s\", value=%p str=%p\n",option,object_name(option),option->get_value(),option->get_value()->sval);
73 default_option("prompt");
74 //fprintf(stderr,"opt=%p\"%s\" value after default set=%p str=%p\n",option,object_name(option),option->get_value(),option->get_value()->sval);
79 cl_prompt_option::option_changed(void)
84 option->get_value(&s);
89 cl_debug_option::cl_debug_option(class cl_console_base *console):
90 cl_prompt_option(console)
94 cl_debug_option::init(void)
97 help= format_string("Debug messages to console%d", con->get_id());
98 create(con, bool_opt, "debug", help);
100 default_option("debug");
105 cl_debug_option::option_changed(void)
110 option->get_value(&b);
112 con->flags|= CONS_DEBUG;
114 con->flags&= ~CONS_DEBUG;
120 *____________________________________________________________________________
124 cl_console_base::init(void)
127 prompt_option= new cl_prompt_option(this);
128 prompt_option->init();
129 null_prompt_option= new cl_optref(this);
130 null_prompt_option->init();
131 null_prompt_option->use("null_prompt");
132 debug_option= new cl_debug_option(this);
133 debug_option->init();
135 flags&= ~CONS_PROMPT;
143 cl_console_base::welcome(void)
145 if (!(flags & CONS_NOWELCOME))
147 dd_printf("uCsim %s, Copyright (C) 1997 Daniel Drotos, Talker Bt.\n"
148 "uCsim comes with ABSOLUTELY NO WARRANTY; for details type "
150 "This is free software, and you are welcome to redistribute it\n"
151 "under certain conditions; type `show c' for details.\n",
157 cl_console_base::print_prompt(void)
159 if (flags & (CONS_PROMPT | CONS_FROZEN | CONS_INACTIVE))
162 flags |= CONS_PROMPT;
163 if (/*app->args->arg_avail('P')*/null_prompt_option->get_value(bool(0)))
169 dd_printf("%d%s", id, (prompt && prompt[0]) ? prompt : "> ");
170 // ((p= app->args->get_sarg(0, "prompt"))?p:"> "));
175 cl_console_base::dd_printf(char *format, ...)
180 va_start(ap, format);
181 ret= cmd_do_print(format, ap);
188 cl_console_base::debug(char *format, ...)
190 if ((flags & CONS_DEBUG) == 0)
196 va_start(ap, format);
197 ret= cmd_do_print(format, ap);
204 * Printing out an integer in binary format
208 cl_console_base::print_bin(long data, int bits)
212 mask= mask << ((bits >= 1)?(bits-1):0);
215 dd_printf("%c", (data&mask)?'1':'0');
221 cl_console_base::print_char_octal(char c)
223 if (strchr("\a\b\f\n\r\t\v\"", c))
226 case '\a': dd_printf("\a"); break;
227 case '\b': dd_printf("\b"); break;
228 case '\f': dd_printf("\f"); break;
229 case '\n': dd_printf("\n"); break;
230 case '\r': dd_printf("\r"); break;
231 case '\t': dd_printf("\t"); break;
232 case '\v': dd_printf("\v"); break;
233 case '\"': dd_printf("\""); break;
238 dd_printf("\\%03hho", c);
242 cl_console_base::interpret(char *cmd)
244 dd_printf("Unknown command\n");
249 cl_console_base::set_id(int new_id)
254 set_name(s= format_string("console%d", id));
259 cl_console_base::set_prompt(char *p)
270 cl_console_base::input_active(void) const
272 if (((flags & CONS_FROZEN) == 0 ||
273 (flags & CONS_INTERACTIVE) != 0) &&
274 (flags & CONS_INACTIVE) == 0)
283 cl_console_base::proc_input(class cl_cmdset *cmdset)
293 char *cmdstr = read_line();
296 if (flags & CONS_FROZEN)
298 app->get_sim()->stop(resUSER);
299 flags&= ~CONS_FROZEN;
304 if (cmdstr && *cmdstr == '\004')
308 class cl_cmdline *cmdline= 0;
309 class cl_cmd *cm = 0;
310 if (flags & CONS_ECHO)
311 dd_printf("%s\n", cmdstr);
312 cmdline= new cl_cmdline(app, cmdstr, this);
314 if (cmdline->repeat() &&
320 cmdline = last_cmdline;
324 cm= cmdset->get_cmd(cmdline, accept_last());
334 retval= cm->work(app, cmdline, this);
338 last_cmdline = cmdline;
345 class YY_cl_ucsim_parser_CLASS *pars;
346 class cl_ucsim_lexer *lexer;
347 lexer = new cl_ucsim_lexer(cmdstr);
348 pars = new YY_cl_ucsim_parser_CLASS(lexer);
354 retval= interpret(cmdstr);*/
357 //retval= sim->do_cmd(cmd, this);
367 * Command interpreter
368 *____________________________________________________________________________
371 cl_commander_base::cl_commander_base(class cl_app *the_app, class cl_cmdset *acmdset):
375 cons= new cl_list(1, 1, "consoles");
376 actual_console= frozen_console= 0;
380 cl_commander_base::~cl_commander_base(void)
387 cl_commander_base::add_console(class cl_console_base *console)
391 int i=cons->add(console);
398 cl_commander_base::del_console(class cl_console_base *console)
400 cons->disconn(console);
405 cl_commander_base::activate_console(class cl_console_base *console)
407 console->flags&= ~CONS_INACTIVE;
408 //console->print_prompt();
413 cl_commander_base::deactivate_console(class cl_console_base *console)
415 console->flags|= CONS_INACTIVE;
420 * Printing to all consoles
424 cl_commander_base::all_printf(char *format, ...)
429 for (i= 0; i < cons->count; i++)
431 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
433 va_start(ap, format);
434 ret= c->cmd_do_print(format, ap);
441 cl_commander_base::prompt(void)
445 for (i= 0; i < cons->count; i++)
447 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
453 * Printing to actual_console
457 cl_commander_base::dd_printf(char *format, va_list ap)
460 class cl_console_base *con;
466 else if (frozen_console)
476 ret= con->cmd_do_print(format, ap);
482 cl_commander_base::dd_printf(char *format, ...)
487 va_start(ap, format);
488 ret= dd_printf(format, ap);
495 * Printing to consoles which have CONS_DEBUG flag set
499 cl_commander_base::debug(char *format, ...)
504 for (i= 0; i < cons->count; i++)
506 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
507 if (c->flags & CONS_DEBUG)
509 va_start(ap, format);
510 ret= c->cmd_do_print(format, ap);
518 cl_commander_base::debug(char *format, va_list ap)
522 for (i= 0; i < cons->count; i++)
524 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
525 if (c->flags & CONS_DEBUG)
527 ret= c->cmd_do_print(format, ap);
534 cl_commander_base::flag_printf(int iflags, char *format, ...)
539 for (i= 0; i < cons->count; i++)
541 class cl_console_base *c= (class cl_console_base*)(cons->at(i));
542 if ((c->flags & iflags) == iflags)
544 va_start(ap, format);
545 ret= c->cmd_do_print(format, ap);
553 cl_commander_base::input_avail_on_frozen(void)
555 if (!frozen_console || frozen_console->is_tty())
557 return(frozen_console->input_avail());
561 cl_commander_base::exec_on(class cl_console_base *cons, char *file_name)
563 if (!cons || !file_name || !fopen(file_name, "r"))
566 class cl_console_base *subcon = cons->clone_for_exec(file_name);
567 subcon->flags |= CONS_NOWELCOME;
572 /* End of cmd.src/newcmd.cc */