2 * Simulator of microcontrollers (utils.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
43 get_sub_opt(char **option, const char * const *tokens, char **valuep)
48 if (!(end= strchr(*option, ',')))
49 end= *option + strlen(*option);
52 if ((equ= strchr(*option, '=')))
61 strcmp(*option, tokens[i]))
66 return tokens[i]?i:-1;
71 get_id_string(struct id_element *ids, int id)
75 while (ids[i].id_string &&
78 return(ids[i].id_string);
82 get_id_string(struct id_element *ids, int id, char *def)
84 char *s= get_id_string(ids, id);
90 get_string_id(struct id_element *ids, char *str)
94 while (ids[i].id_string &&
95 strcmp(ids[i].id_string, str) != 0)
101 get_string_id(struct id_element *ids, char *str, int def)
105 while (ids[i].id_string &&
106 strcmp(ids[i].id_string, str) != 0)
108 return(ids[i].id_string?ids[i].id:def);
112 extern "C" int vasprintf(char **strp, const char *format, va_list ap);
113 extern "C" int vsnprintf(char *str, size_t size,const char *format,va_list ap);
116 vformat_string(char *format, va_list ap)
118 #ifdef HAVE_VASPRINTF
120 vasprintf(&msg, format, ap);
123 # ifdef HAVE_VSNPRINTF
124 char *msg= (char*)malloc(80*25);
125 vsnprintf(msg, 80*25, format, ap);
129 char *msg= (char*)malloc(80*25);
130 vsprintf(msg, format, ap); /* Dangerous */
138 format_string(char *format, ...)
142 va_start(ap, format);
143 char *s= vformat_string(format, ap);
150 print_char_octal(char c, FILE *f)
152 if (strchr("\a\b\f\n\r\t\v\"", c))
155 case '\a': fprintf(f, "\a"); break;
156 case '\b': fprintf(f, "\b"); break;
157 case '\f': fprintf(f, "\f"); break;
158 case '\n': fprintf(f, "\n"); break;
159 case '\r': fprintf(f, "\r"); break;
160 case '\t': fprintf(f, "\t"); break;
161 case '\v': fprintf(f, "\v"); break;
162 case '\"': fprintf(f, "\""); break;
167 fprintf(f, "\\%03hho", c);
172 object_name(class cl_base *o)
185 /* End of utils.cc */