1 /*
2  * Copyright (c) Tony Bybell 1999-2017.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  */
9 
10 
11 /* AIX may need this for alloca to work */
12 #if defined _AIX
13   #pragma alloca
14 #endif
15 
16 #include "globals.h"
17 #include <config.h>
18 #include <gtk/gtk.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <sys/types.h>
22 #include <fcntl.h>
23 #include <errno.h>
24 #include <sys/types.h>
25 #include "analyzer.h"
26 #include "currenttime.h"
27 #include "symbol.h"
28 #include "vcd.h"
29 #include "wavealloca.h"
30 #include "fgetdynamic.h"
31 #include "debug.h"
32 #include "main.h"
33 #include "menu.h"
34 #include "color.h"
35 #include "vlist.h"
36 #include "rc.h"
37 
38 #ifdef MAC_INTEGRATION
39 #include <gtkosxapplication.h>
40 #endif
41 
42 #ifndef _MSC_VER
43 #ifndef __MINGW32__
44         #include <unistd.h>
45         #include <pwd.h>
46         static char *rcname=".gtkwaverc";       /* name of environment file--POSIX */
47 #else
48         static char *rcname="gtkwave.ini";      /* name of environment file--WIN32 */
49 #endif
50 #else
51         static char *rcname="gtkwave.ini";      /* name of environment file--WIN32 */
52         #define strcasecmp _stricmp
53 #endif
54 
55 
56 /*
57  * functions that set the individual rc variables..
58  */
f_accel(char * str)59 int f_accel(char *str)
60 {
61 DEBUG(printf("f_accel(\"%s\")\n",str));
62 
63 if(strlen(str)) { set_wave_menu_accelerator(str); }
64 
65 return(0);
66 }
67 
f_alt_hier_delimeter(char * str)68 int f_alt_hier_delimeter(char *str)
69 {
70 DEBUG(printf("f_alt_hier_delimeter(\"%s\")\n",str));
71 
72 if(strlen(str)) { GLOBALS->alt_hier_delimeter=str[0]; }
73 return(0);
74 }
75 
f_analog_redraw_skip_count(char * str)76 int f_analog_redraw_skip_count(char *str)
77 {
78 DEBUG(printf("f_analog_redraw_skip_count(\"%s\")\n",str));
79 GLOBALS->analog_redraw_skip_count=atoi_64(str);
80 if(GLOBALS->analog_redraw_skip_count < 0)
81 	{
82 	GLOBALS->analog_redraw_skip_count = 0;
83 	}
84 
85 return(0);
86 }
87 
f_append_vcd_hier(char * str)88 int f_append_vcd_hier(char *str)
89 {
90 DEBUG(printf("f_append_vcd_hier(\"%s\")\n",str));
91 append_vcd_slisthier(str);
92 return(0);
93 }
94 
f_atomic_vectors(char * str)95 int f_atomic_vectors(char *str)
96 {
97 DEBUG(printf("f_atomic_vectors(\"%s\")\n",str));
98 GLOBALS->atomic_vectors=atoi_64(str)?1:0;
99 return(0);
100 }
101 
f_autoname_bundles(char * str)102 int f_autoname_bundles(char *str)
103 {
104 DEBUG(printf("f_autoname_bundles(\"%s\")\n",str));
105 GLOBALS->autoname_bundles=atoi_64(str)?1:0;
106 return(0);
107 }
108 
f_autocoalesce(char * str)109 int f_autocoalesce(char *str)
110 {
111 DEBUG(printf("f_autocoalesce(\"%s\")\n",str));
112 GLOBALS->autocoalesce=atoi_64(str)?1:0;
113 return(0);
114 }
115 
f_autocoalesce_reversal(char * str)116 int f_autocoalesce_reversal(char *str)
117 {
118 DEBUG(printf("f_autocoalesce_reversal(\"%s\")\n",str));
119 GLOBALS->autocoalesce_reversal=atoi_64(str)?1:0;
120 return(0);
121 }
122 
f_constant_marker_update(char * str)123 int f_constant_marker_update(char *str)
124 {
125 DEBUG(printf("f_constant_marker_update(\"%s\")\n",str));
126 GLOBALS->constant_marker_update=atoi_64(str)?1:0;
127 return(0);
128 }
129 
f_context_tabposition(char * str)130 int f_context_tabposition(char *str)
131 {
132 DEBUG(printf("f_convert_to_reals(\"%s\")\n",str));
133 GLOBALS->context_tabposition=atoi_64(str)?1:0;
134 return(0);
135 }
136 
f_convert_to_reals(char * str)137 int f_convert_to_reals(char *str)
138 {
139 DEBUG(printf("f_convert_to_reals(\"%s\")\n",str));
140 GLOBALS->convert_to_reals=atoi_64(str)?1:0;
141 return(0);
142 }
143 
f_cursor_snap(char * str)144 int f_cursor_snap(char *str)
145 {
146 int val;
147 DEBUG(printf("f_cursor_snap(\"%s\")\n",str));
148 val=atoi_64(str);
149 GLOBALS->cursor_snap=(val<=0)?0:val;
150 return(0);
151 }
152 
f_disable_ae2_alias(char * str)153 int f_disable_ae2_alias(char *str)
154 {
155 DEBUG(printf("f_disable_ae2_alias(\"%s\")\n",str));
156 GLOBALS->disable_ae2_alias=atoi_64(str)?1:0;
157 return(0);
158 }
159 
f_disable_auto_comphier(char * str)160 int f_disable_auto_comphier(char *str)
161 {
162 DEBUG(printf("f_disable_auto_comphier(\"%s\")\n",str));
163 GLOBALS->disable_auto_comphier=atoi_64(str)?1:0;
164 return(0);
165 }
166 
f_disable_empty_gui(char * str)167 int f_disable_empty_gui(char *str)
168 {
169 DEBUG(printf("f_disable_empty_gui(\"%s\")\n",str));
170 GLOBALS->disable_empty_gui=atoi_64(str)?1:0;
171 return(0);
172 }
173 
f_disable_mouseover(char * str)174 int f_disable_mouseover(char *str)
175 {
176 DEBUG(printf("f_disable_mouseover(\"%s\")\n",str));
177 GLOBALS->disable_mouseover=atoi_64(str)?1:0;
178 return(0);
179 }
180 
f_clipboard_mouseover(char * str)181 int f_clipboard_mouseover(char *str)
182 {
183 DEBUG(printf("f_clipboard_mouseover(\"%s\")\n",str));
184 GLOBALS->clipboard_mouseover=atoi_64(str)?1:0;
185 return(0);
186 }
187 
f_disable_tooltips(char * str)188 int f_disable_tooltips(char *str)
189 {
190 DEBUG(printf("f_disable_tooltips(\"%s\")\n",str));
191 GLOBALS->disable_tooltips=atoi_64(str)?1:0;
192 return(0);
193 }
194 
f_do_initial_zoom_fit(char * str)195 int f_do_initial_zoom_fit(char *str)
196 {
197 DEBUG(printf("f_do_initial_zoom_fit(\"%s\")\n",str));
198 GLOBALS->do_initial_zoom_fit=atoi_64(str)?1:0;
199 return(0);
200 }
201 
f_dragzoom_threshold(char * str)202 int f_dragzoom_threshold(char *str)
203 {
204 DEBUG(printf("f_dragzoom_threshold(\"%s\")\n",str));
205 GLOBALS->dragzoom_threshold=atoi_64(str);
206 return(0);
207 }
208 
f_dynamic_resizing(char * str)209 int f_dynamic_resizing(char *str)
210 {
211 DEBUG(printf("f_dynamic_resizing(\"%s\")\n",str));
212 GLOBALS->do_resize_signals=atoi_64(str)?1:0;
213 return(0);
214 }
215 
f_editor(char * str)216 int f_editor(char *str)
217 {
218 char *path, *pathend;
219 
220 DEBUG(printf("f_editor(\"%s\")\n",str));
221 
222 path = strchr(str, '\"');
223 if(path)
224 	{
225 	path++;
226 	if(*path)
227 		{
228 		pathend = strchr(path, '\"');
229 		if(pathend)
230 			{
231 			*pathend = 0;
232 			if(GLOBALS->editor_name) free_2(GLOBALS->editor_name);
233 			GLOBALS->editor_name=(char *)strdup_2(path);
234 			}
235 		}
236 	}
237 
238 return(0);
239 }
240 
f_enable_fast_exit(char * str)241 int f_enable_fast_exit(char *str)
242 {
243 DEBUG(printf("f_enable_fast_exit(\"%s\")\n",str));
244 GLOBALS->enable_fast_exit=atoi_64(str)?1:0;
245 return(0);
246 }
247 
f_enable_ghost_marker(char * str)248 int f_enable_ghost_marker(char *str)
249 {
250 DEBUG(printf("f_enable_ghost_marker(\"%s\")\n",str));
251 GLOBALS->enable_ghost_marker=atoi_64(str)?1:0;
252 return(0);
253 }
254 
f_enable_horiz_grid(char * str)255 int f_enable_horiz_grid(char *str)
256 {
257 DEBUG(printf("f_enable_horiz_grid(\"%s\")\n",str));
258 GLOBALS->enable_horiz_grid=atoi_64(str)?1:0;
259 return(0);
260 }
261 
f_enable_vcd_autosave(char * str)262 int f_enable_vcd_autosave(char *str)
263 {
264 DEBUG(printf("f_enable_vcd_autosave(\"%s\")\n",str));
265 GLOBALS->make_vcd_save_file=atoi_64(str)?1:0;
266 return(0);
267 }
268 
f_enable_vert_grid(char * str)269 int f_enable_vert_grid(char *str)
270 {
271 DEBUG(printf("f_enable_vert_grid(\"%s\")\n",str));
272 GLOBALS->enable_vert_grid=atoi_64(str)?1:0;
273 return(0);
274 }
275 
f_fill_waveform(char * str)276 int f_fill_waveform(char *str)
277 {
278 DEBUG(printf("f_fill_waveform(\"%s\")\n",str));
279 GLOBALS->fill_waveform=atoi_64(str)?1:0;
280 return(0);
281 }
282 
f_fontname_logfile(char * str)283 int f_fontname_logfile(char *str)
284 {
285 DEBUG(printf("f_fontname_logfile(\"%s\")\n",str));
286 if(GLOBALS->fontname_logfile) free_2(GLOBALS->fontname_logfile);
287 GLOBALS->fontname_logfile=(char *)malloc_2(strlen(str)+1);
288 strcpy(GLOBALS->fontname_logfile,str);
289 return(0);
290 }
291 
f_fontname_signals(char * str)292 int f_fontname_signals(char *str)
293 {
294 DEBUG(printf("f_fontname_signals(\"%s\")\n",str));
295 if(GLOBALS->fontname_signals) free_2(GLOBALS->fontname_signals);
296 GLOBALS->fontname_signals=(char *)malloc_2(strlen(str)+1);
297 strcpy(GLOBALS->fontname_signals,str);
298 return(0);
299 }
300 
f_fontname_waves(char * str)301 int f_fontname_waves(char *str)
302 {
303 DEBUG(printf("f_fontname_signals(\"%s\")\n",str));
304 if(GLOBALS->fontname_waves) free_2(GLOBALS->fontname_waves);
305 GLOBALS->fontname_waves=(char *)malloc_2(strlen(str)+1);
306 strcpy(GLOBALS->fontname_waves,str);
307 return(0);
308 }
309 
f_force_toolbars(char * str)310 int f_force_toolbars(char *str)
311 {
312 DEBUG(printf("f_force_toolbars(\"%s\")\n",str));
313 GLOBALS->force_toolbars=atoi_64(str)?1:0;
314 return(0);
315 }
316 
f_hide_sst(char * str)317 int f_hide_sst(char *str)
318 {
319 DEBUG(printf("f_hide_sst(\"%s\")\n",str));
320 GLOBALS->hide_sst=atoi_64(str)?1:0;
321 return(0);
322 }
323 
f_hier_ignore_escapes(char * str)324 int f_hier_ignore_escapes(char *str)
325 {
326 DEBUG(printf("f_hier_ignore_escapes(\"%s\")\n",str));
327 GLOBALS->hier_ignore_escapes=atoi_64(str)?1:0;
328 return(0);
329 }
330 
f_keep_xz_colors(char * str)331 int f_keep_xz_colors(char *str)
332 {
333 DEBUG(printf("f_keep_xz_colors(\"%s\")\n",str));
334 GLOBALS->keep_xz_colors=atoi_64(str)?1:0;
335 return(0);
336 }
337 
f_sst_dbl_action_type(char * str)338 int f_sst_dbl_action_type(char *str)
339 {
340 DEBUG(printf("f_sst_dbl_action_type(\"%s\")\n",str));
341 
342 switch(str[0])
343 	{
344 	case 'I': case 'i': GLOBALS->sst_dbl_action_type = SST_ACTION_INSERT; break;
345 	case 'R': case 'r': GLOBALS->sst_dbl_action_type = SST_ACTION_REPLACE; break;
346 	case 'A': case 'a': GLOBALS->sst_dbl_action_type = SST_ACTION_APPEND; break;
347 	case 'P': case 'p': GLOBALS->sst_dbl_action_type = SST_ACTION_PREPEND; break;
348 
349 	default: GLOBALS->sst_dbl_action_type = SST_ACTION_NONE;
350 	}
351 
352 return(0);
353 }
354 
f_sst_dynamic_filter(char * str)355 int f_sst_dynamic_filter(char *str)
356 {
357 DEBUG(printf("f_sst_dynamic_filter(\"%s\")\n",str));
358 GLOBALS->do_dynamic_treefilter=atoi_64(str)?1:0;
359 return(0);
360 }
361 
f_sst_expanded(char * str)362 int f_sst_expanded(char *str)
363 {
364 DEBUG(printf("f_sst_expanded(\"%s\")\n",str));
365 GLOBALS->sst_expanded=atoi_64(str)?1:0;
366 return(0);
367 }
368 
f_hier_delimeter(char * str)369 int f_hier_delimeter(char *str)
370 {
371 DEBUG(printf("f_hier_delimeter(\"%s\")\n",str));
372 
373 if(strlen(str)) { GLOBALS->hier_delimeter=str[0]; GLOBALS->hier_was_explicitly_set=1; }
374 return(0);
375 }
376 
f_hier_grouping(char * str)377 int f_hier_grouping(char *str)
378 {
379 DEBUG(printf("f_hier_grouping(\"%s\")\n",str));
380 GLOBALS->hier_grouping=atoi_64(str)?1:0;
381 return(0);
382 }
383 
f_hier_max_level(char * str)384 int f_hier_max_level(char *str)
385 {
386 DEBUG(printf("f_hier_max_level(\"%s\")\n",str));
387 GLOBALS->hier_max_level_shadow=GLOBALS->hier_max_level=atoi_64(str);
388 return(0);
389 }
390 
f_hpane_pack(char * str)391 int f_hpane_pack(char *str)
392 {
393 DEBUG(printf("f_hpane_pack(\"%s\")\n",str));
394 GLOBALS->paned_pack_semantics=atoi_64(str)?1:0;
395 return(0);
396 }
397 
f_highlight_wavewindow(char * str)398 int f_highlight_wavewindow(char *str)
399 {
400 DEBUG(printf("f_highlight_wavewindow(\"%s\")\n",str));
401 GLOBALS->highlight_wavewindow=atoi_64(str)?1:0;
402 return(0);
403 }
404 
f_ignore_savefile_pane_pos(char * str)405 int f_ignore_savefile_pane_pos(char *str)
406 {
407 DEBUG(printf("f_ignore_savefile_pane_pos(\"%s\")\n",str));
408 GLOBALS->ignore_savefile_pane_pos=atoi_64(str)?1:0;
409 return(0);
410 }
411 
f_ignore_savefile_pos(char * str)412 int f_ignore_savefile_pos(char *str)
413 {
414 DEBUG(printf("f_ignore_savefile_pos(\"%s\")\n",str));
415 GLOBALS->ignore_savefile_pos=atoi_64(str)?1:0;
416 return(0);
417 }
418 
f_ignore_savefile_size(char * str)419 int f_ignore_savefile_size(char *str)
420 {
421 DEBUG(printf("f_ignore_savefile_size(\"%s\")\n",str));
422 GLOBALS->ignore_savefile_size=atoi_64(str)?1:0;
423 return(0);
424 }
425 
f_initial_signal_window_width(char * str)426 int f_initial_signal_window_width(char *str)
427 {
428 int val;
429 DEBUG(printf("f_initial_signal_window_width(\"%s\")\n",str));
430 val=atoi_64(str);
431 GLOBALS->initial_signal_window_width=(val<0)?0:val;
432 return(0);
433 }
434 
f_initial_window_x(char * str)435 int f_initial_window_x(char *str)
436 {
437 int val;
438 DEBUG(printf("f_initial_window_x(\"%s\")\n",str));
439 val=atoi_64(str);
440 GLOBALS->initial_window_x=(val<=0)?-1:val;
441 return(0);
442 }
443 
f_initial_window_xpos(char * str)444 int f_initial_window_xpos(char *str)
445 {
446 int val;
447 DEBUG(printf("f_initial_window_xpos(\"%s\")\n",str));
448 val=atoi_64(str);
449 GLOBALS->initial_window_xpos=(val<=0)?-1:val;
450 return(0);
451 }
452 
f_initial_window_y(char * str)453 int f_initial_window_y(char *str)
454 {
455 int val;
456 DEBUG(printf("f_initial_window_y(\"%s\")\n",str));
457 val=atoi_64(str);
458 GLOBALS->initial_window_y=(val<=0)?-1:val;
459 return(0);
460 }
461 
f_initial_window_ypos(char * str)462 int f_initial_window_ypos(char *str)
463 {
464 int val;
465 DEBUG(printf("f_initial_window_ypos(\"%s\")\n",str));
466 val=atoi_64(str);
467 GLOBALS->initial_window_ypos=(val<=0)?-1:val;
468 return(0);
469 }
470 
f_left_justify_sigs(char * str)471 int f_left_justify_sigs(char *str)
472 {
473 DEBUG(printf("f_left_justify_sigs(\"%s\")\n",str));
474 GLOBALS->left_justify_sigs=atoi_64(str)?1:0;
475 return(0);
476 }
477 
f_lxt_clock_compress_to_z(char * str)478 int f_lxt_clock_compress_to_z(char *str)
479 {
480 DEBUG(printf("f_lxt_clock_compress_to_z(\"%s\")\n",str));
481 GLOBALS->lxt_clock_compress_to_z=atoi_64(str)?1:0;
482 return(0);
483 }
484 
f_max_fsdb_trees(char * str)485 int f_max_fsdb_trees(char *str)
486 {
487 int val;
488 DEBUG(printf("f_max_fsdb_trees(\"%s\")\n",str));
489 val=atoi_64(str);
490 GLOBALS->extload_max_tree=(val<0)?0:val;
491 return(0);
492 }
493 
494 
f_page_divisor(char * str)495 int f_page_divisor(char *str)
496 {
497 DEBUG(printf("f_page_divisor(\"%s\")\n",str));
498 sscanf(str,"%lg",&GLOBALS->page_divisor);
499 
500 if(GLOBALS->page_divisor<0.01)
501 	{
502 	GLOBALS->page_divisor=0.01;
503 	}
504 else
505 if(GLOBALS->page_divisor>100.0)
506 	{
507 	GLOBALS->page_divisor=100.0;
508 	}
509 
510 if(GLOBALS->page_divisor>1.0) GLOBALS->page_divisor=1.0/GLOBALS->page_divisor;
511 
512 return(0);
513 }
514 
f_ps_maxveclen(char * str)515 int f_ps_maxveclen(char *str)
516 {
517 DEBUG(printf("f_ps_maxveclen(\"%s\")\n",str));
518 GLOBALS->ps_maxveclen=atoi_64(str);
519 if(GLOBALS->ps_maxveclen<4)
520 	{
521 	GLOBALS->ps_maxveclen=4;
522 	}
523 else
524 if(GLOBALS->ps_maxveclen>66)
525 	{
526 	GLOBALS->ps_maxveclen=66;
527 	}
528 
529 return(0);
530 }
531 
f_scale_to_time_dimension(char * str)532 int f_scale_to_time_dimension(char *str)
533 {
534 int which = tolower((int)(*str));
535 DEBUG(printf("f_scale_to_time_dimension(\"%s\")\n",str));
536 
537 if(strchr(WAVE_SI_UNITS, which) || (which == 's'))
538 	{
539 	GLOBALS->scale_to_time_dimension = which;
540 	}
541 	else
542 	{
543 	GLOBALS->scale_to_time_dimension = 0;	/* also covers '*' case as not found above */
544 	}
545 
546 return(0);
547 }
548 
f_show_base_symbols(char * str)549 int f_show_base_symbols(char *str)
550 {
551 DEBUG(printf("f_show_base_symbols(\"%s\")\n",str));
552 GLOBALS->show_base=atoi_64(str)?1:0;
553 return(0);
554 }
555 
f_show_grid(char * str)556 int f_show_grid(char *str)
557 {
558 DEBUG(printf("f_show_grid(\"%s\")\n",str));
559 GLOBALS->display_grid=atoi_64(str)?1:0;
560 return(0);
561 }
562 
f_splash_disable(char * str)563 int f_splash_disable(char *str)
564 {
565 DEBUG(printf("f_splash_disable(\"%s\")\n",str));
566 GLOBALS->splash_disable=atoi_64(str)?1:0;
567 return(0);
568 }
569 
f_strace_repeat_count(char * str)570 int f_strace_repeat_count(char *str)
571 {
572 DEBUG(printf("f_strace_repeat_count(\"%s\")\n",str));
573 GLOBALS->strace_repeat_count=atoi_64(str);
574 return(0);
575 }
576 
f_use_big_fonts(char * str)577 int f_use_big_fonts(char *str)
578 {
579 DEBUG(printf("f_use_big_fonts(\"%s\")\n",str));
580 GLOBALS->use_big_fonts=atoi_64(str)?1:0;
581 return(0);
582 }
583 
f_use_frequency_display(char * str)584 int f_use_frequency_display(char *str)
585 {
586 DEBUG(printf("f_use_frequency_display(\"%s\")\n",str));
587 GLOBALS->use_frequency_delta=atoi_64(str)?1:0;
588 return(0);
589 }
590 
f_use_full_precision(char * str)591 int f_use_full_precision(char *str)
592 {
593 DEBUG(printf("f_use_full_precision(\"%s\")\n",str));
594 GLOBALS->use_full_precision=atoi_64(str)?1:0;
595 return(0);
596 }
597 
f_use_maxtime_display(char * str)598 int f_use_maxtime_display(char *str)
599 {
600 DEBUG(printf("f_use_maxtime_display(\"%s\")\n",str));
601 GLOBALS->use_maxtime_display=atoi_64(str)?1:0;
602 return(0);
603 }
604 
f_use_nonprop_fonts(char * str)605 int f_use_nonprop_fonts(char *str)
606 {
607 DEBUG(printf("f_use_nonprop_fonts(\"%s\")\n",str));
608 GLOBALS->use_nonprop_fonts=atoi_64(str)?1:0;
609 return(0);
610 }
611 
f_use_pango_fonts(char * str)612 int f_use_pango_fonts(char *str)
613 {
614 DEBUG(printf("f_use_pango_fonts(\"%s\")\n",str));
615 GLOBALS->use_pango_fonts=atoi_64(str)?1:0;
616 return(0);
617 }
618 
f_use_roundcaps(char * str)619 int f_use_roundcaps(char *str)
620 {
621 DEBUG(printf("f_use_roundcaps(\"%s\")\n",str));
622 GLOBALS->use_roundcaps=atoi_64(str)?1:0;
623 return(0);
624 }
625 
f_ruler_origin(char * str)626 int f_ruler_origin(char *str)
627 {
628 DEBUG(printf("f_ruler_origin(\"%s\")\n",str));
629 GLOBALS->ruler_origin=atoi_64(str);
630 return(0);
631 }
632 
f_ruler_step(char * str)633 int f_ruler_step(char *str)
634 {
635 DEBUG(printf("f_ruler_step(\"%s\")\n",str));
636 GLOBALS->ruler_step=atoi_64(str);
637 return(0);
638 }
639 
f_use_scrollbar_only(char * str)640 int f_use_scrollbar_only(char *str)
641 {
642 DEBUG(printf("f_use_scrollbar_only(\"%s\")\n",str));
643 GLOBALS->use_scrollbar_only=atoi_64(str)?1:0;
644 return(0);
645 }
646 
f_use_scrollwheel_as_y(char * str)647 int f_use_scrollwheel_as_y(char *str)
648 {
649 DEBUG(printf("f_use_scrollwheel_as_y(\"%s\")\n",str));
650 GLOBALS->use_scrollwheel_as_y=atoi_64(str)?1:0;
651 return(0);
652 }
653 
f_use_standard_clicking(char * str)654 int f_use_standard_clicking(char *str)
655 {
656 DEBUG(printf("f_use_standard_clicking(\"%s\")\n",str));
657 GLOBALS->use_standard_clicking=atoi_64(str)?1:0;
658 return(0);
659 }
660 
f_use_standard_trace_select(char * str)661 int f_use_standard_trace_select(char *str)
662 {
663 DEBUG(printf("f_f_use_standard_trace_select(\"%s\")\n",str));
664 GLOBALS->use_standard_trace_select=atoi_64(str)?1:0;
665 return(0);
666 }
667 
f_use_toolbutton_interface(char * str)668 int f_use_toolbutton_interface(char *str)
669 {
670 #ifndef WAVE_USE_GTK2
671 (void)str;
672 #endif
673 
674 DEBUG(printf("f_use_toolbutton_interface(\"%s\")\n",str));
675 #ifdef WAVE_USE_GTK2
676 GLOBALS->use_toolbutton_interface=atoi_64(str)?1:0;
677 #endif
678 return(0);
679 }
680 
f_vcd_explicit_zero_subscripts(char * str)681 int f_vcd_explicit_zero_subscripts(char *str)
682 {
683 DEBUG(printf("f_vcd_explicit_zero_subscripts(\"%s\")\n",str));
684 GLOBALS->vcd_explicit_zero_subscripts=atoi_64(str)?0:-1;	/* 0==yes, -1==no */
685 return(0);
686 }
687 
f_vcd_preserve_glitches(char * str)688 int f_vcd_preserve_glitches(char *str)
689 {
690 DEBUG(printf("f_vcd_preserve_glitches(\"%s\")\n",str));
691 GLOBALS->vcd_preserve_glitches=atoi_64(str)?1:0;
692 return(0);
693 }
694 
f_vcd_preserve_glitches_real(char * str)695 int f_vcd_preserve_glitches_real(char *str)
696 {
697 DEBUG(printf("f_vcd_preserve_glitches_real(\"%s\")\n",str));
698 GLOBALS->vcd_preserve_glitches_real=atoi_64(str)?1:0;
699 return(0);
700 }
701 
f_vcd_warning_filesize(char * str)702 int f_vcd_warning_filesize(char *str)
703 {
704 DEBUG(printf("f_vcd_warning_filesize(\"%s\")\n",str));
705 GLOBALS->vcd_warning_filesize=atoi_64(str);
706 return(0);
707 }
708 
f_vector_padding(char * str)709 int f_vector_padding(char *str)
710 {
711 DEBUG(printf("f_vector_padding(\"%s\")\n",str));
712 GLOBALS->vector_padding=atoi_64(str);
713 if(GLOBALS->vector_padding<4) GLOBALS->vector_padding=4;
714 else if(GLOBALS->vector_padding>16) GLOBALS->vector_padding=16;
715 return(0);
716 }
717 
f_vlist_compression(char * str)718 int f_vlist_compression(char *str)
719 {
720 DEBUG(printf("f_vlist_compression(\"%s\")\n",str));
721 GLOBALS->vlist_compression_depth=atoi_64(str);
722 if(GLOBALS->vlist_compression_depth<0) GLOBALS->vlist_compression_depth = -1;
723 if(GLOBALS->vlist_compression_depth>9) GLOBALS->vlist_compression_depth = 9;
724 return(0);
725 }
726 
f_vlist_prepack(char * str)727 int f_vlist_prepack(char *str)
728 {
729 DEBUG(printf("f_vlist_prepack(\"%s\")\n",str));
730 GLOBALS->vlist_prepack=atoi_64(str);
731 return(0);
732 }
733 
f_vlist_spill(char * str)734 int f_vlist_spill(char *str)
735 {
736 DEBUG(printf("f_vlist_spill(\"%s\")\n",str));
737 GLOBALS->vlist_spill_to_disk=atoi_64(str);
738 return(0);
739 }
740 
f_wave_scrolling(char * str)741 int f_wave_scrolling(char *str)
742 {
743 DEBUG(printf("f_wave_scrolling(\"%s\")\n",str));
744 GLOBALS->wave_scrolling=atoi_64(str)?1:0;
745 return(0);
746 }
747 
f_zoom_base(char * str)748 int f_zoom_base(char *str)
749 {
750 float f;
751 DEBUG(printf("f_zoom_base(\"%s\")\n",str));
752 sscanf(str,"%f",&f);
753 if(f<1.5) f=1.5; else if(f>10.0) f=10.0;
754 GLOBALS->zoombase=(gdouble)f;
755 return(0);
756 }
757 
f_zoom_center(char * str)758 int f_zoom_center(char *str)
759 {
760 DEBUG(printf("f_zoom_center(\"%s\")\n",str));
761 GLOBALS->do_zoom_center=atoi_64(str)?1:0;
762 return(0);
763 }
764 
f_zoom_dynamic(char * str)765 int f_zoom_dynamic(char *str)
766 {
767 DEBUG(printf("f_zoom_dynamic(\"%s\")\n",str));
768 GLOBALS->zoom_dyn=atoi_64(str)?1:0;
769 return(0);
770 }
771 
f_zoom_dynamic_end(char * str)772 int f_zoom_dynamic_end(char *str)
773 {
774 DEBUG(printf("f_zoom_dynamic_end(\"%s\")\n",str));
775 GLOBALS->zoom_dyne=atoi_64(str)?1:0;
776 return(0);
777 }
778 
f_zoom_pow10_snap(char * str)779 int f_zoom_pow10_snap(char *str)
780 {
781 DEBUG(printf("f_zoom_pow10_snap(\"%s\")\n",str));
782 GLOBALS->zoom_pow10_snap=atoi_64(str)?1:0;
783 return(0);
784 }
785 
f_alt_wheel_mode(char * str)786 int f_alt_wheel_mode(char *str)
787 {
788 DEBUG(printf("f_alt_wheel_mode(\"%s\")\n",str));
789 GLOBALS->alt_wheel_mode=atoi_64(str)?1:0;
790 return(0);
791 }
792 
793 
rc_compare(const void * v1,const void * v2)794 int rc_compare(const void *v1, const void *v2)
795 {
796 return(strcasecmp((char *)v1, ((struct rc_entry *)v2)->name));
797 }
798 
799 
800 /* make the color functions */
801 #define color_make(Z) int f_color_##Z (char *str) \
802 { \
803 int rgb; \
804 if((rgb=get_rgb_from_name(str))!=~0) \
805 	{ \
806 	GLOBALS->color_##Z=rgb; \
807 	} \
808 return(0); \
809 }
810 
811 
812 
813 color_make(back)
814 color_make(baseline)
815 color_make(grid)
816 color_make(grid2)
817 color_make(high)
818 color_make(highfill)
819 color_make(low)
820 color_make(1)
821 color_make(1fill)
822 color_make(0)
823 color_make(mark)
824 color_make(mid)
825 color_make(time)
826 color_make(timeb)
827 color_make(trans)
828 color_make(umark)
829 color_make(value)
830 color_make(vbox)
831 color_make(vtrans)
832 color_make(x)
833 color_make(xfill)
834 color_make(u)
835 color_make(ufill)
836 color_make(w)
837 color_make(wfill)
838 color_make(dash)
839 color_make(dashfill)
840 color_make(white)
841 color_make(black)
842 color_make(ltgray)
843 color_make(normal)
844 color_make(mdgray)
845 color_make(dkgray)
846 color_make(dkblue)
847 color_make(brkred)
848 color_make(ltblue)
849 color_make(gmstrd)
850 
851 
852 /*
853  * rc variables...these MUST be in alphabetical order for the bsearch!
854  */
855 static struct rc_entry rcitems[]=
856 {
857 { "accel", f_accel },
858 { "alt_hier_delimeter", f_alt_hier_delimeter },
859 { "alt_wheel_mode", f_alt_wheel_mode },
860 { "analog_redraw_skip_count", f_analog_redraw_skip_count },
861 { "append_vcd_hier", f_append_vcd_hier },
862 { "atomic_vectors", f_atomic_vectors },
863 { "autocoalesce", f_autocoalesce },
864 { "autocoalesce_reversal", f_autocoalesce_reversal },
865 { "autoname_bundles", f_autoname_bundles },
866 { "clipboard_mouseover", f_clipboard_mouseover },
867 { "color_0", f_color_0 },
868 { "color_1", f_color_1 },
869 { "color_1fill", f_color_1fill },
870 { "color_back", f_color_back },
871 { "color_baseline", f_color_baseline },
872 { "color_black", f_color_black },
873 { "color_brkred", f_color_brkred },
874 { "color_dash", f_color_dash },
875 { "color_dashfill", f_color_dashfill },
876 { "color_dkblue", f_color_dkblue },
877 { "color_dkgray", f_color_dkgray },
878 { "color_gmstrd", f_color_gmstrd },
879 { "color_grid", f_color_grid },
880 { "color_grid2", f_color_grid2 },
881 { "color_high", f_color_high },
882 { "color_highfill", f_color_highfill },
883 { "color_low", f_color_low },
884 { "color_ltblue", f_color_ltblue },
885 { "color_ltgray", f_color_ltgray },
886 { "color_mark", f_color_mark },
887 { "color_mdgray", f_color_mdgray },
888 { "color_mid", f_color_mid },
889 { "color_normal", f_color_normal },
890 { "color_time", f_color_time },
891 { "color_timeb", f_color_timeb },
892 { "color_trans", f_color_trans },
893 { "color_u", f_color_u },
894 { "color_ufill", f_color_ufill },
895 { "color_umark", f_color_umark },
896 { "color_value", f_color_value },
897 { "color_vbox", f_color_vbox },
898 { "color_vtrans", f_color_vtrans },
899 { "color_w", f_color_w },
900 { "color_wfill", f_color_wfill },
901 { "color_white", f_color_white },
902 { "color_x", f_color_x },
903 { "color_xfill", f_color_xfill },
904 { "constant_marker_update", f_constant_marker_update },
905 { "context_tabposition", f_context_tabposition },
906 { "convert_to_reals", f_convert_to_reals },
907 { "cursor_snap", f_cursor_snap },
908 { "disable_ae2_alias", f_disable_ae2_alias },
909 { "disable_auto_comphier", f_disable_auto_comphier },
910 { "disable_empty_gui", f_disable_empty_gui },
911 { "disable_mouseover", f_disable_mouseover },
912 { "disable_tooltips", f_disable_tooltips },
913 { "do_initial_zoom_fit", f_do_initial_zoom_fit },
914 { "dragzoom_threshold", f_dragzoom_threshold },
915 { "dynamic_resizing", f_dynamic_resizing },
916 { "editor", f_editor },
917 { "enable_fast_exit", f_enable_fast_exit },
918 { "enable_ghost_marker", f_enable_ghost_marker },
919 { "enable_horiz_grid", f_enable_horiz_grid },
920 { "enable_vcd_autosave", f_enable_vcd_autosave },
921 { "enable_vert_grid", f_enable_vert_grid },
922 { "fill_waveform", f_fill_waveform },
923 { "fontname_logfile", f_fontname_logfile },
924 { "fontname_signals", f_fontname_signals },
925 { "fontname_waves", f_fontname_waves },
926 { "force_toolbars", f_force_toolbars },
927 { "hide_sst", f_hide_sst },
928 { "hier_delimeter", f_hier_delimeter },
929 { "hier_grouping", f_hier_grouping },
930 { "hier_ignore_escapes", f_hier_ignore_escapes },
931 { "hier_max_level", f_hier_max_level },
932 { "highlight_wavewindow", f_highlight_wavewindow },
933 { "hpane_pack", f_hpane_pack },
934 { "ignore_savefile_pane_pos", f_ignore_savefile_pane_pos },
935 { "ignore_savefile_pos", f_ignore_savefile_pos },
936 { "ignore_savefile_size", f_ignore_savefile_size },
937 { "initial_signal_window_width", f_initial_signal_window_width },
938 { "initial_window_x", f_initial_window_x },
939 { "initial_window_xpos", f_initial_window_xpos },
940 { "initial_window_y", f_initial_window_y },
941 { "initial_window_ypos", f_initial_window_ypos },
942 { "keep_xz_colors", f_keep_xz_colors },
943 { "left_justify_sigs", f_left_justify_sigs },
944 { "lxt_clock_compress_to_z", f_lxt_clock_compress_to_z },
945 { "max_fsdb_trees", f_max_fsdb_trees },
946 { "page_divisor", f_page_divisor },
947 { "ps_maxveclen", f_ps_maxveclen },
948 { "ruler_origin", f_ruler_origin },
949 { "ruler_step", f_ruler_step },
950 { "scale_to_time_dimension", f_scale_to_time_dimension },
951 { "show_base_symbols", f_show_base_symbols },
952 { "show_grid", f_show_grid },
953 { "splash_disable", f_splash_disable },
954 { "sst_dbl_action_type", f_sst_dbl_action_type },
955 { "sst_dynamic_filter", f_sst_dynamic_filter },
956 { "sst_expanded", f_sst_expanded },
957 { "strace_repeat_count", f_strace_repeat_count },
958 { "use_big_fonts", f_use_big_fonts },
959 { "use_frequency_display", f_use_frequency_display },
960 { "use_full_precision", f_use_full_precision },
961 { "use_maxtime_display", f_use_maxtime_display },
962 { "use_nonprop_fonts", f_use_nonprop_fonts },
963 { "use_pango_fonts", f_use_pango_fonts },
964 { "use_roundcaps", f_use_roundcaps },
965 { "use_scrollbar_only", f_use_scrollbar_only },
966 { "use_scrollwheel_as_y", f_use_scrollwheel_as_y },
967 { "use_standard_clicking", f_use_standard_clicking },
968 { "use_standard_trace_select", f_use_standard_trace_select },
969 { "use_toolbutton_interface", f_use_toolbutton_interface },
970 { "vcd_explicit_zero_subscripts", f_vcd_explicit_zero_subscripts },
971 { "vcd_preserve_glitches", f_vcd_preserve_glitches },
972 { "vcd_preserve_glitches_real", f_vcd_preserve_glitches_real },
973 { "vcd_warning_filesize", f_vcd_warning_filesize },
974 { "vector_padding", f_vector_padding },
975 { "vlist_compression", f_vlist_compression },
976 { "vlist_prepack", f_vlist_prepack },
977 { "vlist_spill", f_vlist_spill },
978 { "wave_scrolling", f_wave_scrolling },
979 { "zoom_base", f_zoom_base },
980 { "zoom_center", f_zoom_center },
981 { "zoom_dynamic", f_zoom_dynamic },
982 { "zoom_dynamic_end", f_zoom_dynamic_end },
983 { "zoom_pow10_snap", f_zoom_pow10_snap }
984 };
985 
986 
vanilla_rc(void)987 static void vanilla_rc(void)
988 {
989 f_enable_fast_exit 	("on");
990 f_alt_wheel_mode 	("on");
991 f_splash_disable 	("off");
992 f_zoom_pow10_snap	("on");
993 f_hier_max_level	("1");
994 f_cursor_snap		("8");
995 f_use_frequency_display ("off");
996 f_use_maxtime_display	("off");
997 f_use_roundcaps		("on");
998 f_use_nonprop_fonts	("on");
999 f_use_pango_fonts	("on");
1000 f_constant_marker_update("on");
1001 f_show_base_symbols	("off");
1002 f_color_back   		("000000"); /* black */
1003 f_color_baseline 	("ffffff"); /* white */
1004 f_color_grid		("202070"); /* dark dark blue */
1005 f_color_grid2		("6a5acd"); /* slate blue */
1006 f_color_high		("79f6f2"); /* light light blue */
1007 f_color_highfill	("4ca09d"); /* dark dark blue */
1008 f_color_low		("5dbebb"); /* light blue */
1009 f_color_1		("00ff00"); /* green */
1010 f_color_1fill		("004d00"); /* dark dark green */
1011 f_color_0		("008000"); /* dark green */
1012 f_color_trans		("00c000"); /* medium green */
1013 f_color_mid		("c0c000"); /* mustard */
1014 f_color_value		("ffffff"); /* white */
1015 f_color_vbox		("00ff00"); /* green */
1016 f_color_vtrans		("00c000"); /* medium green */
1017 f_color_x		("ff0000"); /* red */
1018 f_color_xfill		("400000"); /* dark maroon */
1019 f_color_u		("cc0000"); /* brick */
1020 f_color_ufill		("200000"); /* dark maroon */
1021 f_color_w		("79f6f2"); /* light light blue */
1022 f_color_wfill		("3f817f"); /* dark blue-green */
1023 f_color_dash		("edf508"); /* yellow */
1024 f_color_dashfill	("7d8104"); /* green mustard */
1025 f_color_umark		("ff8080"); /* pink */
1026 f_color_mark		("ffff80"); /* light yellow */
1027 f_color_time		("ffffff"); /* white */
1028 f_color_timeb		("000000"); /* black */
1029 f_color_white		("ffffff"); /* white */
1030 f_color_black		("000000"); /* black */
1031 f_color_ltgray		("f5f5f5");
1032 f_color_normal		("e6e6e6");
1033 f_color_mdgray		("cccccc");
1034 f_color_dkgray		("aaaaaa");
1035 f_color_dkblue		("4464ac");
1036 f_color_brkred		("cc0000"); /* brick */
1037 f_color_ltblue	        ("5dbebb"); /* light blue    */
1038 f_color_gmstrd          ("7d8104"); /* green mustard */
1039 }
1040 
insert_rc_variable(char * str)1041 int insert_rc_variable(char *str)
1042 {
1043 int i;
1044 int len;
1045 int ok = 0;
1046 
1047 len=strlen(str);
1048 if(len)
1049 	{
1050 	for(i=0;i<len;i++)
1051 		{
1052 		int pos;
1053 		if((str[i]==' ')||(str[i]=='\t')) continue;	/* skip leading ws */
1054 		if(str[i]=='#') break; 				/* is a comment */
1055 		for(pos=i;i<len;i++)
1056 			{
1057 			if((str[i]==' ')||(str[i]=='\t'))
1058 				{
1059 				str[i]=0; /* null term envname */
1060 
1061 				for(i=i+1;i<len;i++)
1062 					{
1063 					struct rc_entry *r;
1064 
1065 					if((str[i]==' ')||(str[i]=='\t')) continue;
1066 					if((r=bsearch((void *)(str+pos), (void *)rcitems,
1067 						sizeof(rcitems)/sizeof(struct rc_entry),
1068 						sizeof(struct rc_entry), rc_compare)))
1069 						{
1070 						int j;
1071 							for(j=len-1;j>=i;j--)
1072 							{
1073 							if((str[j]==' ')||(str[j]=='\t')) /* nuke trailing spaces */
1074 								{
1075 								str[j]=0;
1076 								continue;
1077 								}
1078 								else
1079 								{
1080 								break;
1081 								}
1082 							}
1083 						r->func(str+i); /* call resolution function */
1084 						ok = 1;
1085 						}
1086 					break;
1087 					}
1088 				break;	/* added so multiple word values work properly*/
1089 				}
1090 			}
1091 		break;
1092 		}
1093 	}
1094 
1095 return(ok);
1096 }
1097 
1098 
read_rc_file(char * override_rc)1099 void read_rc_file(char *override_rc)
1100 {
1101 FILE *handle = NULL;
1102 int i;
1103 int num_rcitems = sizeof(rcitems)/sizeof(struct rc_entry);
1104 
1105 for(i=0;i<(num_rcitems-1);i++)
1106 	{
1107 	if(strcmp(rcitems[i].name, rcitems[i+1].name) > 0)
1108 		{
1109 		fprintf(stderr, "rcitems misordering: '%s' vs '%s'\n", rcitems[i].name, rcitems[i+1].name);
1110 		exit(255);
1111 		}
1112 	}
1113 
1114 /* move defaults first and only go whitescreen if instructed to do so */
1115 if(GLOBALS->possibly_use_rc_defaults) vanilla_rc();
1116 
1117 if((override_rc)&&((handle=fopen(override_rc,"rb"))))
1118 	{
1119 	/* good, we have a handle */
1120 	wave_gconf_client_set_string("/current/rcfile", override_rc);
1121 	}
1122 else
1123 #if !defined __MINGW32__ && !defined _MSC_VER
1124 if(!(handle=fopen(rcname,"rb")))
1125 	{
1126 	struct passwd *pw = NULL;
1127 	char *home = NULL;
1128 	char *rcpath = NULL;
1129 
1130 	pw=getpwuid(geteuid());
1131 	if(pw)
1132 		{
1133 		home=pw->pw_dir;
1134 		}
1135 
1136 	if(!home)
1137 		{
1138 		home = getenv("HOME");
1139 		}
1140 
1141 	if(home)
1142 		{
1143 		rcpath=(char *)alloca(strlen(home)+1+strlen(rcname)+1);
1144 		strcpy(rcpath,home);
1145 		strcat(rcpath,"/");
1146 		strcat(rcpath,rcname);
1147 		}
1148 
1149 	if( !rcpath || !(handle=fopen(rcpath,"rb")) )
1150 		{
1151 #ifdef MAC_INTEGRATION
1152 		const gchar *bundle_id = gtkosx_application_get_bundle_id();
1153 		if(bundle_id)
1154 			{
1155 			const gchar *rpath = gtkosx_application_get_resource_path();
1156 			const char *suf = "/gtkwaverc";
1157 
1158 			rcpath = NULL;
1159 			if(rpath)
1160 				{
1161 				rcpath = (char *)alloca(strlen(rpath) + strlen(suf) + 1);
1162 				strcpy(rcpath, rpath);
1163 				strcat(rcpath, suf);
1164 				}
1165 
1166 			if(!rcpath || !(handle=fopen(rcpath,"rb")))
1167 				{
1168 				wave_gconf_client_set_string("/current/rcfile", "");
1169 				errno=0;
1170 				return; /* no .rc file */
1171 				}
1172 				else
1173 				{
1174 				wave_gconf_client_set_string("/current/rcfile", rcpath);
1175 				}
1176 			}
1177 			else
1178 #endif
1179 			{
1180 			wave_gconf_client_set_string("/current/rcfile", "");
1181 			errno=0;
1182 			return; /* no .rc file */
1183 			}
1184 		}
1185 		else
1186 		{
1187 		wave_gconf_client_set_string("/current/rcfile", rcpath);
1188 		}
1189 	}
1190 #else
1191 if(!(handle=fopen(rcname,"rb")))		/* no concept of ~ in win32 */
1192 	{
1193         /* Try to find rcname in USERPROFILE */
1194         char *home;
1195         char *rcpath;
1196 
1197         home=getenv("USERPROFILE");
1198         if (home != NULL) {
1199             /* printf("USERPROFILE = %s\n", home); */
1200             rcpath=(char *)alloca(strlen(home)+1+strlen(rcname)+1);
1201             strcpy(rcpath,home);
1202             strcat(rcpath,"\\");
1203             strcat(rcpath,rcname);
1204             /* printf("rcpath = %s\n", rcpath); */
1205         }
1206         if ((home == NULL) || (!(handle=fopen(rcpath,"rb")))) {
1207             /* printf("No rc file\n"); */
1208 	    wave_gconf_client_set_string("/current/rcfile", "");
1209   	    errno=0;
1210 	    if(GLOBALS->possibly_use_rc_defaults) vanilla_rc();
1211 	    return; /* no .rc file */
1212 	    }
1213 
1214 	wave_gconf_client_set_string("/current/rcfile", rcpath);
1215 	}
1216 #endif
1217 
1218 GLOBALS->rc_line_no=0;
1219 while(!feof(handle))
1220 	{
1221 	char *str;
1222 
1223 	GLOBALS->rc_line_no++;
1224 	if((str=fgetmalloc(handle)))
1225 		{
1226 		insert_rc_variable(str);
1227 		free_2(str);
1228 		}
1229 	}
1230 
1231 fclose(handle);
1232 errno=0;
1233 return;
1234 }
1235