2 * Simulator of microcontrollers (option.cc)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
10 /* This file is part of microcontroller simulator: ucsim.
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.
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.
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
46 * Base class for option's objects
47 *____________________________________________________________________________
51 cl_option::cl_option(class cl_base *the_creator, char *aname, char *Ihelp):
57 users= new cl_list(2, 2);
58 memset(&value, 0, sizeof(value));
62 cl_option::operator=(class cl_option &o)
64 //memcpy(&value, &(o.value), sizeof(union option_value));
65 //fprintf(stderr,"opt%p\"%s\"=%p\"%s\"\nold=%p\n",this,object_name(this),&o,object_name(&o),value.sval);
67 //fprintf(stderr,"new=%p\n",value.sval);
72 cl_option::~cl_option(void)
80 cl_option::pre_remove(void)
84 for (i= 0; i < users->count; i++)
86 class cl_optref *user= (class cl_optref *)(users->at(i));
87 user->option_removing();
92 cl_option::new_reference(class cl_optref *ref)
98 cl_option::del_reference(class cl_optref *ref)
104 cl_option::inform_users(void)
108 for (i= 0; i < users->count; i++)
110 class cl_optref *user= (class cl_optref *)(users->at(i));
111 //fprintf(stderr,"%p\"%s\" informs user %p\"%s\"\n",this,object_name(this),user,object_name(user));
112 user->option_changed();
118 cl_option::get_value(bool *val)
125 cl_option::set_value(bool opt)
133 cl_option::get_value(char **val)
140 cl_option::set_value(char *opt)
142 //fprintf(stderr,"set_string_value (%s) to %p\"%s\"\n",opt,this,object_name(this));
143 //fprintf(stderr,"old value=%p\"%s\"\n",value.sval,value.sval);
148 value.sval= strdup(opt);
150 value.sval= strdup("");
151 //fprintf(stderr,"new value=%p\"%s\"\n",value.sval,value.sval);
161 cl_options::key_of(void *item)
163 return(((class cl_base *)item)->get_name());
167 cl_options::compare(void *key1, void *key2)
169 //class cl_option *k1, *k2;
173 k1= /*(class cl_option *)*/(char *)key1;
174 k2= /*(class cl_option *)*/(char *)key2;
175 if ((i= strcmp(k1, k2)) != 0)
181 cl_options::new_option(class cl_option *opt)
187 cl_options::del_option(class cl_option *opt)
195 cl_options::get_option(char *the_name)
199 if (search(the_name, idx))
200 return((class cl_option *)(at(idx)));
205 cl_options::get_option(char *the_name, class cl_base *creator)
210 if (!search(the_name, idx))
215 o= (class cl_option *)(at(idx));
216 while (compare(the_name, key_of(o)) == 0 &&
220 o= (class cl_option *)(at(idx));
222 if (compare(the_name, key_of(o)) != 0)
225 o= (class cl_option *)(at(idx));
226 while (compare(the_name, key_of(o)) == 0 &&
227 o->get_creator() != creator &&
231 o= (class cl_option *)(at(idx));
232 if (compare(the_name, key_of(o)) == 0 &&
233 o->get_creator() == creator)
236 if (compare(the_name, key_of(o)) == 0 &&
237 o->get_creator() == creator)
243 cl_options::get_option(char *the_name, char *creator)
248 if (!search(the_name, idx))
253 o= (class cl_option *)(at(idx));
254 while (compare(the_name, key_of(o)) == 0 &&
258 o= (class cl_option *)(at(idx));
260 if (compare(the_name, key_of(o)) != 0)
263 o= (class cl_option *)(at(idx));
264 while (compare(the_name, key_of(o)) == 0 &&
265 strcmp(object_name(o->get_creator()), creator) != 0 &&
269 o= (class cl_option *)(at(idx));
270 if (compare(the_name, key_of(o)) == 0 &&
271 strcmp(object_name(o->get_creator()), creator) == 0)
274 if (compare(the_name, key_of(o)) == 0 &&
275 strcmp(object_name(o->get_creator()), creator) == 0)
281 cl_options::get_option(int idx)
285 return((class cl_option *)(at(idx)));
289 cl_options::nuof_options(char *the_name)
293 for (i= 0; i < count; i++)
295 class cl_option *o= (class cl_option *)(at(i));
296 if (strcmp(the_name, o->get_name()) == 0)
303 cl_options::nuof_options(char *the_name, char *creator)
307 for (i= 0; i < count; i++)
309 class cl_option *o= (class cl_option *)(at(i));
310 if (strcmp(the_name, o->get_name()) == 0 &&
311 strcmp(creator, object_name(o->get_creator())) == 0)
318 cl_options::set_value(char *the_name, cl_base *creator, bool value)
320 class cl_option *o= get_option(the_name, creator);
328 cl_options::set_value(char *the_name, cl_base *creator, char *value)
330 class cl_option *o= get_option(the_name, creator);
339 * Reference to an option
342 cl_optref::cl_optref(class cl_base *the_owner)
348 cl_optref::cl_optref(class cl_base *the_owner, class cl_option *new_option)
352 application->options->new_option(option);
355 option->new_reference(this);
356 set_name(option->get_name());
360 cl_optref::~cl_optref(void)
364 option->del_reference(this);
365 if (option->get_creator() == owner)
366 application->options->del_option(option);
371 cl_optref::create(class cl_base *creator,
372 enum option_type type,
373 char *the_name, char *help)
376 option->del_reference(this);
383 option= new cl_option(creator, the_name, help);
386 option= new cl_option(creator, the_name, help);
389 option= new cl_bool_option(creator, the_name, help);
392 option= new cl_string_option(creator, the_name, help);
395 option= new cl_option(creator, the_name, help);
403 application->options->new_option(option);
404 option->new_reference(this);
405 set_name(option->get_name());
412 cl_optref::default_option(char *the_name)
414 class cl_option *o= application->options->get_option(the_name, application);
419 //memcpy(option->get_value(), o->get_value(), sizeof(union option_value));
421 option->inform_users();
424 fprintf(stderr,"can not set opt from default, option=%p, o=%p\n",option,o);*/
432 option->del_reference(this);
433 option->new_reference(this);
439 cl_optref::use(char *the_name)
442 option->del_reference(this);
443 option= application->options->get_option(the_name);
446 option->new_reference(this);
447 set_name(option->get_name());
453 cl_optref::option_removing(void)
459 cl_optref::get_value(bool)
463 fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent "
464 "bool option: %s\n", object_name(owner), get_name());
470 option->get_value(&v);
476 cl_optref::get_value(char *)
480 fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent "
481 "string option: %s\n", object_name(owner), get_name());
487 option->get_value(&s);
494 * BOOL type of option
495 *____________________________________________________________________________
499 cl_bool_option::cl_bool_option(class cl_base *the_creator,
500 char *aname, char *Ihelp):
501 cl_option(the_creator, aname, Ihelp)
505 cl_bool_option::print(class cl_console *con)
507 if (/**(bool *)option*/value.bval)
508 con->dd_printf("TRUE");
510 con->dd_printf("FALSE");
514 cl_bool_option::set_value(char *s)
524 /**(bool *)option=*/ value.bval= DD_TRUE;
526 /**(bool *)option=*/ value.bval= DD_FALSE;
533 * STRING type of option
534 *____________________________________________________________________________
538 cl_string_option::cl_string_option(class cl_base *the_creator,
539 char *aname, char *Ihelp):
540 cl_option(the_creator, aname, Ihelp)
544 cl_string_option::operator=(class cl_option &o)
546 //fprintf(stderr,"string=otheropt%p\"%s\"\nold=%p\"%s\"\n",&o,object_name(&o),value.sval,value.sval);
547 set_value((o.get_value())->sval);
548 //fprintf(stderr,"new=%p\"%s\"\n",value.sval,value.sval);
553 cl_string_option::print(class cl_console *con)
555 if (/**(bool *)option*/value.sval)
556 con->dd_printf("\"%s\"", value.sval);
558 con->dd_printf("(null)");
565 cl_cons_debug_opt::cl_cons_debug_opt(class cl_app *the_app,
568 cl_option(0, Iid, Ihelp)
574 cl_cons_debug_opt::print(class cl_console *con)
576 if (/*sim->cmd->actual_console &&
577 sim->cmd->actual_console*/con->flags & CONS_DEBUG)
578 con->dd_printf("TRUE");
580 con->dd_printf("FALSE");
584 cl_cons_debug_opt::get_value(bool *val)
587 *val= app->get_commander()->actual_console?
588 (app->get_commander()->actual_console->flags & CONS_DEBUG):0;
592 cl_cons_debug_opt::set_value(bool opt)
594 if (app->get_commander()->actual_console)
597 app->get_commander()->actual_console->flags|= CONS_DEBUG;
599 app->get_commander()->actual_console->flags&= ~CONS_DEBUG;
605 cl_cons_debug_opt::set_value(char *s)
610 app->get_commander()->actual_console)
616 //app->get_commander()->actual_console->flags|= CONS_DEBUG;
619 //app->get_commander()->actual_console->flags&= ~CONS_DEBUG;
625 /* End of option.cc */