Advertisement
milanmetal

GtkWave / main.c modified / no toolbar

Nov 26th, 2018
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 95.65 KB | None | 0 0
  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. /* AIX may need this for alloca to work */
  11. #if defined _AIX
  12.   #pragma alloca
  13. #endif
  14.  
  15. #include "globals.h"
  16. #include <config.h>
  17. #include <gtk/gtk.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #ifdef __MINGW32__
  21. #include <windows.h>
  22. #endif
  23. #include "fsdb_wrapper_api.h"
  24.  
  25. /*
  26. #define WAVE_CRASH_ON_GTK_WARNING
  27. */
  28.  
  29. #include "wave_locale.h"
  30.  
  31. #if !defined _MSC_VER && !defined __MINGW32__
  32. #include <signal.h>
  33. #include <sys/types.h>
  34. #include <sys/wait.h>
  35. #include <sys/time.h>
  36. #include <sys/types.h>
  37. #endif
  38.  
  39. #if !defined _MSC_VER && defined WAVE_USE_GTK2
  40. #define WAVE_USE_XID
  41. #else
  42. #undef WAVE_USE_XID
  43. #endif
  44.  
  45. #ifdef HAVE_GETOPT_LONG
  46. #include <getopt.h>
  47. #else
  48. #include "gnu-getopt.h"
  49. #ifndef _MSC_VER
  50. #include <unistd.h>
  51. #else
  52. #define strcasecmp _stricmp
  53. #endif
  54. #endif
  55.  
  56. #include "symbol.h"
  57. #include "lx2.h"
  58. #include "ae2.h"
  59. #include "vzt.h"
  60. #include "ghw.h"
  61. #include "fst.h"
  62. #include "main.h"
  63. #include "menu.h"
  64. #include "vcd.h"
  65. #include "lxt.h"
  66. #include "lxt2_read.h"
  67. #include "vzt_read.h"
  68. #include "pixmaps.h"
  69. #include "currenttime.h"
  70. #include "fgetdynamic.h"
  71. #include "rc.h"
  72. #include "translate.h"
  73. #include "ptranslate.h"
  74. #include "ttranslate.h"
  75.  
  76. #include "tcl_helper.h"
  77. #if defined(HAVE_LIBTCL)
  78. #include <tcl.h>
  79. #include <tk.h>
  80. #endif
  81.  
  82. #ifdef MAC_INTEGRATION
  83. #include <gtkosxapplication.h>
  84. #endif
  85.  
  86. char *gtkwave_argv0_cached = NULL;
  87.  
  88. static void switch_page(GtkNotebook     *notebook,
  89.             GtkNotebookPage *page,
  90.             guint            page_num,
  91.             gpointer         user_data)
  92. {
  93. (void)notebook;
  94. (void)page;
  95. (void)user_data;
  96.  
  97. char timestr[32];
  98. struct Global *g_old = GLOBALS;
  99.  
  100. set_GLOBALS((*GLOBALS->contexts)[page_num]);
  101.  
  102. GLOBALS->lxt_clock_compress_to_z = g_old->lxt_clock_compress_to_z;
  103. GLOBALS->autoname_bundles = g_old->autoname_bundles;
  104. GLOBALS->autocoalesce_reversal = g_old->autocoalesce_reversal;
  105. GLOBALS->autocoalesce = g_old->autocoalesce;
  106. GLOBALS->hier_grouping = g_old->hier_grouping;
  107. GLOBALS->wave_scrolling = g_old->wave_scrolling;
  108. GLOBALS->constant_marker_update = g_old->constant_marker_update;
  109. GLOBALS->do_zoom_center = g_old->do_zoom_center;
  110. GLOBALS->use_roundcaps = g_old->use_roundcaps;
  111. GLOBALS->do_resize_signals = g_old->do_resize_signals;
  112. GLOBALS->alt_wheel_mode = g_old->alt_wheel_mode;
  113. GLOBALS->initial_signal_window_width = g_old->initial_signal_window_width;
  114. GLOBALS->scale_to_time_dimension = g_old->scale_to_time_dimension;
  115. GLOBALS->use_full_precision = g_old->use_full_precision;
  116. GLOBALS->show_base = g_old->show_base;
  117. GLOBALS->display_grid = g_old->display_grid;
  118. GLOBALS->highlight_wavewindow = g_old->highlight_wavewindow;
  119. GLOBALS->fill_waveform = g_old->fill_waveform;
  120. GLOBALS->use_standard_trace_select = g_old->use_standard_trace_select;
  121. GLOBALS->disable_mouseover = g_old->disable_mouseover;
  122. GLOBALS->clipboard_mouseover = g_old->clipboard_mouseover;
  123. GLOBALS->keep_xz_colors = g_old->keep_xz_colors;
  124. GLOBALS->zoom_pow10_snap = g_old->zoom_pow10_snap;
  125. GLOBALS->zoom_dyn = g_old->zoom_dyn;
  126. GLOBALS->zoom_dyne = g_old->zoom_dyne;
  127. GLOBALS->hier_ignore_escapes = g_old->hier_ignore_escapes;
  128. GLOBALS->sst_dbl_action_type = g_old->sst_dbl_action_type;
  129.  
  130. reformat_time(timestr, GLOBALS->tims.first + GLOBALS->global_time_offset, GLOBALS->time_dimension);
  131. gtk_entry_set_text(GTK_ENTRY(GLOBALS->from_entry),timestr);
  132. reformat_time(timestr, GLOBALS->tims.last +  GLOBALS->global_time_offset, GLOBALS->time_dimension);
  133. gtk_entry_set_text(GTK_ENTRY(GLOBALS->to_entry),timestr);
  134.  
  135. update_maxmarker_labels();
  136. update_basetime(GLOBALS->tims.baseline);
  137.  
  138. GLOBALS->keypress_handler_id = g_old->keypress_handler_id;
  139.  
  140. if(GLOBALS->second_page_created)
  141.     {
  142.     wave_gtk_window_set_title(GTK_WINDOW(GLOBALS->mainwindow), GLOBALS->winname, GLOBALS->dumpfile_is_modified ? WAVE_SET_TITLE_MODIFIED: WAVE_SET_TITLE_NONE, 0);
  143.  
  144.     MaxSignalLength();
  145.     signalarea_configure_event(GLOBALS->signalarea, NULL);
  146.     wavearea_configure_event(GLOBALS->wavearea, NULL);
  147.     }
  148.  
  149. }
  150.  
  151.  
  152. void kill_stems_browser_single(void *V)
  153. {
  154. struct Global *G = (struct Global *)V;
  155. #if !defined _MSC_VER
  156.     if(G && G->anno_ctx)
  157.         {
  158. #ifdef __MINGW32__
  159.         if(G->anno_ctx->browser_process)
  160.             {
  161.             TerminateProcess(G->anno_ctx->browser_process, 0);
  162.             CloseHandle(G->anno_ctx->browser_process);
  163.             G->anno_ctx->browser_process = 0;
  164.             }
  165. #else
  166.         if(G->anno_ctx->browser_process)
  167.             {
  168. #ifdef __CYGWIN__
  169.             G->anno_ctx->cygwin_remote_kill = 1; /* let cygwin child exit() on its own */
  170. #else
  171.             kill(G->anno_ctx->browser_process, SIGKILL);
  172. #endif
  173.             G->anno_ctx->browser_process = (pid_t)0;
  174.             }
  175. #endif
  176.         G->anno_ctx = NULL;
  177.         }
  178. #endif
  179. }
  180.  
  181. #if !defined _MSC_VER
  182. void kill_stems_browser(void)
  183. {
  184. unsigned int ix;
  185.  
  186. for(ix=0;ix<GLOBALS->num_notebook_pages;ix++)
  187.     {
  188.         struct Global *G = (*GLOBALS->contexts)[ix];
  189.     kill_stems_browser_single(G);
  190.     }
  191. }
  192. #endif
  193.  
  194.  
  195. #ifdef WAVE_USE_XID
  196. static int plug_destroy (GtkWidget *widget, gpointer data)
  197. {
  198. (void)widget;
  199. (void)data;
  200.  
  201. exit(0);
  202.  
  203. return(FALSE);
  204. }
  205. #endif
  206.  
  207. #if defined __MINGW32__
  208. static void close_all_fst_files(void) /* so mingw does delete of reader tempfiles */
  209. {
  210. unsigned int i;
  211. for(i=0;i<GLOBALS->num_notebook_pages;i++)
  212.     {
  213.         if((*GLOBALS->contexts)[i]->fst_fst_c_1)
  214.         {
  215.         fstReaderClose((*GLOBALS->contexts)[i]->fst_fst_c_1);
  216.         (*GLOBALS->contexts)[i]->fst_fst_c_1 = NULL;
  217.         }
  218.         }
  219. }
  220. #endif
  221.  
  222.  
  223. #ifdef WAVE_FSDB_READER_IS_PRESENT
  224. static void close_all_fsdb_files(void) /* otherwise fsdb can leave around stray files if .gz/.bz2 was in use */
  225. {
  226. unsigned int i;
  227. for(i=0;i<GLOBALS->num_notebook_pages;i++)
  228.     {
  229.     if((*GLOBALS->contexts)[i]->extload_ffr_ctx)
  230.         {
  231.         fsdbReaderClose((*GLOBALS->contexts)[i]->extload_ffr_ctx);
  232.         (*GLOBALS->contexts)[i]->extload_ffr_ctx = NULL;
  233.         }
  234.         }
  235. }
  236. #endif
  237.  
  238.  
  239. static void print_help(char *nam)
  240. {
  241. #if defined(EXTLOAD_SUFFIX) && defined(EXTCONV_PATH)
  242. int slen = strlen(EXTLOAD_SUFFIX);
  243. char *ucase_ext = wave_alloca(slen+1);
  244. int i;
  245.  
  246. for(i=0;i<slen;i++)
  247.         {
  248.         ucase_ext[i] = toupper(EXTLOAD_SUFFIX[i]);
  249.         }
  250. ucase_ext[i] = 0;
  251. #endif
  252.  
  253.  
  254. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __FreeBSD__ && !defined __CYGWIN__
  255. #define WAVE_GETOPT_CPUS "  -c, --cpu=NUMCPUS          specify number of CPUs for parallelizable ops\n"
  256. #else
  257. #define WAVE_GETOPT_CPUS
  258. #endif
  259.  
  260. #if !defined _MSC_VER && !defined __MINGW32__
  261. #if defined(EXTLOAD_SUFFIX) && defined(EXTCONV_PATH)
  262. #define VCD_GETOPT       "  -o, --optimize             optimize VCD/%s to FST\n"
  263. #else
  264. #define VCD_GETOPT       "  -o, --optimize             optimize VCD to FST\n"
  265. #endif
  266. #else
  267. #define VCD_GETOPT
  268. #endif
  269.  
  270. #if !defined _MSC_VER
  271. #define STEMS_GETOPT     "  -t, --stems=FILE           specify stems file for source code annotation\n"
  272. #define DUAL_GETOPT      "  -D, --dualid=WHICH         specify multisession identifier\n"
  273. #define INTR_GETOPT      "  -I, --interactive          interactive VCD mode (filename is shared mem ID)\n"
  274. #else
  275. #define STEMS_GETOPT
  276. #define DUAL_GETOPT
  277. #define INTR_GETOPT
  278. #endif
  279.  
  280. #ifdef WAVE_USE_XID
  281. #define XID_GETOPT   "  -X, --xid=XID              specify XID of window for GtkPlug to connect to\n"
  282. #else
  283. #define XID_GETOPT
  284. #endif
  285.  
  286. #if defined(WIN32) && defined(USE_TCL_STUBS)
  287. #define WISH_GETOPT
  288. #else
  289. #define WISH_GETOPT  "  -T, --tcl_init=FILE        specify Tcl command script file to be loaded on startup\n" \
  290.              "  -W, --wish                 enable Tcl command line on stdio\n"
  291. #endif
  292.  
  293. #if defined(HAVE_LIBTCL)
  294. #define REPSCRIPT_GETOPT WISH_GETOPT \
  295.                          "  -R, --repscript=FILE       specify timer-driven Tcl command script file\n" \
  296.                          "  -P, --repperiod=VALUE      specify repscript period in msec (default: 500)\n"
  297. #else
  298. #define REPSCRIPT_GETOPT
  299. #endif
  300.  
  301. #if !defined _MSC_VER && !defined __MINGW32__
  302. #define OUTPUT_GETOPT "  -O, --output=FILE          specify filename for stdout/stderr redirect\n"
  303. #define CHDIR_GETOPT "  -2, --chdir=DIR            specify new current working directory\n"
  304. #else
  305. #define OUTPUT_GETOPT
  306. #define CHDIR_GETOPT
  307. #endif
  308.  
  309. #if defined(WAVE_HAVE_GCONF) || defined(WAVE_HAVE_GSETTINGS)
  310. #define RPC_GETOPT  "  -1, --rpcid=RPCID          specify RPCID of GConf session\n"
  311. #if defined(WAVE_HAVE_GCONF)
  312. #define RPC_GETOPT3 "  -3, --restore              restore previous RPCID numbered session\n"
  313. #else
  314. #define RPC_GETOPT3 "  -3, --restore              restore previous session\n"
  315. #endif
  316. #else
  317. #define RPC_GETOPT
  318. #define RPC_GETOPT3
  319. #endif
  320.  
  321. #if defined(WAVE_USE_GTK2)
  322. #define SLIDEZOOM_OPT "  -z, --slider-zoom          enable horizontal slider stretch zoom\n"
  323. #else
  324. #define SLIDEZOOM_OPT
  325. #endif
  326.  
  327. printf(
  328. "Usage: %s [OPTION]... [DUMPFILE] [SAVEFILE] [RCFILE]\n\n"
  329. "  -n, --nocli=DIRPATH        use file requester for dumpfile name\n"
  330. "  -f, --dump=FILE            specify dumpfile name\n"
  331. "  -F, --fastload             generate/use VCD recoder fastload files\n"
  332. VCD_GETOPT
  333. "  -a, --save=FILE            specify savefile name\n"
  334. "  -A, --autosavename         assume savefile is suffix modified dumpfile name\n"
  335. "  -r, --rcfile=FILE          specify override .rcfile name\n"
  336. "  -d, --defaultskip          if missing .rcfile, do not use useful defaults\n"
  337. DUAL_GETOPT
  338. "  -l, --logfile=FILE         specify simulation logfile name for time values\n"
  339. "  -s, --start=TIME           specify start time for LXT2/VZT block skip\n"
  340. "  -e, --end=TIME             specify end time for LXT2/VZT block skip\n"
  341. STEMS_GETOPT
  342. WAVE_GETOPT_CPUS
  343. "  -N, --nowm                 disable window manager for most windows\n"
  344. "  -M, --nomenus              do not render menubar (for making applets)\n"
  345. "  -S, --script=FILE          specify Tcl command script file for execution\n"
  346. REPSCRIPT_GETOPT
  347. XID_GETOPT
  348. RPC_GETOPT
  349. CHDIR_GETOPT
  350. RPC_GETOPT3
  351. "  -4, --rcvar                specify single rc variable values individually\n"
  352. "  -5, --sstexclude           specify sst exclusion filter filename\n"
  353. INTR_GETOPT
  354. "  -C, --comphier             use compressed hierarchy names (slower)\n"
  355. "  -g, --giga                 use gigabyte mempacking when recoding (slower)\n"
  356. "  -L, --legacy               use legacy VCD mode rather than the VCD recoder\n"
  357. "  -v, --vcd                  use stdin as a VCD dumpfile\n"
  358. OUTPUT_GETOPT
  359. SLIDEZOOM_OPT
  360. "  -V, --version              display version banner then exit\n"
  361. "  -h, --help                 display this help then exit\n"
  362. "  -x, --exit                 exit after loading trace (for loader benchmarks)\n\n"
  363.  
  364. "VCD files and save files may be compressed with zip or gzip.\n"
  365. "GHW files may be compressed with gzip or bzip2.\n"
  366. "Other formats must remain uncompressed due to their non-linear access.\n"
  367. "Note that DUMPFILE is optional if the --dump or --nocli options are specified.\n"
  368. "SAVEFILE and RCFILE are always optional.\n\n"
  369.  
  370. "Report bugs to <"PACKAGE_BUGREPORT">.\n",nam
  371. #if !defined _MSC_VER && !defined __MINGW32__
  372. #if defined(EXTLOAD_SUFFIX) && defined(EXTCONV_PATH)
  373. ,ucase_ext
  374. #endif
  375. #endif
  376. );
  377.  
  378. #ifdef __MINGW32__
  379. fflush(stdout); /* fix for possible problem with mingw/msys shells */
  380. #endif
  381.  
  382. exit(0);
  383. }
  384.  
  385.  
  386. /*
  387.  * file selection for -n/--nocli flag
  388.  */
  389.  
  390. static void wave_get_filename_cleanup(GtkWidget *widget, gpointer data)
  391. {
  392. (void)widget;
  393. (void)data;
  394.  
  395. gtk_main_quit(); /* do nothing but exit gtk loop */
  396. }
  397.  
  398. static char *wave_get_filename(char *dfile)
  399. {
  400. if(dfile)
  401.     {
  402.     int len = strlen(dfile);
  403.     GLOBALS->ftext_main_main_c_1 = malloc_2(strlen(dfile)+2);
  404.     strcpy(GLOBALS->ftext_main_main_c_1, dfile);
  405. #if !defined _MSC_VER && !defined __MINGW32__
  406.     if((len)&&(dfile[len-1]!='/'))
  407.         {
  408.         strcpy(GLOBALS->ftext_main_main_c_1 + len, "/");
  409.         }
  410. #else
  411.     if((len)&&(dfile[len-1]!='\\'))
  412.         {
  413.         strcpy(GLOBALS->ftext_main_main_c_1 + len, "\\");
  414.         }
  415. #endif
  416.     }
  417. fileselbox_old("GTKWave: Select a dumpfile...",&GLOBALS->ftext_main_main_c_1,GTK_SIGNAL_FUNC(wave_get_filename_cleanup), GTK_SIGNAL_FUNC(wave_get_filename_cleanup), NULL, 0);
  418. gtk_main();
  419.  
  420. return(GLOBALS->ftext_main_main_c_1);
  421. }
  422.  
  423. /*
  424.  * Modify the name of the executable (argv[0]) handed to Tk_MainEx;
  425.  * The new executable name has _[pid] appended. This gives a unique
  426.  * (and known) name to the interpreter (for use with send).
  427.  */
  428. void addPidToExecutableName(int argc, char* argv[], char* argv_mod[])
  429. {
  430.   char* pos;
  431.   char* buffer;
  432.  
  433.   int i;
  434.   for(i=0;i<argc;i++)
  435.     {
  436.       argv_mod[i] = argv[i];
  437.     }
  438.  
  439.   buffer = malloc_2(strlen(argv[0])+1+10);
  440.   pos = buffer;
  441.   strcpy(pos, argv[0]);
  442.   pos = buffer + strlen(buffer);
  443.   strcpy(pos, "_");
  444.   pos = buffer + strlen(buffer);
  445.   sprintf(pos, "%d", getpid());
  446.  
  447.   argv_mod[0] = buffer;
  448. }
  449.  
  450.  
  451. int main(int argc, char *argv[])
  452. {
  453. return(main_2(0, argc, argv));
  454. }
  455.  
  456. int main_2(int opt_vcd, int argc, char *argv[])
  457. {
  458. static char *winprefix="GTKWave - ";
  459. static char *winstd="GTKWave (stdio) ";
  460. static char *vcd_autosave_name="vcd_autosave.sav";
  461. char *output_name = NULL;
  462. char *chdir_cache = NULL;
  463.  
  464. int magic_word_filetype = G_FT_UNKNOWN;
  465.  
  466. int i;
  467. int c;
  468. char is_vcd=0;
  469. char is_wish=0;
  470. char is_interactive=0;
  471. char is_smartsave = 0;
  472. char is_legacy = 0;
  473. char is_fastload = VCD_FSL_NONE;
  474. char is_giga = 0;
  475. char fast_exit=0;
  476. char opt_errors_encountered=0;
  477. char is_missing_file = 0;
  478.  
  479. char *wname=NULL;
  480. char *override_rc=NULL;
  481. char *scriptfile=NULL;
  482. FILE *wave = NULL;
  483. FILE *vcd_save_handle_cached = NULL;
  484.  
  485. GtkWidget *main_vbox = NULL, *top_table = NULL, *whole_table = NULL;
  486. GtkWidget *menubar;
  487. GtkWidget *text1;
  488. GtkWidget *zoombuttons;
  489. GtkWidget *pagebuttons;
  490. GtkWidget *fetchbuttons;
  491. GtkWidget *discardbuttons;
  492. GtkWidget *shiftbuttons;
  493. GtkWidget *edgebuttons;
  494. GtkWidget *entry;
  495. GtkWidget *timebox;
  496. GtkWidget *panedwindow;
  497. GtkWidget *dummy1, *dummy2;
  498. GtkWidget *toolhandle=NULL;
  499. int tcl_interpreter_needs_making = 0;
  500. struct Global *old_g = NULL;
  501.  
  502. int splash_disable_rc_override = 0;
  503. int mainwindow_already_built = 0;
  504. #ifdef MAC_INTEGRATION
  505. GdkPixbuf *dock_pb;
  506. #endif
  507.  
  508. struct rc_override *rc_override_head = NULL, *rc_override_curr = NULL;
  509.  
  510. WAVE_LOCALE_FIX
  511.  
  512. /* Initialize the GLOBALS structure for the first time... */
  513.  
  514. if(!GLOBALS)
  515.     {
  516.     set_GLOBALS(initialize_globals());
  517.     mainwindow_already_built = 0;
  518.     tcl_interpreter_needs_making = 1;
  519.  
  520.     GLOBALS->logfiles = calloc(1, sizeof(void *)); /* calloc is deliberate! */
  521.     }
  522.     else
  523.     {
  524.     old_g = GLOBALS;
  525.  
  526.     set_GLOBALS(initialize_globals());
  527.  
  528.     GLOBALS->second_page_created = old_g->second_page_created = 1;
  529.  
  530.     GLOBALS->notebook = old_g->notebook;
  531.     GLOBALS->num_notebook_pages = old_g->num_notebook_pages;
  532.     GLOBALS->num_notebook_pages_cumulative = old_g->num_notebook_pages_cumulative;
  533.     GLOBALS->contexts = old_g->contexts;
  534.  
  535.     GLOBALS->mainwindow = old_g->mainwindow;
  536.     splash_disable_rc_override = 1;
  537.  
  538.     /* busy.c */
  539.     GLOBALS->busycursor_busy_c_1 = old_g->busycursor_busy_c_1;
  540.  
  541.     /* logfiles.c */
  542.     GLOBALS->logfiles = old_g->logfiles;
  543.  
  544.     /* menu.c */
  545. #if defined(HAVE_LIBTCL)
  546.     GLOBALS->interp = old_g->interp;
  547. #endif
  548. #ifndef WAVE_USE_MLIST_T
  549.     GLOBALS->item_factory_menu_c_1 = old_g->item_factory_menu_c_1;
  550. #endif
  551.     GLOBALS->vcd_jmp_buf = old_g->vcd_jmp_buf;
  552.  
  553.     /* currenttime.c */
  554.     GLOBALS->max_or_marker_label_currenttime_c_1 = old_g->max_or_marker_label_currenttime_c_1;
  555.     GLOBALS->maxtext_currenttime_c_1=(char *)malloc_2(40);
  556.     GLOBALS->maxtimewid_currenttime_c_1 = old_g->maxtimewid_currenttime_c_1;
  557.     GLOBALS->curtext_currenttime_c_1 = old_g->curtext_currenttime_c_1;
  558.     GLOBALS->base_or_curtime_label_currenttime_c_1 = old_g->base_or_curtime_label_currenttime_c_1;
  559.     GLOBALS->curtimewid_currenttime_c_1 = old_g->curtimewid_currenttime_c_1;
  560.  
  561.     /* status.c */
  562.     GLOBALS->text_status_c_2 = old_g->text_status_c_2;
  563.     GLOBALS->vscrollbar_status_c_2 = old_g->vscrollbar_status_c_2;
  564. #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
  565.     GLOBALS->iter_status_c_3 = old_g->iter_status_c_3;
  566.     GLOBALS->bold_tag_status_c_3 = old_g->bold_tag_status_c_3;
  567. #endif
  568.  
  569.     /* timeentry.c */
  570.     GLOBALS->from_entry = old_g->from_entry;
  571.     GLOBALS->to_entry = old_g->to_entry;
  572.  
  573.     /* rc.c */
  574.     GLOBALS->possibly_use_rc_defaults = old_g->possibly_use_rc_defaults;
  575.     GLOBALS->ignore_savefile_pane_pos = old_g->ignore_savefile_pane_pos;
  576.     GLOBALS->ignore_savefile_pos = old_g->ignore_savefile_pos;
  577.     GLOBALS->ignore_savefile_size = old_g->ignore_savefile_size;
  578.  
  579.     GLOBALS->color_back = old_g->color_back;
  580.     GLOBALS->color_baseline = old_g->color_baseline;
  581.     GLOBALS->color_grid = old_g->color_grid;
  582.     GLOBALS->color_grid2 = old_g->color_grid2;
  583.     GLOBALS->color_high = old_g->color_high;
  584.     GLOBALS->color_highfill = old_g->color_highfill;
  585.     GLOBALS->color_low = old_g->color_low;
  586.     GLOBALS->color_1 = old_g->color_1;
  587.     GLOBALS->color_1fill = old_g->color_1fill;
  588.     GLOBALS->color_0 = old_g->color_0;
  589.     GLOBALS->color_mark = old_g->color_mark;
  590.     GLOBALS->color_mid = old_g->color_mid;
  591.     GLOBALS->color_time = old_g->color_time;
  592.     GLOBALS->color_timeb = old_g->color_timeb;
  593.     GLOBALS->color_trans = old_g->color_trans;
  594.     GLOBALS->color_umark = old_g->color_umark;
  595.     GLOBALS->color_value = old_g->color_value;
  596.     GLOBALS->color_vbox = old_g->color_vbox;
  597.     GLOBALS->color_vtrans = old_g->color_vtrans;
  598.     GLOBALS->color_x = old_g->color_x;
  599.     GLOBALS->color_xfill = old_g->color_xfill;
  600.     GLOBALS->color_u = old_g->color_u;
  601.     GLOBALS->color_ufill = old_g->color_ufill;
  602.     GLOBALS->color_w = old_g->color_w;
  603.     GLOBALS->color_wfill = old_g->color_wfill;
  604.     GLOBALS->color_dash = old_g->color_dash;
  605.     GLOBALS->color_dashfill = old_g->color_dashfill;
  606.     GLOBALS->color_white = old_g->color_white;
  607.     GLOBALS->color_black = old_g->color_black;
  608.     GLOBALS->color_ltgray = old_g->color_ltgray;
  609.     GLOBALS->color_normal = old_g->color_normal;
  610.     GLOBALS->color_mdgray = old_g->color_mdgray;
  611.     GLOBALS->color_dkgray = old_g->color_dkgray;
  612.     GLOBALS->color_dkblue = old_g->color_dkblue;
  613.     GLOBALS->color_brkred = old_g->color_brkred;
  614.     GLOBALS->color_ltblue = old_g->color_ltblue;
  615.     GLOBALS->color_gmstrd = old_g->color_gmstrd;
  616.  
  617.     GLOBALS->atomic_vectors = old_g->atomic_vectors;
  618.     GLOBALS->autoname_bundles = old_g->autoname_bundles;
  619.     GLOBALS->autocoalesce = old_g->autocoalesce;
  620.     GLOBALS->autocoalesce_reversal = old_g->autocoalesce_reversal;
  621.     GLOBALS->constant_marker_update = old_g->constant_marker_update;
  622.     GLOBALS->convert_to_reals = old_g->convert_to_reals;
  623.     GLOBALS->disable_mouseover = old_g->disable_mouseover;
  624.     GLOBALS->clipboard_mouseover = old_g->clipboard_mouseover;
  625.     GLOBALS->keep_xz_colors = old_g->keep_xz_colors;
  626.     GLOBALS->disable_tooltips = old_g->disable_tooltips;
  627.     GLOBALS->do_initial_zoom_fit = old_g->do_initial_zoom_fit;
  628.     GLOBALS->do_resize_signals = old_g->do_resize_signals;
  629.     GLOBALS->alt_wheel_mode = old_g->alt_wheel_mode;
  630.     GLOBALS->initial_signal_window_width = old_g->initial_signal_window_width;
  631.     GLOBALS->scale_to_time_dimension = old_g->scale_to_time_dimension;
  632.     GLOBALS->enable_fast_exit = old_g->enable_fast_exit;
  633.     GLOBALS->enable_ghost_marker = old_g->enable_ghost_marker;
  634.     GLOBALS->enable_horiz_grid = old_g->enable_horiz_grid;
  635.     GLOBALS->fill_waveform = old_g->fill_waveform;
  636.     GLOBALS->make_vcd_save_file = old_g->make_vcd_save_file;
  637.     GLOBALS->enable_vert_grid = old_g->enable_vert_grid;
  638.     GLOBALS->force_toolbars = old_g->force_toolbars;
  639.     GLOBALS->hide_sst = old_g->hide_sst;
  640.     GLOBALS->sst_expanded = old_g->sst_expanded;
  641.     GLOBALS->hier_grouping = old_g->hier_grouping;
  642.     GLOBALS->hier_max_level = old_g->hier_max_level;
  643.     GLOBALS->hier_max_level_shadow = old_g->hier_max_level_shadow;
  644.     GLOBALS->paned_pack_semantics = old_g->paned_pack_semantics;
  645.     GLOBALS->left_justify_sigs = old_g->left_justify_sigs;
  646.     GLOBALS->lxt_clock_compress_to_z = old_g->lxt_clock_compress_to_z;
  647.     GLOBALS->ps_maxveclen = old_g->ps_maxveclen;
  648.     GLOBALS->show_base = old_g->show_base;
  649.     GLOBALS->display_grid = old_g->display_grid;
  650.     GLOBALS->highlight_wavewindow = old_g->highlight_wavewindow;
  651.     GLOBALS->fill_waveform = old_g->fill_waveform;
  652.     GLOBALS->use_standard_trace_select = old_g->use_standard_trace_select;
  653.     GLOBALS->use_big_fonts = old_g->use_big_fonts;
  654.     GLOBALS->use_full_precision = old_g->use_full_precision;
  655.     GLOBALS->use_frequency_delta = old_g->use_frequency_delta;
  656.     GLOBALS->use_maxtime_display = old_g->use_maxtime_display;
  657.     GLOBALS->use_nonprop_fonts = old_g->use_nonprop_fonts;
  658.     GLOBALS->use_roundcaps = old_g->use_roundcaps;
  659.     GLOBALS->use_scrollbar_only = old_g->use_scrollbar_only;
  660.     GLOBALS->vcd_explicit_zero_subscripts = old_g->vcd_explicit_zero_subscripts;
  661.     GLOBALS->vcd_preserve_glitches = old_g->vcd_preserve_glitches;
  662.     GLOBALS->vcd_preserve_glitches_real = old_g->vcd_preserve_glitches_real;
  663.     GLOBALS->vcd_warning_filesize = old_g->vcd_warning_filesize;
  664.     GLOBALS->vector_padding = old_g->vector_padding;
  665.     GLOBALS->vlist_compression_depth = old_g->vlist_compression_depth;
  666.     GLOBALS->wave_scrolling = old_g->wave_scrolling;
  667.     GLOBALS->do_zoom_center = old_g->do_zoom_center;
  668.     GLOBALS->zoom_pow10_snap = old_g->zoom_pow10_snap;
  669.     GLOBALS->zoom_dyn = old_g->zoom_dyn;
  670.     GLOBALS->zoom_dyne = old_g->zoom_dyne;
  671.     GLOBALS->alt_hier_delimeter = old_g->alt_hier_delimeter;
  672.     GLOBALS->cursor_snap = old_g->cursor_snap;
  673.     GLOBALS->hier_delimeter = old_g->hier_delimeter;
  674.     GLOBALS->hier_was_explicitly_set = old_g->hier_was_explicitly_set;
  675.     GLOBALS->page_divisor = old_g->page_divisor;
  676.     GLOBALS->ps_maxveclen = old_g->ps_maxveclen;
  677.     GLOBALS->vector_padding = old_g->vector_padding;
  678.     GLOBALS->vlist_compression_depth = old_g->vlist_compression_depth;
  679.     GLOBALS->zoombase = old_g->zoombase;
  680.     GLOBALS->splash_disable = old_g->splash_disable;
  681.     GLOBALS->use_pango_fonts = old_g->use_pango_fonts;
  682.     GLOBALS->hier_ignore_escapes = old_g->hier_ignore_escapes;
  683.  
  684.     GLOBALS->ruler_origin = old_g->ruler_origin;
  685.     GLOBALS->ruler_step = old_g->ruler_step;
  686.     GLOBALS->disable_ae2_alias = old_g->disable_ae2_alias;
  687.  
  688.     GLOBALS->vlist_spill_to_disk = old_g->vlist_spill_to_disk;
  689.     GLOBALS->vlist_prepack = old_g->vlist_prepack;
  690.     GLOBALS->do_dynamic_treefilter = old_g->do_dynamic_treefilter;
  691.     GLOBALS->use_standard_clicking = old_g->use_standard_clicking;
  692.     GLOBALS->dragzoom_threshold = old_g->dragzoom_threshold;
  693.     GLOBALS->use_toolbutton_interface = old_g->use_toolbutton_interface;
  694.  
  695.     GLOBALS->use_scrollwheel_as_y = old_g->use_scrollwheel_as_y;
  696.     GLOBALS->enable_slider_zoom = old_g->enable_slider_zoom;
  697.  
  698.     GLOBALS->missing_file_toolbar = old_g->missing_file_toolbar;
  699.  
  700.     GLOBALS->analog_redraw_skip_count = old_g->analog_redraw_skip_count;
  701.     GLOBALS->context_tabposition = old_g->context_tabposition;
  702.     GLOBALS->disable_empty_gui =  old_g->disable_empty_gui;
  703.     GLOBALS->make_vcd_save_file = old_g->make_vcd_save_file;
  704.     GLOBALS->strace_repeat_count = old_g->strace_repeat_count;
  705.  
  706.     GLOBALS->extload_max_tree = old_g->extload_max_tree;
  707.     GLOBALS->do_hier_compress = old_g->do_hier_compress;
  708.     GLOBALS->disable_auto_comphier = old_g->disable_auto_comphier;
  709.     GLOBALS->sst_dbl_action_type = old_g->sst_dbl_action_type;
  710.  
  711.     strcpy2_into_new_context(GLOBALS, &GLOBALS->sst_exclude_filename, &old_g->sst_exclude_filename);
  712.  
  713.     strcpy2_into_new_context(GLOBALS, &GLOBALS->editor_name, &old_g->editor_name);
  714.     strcpy2_into_new_context(GLOBALS, &GLOBALS->fontname_logfile, &old_g->fontname_logfile);
  715.     strcpy2_into_new_context(GLOBALS, &GLOBALS->fontname_signals, &old_g->fontname_signals);
  716.     strcpy2_into_new_context(GLOBALS, &GLOBALS->fontname_waves, &old_g->fontname_waves);
  717.         strcpy2_into_new_context(GLOBALS, &GLOBALS->argvlist, &old_g->argvlist);
  718.  
  719.     mainwindow_already_built = 1;
  720.     }
  721.  
  722. GLOBALS->whoami=malloc_2(strlen(argv[0])+1);    /* cache name in case we fork later */
  723. strcpy(GLOBALS->whoami, argv[0]);
  724.  
  725. if(!mainwindow_already_built)
  726.     {
  727. #ifdef __MINGW32__
  728.     gtk_disable_setlocale();
  729. #endif
  730.     if(!gtk_init_check(&argc, &argv))
  731.         {
  732. #if defined(__APPLE__)
  733. #ifndef MAC_INTEGRATION
  734.         if(!getenv("DISPLAY"))
  735.             {
  736.             fprintf(stderr, "DISPLAY environment variable is not set.  Have you ensured\n");
  737.             fprintf(stderr, "that x11 has been initialized through open-x11, launching\n");
  738.             fprintf(stderr, "gtkwave in an xterm or x11 window, etc?\n\n");
  739.             fprintf(stderr, "Attempting to initialize using DISPLAY=:0.0 value...\n\n");
  740.             setenv("DISPLAY", ":0.0", 0);
  741.             if(gtk_init_check(&argc, &argv))
  742.                 {
  743.                 goto do_primary_inits;
  744.                 }
  745.             }
  746. #endif
  747. #endif
  748.         fprintf(stderr, "Could not initialize GTK!  Is DISPLAY env var/xhost set?\n\n");
  749.         print_help(argv[0]);
  750.         }
  751.  
  752. #ifdef WAVE_CRASH_ON_GTK_WARNING
  753.     g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING);
  754. #endif
  755.     }
  756.  
  757. #if defined(__APPLE__)
  758. #ifndef MAC_INTEGRATION
  759. do_primary_inits:  
  760. #endif
  761. #endif
  762.  
  763. if(!mainwindow_already_built)
  764.     {
  765.     wave_gconf_init(argc, argv);
  766.     }
  767.  
  768. if(!gtkwave_argv0_cached) gtkwave_argv0_cached = argv[0]; /* for new window option */
  769.  
  770. init_filetrans_data(); /* for file translation splay trees */
  771. init_proctrans_data(); /* for proc translation structs */
  772. init_ttrans_data();    /* for transaction proc translation structs */
  773.  
  774. if(!mainwindow_already_built)
  775.     {
  776.     atexit(remove_all_proc_filters);
  777.     atexit(remove_all_ttrans_filters);
  778. #if defined __MINGW32__
  779.     atexit(close_all_fst_files);
  780. #endif
  781. #ifdef WAVE_FSDB_READER_IS_PRESENT
  782.     atexit(close_all_fsdb_files);
  783. #endif
  784.     }
  785.  
  786. if(mainwindow_already_built)
  787.     {
  788.     optind = 1;
  789.     }
  790. else
  791. while (1)
  792.         {
  793.         int option_index = 0;
  794.  
  795.         static struct option long_options[] =
  796.                 {
  797.                 {"dump", 1, 0, 'f'},
  798.         {"fastload", 0, 0, 'F'},
  799.                 {"optimize", 0, 0, 'o'},
  800.                 {"nocli", 1, 0, 'n'},
  801.                 {"save", 1, 0, 'a'},
  802.                 {"autosavename", 0, 0, 'A'},
  803.                 {"rcfile", 1, 0, 'r'},
  804.                 {"defaultskip", 0, 0, 'd'},
  805.                 {"logfile", 1, 0, 'l'},
  806.                 {"start", 1, 0, 's'},
  807.                 {"end", 1, 0, 'e'},
  808.                 {"cpus", 1, 0, 'c'},
  809.                 {"stems", 1, 0, 't'},
  810.                 {"nowm", 0, 0, 'N'},
  811.                 {"script", 1, 0, 'S'},
  812.                 {"vcd", 0, 0, 'v'},
  813.                 {"version", 0, 0, 'V'},
  814.                 {"help", 0, 0, 'h'},
  815.                 {"exit", 0, 0, 'x'},
  816.                 {"xid", 1, 0, 'X'},
  817.                 {"nomenus", 0, 0, 'M'},
  818.                 {"dualid", 1, 0, 'D'},
  819.                 {"interactive", 0, 0, 'I'},
  820.         {"giga", 0, 0, 'g'},
  821.         {"comphier", 0, 0, 'C'},
  822.                 {"legacy", 0, 0, 'L'},
  823.         {"tcl_init", 1, 0, 'T'},
  824.         {"wish", 0, 0, 'W'},
  825.                 {"repscript", 1, 0, 'R'},
  826.                 {"repperiod", 1, 0, 'P'},
  827.         {"output", 1, 0, 'O' },
  828.                 {"slider-zoom", 0, 0, 'z'},
  829.         {"rpcid", 1, 0, '1' },
  830.         {"chdir", 1, 0, '2'},
  831.         {"restore", 0, 0, '3'},
  832.                 {"rcvar", 1, 0, '4'},
  833.         {"sstexclude", 1, 0, '5'},
  834.                 {0, 0, 0, 0}
  835.                 };
  836.  
  837.         c = getopt_long (argc, argv, "zf:Fon:a:Ar:dl:s:e:c:t:NS:vVhxX:MD:IgCLR:P:O:WT:1:2:34:5:", long_options,
  838. &option_index);
  839.  
  840.         if (c == -1) break;     /* no more args */
  841.  
  842.         switch (c)
  843.                 {
  844.         case 'V':
  845.             printf(
  846.             WAVE_VERSION_INFO"\n\n"
  847.             "This is free software; see the source for copying conditions.  There is NO\n"
  848.             "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
  849.             );
  850.             exit(0);
  851.  
  852.         case 'W':
  853. #if defined(HAVE_LIBTCL)
  854. #if defined(WIN32) && defined(USE_TCL_STUBS)
  855. #else
  856.             is_wish = 1;
  857. #endif
  858. #else
  859.             fprintf(stderr, "GTKWAVE | Tcl support not compiled into this executable, exiting.\n");
  860.             exit(255);
  861. #endif
  862.             break;
  863.  
  864.         case 'I':
  865. #if !defined _MSC_VER
  866.             is_interactive = 1;
  867. #endif
  868.             break;
  869.  
  870.         case 'L':
  871.             is_legacy = 1;
  872.             break;
  873.  
  874.         case 'D':
  875. #if !defined _MSC_VER
  876.             {
  877.             char *s = optarg;
  878.             char *plus = strchr(s, '+');
  879.             if((plus)&&(*(plus+1)))
  880.                 {
  881.                 sscanf(plus+1, "%x", &GLOBALS->dual_attach_id_main_c_1);
  882.                 if(plus != s)
  883.                     {
  884.                     char p = *(plus-1);
  885.  
  886.                     if(p=='0')
  887.                         {
  888.                         GLOBALS->dual_id = 0;
  889.                         break;
  890.                         }
  891.                     else
  892.                     if(p=='1')
  893.                         {
  894.                         GLOBALS->dual_id = 1;
  895.                         break;
  896.                         }
  897.                     }
  898.                 }
  899.  
  900.             fprintf(stderr, "Malformed dual session ID.  Must be of form m+nnnnnnnn where m is 0 or 1,\n"
  901.                     "and n is a hexadecimal shared memory ID for use with shmat()\n");
  902.             exit(255);
  903.             }
  904. #else
  905.             {
  906.             fprintf(stderr, "Dual operation not implemented for Win32, exiting.\n");
  907.             exit(255);
  908.             }
  909. #endif
  910.             break;
  911.  
  912.         case 'A':
  913.             is_smartsave = 1;
  914.             break;
  915.  
  916.                 case 'v':
  917.             is_vcd = 1;
  918.             if(GLOBALS->loaded_file_name) free_2(GLOBALS->loaded_file_name);
  919.             GLOBALS->loaded_file_name = malloc_2(4+1);
  920.             strcpy(GLOBALS->loaded_file_name, "-vcd");
  921.                         break;
  922.  
  923.         case 'o':
  924.             opt_vcd = 1;
  925.             break;
  926.  
  927.         case 'n':
  928.             wave_get_filename(optarg);
  929.             if(GLOBALS->filesel_ok)
  930.                 {
  931.                 if(GLOBALS->loaded_file_name) free_2(GLOBALS->loaded_file_name);
  932.                 GLOBALS->loaded_file_name = GLOBALS->ftext_main_main_c_1;
  933.                 GLOBALS->ftext_main_main_c_1 = NULL;
  934.                 }
  935.             break;
  936.  
  937.                 case 'h':
  938.             print_help(argv[0]);
  939.                         break;
  940.  
  941. #ifdef WAVE_USE_XID
  942.                 case 'X':
  943.                         sscanf(optarg, "%x", &GLOBALS->socket_xid);
  944.             splash_disable_rc_override = 1;
  945.                         break;
  946. #endif
  947.  
  948.         case '1':
  949.             sscanf(optarg, "%d", &wave_rpc_id);
  950.             if(wave_rpc_id < 0) wave_rpc_id = 0;
  951.             break;
  952.  
  953.         case '2':
  954. #ifndef _MSC_VER
  955.             {
  956.             char *chdir_env = getenv("GTKWAVE_CHDIR");
  957.  
  958.             if(chdir_cache)
  959.                 {
  960.                 free_2(chdir_cache);
  961.                 }
  962.  
  963.             chdir_cache = strdup_2(chdir_env ? chdir_env : optarg);
  964.             if(chdir(chdir_cache) < 0)
  965.                 {
  966.                 fprintf(stderr, "GTKWAVE | Could not chdir '%s', exiting.\n", chdir_cache);
  967.                 perror("Why");
  968.                 exit(255);
  969.                 }
  970.             }
  971. #endif
  972.             break;
  973.  
  974.         case '3':
  975. #if defined(WAVE_HAVE_GCONF) || defined(WAVE_HAVE_GSETTINGS)
  976.             {
  977.             is_vcd = 0;
  978.             wave_gconf_restore(&GLOBALS->loaded_file_name, &wname, &override_rc, &chdir_cache, &opt_vcd);
  979.                         if(chdir_cache)
  980.                                 {
  981.                                 if(chdir(chdir_cache) < 0)
  982.                                         {
  983.                                         fprintf(stderr, "GTKWAVE | Could not chdir '%s', exiting.\n", chdir_cache);
  984.                                         perror("Why");
  985.                                         exit(255);
  986.                                         }
  987.                                 }
  988.             fprintf(stderr, "GTKWAVE | restore cwd      '%s'\n", chdir_cache ? chdir_cache : "(none)");
  989.             fprintf(stderr, "GTKWAVE | restore dumpfile '%s'\n", GLOBALS->loaded_file_name ? GLOBALS->loaded_file_name : "(none)");
  990.             fprintf(stderr, "GTKWAVE | restore savefile '%s'\n", wname ? wname : "(none)");
  991.             fprintf(stderr, "GTKWAVE | restore rcfile   '%s'\n", override_rc ? override_rc : "(none)");
  992.             fprintf(stderr, "GTKWAVE | restore optimize '%s'\n", opt_vcd ? "yes" : "no");
  993.             }
  994. #endif
  995.             break;
  996.  
  997.         case 'M':
  998.             GLOBALS->disable_menus = 1;
  999.             break;
  1000.  
  1001.                 case 'x':
  1002.             fast_exit = 1;
  1003.             splash_disable_rc_override = 1;
  1004.                         break;
  1005.  
  1006.         case 'd':
  1007.             GLOBALS->possibly_use_rc_defaults = 0;
  1008.             break;
  1009.  
  1010.                 case 'f':
  1011.             is_vcd = 0;
  1012.             if(GLOBALS->loaded_file_name) free_2(GLOBALS->loaded_file_name);
  1013.             GLOBALS->loaded_file_name = malloc_2(strlen(optarg)+1);
  1014.             strcpy(GLOBALS->loaded_file_name, optarg);
  1015.             break;
  1016.  
  1017.         case 'F':
  1018.             is_fastload = VCD_FSL_WRITE;
  1019.             is_giga = 1;
  1020.             break;
  1021.  
  1022.                 case 'a':
  1023.             if(wname) free_2(wname);
  1024.             wname = malloc_2(strlen(optarg)+1);
  1025.             strcpy(wname, optarg);
  1026.             break;
  1027.  
  1028.                 case 'r':
  1029.             if(override_rc) free_2(override_rc);
  1030.             override_rc = malloc_2(strlen(optarg)+1);
  1031.             strcpy(override_rc, optarg);
  1032.             break;
  1033.  
  1034.         case '4':
  1035.             {
  1036.             struct rc_override *rco = calloc_2(1, sizeof(struct rc_override));
  1037.             rco->str = strdup_2(optarg);
  1038.  
  1039.             if(rc_override_curr)
  1040.                 {
  1041.                 rc_override_curr->next = rco;
  1042.                 rc_override_curr = rco;
  1043.                 }
  1044.                 else
  1045.                 {
  1046.                 rc_override_head = rc_override_curr = rco;
  1047.                 }
  1048.             }
  1049.             break;
  1050.  
  1051.                 case '5':
  1052.                         {
  1053.                         if(GLOBALS->sst_exclude_filename)
  1054.                                 {
  1055.                                 free_2(GLOBALS->sst_exclude_filename);
  1056.                                 }
  1057.                         GLOBALS->sst_exclude_filename = strdup_2(optarg);
  1058.                         }
  1059.                         break;
  1060.  
  1061.                 case 's':
  1062.             if(GLOBALS->skip_start) free_2(GLOBALS->skip_start);
  1063.             GLOBALS->skip_start = malloc_2(strlen(optarg)+1);
  1064.             strcpy(GLOBALS->skip_start, optarg);
  1065.             break;
  1066.  
  1067.                 case 'e':
  1068.             if(GLOBALS->skip_end) free_2(GLOBALS->skip_end);
  1069.             GLOBALS->skip_end = malloc_2(strlen(optarg)+1);
  1070.             strcpy(GLOBALS->skip_end, optarg);
  1071.                         break;
  1072.  
  1073.         case 't':
  1074. #if !defined _MSC_VER
  1075.             if(GLOBALS->stems_name) free_2(GLOBALS->stems_name);
  1076.             GLOBALS->stems_name = malloc_2(strlen(optarg)+1);
  1077.             strcpy(GLOBALS->stems_name, optarg);
  1078. #else
  1079.             fprintf(stderr, "GTKWAVE | Warning: '%c' option does not exist in this executable\n", c);
  1080. #endif
  1081.             break;
  1082.  
  1083.                 case 'c':
  1084. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __FreeBSD__ && !defined __CYGWIN__
  1085.             GLOBALS->num_cpus = atoi(optarg);
  1086.             if(GLOBALS->num_cpus<1) GLOBALS->num_cpus = 1;
  1087.             if(GLOBALS->num_cpus>8) GLOBALS->num_cpus = 8;
  1088. #else
  1089.             fprintf(stderr, "GTKWAVE | Warning: '%c' option does not exist in this executable\n", c);
  1090. #endif
  1091.                         break;
  1092.  
  1093.         case 'N':
  1094.             GLOBALS->disable_window_manager = 1;
  1095.             break;
  1096.  
  1097.         case 'S':
  1098.             if(scriptfile) free_2(scriptfile);
  1099.             scriptfile = malloc_2(strlen(optarg)+1);
  1100.             strcpy(scriptfile, optarg);
  1101.             splash_disable_rc_override = 1;
  1102.             break;
  1103.  
  1104.         case 'l':
  1105.             {
  1106.             struct logfile_chain *l = calloc_2(1, sizeof(struct logfile_chain));
  1107.             struct logfile_chain *ltraverse;
  1108.             l->name = malloc_2(strlen(optarg)+1);
  1109.             strcpy(l->name, optarg);
  1110.  
  1111.             if(GLOBALS->logfile)
  1112.                 {
  1113.                 ltraverse = GLOBALS->logfile;
  1114.                 while(ltraverse->next) ltraverse = ltraverse->next;
  1115.                 ltraverse->next = l;
  1116.                 }
  1117.                 else
  1118.                 {
  1119.                 GLOBALS->logfile = l;
  1120.                 }
  1121.             }
  1122.             break;
  1123.  
  1124.         case 'g':
  1125.             is_giga = 1;
  1126.             break;
  1127.  
  1128.         case 'C':
  1129.             GLOBALS->do_hier_compress = 1;
  1130.             break;
  1131.  
  1132.                 case 'R':
  1133.                         if(GLOBALS->repscript_name) free_2(GLOBALS->repscript_name);
  1134.                         GLOBALS->repscript_name = malloc_2(strlen(optarg)+1);
  1135.                         strcpy(GLOBALS->repscript_name, optarg);
  1136.                         break;
  1137.  
  1138.                 case 'P':
  1139.                         {
  1140.                         int pd = atoi(optarg);
  1141.                         if(pd > 0)
  1142.                                 {
  1143.                                 GLOBALS->repscript_period = pd;
  1144.                                 }
  1145.                         }
  1146.                         break;
  1147.  
  1148.                 case 'T':
  1149. #if defined(WIN32) && defined(USE_TCL_STUBS)
  1150.             fprintf(stderr, "GTKWAVE | Warning: '%c' option does not exist in this executable\n", c);
  1151. #else
  1152.                 {
  1153.               char* pos;
  1154.               is_wish = 1;
  1155.               if(GLOBALS->tcl_init_cmd)
  1156.                 {
  1157.                   int length = strlen(GLOBALS->tcl_init_cmd)+9+strlen(optarg);
  1158.                   char* buffer = malloc_2(strlen(GLOBALS->tcl_init_cmd)+1);
  1159.                   strcpy(buffer, GLOBALS->tcl_init_cmd);
  1160.                   free_2(GLOBALS->tcl_init_cmd);
  1161.                   GLOBALS->tcl_init_cmd = malloc_2(length+1);
  1162.                   strcpy(GLOBALS->tcl_init_cmd, buffer);
  1163.                   pos = GLOBALS->tcl_init_cmd + strlen(GLOBALS->tcl_init_cmd);
  1164.                   free_2(buffer);
  1165.                 }
  1166.               else
  1167.                 {
  1168.                   int length = 9+strlen(optarg);
  1169.                   GLOBALS->tcl_init_cmd = malloc_2(length+1);
  1170.                   pos = GLOBALS->tcl_init_cmd;
  1171.                 }
  1172.               strcpy(pos, "; source ");
  1173.               pos = GLOBALS->tcl_init_cmd + strlen(GLOBALS->tcl_init_cmd);
  1174.               strcpy(pos, optarg);
  1175.             }
  1176. #endif
  1177.             break;
  1178.  
  1179.                 case 'O':
  1180.             if(output_name) free_2(output_name);
  1181.             output_name = malloc_2(strlen(optarg)+1);
  1182.             strcpy(output_name, optarg);
  1183.             break;
  1184.  
  1185.         case 'z':
  1186.             GLOBALS->enable_slider_zoom = 1;
  1187.             break;
  1188.  
  1189.                 case '?':
  1190.             opt_errors_encountered=1;
  1191.                         break;
  1192.  
  1193.                 default:
  1194.                         /* unreachable */
  1195.                         break;
  1196.                 }
  1197.         } /* ...while(1) */
  1198.  
  1199. if(opt_errors_encountered)
  1200.     {
  1201.     print_help(argv[0]);
  1202.     }
  1203.  
  1204. if (optind < argc)
  1205.         {
  1206.         while (optind < argc)
  1207.         {
  1208.                 if(argv[optind][0] == '-')
  1209.                         {
  1210.                         if(!strcmp(argv[optind], "--"))
  1211.                                 {
  1212.                                 break;
  1213.                                 }
  1214.                         }
  1215.  
  1216.         if(!GLOBALS->loaded_file_name)
  1217.             {
  1218.             is_vcd = 0;
  1219.             GLOBALS->loaded_file_name = malloc_2(strlen(argv[optind])+1);
  1220.             strcpy(GLOBALS->loaded_file_name, argv[optind++]);
  1221.             }
  1222.         else if(!wname)
  1223.             {
  1224.             wname = malloc_2(strlen(argv[optind])+1);
  1225.             strcpy(wname, argv[optind++]);
  1226.             }
  1227.         else if(!override_rc)
  1228.             {
  1229.             override_rc = malloc_2(strlen(argv[optind])+1);
  1230.             strcpy(override_rc, argv[optind++]);
  1231.             break; /* skip any extra args */
  1232.             }
  1233.         }
  1234.         }
  1235.  
  1236. if(is_wish && is_vcd)
  1237.     {
  1238.     fprintf(stderr,
  1239.         "GTKWAVE | Cannot use --vcd and --wish options together as both use stdin,\n"
  1240.         "GTKWAVE | exiting!\n");
  1241.     exit(255);
  1242.     }
  1243.  
  1244.  
  1245. #if defined(EXTLOAD_SUFFIX) && defined(EXTCONV_PATH)
  1246. #if !defined(FSDB_IS_PRESENT) || !defined(FSDB_NSYS_IS_PRESENT)
  1247. if(GLOBALS->loaded_file_name && suffix_check(GLOBALS->loaded_file_name, "."EXTLOAD_SUFFIX))
  1248.     {
  1249.     opt_vcd = 1;
  1250.     }
  1251. #endif
  1252. #endif
  1253. #if defined(EXT2LOAD_SUFFIX) && defined(EXT2CONV_PATH)
  1254. if(GLOBALS->loaded_file_name && suffix_check(GLOBALS->loaded_file_name, "."EXT2LOAD_SUFFIX))
  1255.     {
  1256.     opt_vcd = 1;
  1257.     }
  1258. #endif
  1259. #if defined(EXT3LOAD_SUFFIX) && defined(EXT3CONV_PATH)
  1260. if(GLOBALS->loaded_file_name && suffix_check(GLOBALS->loaded_file_name, "."EXT3LOAD_SUFFIX))
  1261.     {
  1262.     opt_vcd = 1;
  1263.     }
  1264. #endif
  1265.  
  1266. /* attempt to load a dump+save file if only a savefile is specified at the command line */
  1267. if((GLOBALS->loaded_file_name) && (!wname) &&
  1268.     (suffix_check(GLOBALS->loaded_file_name, ".gtkw") || suffix_check(GLOBALS->loaded_file_name, ".sav")))
  1269.     {
  1270.     char *extracted_name = extract_dumpname_from_save_file(GLOBALS->loaded_file_name, &GLOBALS->dumpfile_is_modified, &opt_vcd);
  1271.     if(extracted_name)
  1272.         {
  1273.         if(mainwindow_already_built)
  1274.             {
  1275.             deal_with_rpc_open_2(GLOBALS->loaded_file_name, NULL, TRUE);
  1276.             GLOBALS->loaded_file_name = extracted_name;
  1277.             /* wname is still NULL */
  1278.             }
  1279.             else
  1280.             {
  1281.             wname = GLOBALS->loaded_file_name;
  1282.             GLOBALS->loaded_file_name = extracted_name;
  1283.             }
  1284.         }
  1285.                 else
  1286.                 {
  1287.                 char *dfn = NULL;
  1288.                 char *sfn = NULL;
  1289.                 off_t dumpsiz = -1;
  1290.                 time_t dumptim = -1;
  1291.  
  1292.                 read_save_helper(GLOBALS->loaded_file_name, &dfn, &sfn, &dumpsiz, &dumptim, &opt_vcd);
  1293.  
  1294.                 fprintf(stderr, "GTKWAVE | Could not initialize '%s' found in '%s', exiting.\n", dfn ? dfn : "(null)", GLOBALS->loaded_file_name);
  1295.                 if(dfn) free_2(dfn);
  1296.                 if(sfn) free_2(sfn);
  1297.                 exit(255);  
  1298.                 }
  1299.     }
  1300. else /* same as above but with --save specified */
  1301. if((!GLOBALS->loaded_file_name) && wname)
  1302.     {
  1303.     GLOBALS->loaded_file_name = extract_dumpname_from_save_file(wname, &GLOBALS->dumpfile_is_modified, &opt_vcd);
  1304.     /* still can be NULL if file not found... */
  1305.         if(!GLOBALS->loaded_file_name)
  1306.                 {
  1307.                 char *dfn = NULL;
  1308.                 char *sfn = NULL;
  1309.                 off_t dumpsiz = -1;
  1310.                 time_t dumptim = -1;
  1311.  
  1312.                 read_save_helper(wname, &dfn, &sfn, &dumpsiz, &dumptim, &opt_vcd);
  1313.  
  1314.                 fprintf(stderr, "GTKWAVE | Could not initialize '%s' found in '%s', exiting.\n", dfn ? dfn : "(null)", wname);
  1315.                 if(dfn) free_2(dfn);
  1316.                 if(sfn) free_2(sfn);
  1317.                 exit(255);  
  1318.                 }
  1319.     }
  1320.  
  1321.  
  1322. if(!old_g) /* copy all variables earlier when old_g is set */
  1323.     {
  1324.     read_rc_file(override_rc);
  1325.     }
  1326.  
  1327. GLOBALS->splash_disable |= splash_disable_rc_override;
  1328.  
  1329. if(!GLOBALS->loaded_file_name)
  1330.     {
  1331.     /* if rc can gates off gui, default is not to disable */
  1332.     if(GLOBALS->disable_empty_gui)
  1333.         {
  1334.         print_help(argv[0]);
  1335.         }
  1336.     }
  1337.  
  1338. if(is_giga)
  1339.     {
  1340.     GLOBALS->vlist_spill_to_disk = 1;
  1341.     GLOBALS->vlist_prepack = 1;
  1342.     }
  1343.  
  1344. if(output_name)
  1345.     {
  1346. #if !defined _MSC_VER && !defined __MINGW32__
  1347.     int iarg;
  1348.     time_t walltime;
  1349.     int fd_replace = open(output_name, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
  1350.     if(fd_replace<0)
  1351.         {
  1352.         fprintf(stderr, "Could not open redirect file, exiting.\n");
  1353.         perror("Why");
  1354.         exit(255);
  1355.         }
  1356.  
  1357.     dup2(fd_replace, 1);
  1358.     dup2(fd_replace, 2);
  1359.  
  1360.         time(&walltime);
  1361.         printf(WAVE_VERSION_INFO"\nDate: %s\n\n",asctime(localtime(&walltime)));
  1362.  
  1363.     for(iarg=0;iarg<argc;iarg++)
  1364.         {
  1365.         if(iarg) printf("\t");
  1366.         printf("%s\n", argv[iarg]);
  1367.         }
  1368.  
  1369.     printf("\n\n");
  1370.     fflush(stdout);
  1371.  
  1372. #endif
  1373.     free_2(output_name);
  1374.     output_name = NULL;
  1375.     }
  1376.  
  1377. fprintf(stderr, "\n%s\n\n",WAVE_VERSION_INFO);
  1378.  
  1379.  
  1380. if(!old_g) /* copy all variables earlier when old_g is set */
  1381.     {
  1382.     while(rc_override_head)
  1383.         {
  1384.         int rco_succ;
  1385.         char *rco_copy_str = strdup_2(rc_override_head->str);
  1386.         rco_succ = insert_rc_variable(rc_override_head->str);
  1387.         fprintf(stderr, "RCVAR   | '%s' %s\n", rco_copy_str, rco_succ ? "FOUND" : "NOT FOUND");
  1388.         free_2(rco_copy_str);
  1389.         rc_override_curr = rc_override_head->next;
  1390.         free_2(rc_override_head->str);
  1391.         free_2(rc_override_head);
  1392.         rc_override_head = rc_override_curr;
  1393.         }
  1394.     }
  1395.  
  1396. if(!is_wish)
  1397.     {
  1398.     if(tcl_interpreter_needs_making)
  1399.             {
  1400.             GLOBALS->argvlist = zMergeTclList(argc, (const char**)argv);
  1401.             make_tcl_interpreter(argv);
  1402.             }
  1403.     }
  1404.  
  1405. if((!wname)&&(GLOBALS->make_vcd_save_file))
  1406.     {
  1407.     vcd_save_handle_cached = GLOBALS->vcd_save_handle=fopen(vcd_autosave_name,"wb");
  1408.     errno=0;    /* just in case */
  1409.     is_smartsave = (GLOBALS->vcd_save_handle != NULL); /* use smartsave if for some reason can't open auto savefile */
  1410.     }
  1411.  
  1412. if(!GLOBALS->loaded_file_name)
  1413.     {
  1414.     GLOBALS->loaded_file_name = strdup_2("[no file loaded]");
  1415.     is_missing_file = 1;
  1416.     GLOBALS->min_time=LLDescriptor(0);
  1417.     GLOBALS->max_time=LLDescriptor(0);
  1418.     if(!is_wish)
  1419.         {
  1420.         fprintf(stderr, "GTKWAVE | Use the -h, --help command line flags to display help.\n");
  1421.         }
  1422.     }
  1423.  
  1424. /* load either the vcd or aet file depending on suffix then mode setting */
  1425. if(is_vcd)
  1426.     {
  1427.     GLOBALS->winname=malloc_2(strlen(winstd)+4+1);
  1428.     strcpy(GLOBALS->winname,winstd);
  1429.     }
  1430.     else
  1431.     {
  1432.     if(!is_interactive)
  1433.         {
  1434.         GLOBALS->winname=malloc_2(strlen(GLOBALS->loaded_file_name)+strlen(winprefix)+1);
  1435.         strcpy(GLOBALS->winname,winprefix);
  1436.         }
  1437.         else
  1438.         {
  1439.         char *iact = "GTKWave - Interactive Shared Memory ID ";
  1440.         GLOBALS->winname=malloc_2(strlen(GLOBALS->loaded_file_name)+strlen(iact)+1);
  1441.         strcpy(GLOBALS->winname,iact);
  1442.         }
  1443.     }
  1444.  
  1445. strcat(GLOBALS->winname,GLOBALS->loaded_file_name);
  1446. sst_exclusion_loader();
  1447.  
  1448. loader_check_head:
  1449.  
  1450. if(!is_missing_file)
  1451.     {
  1452.     magic_word_filetype = determine_gtkwave_filetype(GLOBALS->loaded_file_name);
  1453.     }
  1454.  
  1455. if(is_missing_file)
  1456.     {
  1457.     GLOBALS->loaded_file_type = MISSING_FILE;
  1458.     }
  1459. else
  1460. #if defined(EXTLOAD_SUFFIX)
  1461. if(
  1462.    (suffix_check(GLOBALS->loaded_file_name, "."EXTLOAD_SUFFIX      ) && !opt_vcd) ||
  1463.    (suffix_check(GLOBALS->loaded_file_name, "."EXTLOAD_SUFFIX".gz" ) && !opt_vcd) ||   /* loader automatically does gzip -cd */
  1464.    (suffix_check(GLOBALS->loaded_file_name, "."EXTLOAD_SUFFIX".bz2") && !opt_vcd)      /* loader automatically does bzip2 -cd */
  1465.   )
  1466.     {
  1467.     TimeType extload_max;
  1468.  
  1469.     GLOBALS->loaded_file_type = EXTLOAD_FILE;
  1470.     extload_max = extload_main(GLOBALS->loaded_file_name, GLOBALS->skip_start, GLOBALS->skip_end);
  1471.     if((!GLOBALS->extload) || (GLOBALS->extload_already_errored) || (!extload_max))
  1472.         {
  1473.         fprintf(stderr, "GTKWAVE | Could not initialize '%s'%s.\n", GLOBALS->loaded_file_name, GLOBALS->vcd_jmp_buf ? "" : ", exiting");
  1474.         vcd_exit(255);
  1475.         }
  1476.     }
  1477. else
  1478. #endif
  1479. if((magic_word_filetype == G_FT_LXT) || (magic_word_filetype == G_FT_LXT2) || suffix_check(GLOBALS->loaded_file_name, ".lxt") || suffix_check(GLOBALS->loaded_file_name, ".lx2") || suffix_check(GLOBALS->loaded_file_name, ".lxt2"))
  1480.     {
  1481.     FILE *f = fopen(GLOBALS->loaded_file_name, "rb");
  1482.     int typ = 0;
  1483.  
  1484.     if(f)
  1485.         {
  1486.         char buf[2];
  1487.         unsigned int matchword;
  1488.  
  1489.         if(fread(buf, 2, 1, f))
  1490.             {
  1491.             matchword = (((unsigned int)buf[0])<<8) | ((unsigned int)buf[1]);
  1492.             if(matchword == LT_HDRID) typ = 1;
  1493.             }
  1494.  
  1495.         fclose(f);
  1496.         }
  1497.  
  1498.     if(typ)
  1499.         {
  1500.               GLOBALS->loaded_file_type = LXT_FILE;
  1501.           lxt_main(GLOBALS->loaded_file_name);
  1502.         }
  1503.         else
  1504.         {
  1505. #if !defined _MSC_VER
  1506.         GLOBALS->stems_type = WAVE_ANNO_LXT2;
  1507.         GLOBALS->aet_name = malloc_2(strlen(GLOBALS->loaded_file_name)+1);
  1508.         strcpy(GLOBALS->aet_name, GLOBALS->loaded_file_name);
  1509. #endif
  1510.                 GLOBALS->loaded_file_type = LX2_FILE;
  1511.         lx2_main(GLOBALS->loaded_file_name, GLOBALS->skip_start, GLOBALS->skip_end);
  1512.         if(!GLOBALS->lx2_lx2_c_1)
  1513.             {
  1514.             fprintf(stderr, "GTKWAVE | Could not initialize '%s'%s.\n", GLOBALS->loaded_file_name, GLOBALS->vcd_jmp_buf ? "" : ", exiting");
  1515.             vcd_exit(255);
  1516.             }
  1517.         }
  1518.     }
  1519. else
  1520. if((magic_word_filetype == G_FT_FST) || suffix_check(GLOBALS->loaded_file_name, ".fst"))
  1521.     {
  1522. #if !defined _MSC_VER
  1523.     GLOBALS->stems_type = WAVE_ANNO_FST;
  1524.     GLOBALS->aet_name = malloc_2(strlen(GLOBALS->loaded_file_name)+1);
  1525.     strcpy(GLOBALS->aet_name, GLOBALS->loaded_file_name);
  1526. #endif
  1527.         GLOBALS->loaded_file_type = FST_FILE;
  1528.     fst_main(GLOBALS->loaded_file_name, GLOBALS->skip_start, GLOBALS->skip_end);
  1529.     if(!GLOBALS->fst_fst_c_1)
  1530.         {
  1531.         fprintf(stderr, "GTKWAVE | Could not initialize '%s'%s.\n", GLOBALS->loaded_file_name, GLOBALS->vcd_jmp_buf ? "" : ", exiting");
  1532.         vcd_exit(255);
  1533.         }
  1534.     }
  1535. else
  1536. if((magic_word_filetype == G_FT_VZT) || suffix_check(GLOBALS->loaded_file_name, ".vzt"))
  1537.     {
  1538. #if !defined _MSC_VER
  1539.     GLOBALS->stems_type = WAVE_ANNO_VZT;
  1540.     GLOBALS->aet_name = malloc_2(strlen(GLOBALS->loaded_file_name)+1);
  1541.     strcpy(GLOBALS->aet_name, GLOBALS->loaded_file_name);
  1542. #endif
  1543.         GLOBALS->loaded_file_type = VZT_FILE;
  1544.     vzt_main(GLOBALS->loaded_file_name, GLOBALS->skip_start, GLOBALS->skip_end);
  1545.     if(!GLOBALS->vzt_vzt_c_1)
  1546.         {
  1547.         fprintf(stderr, "GTKWAVE | Could not initialize '%s'%s.\n", GLOBALS->loaded_file_name, GLOBALS->vcd_jmp_buf ? "" : ", exiting");
  1548.         vcd_exit(255);
  1549.         }
  1550.     }
  1551. else if(suffix_check(GLOBALS->loaded_file_name, ".aet") || suffix_check(GLOBALS->loaded_file_name, ".ae2"))
  1552.     {
  1553. #if !defined _MSC_VER
  1554.     GLOBALS->stems_type = WAVE_ANNO_AE2;
  1555.     GLOBALS->aet_name = malloc_2(strlen(GLOBALS->loaded_file_name)+1);
  1556.     strcpy(GLOBALS->aet_name, GLOBALS->loaded_file_name);
  1557. #endif
  1558.         GLOBALS->loaded_file_type = AE2_FILE;
  1559.     ae2_main(GLOBALS->loaded_file_name, GLOBALS->skip_start, GLOBALS->skip_end);
  1560. #ifdef AET2_IS_PRESENT
  1561.     if(!GLOBALS->ae2)
  1562.         {
  1563.         fprintf(stderr, "GTKWAVE | Could not initialize '%s'%s.\n", GLOBALS->loaded_file_name, GLOBALS->vcd_jmp_buf ? "" : ", exiting");
  1564.         vcd_exit(255);
  1565.         }
  1566. #else
  1567.         /* fails in stubbed out ae2_main() */
  1568. #endif
  1569.     }
  1570. else if (suffix_check(GLOBALS->loaded_file_name, ".ghw") || suffix_check(GLOBALS->loaded_file_name, ".ghw.gz") ||
  1571.         suffix_check(GLOBALS->loaded_file_name, ".ghw.bz2"))
  1572.     {
  1573.           GLOBALS->loaded_file_type = GHW_FILE;
  1574.       if(!ghw_main(GLOBALS->loaded_file_name))
  1575.         {
  1576.         /* error message printed in ghw_main() */
  1577.         vcd_exit(255);
  1578.         }
  1579.     }
  1580. else if (strlen(GLOBALS->loaded_file_name)>4)   /* case for .aet? type filenames */
  1581.     {
  1582.     char sufbuf[5];
  1583.     memcpy(sufbuf, GLOBALS->loaded_file_name+strlen(GLOBALS->loaded_file_name)-5, 4);
  1584.     sufbuf[4] = 0;
  1585.     if(!strcasecmp(sufbuf, ".aet")) /* strncasecmp() in windows? */
  1586.         {
  1587. #if !defined _MSC_VER
  1588.         GLOBALS->stems_type = WAVE_ANNO_AE2;
  1589.         GLOBALS->aet_name = malloc_2(strlen(GLOBALS->loaded_file_name)+1);
  1590.         strcpy(GLOBALS->aet_name, GLOBALS->loaded_file_name);
  1591. #endif
  1592.                 GLOBALS->loaded_file_type = AE2_FILE;
  1593. #ifdef AET2_IS_PRESENT
  1594.         ae2_main(GLOBALS->loaded_file_name, GLOBALS->skip_start, GLOBALS->skip_end);
  1595.         if(!GLOBALS->ae2)
  1596.             {
  1597.             fprintf(stderr, "GTKWAVE | Could not initialize '%s'%s.\n", GLOBALS->loaded_file_name, GLOBALS->vcd_jmp_buf ? "" : ", exiting");
  1598.             vcd_exit(255);
  1599.             }
  1600. #else
  1601.         /* fails in stubbed out ae2_main() */
  1602. #endif
  1603.         }
  1604.         else
  1605.         {
  1606.         goto load_vcd;
  1607.         }
  1608.     }
  1609. else    /* nothing else left so default to "something" */
  1610.     {
  1611. load_vcd:
  1612. #if !defined _MSC_VER && !defined __MINGW32__
  1613.     if(opt_vcd) {
  1614.                   GLOBALS->unoptimized_vcd_file_name = calloc_2(1,strlen(GLOBALS->loaded_file_name) + 1);
  1615.                   strcpy(GLOBALS->unoptimized_vcd_file_name, GLOBALS->loaded_file_name);
  1616.                   optimize_vcd_file();
  1617.                   /* is_vcd = 0; */ /* scan-build */
  1618.           GLOBALS->optimize_vcd = 1;
  1619.                   goto loader_check_head;
  1620.         }
  1621.  
  1622. #endif
  1623.  
  1624. #if !defined _MSC_VER
  1625.     if(is_interactive)
  1626.         {
  1627.         GLOBALS->loaded_file_type = DUMPLESS_FILE;
  1628.         vcd_partial_main(GLOBALS->loaded_file_name);
  1629.         }
  1630.         else
  1631. #endif
  1632.         {
  1633.         if(is_legacy)
  1634.             {
  1635.               GLOBALS->loaded_file_type = (strcmp(GLOBALS->loaded_file_name, "-vcd")) ? VCD_FILE : DUMPLESS_FILE;
  1636.               vcd_main(GLOBALS->loaded_file_name);
  1637.             }
  1638.             else
  1639.             {
  1640.               if(strcmp(GLOBALS->loaded_file_name, "-vcd"))
  1641.                 {
  1642.                 GLOBALS->loaded_file_type = VCD_RECODER_FILE;
  1643.                 GLOBALS->use_fastload = is_fastload;
  1644.                 }
  1645.                 else
  1646.                 {
  1647.                 GLOBALS->loaded_file_type = DUMPLESS_FILE;
  1648.                 GLOBALS->use_fastload = VCD_FSL_NONE;
  1649.                 }
  1650.               vcd_recoder_main(GLOBALS->loaded_file_name);
  1651.             }
  1652.         }
  1653.     }
  1654.  
  1655.  
  1656. if(((GLOBALS->loaded_file_type != FST_FILE) && (GLOBALS->loaded_file_type != AE2_FILE)
  1657. #if defined(EXTLOAD_SUFFIX)
  1658.                                                                                       && (GLOBALS->loaded_file_type != EXTLOAD_FILE)
  1659. #endif
  1660.                                                                                                                                     ) || (!GLOBALS->fast_tree_sort))
  1661.     {
  1662.     GLOBALS->do_hier_compress = 0; /* for now, add more file formats in the future */
  1663.     }
  1664.  
  1665. /* deallocate the symbol hash table */
  1666. sym_hash_destroy(GLOBALS);
  1667.  
  1668. /* reset/initialize various markers and time values */
  1669. for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++) GLOBALS->named_markers[i]=-1; /* reset all named markers */
  1670.  
  1671. GLOBALS->tims.last=GLOBALS->max_time;
  1672. GLOBALS->tims.end=GLOBALS->tims.last;       /* until the configure_event of wavearea */
  1673. GLOBALS->tims.first=GLOBALS->tims.start=GLOBALS->tims.laststart=GLOBALS->min_time;
  1674. GLOBALS->tims.zoom=GLOBALS->tims.prevzoom=0;    /* 1 pixel/ns default */
  1675. GLOBALS->tims.marker=GLOBALS->tims.lmbcache=-1; /* uninitialized at first */
  1676. GLOBALS->tims.baseline=-1;      /* middle button toggle marker */
  1677.  
  1678. if((wname)||(vcd_save_handle_cached)||(is_smartsave))
  1679.     {
  1680.     int wave_is_compressed;
  1681.         char *str = NULL;
  1682.  
  1683.     GLOBALS->is_gtkw_save_file = (!wname) || suffix_check(wname, ".gtkw");
  1684.  
  1685.     if(vcd_save_handle_cached)
  1686.         {
  1687.         wname=vcd_autosave_name;
  1688.         GLOBALS->do_initial_zoom_fit=1;
  1689.         }
  1690.     else
  1691.     if((!wname) /* && (is_smartsave) */)
  1692.         {
  1693.         char *pnt = wave_alloca(strlen(GLOBALS->loaded_file_name) + 1);
  1694.         char *pnt2;
  1695.         strcpy(pnt, GLOBALS->loaded_file_name);
  1696.  
  1697.             if((strlen(pnt)>2)&&(!strcasecmp(pnt+strlen(pnt)-3,".gz")))
  1698.             {
  1699.             pnt[strlen(pnt)-3] = 0x00;
  1700.             }
  1701.         else if ((strlen(pnt)>3)&&(!strcasecmp(pnt+strlen(pnt)-4,".zip")))
  1702.             {
  1703.             pnt[strlen(pnt)-4] = 0x00;
  1704.             }
  1705.  
  1706.         pnt2 = pnt + strlen(pnt);
  1707.         if(pnt != pnt2)
  1708.             {
  1709.             do
  1710.                 {
  1711.                 if(*pnt2 == '.')
  1712.                     {
  1713.                     *pnt2 = 0x00;
  1714.                     break;
  1715.                     }
  1716.                 } while(pnt2-- != pnt);
  1717.             }
  1718.  
  1719.         wname = malloc_2(strlen(pnt) + 6);
  1720.         strcpy(wname, pnt);
  1721.         strcat(wname, ".gtkw");
  1722.         }
  1723.  
  1724.     if(((strlen(wname)>2)&&(!strcasecmp(wname+strlen(wname)-3,".gz")))||
  1725.        ((strlen(wname)>3)&&(!strcasecmp(wname+strlen(wname)-4,".zip"))))
  1726.             {
  1727.             int dlen;
  1728.             dlen=strlen(WAVE_DECOMPRESSOR);
  1729.             str=wave_alloca(strlen(wname)+dlen+1);
  1730.             strcpy(str,WAVE_DECOMPRESSOR);
  1731.             strcpy(str+dlen,wname);
  1732.             wave=popen(str,"r");
  1733.             wave_is_compressed=~0;
  1734.             }
  1735.             else
  1736.             {
  1737.             wave=fopen(wname,"rb");
  1738.             wave_is_compressed=0;
  1739.  
  1740.         GLOBALS->filesel_writesave = malloc_2(strlen(wname)+1); /* don't handle compressed files */
  1741.         strcpy(GLOBALS->filesel_writesave, wname);
  1742.             }
  1743.  
  1744.     if(!wave)
  1745.             {
  1746.             fprintf(stderr, "** WARNING: Error opening save file '%s', skipping.\n",wname);
  1747.             }
  1748.             else
  1749.             {
  1750.             char *iline;
  1751.         int s_ctx_iter;
  1752.  
  1753.                 WAVE_STRACE_ITERATOR(s_ctx_iter)
  1754.                         {
  1755.                         GLOBALS->strace_ctx = &GLOBALS->strace_windows[GLOBALS->strace_current_window = s_ctx_iter];
  1756.                         GLOBALS->strace_ctx->shadow_encountered_parsewavline = 0;
  1757.             }
  1758.  
  1759.         if(GLOBALS->is_lx2)
  1760.             {
  1761.                 while((iline=fgetmalloc(wave)))
  1762.                         {
  1763.                         parsewavline_lx2(iline, NULL, 0);
  1764.                 free_2(iline);
  1765.                         }
  1766.  
  1767.             switch(GLOBALS->is_lx2)
  1768.                 {
  1769.                 case LXT2_IS_LXT2: lx2_import_masked(); break;
  1770.                 case LXT2_IS_AET2: ae2_import_masked(); break;
  1771.                 case LXT2_IS_VZT:  vzt_import_masked(); break;
  1772.                 case LXT2_IS_VLIST: vcd_import_masked(); break;
  1773.                 case LXT2_IS_FST: fst_import_masked(); break;
  1774.                 case LXT2_IS_FSDB: fsdb_import_masked(); break;
  1775.                 }
  1776.  
  1777.             if(wave_is_compressed)
  1778.                     {
  1779.                 pclose(wave);
  1780.                     wave=popen(str,"r");
  1781.                     }
  1782.                     else
  1783.                     {
  1784.                 fclose(wave);
  1785.                     wave=fopen(wname,"rb");
  1786.                     }
  1787.  
  1788.             if(!wave)
  1789.                     {
  1790.                     fprintf(stderr, "** WARNING: Error opening save file '%s', skipping.\n",wname);
  1791.                 EnsureGroupsMatch();
  1792.                 goto savefile_bail;
  1793.                     }
  1794.             }
  1795.  
  1796.         read_save_helper_relative_init(wname);
  1797.         GLOBALS->default_flags=TR_RJUSTIFY;
  1798.         GLOBALS->default_fpshift = 0;
  1799.         GLOBALS->shift_timebase_default_for_add=LLDescriptor(0);
  1800.         GLOBALS->strace_current_window = 0; /* in case there are shadow traces */
  1801.         GLOBALS->which_t_color = 0;
  1802.             while((iline=fgetmalloc(wave)))
  1803.                     {
  1804.                     parsewavline(iline, NULL, 0);
  1805.             GLOBALS->strace_ctx->shadow_encountered_parsewavline |= GLOBALS->strace_ctx->shadow_active;
  1806.             free_2(iline);
  1807.                     }
  1808.         GLOBALS->which_t_color = 0;
  1809.         GLOBALS->default_flags=TR_RJUSTIFY;
  1810.         GLOBALS->default_fpshift = 0;
  1811.         GLOBALS->shift_timebase_default_for_add=LLDescriptor(0);
  1812.  
  1813.         if(wave_is_compressed) pclose(wave); else fclose(wave);
  1814.  
  1815.         EnsureGroupsMatch();
  1816.  
  1817.         WAVE_STRACE_ITERATOR(s_ctx_iter)
  1818.             {
  1819.             GLOBALS->strace_ctx = &GLOBALS->strace_windows[GLOBALS->strace_current_window = s_ctx_iter];
  1820.  
  1821.                     if(GLOBALS->strace_ctx->shadow_encountered_parsewavline)
  1822.                             {
  1823.                 GLOBALS->strace_ctx->shadow_encountered_parsewavline = 0;
  1824.  
  1825.                             if(GLOBALS->strace_ctx->shadow_straces)
  1826.                                     {
  1827.                                     GLOBALS->strace_ctx->shadow_active = 1;
  1828.  
  1829.                                     swap_strace_contexts();
  1830.                                     strace_maketimetrace(1);
  1831.                                     swap_strace_contexts();
  1832.  
  1833.                     GLOBALS->strace_ctx->shadow_active = 0;
  1834.                                     }
  1835.                 }
  1836.                         }
  1837.             }
  1838.     }
  1839.  
  1840. savefile_bail:
  1841. GLOBALS->current_translate_file = 0;
  1842.  
  1843. if(fast_exit)
  1844.     {
  1845.     printf("Exiting early because of --exit request.\n");
  1846.     exit(0);
  1847.     }
  1848.  
  1849. if ((GLOBALS->loaded_file_type != MISSING_FILE) && (!GLOBALS->zoom_was_explicitly_set) &&
  1850.     ((GLOBALS->tims.last-GLOBALS->tims.first)<=400)) GLOBALS->do_initial_zoom_fit=1;  /* force zoom on small traces */
  1851.  
  1852. calczoom(GLOBALS->tims.zoom);
  1853.  
  1854. if(!mainwindow_already_built)
  1855. {
  1856. #ifdef WAVE_USE_XID
  1857. if(!GLOBALS->socket_xid)
  1858. #endif
  1859.         {
  1860.     GLOBALS->mainwindow = gtk_window_new(GLOBALS->disable_window_manager ? GTK_WINDOW_POPUP : GTK_WINDOW_TOPLEVEL);
  1861.     wave_gtk_window_set_title(GTK_WINDOW(GLOBALS->mainwindow), GLOBALS->winname, GLOBALS->dumpfile_is_modified ? WAVE_SET_TITLE_MODIFIED: WAVE_SET_TITLE_NONE, 0);
  1862.  
  1863.     if((GLOBALS->initial_window_width>0)&&(GLOBALS->initial_window_height>0))
  1864.         {
  1865.         gtk_window_set_default_size(GTK_WINDOW (GLOBALS->mainwindow), GLOBALS->initial_window_width, GLOBALS->initial_window_height);
  1866.         }
  1867.         else
  1868.         {
  1869.         gtk_window_set_default_size(GTK_WINDOW(GLOBALS->mainwindow), GLOBALS->initial_window_x, GLOBALS->initial_window_y);
  1870.         }
  1871.  
  1872.     gtk_signal_connect(GTK_OBJECT(GLOBALS->mainwindow), "delete_event",     /* formerly was "destroy" */GTK_SIGNAL_FUNC(file_quit_cmd_callback), "WM destroy");
  1873.  
  1874.     gtk_widget_show(GLOBALS->mainwindow);
  1875.     }
  1876. #ifdef WAVE_USE_XID
  1877.     else
  1878.     {
  1879.         GLOBALS->mainwindow = gtk_plug_new(GLOBALS->socket_xid);
  1880.         gtk_widget_show(GLOBALS->mainwindow);
  1881.  
  1882.         gtk_signal_connect(GTK_OBJECT(GLOBALS->mainwindow), "destroy",   /* formerly was "destroy" */GTK_SIGNAL_FUNC(plug_destroy),"Plug destroy");
  1883.     }
  1884. #endif
  1885. }
  1886.  
  1887. #ifdef MAC_INTEGRATION
  1888. dock_pb =
  1889. #endif
  1890. make_pixmaps(GLOBALS->mainwindow);
  1891.  
  1892. #ifdef WAVE_USE_GTK2
  1893. if(GLOBALS->use_toolbutton_interface)
  1894.     {
  1895.     GtkWidget *tb;
  1896.     GtkWidget *stock;
  1897.     GtkStyle *style;
  1898.     int tb_pos;
  1899.  
  1900.     if(!mainwindow_already_built)
  1901.         {
  1902.         main_vbox = gtk_vbox_new(FALSE, 5);
  1903.         gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
  1904.         gtk_container_add(GTK_CONTAINER(GLOBALS->mainwindow), main_vbox);
  1905.         gtk_widget_show(main_vbox);
  1906.  
  1907.         if(!GLOBALS->disable_menus)
  1908.             {
  1909. #ifdef WAVE_USE_XID
  1910.             if(GLOBALS->socket_xid) kill_main_menu_accelerators();
  1911. #endif
  1912.  
  1913. #ifdef WAVE_USE_MLIST_T
  1914.             menubar = alt_menu_top(GLOBALS->mainwindow);
  1915. #else
  1916.             get_main_menu(GLOBALS->mainwindow, &menubar);
  1917. #endif
  1918.             gtk_widget_show(menubar);
  1919.  
  1920. #ifdef MAC_INTEGRATION
  1921. {
  1922. GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
  1923. gtk_widget_hide(menubar);
  1924. gtkosx_application_set_menu_bar(theApp, GTK_MENU_SHELL(menubar));
  1925. gtkosx_application_set_use_quartz_accelerators(theApp, TRUE);
  1926. gtkosx_application_ready(theApp);
  1927. gtkosx_application_set_dock_icon_pixbuf(theApp, dock_pb);
  1928. if(GLOBALS->loaded_file_type == MISSING_FILE)
  1929.     {
  1930.     gtkosx_application_attention_request(theApp, INFO_REQUEST);
  1931.     }
  1932.  
  1933. g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(deal_with_finder_open), NULL);
  1934. g_signal_connect(theApp, "NSApplicationBlockTermination", G_CALLBACK(deal_with_termination), NULL);
  1935. }
  1936. #endif
  1937.  
  1938.             if(GLOBALS->force_toolbars)
  1939.                 {
  1940.                 toolhandle=gtk_handle_box_new();
  1941.                 /* gtk_widget_show(toolhandle); */
  1942.                 gtk_container_add(GTK_CONTAINER(toolhandle), menubar);
  1943.                 gtk_box_pack_start(GTK_BOX(main_vbox), toolhandle, FALSE, TRUE, 0);
  1944.                 }
  1945.                 else
  1946.                 {
  1947.                 gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0);
  1948.                 }
  1949.             }
  1950.  
  1951.         whole_table = gtk_table_new (256, 16, FALSE);
  1952.  
  1953.         tb = gtk_toolbar_new();
  1954.         top_table = tb;     /* export this as our top widget rather than a table */
  1955.  
  1956.         gtk_toolbar_set_style(GTK_TOOLBAR(tb), GTK_TOOLBAR_ICONS);
  1957.         tb_pos = 0;
  1958.  
  1959.         if(GLOBALS->force_toolbars)
  1960.             {
  1961.             toolhandle=gtk_handle_box_new();
  1962.             /* gtk_widget_show(toolhandle); */
  1963.             gtk_container_add(GTK_CONTAINER(toolhandle), top_table);
  1964.             }
  1965.  
  1966.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  1967.                                              GTK_STOCK_CUT,
  1968.                          "Cut Traces",
  1969.                          NULL,
  1970.                          GTK_SIGNAL_FUNC(menu_cut_traces),
  1971.                          NULL,
  1972.                          tb_pos++);
  1973.         style = gtk_widget_get_style(stock);
  1974.         style->xthickness = style->ythickness = 0;
  1975.         gtk_widget_set_style (stock, style);
  1976.         gtk_widget_show(stock);
  1977.  
  1978.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  1979.                                              GTK_STOCK_COPY,
  1980.                          "Copy Traces",
  1981.                          NULL,
  1982.                          GTK_SIGNAL_FUNC(menu_copy_traces),
  1983.                          NULL,
  1984.                          tb_pos++);
  1985.         style = gtk_widget_get_style(stock);
  1986.         style->xthickness = style->ythickness = 0;
  1987.         gtk_widget_set_style (stock, style);
  1988.         gtk_widget_show(stock);
  1989.  
  1990.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  1991.                                              GTK_STOCK_PASTE,
  1992.                          "Paste Traces",
  1993.                          NULL,
  1994.                          GTK_SIGNAL_FUNC(menu_paste_traces),
  1995.                          NULL,
  1996.                          tb_pos++);
  1997.         style = gtk_widget_get_style(stock);
  1998.         style->xthickness = style->ythickness = 0;
  1999.         gtk_widget_set_style (stock, style);
  2000.         gtk_widget_show(stock);
  2001.  
  2002.         gtk_toolbar_insert_space(GTK_TOOLBAR(tb), tb_pos++);
  2003.  
  2004.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  2005.                                              GTK_STOCK_ZOOM_FIT,
  2006.                          "Zoom Fit",
  2007.                          NULL,
  2008.                          GTK_SIGNAL_FUNC(service_zoom_fit),
  2009.                          NULL,
  2010.                          tb_pos++);
  2011.         style = gtk_widget_get_style(stock);
  2012.         style->xthickness = style->ythickness = 0;
  2013.         gtk_widget_set_style (stock, style);
  2014.         gtk_widget_show(stock);
  2015.  
  2016.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  2017.                                              GTK_STOCK_ZOOM_IN,
  2018.                          "Zoom In",
  2019.                          NULL,
  2020.                          GTK_SIGNAL_FUNC(service_zoom_in),
  2021.                          NULL,
  2022.                          tb_pos++);
  2023.         style = gtk_widget_get_style(stock);
  2024.         style->xthickness = style->ythickness = 0;
  2025.         gtk_widget_set_style (stock, style);
  2026.         gtk_widget_show(stock);
  2027.  
  2028.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  2029.                                              GTK_STOCK_ZOOM_OUT,
  2030.                          "Zoom Out",
  2031.                          NULL,
  2032.                          GTK_SIGNAL_FUNC(service_zoom_out),
  2033.                          NULL,
  2034.                          tb_pos++);
  2035.         style = gtk_widget_get_style(stock);
  2036.         style->xthickness = style->ythickness = 0;
  2037.         gtk_widget_set_style (stock, style);
  2038.         gtk_widget_show(stock);
  2039.  
  2040.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  2041.                                              GTK_STOCK_UNDO,
  2042.                          "Zoom Undo",
  2043.                          NULL,
  2044.                          GTK_SIGNAL_FUNC(service_zoom_undo),
  2045.                          NULL,
  2046.                          tb_pos++);
  2047.         style = gtk_widget_get_style(stock);
  2048.         style->xthickness = style->ythickness = 0;
  2049.         gtk_widget_set_style (stock, style);
  2050.         gtk_widget_show(stock);
  2051.  
  2052.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  2053.                                              GTK_STOCK_GOTO_FIRST,
  2054.                          "Zoom to Start",
  2055.                          NULL,
  2056.                          GTK_SIGNAL_FUNC(service_zoom_left),
  2057.                          NULL,
  2058.                          tb_pos++);
  2059.         style = gtk_widget_get_style(stock);
  2060.         style->xthickness = style->ythickness = 0;
  2061.         gtk_widget_set_style (stock, style);
  2062.         gtk_widget_show(stock);
  2063.  
  2064.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  2065.                                              GTK_STOCK_GOTO_LAST,
  2066.                          "Zoom to End",
  2067.                          NULL,
  2068.                          GTK_SIGNAL_FUNC(service_zoom_right),
  2069.                          NULL,
  2070.                          tb_pos++);
  2071.         style = gtk_widget_get_style(stock);
  2072.         style->xthickness = style->ythickness = 0;
  2073.         gtk_widget_set_style (stock, style);
  2074.         gtk_widget_show(stock);
  2075.  
  2076.         gtk_toolbar_insert_space(GTK_TOOLBAR(tb), tb_pos++);
  2077.  
  2078.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  2079.                                              GTK_STOCK_GO_BACK,
  2080.                          "Find Previous Edge",
  2081.                          NULL,
  2082.                          GTK_SIGNAL_FUNC(service_left_edge),
  2083.                          NULL,
  2084.                          tb_pos++);
  2085.         style = gtk_widget_get_style(stock);
  2086.         style->xthickness = style->ythickness = 0;
  2087.         gtk_widget_set_style (stock, style);
  2088.         gtk_widget_show(stock);
  2089.  
  2090.         stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  2091.                                              GTK_STOCK_GO_FORWARD,
  2092.                          "Find Next Edge",
  2093.                          NULL,
  2094.                          GTK_SIGNAL_FUNC(service_right_edge),
  2095.                          NULL,
  2096.                          tb_pos++);
  2097.         style = gtk_widget_get_style(stock);
  2098.         style->xthickness = style->ythickness = 0;
  2099.         gtk_widget_set_style (stock, style);
  2100.         gtk_widget_show(stock);
  2101.  
  2102.         gtk_toolbar_insert_space(GTK_TOOLBAR(tb), tb_pos++);
  2103.  
  2104.         entry = create_entry_box();
  2105.         gtk_widget_show(entry);
  2106.         gtk_toolbar_insert_widget(GTK_TOOLBAR(tb),
  2107.                                           entry,
  2108.                                           NULL,
  2109.                       NULL,
  2110.                       tb_pos++);
  2111.  
  2112.         gtk_toolbar_insert_space(GTK_TOOLBAR(tb), tb_pos++);
  2113.  
  2114.         if((GLOBALS->loaded_file_type != DUMPLESS_FILE)&&(!GLOBALS->disable_menus))
  2115.             {
  2116.             stock = gtk_toolbar_insert_stock(GTK_TOOLBAR(tb),
  2117.                                              GTK_STOCK_REFRESH,
  2118.                          "Reload",
  2119.                          NULL,
  2120.                          GTK_SIGNAL_FUNC(menu_reload_waveform_marshal),
  2121.                          NULL,
  2122.                          tb_pos++);
  2123.             style = gtk_widget_get_style(stock);
  2124.             style->xthickness = style->ythickness = 0;
  2125.             gtk_widget_set_style (stock, style);
  2126.             gtk_widget_show(stock);
  2127.  
  2128.             gtk_toolbar_insert_space(GTK_TOOLBAR(tb), tb_pos++);
  2129.             }
  2130.  
  2131.         timebox = create_time_box();
  2132.         gtk_widget_show (timebox);
  2133.         gtk_toolbar_insert_widget(GTK_TOOLBAR(tb),
  2134.                                           timebox,
  2135.                                           NULL,
  2136.                       NULL,
  2137.                       tb_pos /* ++ */); /* scan-build */
  2138.  
  2139.         GLOBALS->missing_file_toolbar = tb;
  2140.         if(GLOBALS->loaded_file_type == MISSING_FILE)
  2141.             {
  2142.             gtk_widget_set_sensitive(GLOBALS->missing_file_toolbar, FALSE);
  2143.             }
  2144.         } /* of ...if(mainwindow_already_built) */
  2145.     }
  2146.     else
  2147. #endif
  2148.     {
  2149.     if(!mainwindow_already_built)
  2150.         {
  2151.         main_vbox = gtk_vbox_new(FALSE, 5);
  2152.         gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
  2153.         gtk_container_add(GTK_CONTAINER(GLOBALS->mainwindow), main_vbox);
  2154.         gtk_widget_show(main_vbox);
  2155.  
  2156.         if(!GLOBALS->disable_menus)
  2157.             {
  2158. #ifdef WAVE_USE_MLIST_T
  2159.             menubar = alt_menu_top(GLOBALS->mainwindow);
  2160. #else
  2161.             get_main_menu(GLOBALS->mainwindow, &menubar);
  2162. #endif
  2163.             gtk_widget_show(menubar);
  2164.  
  2165. #ifdef MAC_INTEGRATION
  2166. {
  2167. GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
  2168. gtk_widget_hide(menubar);
  2169. gtkosx_application_set_menu_bar(theApp, GTK_MENU_SHELL(menubar));
  2170. gtkosx_application_set_use_quartz_accelerators(theApp, TRUE);
  2171. gtkosx_application_ready(theApp);
  2172. gtkosx_application_set_dock_icon_pixbuf(theApp, dock_pb);
  2173. if(GLOBALS->loaded_file_type == MISSING_FILE)
  2174.     {
  2175.     gtkosx_application_attention_request(theApp, INFO_REQUEST);
  2176.     }
  2177.  
  2178. g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(deal_with_finder_open), NULL);
  2179. g_signal_connect(theApp, "NSApplicationBlockTermination", G_CALLBACK(deal_with_termination), NULL);
  2180. }
  2181. #endif
  2182.  
  2183.             if(GLOBALS->force_toolbars)
  2184.                 {
  2185.                 toolhandle=gtk_handle_box_new();
  2186.                 /* gtk_widget_show(toolhandle); */
  2187.                 gtk_container_add(GTK_CONTAINER(toolhandle), menubar);
  2188.                 gtk_box_pack_start(GTK_BOX(main_vbox), toolhandle, FALSE, TRUE, 0);
  2189.                 }
  2190.                 else
  2191.                 {
  2192.                 gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0);
  2193.                 }
  2194.             }
  2195.  
  2196.         top_table = gtk_table_new (1, 284, FALSE);
  2197.  
  2198.         if(GLOBALS->force_toolbars)
  2199.             {
  2200.             toolhandle=gtk_handle_box_new();
  2201.             /* gtk_widget_show(toolhandle); */
  2202.             gtk_container_add(GTK_CONTAINER(toolhandle), top_table);
  2203.             }
  2204.  
  2205.         whole_table = gtk_table_new (256, 16, FALSE);
  2206.  
  2207.         text1 = create_text ();
  2208.         gtk_table_attach (GTK_TABLE (top_table), text1, 0, 141, 0, 1,
  2209.                                 GTK_FILL,
  2210.                                 GTK_FILL | GTK_SHRINK, 0, 0);
  2211.         gtk_widget_set_usize(GTK_WIDGET(text1), 200, -1);
  2212.         gtk_widget_show (text1);
  2213.  
  2214.         dummy1=gtk_label_new("");
  2215.         gtk_table_attach (GTK_TABLE (top_table), dummy1, 141, 171, 0, 1,
  2216.                                 GTK_FILL,
  2217.                                 GTK_SHRINK, 0, 0);
  2218.         gtk_widget_show (dummy1);
  2219.  
  2220.         zoombuttons = create_zoom_buttons ();
  2221.         gtk_table_attach (GTK_TABLE (top_table), zoombuttons, 171, 173, 0, 1,
  2222.                                 GTK_FILL,
  2223.                                 GTK_SHRINK, 0, 0);
  2224.         gtk_widget_show (zoombuttons);
  2225.  
  2226.         if(!GLOBALS->use_scrollbar_only)
  2227.             {
  2228.             pagebuttons = create_page_buttons ();
  2229.             gtk_table_attach (GTK_TABLE (top_table), pagebuttons, 173, 174, 0, 1,
  2230.                                     GTK_FILL,
  2231.                                     GTK_SHRINK, 0, 0);
  2232.             gtk_widget_show (pagebuttons);
  2233.             fetchbuttons = create_fetch_buttons ();
  2234.             gtk_table_attach (GTK_TABLE (top_table), fetchbuttons, 174, 175, 0, 1,
  2235.                                     GTK_FILL,
  2236.                                     GTK_SHRINK, 0, 0);
  2237.             gtk_widget_show (fetchbuttons);
  2238.             discardbuttons = create_discard_buttons ();
  2239.             gtk_table_attach (GTK_TABLE (top_table), discardbuttons, 175, 176, 0, 1,
  2240.                                     GTK_FILL,
  2241.                                     GTK_SHRINK, 0, 0);
  2242.             gtk_widget_show (discardbuttons);
  2243.  
  2244.             shiftbuttons = create_shift_buttons ();
  2245.             gtk_table_attach (GTK_TABLE (top_table), shiftbuttons, 176, 177, 0, 1,
  2246.                                     GTK_FILL,
  2247.                                     GTK_SHRINK, 0, 0);
  2248.             gtk_widget_show (shiftbuttons);
  2249.             }
  2250.  
  2251.         edgebuttons = create_edge_buttons ();
  2252.         gtk_table_attach (GTK_TABLE (top_table), edgebuttons, 177, 178, 0, 1,
  2253.                                 GTK_FILL,
  2254.                                 GTK_SHRINK, 0, 0);
  2255.         gtk_widget_show (edgebuttons);
  2256.  
  2257.  
  2258.         dummy2=gtk_label_new("");
  2259.         gtk_table_attach (GTK_TABLE (top_table), dummy2, 178, 215, 0, 1,
  2260.                                 GTK_FILL,
  2261.                                 GTK_SHRINK, 0, 0);
  2262.         gtk_widget_show (dummy2);
  2263.  
  2264.         entry = create_entry_box();
  2265.         gtk_table_attach (GTK_TABLE (top_table), entry, 215, 216, 0, 1,
  2266.                                 GTK_SHRINK,
  2267.                                 GTK_SHRINK, 0, 0);
  2268.         gtk_widget_show(entry);
  2269.  
  2270.         timebox = create_time_box();
  2271.         gtk_table_attach (GTK_TABLE (top_table), timebox, 216, 284, 0, 1,
  2272.                                 GTK_FILL | GTK_EXPAND,
  2273.                                 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 20, 0);
  2274.         gtk_widget_show (timebox);
  2275.  
  2276.         if((GLOBALS->loaded_file_type != DUMPLESS_FILE)&&(!GLOBALS->disable_menus))
  2277.             {
  2278.             GtkWidget *r_pixmap = gtk_pixmap_new(GLOBALS->redo_pixmap, GLOBALS->redo_mask);
  2279.             GtkWidget *main_vbox1;
  2280.             GtkWidget *table, *table2;
  2281.             GtkWidget *b1, *frame;
  2282.             GtkTooltips *tooltips;
  2283.  
  2284.             gtk_widget_show(r_pixmap);
  2285.  
  2286.             tooltips=gtk_tooltips_new_2();
  2287.             gtk_tooltips_set_delay_2(tooltips,1500);
  2288.  
  2289.             table = gtk_table_new (1, 1, FALSE);
  2290.  
  2291.             main_vbox1 = gtk_vbox_new (FALSE, 1);
  2292.             gtk_container_border_width (GTK_CONTAINER (main_vbox1), 1);
  2293.             gtk_container_add (GTK_CONTAINER (table), main_vbox1);
  2294.  
  2295.             frame = gtk_frame_new ("Reload ");
  2296.             gtk_box_pack_start (GTK_BOX (main_vbox1), frame, TRUE, TRUE, 0);
  2297.  
  2298.             gtk_widget_show (frame);
  2299.             gtk_widget_show (main_vbox1);
  2300.  
  2301.             table2 = gtk_table_new (2, 1, FALSE);
  2302.  
  2303.             b1 = gtk_button_new();
  2304.             gtk_container_add(GTK_CONTAINER(b1), r_pixmap);
  2305.             gtk_table_attach (GTK_TABLE (table2), b1, 0, 1, 0, 1,
  2306.                                     GTK_FILL | GTK_EXPAND,
  2307.                                     GTK_FILL | GTK_EXPAND | GTK_SHRINK, 1, 1);
  2308.  
  2309.             gtk_signal_connect_object (GTK_OBJECT (b1), "clicked", GTK_SIGNAL_FUNC(menu_reload_waveform_marshal), GTK_OBJECT (table2));
  2310.             gtk_tooltips_set_tip_2(tooltips, b1, "Reload waveform", NULL);
  2311.             gtk_widget_show(b1);
  2312.             gtk_container_add (GTK_CONTAINER (frame), table2);
  2313.             gtk_widget_show(table2);
  2314.  
  2315.             gtk_table_attach (GTK_TABLE (top_table), table, 284, 285, 0, 1,
  2316.                                 0,
  2317.                                 0, 2, 0);
  2318.  
  2319.             /* gtk_widget_show (table); */
  2320.             }
  2321.         } /* of ...if(mainwindow_already_built) */
  2322.     }
  2323.  
  2324.  
  2325. GLOBALS->wavewindow = create_wavewindow();
  2326. load_all_fonts(); /* must be done before create_signalwindow() */
  2327. gtk_widget_show(GLOBALS->wavewindow);
  2328. GLOBALS->signalwindow = create_signalwindow();
  2329.  
  2330. if(GLOBALS->do_resize_signals)
  2331.                 {
  2332.                 int os;
  2333.  
  2334.         if(GLOBALS->initial_signal_window_width > GLOBALS->max_signal_name_pixel_width)
  2335.             {
  2336.             os=GLOBALS->initial_signal_window_width;
  2337.             }
  2338.             else
  2339.             {
  2340.                     os=GLOBALS->max_signal_name_pixel_width;
  2341.             }
  2342.  
  2343.                 os=(os<48)?48:os;
  2344.                 gtk_widget_set_usize(GTK_WIDGET(GLOBALS->signalwindow),
  2345.                                 os+30, -1);
  2346.                 }
  2347. else
  2348.     {
  2349.     if(GLOBALS->initial_signal_window_width)
  2350.         {
  2351.         int os;
  2352.  
  2353.         os=GLOBALS->initial_signal_window_width;
  2354.         os=(os<48)?48:os;
  2355.         gtk_widget_set_usize(GTK_WIDGET(GLOBALS->signalwindow), os+30, -1);
  2356.         }
  2357.     }
  2358.  
  2359. gtk_widget_show(GLOBALS->signalwindow);
  2360.  
  2361. #if GTK_CHECK_VERSION(2,4,0)
  2362. if((!GLOBALS->hide_sst)&&(GLOBALS->loaded_file_type != MISSING_FILE))
  2363.     {
  2364.     GLOBALS->toppanedwindow = gtk_hpaned_new();
  2365.     GLOBALS->sstpane = treeboxframe("SST", GTK_SIGNAL_FUNC(mkmenu_treesearch_cleanup));
  2366.     GLOBALS->expanderwindow = gtk_expander_new_with_mnemonic("_SST");
  2367.     gtk_expander_set_expanded(GTK_EXPANDER(GLOBALS->expanderwindow), (GLOBALS->sst_expanded==TRUE));
  2368.     if(GLOBALS->toppanedwindow_size_cache)
  2369.         {
  2370.         gtk_paned_set_position(GTK_PANED(GLOBALS->toppanedwindow), GLOBALS->toppanedwindow_size_cache);
  2371.         GLOBALS->toppanedwindow_size_cache = 0;
  2372.         }
  2373.     gtk_container_add(GTK_CONTAINER(GLOBALS->expanderwindow), GLOBALS->sstpane);
  2374.     gtk_widget_show(GLOBALS->expanderwindow);
  2375.     }
  2376. #endif
  2377.  
  2378. GLOBALS->panedwindow = panedwindow = gtk_hpaned_new();
  2379. if(GLOBALS->panedwindow_size_cache)
  2380.     {
  2381.     gtk_paned_set_position(GTK_PANED(GLOBALS->panedwindow), GLOBALS->panedwindow_size_cache);
  2382.     GLOBALS->panedwindow_size_cache = 0;
  2383.     }
  2384.  
  2385. #ifdef HAVE_PANED_PACK
  2386. if(GLOBALS->paned_pack_semantics)
  2387.     {
  2388.     gtk_paned_pack1(GTK_PANED(panedwindow), GLOBALS->signalwindow, 0, 0);
  2389.     gtk_paned_pack2(GTK_PANED(panedwindow), GLOBALS->wavewindow, ~0, 0);
  2390.     }
  2391.     else
  2392. #endif
  2393.     {
  2394.     gtk_paned_add1(GTK_PANED(panedwindow), GLOBALS->signalwindow);
  2395.     gtk_paned_add2(GTK_PANED(panedwindow), GLOBALS->wavewindow);
  2396.     }
  2397.  
  2398. gtk_widget_show(panedwindow);
  2399.  
  2400. if(GLOBALS->dnd_sigview)
  2401.     {
  2402.     dnd_setup(GLOBALS->dnd_sigview, GLOBALS->signalarea, 1);
  2403.     }
  2404.     else
  2405.     {
  2406.     dnd_setup(NULL, GLOBALS->signalarea, 1);
  2407.     }
  2408. /* dnd_setup(GLOBALS->signalarea, GLOBALS->signalarea); */
  2409. dnd_setup(GLOBALS->signalarea, GLOBALS->wavearea, 1);
  2410.  
  2411. #if GTK_CHECK_VERSION(2,4,0)
  2412. if((!GLOBALS->hide_sst)&&(GLOBALS->loaded_file_type != MISSING_FILE))
  2413.     {
  2414.     gtk_paned_pack1(GTK_PANED(GLOBALS->toppanedwindow), GLOBALS->expanderwindow, 0, 0);
  2415.     gtk_paned_pack2(GTK_PANED(GLOBALS->toppanedwindow), panedwindow, ~0, 0);
  2416.     gtk_widget_show(GLOBALS->toppanedwindow);
  2417.     }
  2418. #endif
  2419.  
  2420. #if WAVE_USE_GTK2
  2421. if(GLOBALS->treeopen_chain_head)
  2422.     {
  2423.     struct string_chain_t *t = GLOBALS->treeopen_chain_head;
  2424.     struct string_chain_t *t2;
  2425.     while(t)
  2426.         {
  2427.         if(GLOBALS->ctree_main)
  2428.             {
  2429.             force_open_tree_node(t->str, 0, NULL);
  2430.             }
  2431.  
  2432.         t2 = t->next;
  2433.         if(t->str) free_2(t->str);
  2434.         free_2(t);
  2435.         t = t2;
  2436.         }
  2437.  
  2438.     GLOBALS->treeopen_chain_head = GLOBALS->treeopen_chain_curr = NULL;
  2439.     }
  2440. #endif
  2441.  
  2442. if(!mainwindow_already_built)
  2443.     {
  2444.     /* gtk_widget_show(top_table); */
  2445.     gtk_table_attach (GTK_TABLE (whole_table), GLOBALS->force_toolbars?toolhandle:top_table, 0, 16, 0, 1,
  2446.                             GTK_FILL | GTK_EXPAND,
  2447.                             GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
  2448.  
  2449.     if(!GLOBALS->do_resize_signals)
  2450.         {
  2451.         int dri;
  2452.             for(dri=0;dri<2;dri++)
  2453.                     {
  2454.                     GLOBALS->signalwindow_width_dirty=1;
  2455.                     MaxSignalLength();
  2456.                     signalarea_configure_event(GLOBALS->signalarea, NULL);
  2457.                     wavearea_configure_event(GLOBALS->wavearea, NULL);
  2458.                     }
  2459.         }
  2460.     }
  2461.  
  2462.  
  2463. if(!GLOBALS->notebook)
  2464.     {
  2465.     GLOBALS->num_notebook_pages = 1;
  2466.     GLOBALS->this_context_page = 0;
  2467.     GLOBALS->contexts = calloc(1, sizeof(struct Global **)); /* calloc is deliberate! */ /* scan-build */
  2468.     *GLOBALS->contexts = calloc(1, sizeof(struct Global *)); /* calloc is deliberate! */ /* scan-build */
  2469.     (*GLOBALS->contexts)[0] = GLOBALS;
  2470.  
  2471.     GLOBALS->dead_context = calloc(1, sizeof(struct Global **)); /* calloc is deliberate! */ /* scan-build */
  2472.     *GLOBALS->dead_context = calloc(1, sizeof(struct Global *)); /* calloc is deliberate! */ /* scan-build */
  2473.     *(GLOBALS->dead_context)[0] = NULL;
  2474.  
  2475.     GLOBALS->notebook = gtk_notebook_new();
  2476.     gtk_notebook_set_tab_pos(GTK_NOTEBOOK(GLOBALS->notebook), GLOBALS->context_tabposition ? GTK_POS_LEFT : GTK_POS_TOP);
  2477.  
  2478.     gtk_widget_show(GLOBALS->notebook);
  2479.     gtk_notebook_set_show_tabs(GTK_NOTEBOOK(GLOBALS->notebook), 0); /* hide for first time until next tabs */
  2480.     gtk_notebook_set_show_border(GTK_NOTEBOOK(GLOBALS->notebook), 0); /* hide for first time until next tabs */
  2481.     gtk_signal_connect(GTK_OBJECT(GLOBALS->notebook), "switch-page", GTK_SIGNAL_FUNC(switch_page), NULL);
  2482.     }
  2483.     else
  2484.     {
  2485.     unsigned int ix;
  2486.  
  2487.     GLOBALS->this_context_page = GLOBALS->num_notebook_pages;
  2488.     GLOBALS->num_notebook_pages++;
  2489.     GLOBALS->num_notebook_pages_cumulative++; /* this never decreases, acts as an incrementing flipper id for side tabs */
  2490.     *GLOBALS->contexts = realloc(*GLOBALS->contexts, GLOBALS->num_notebook_pages * sizeof(struct Global *)); /* realloc is deliberate! */ /* scan-build */
  2491.     (*GLOBALS->contexts)[GLOBALS->this_context_page] = GLOBALS;
  2492.  
  2493.     for(ix=0;ix<GLOBALS->num_notebook_pages;ix++)
  2494.         {
  2495.         (*GLOBALS->contexts)[ix]->num_notebook_pages = GLOBALS->num_notebook_pages;
  2496.         (*GLOBALS->contexts)[ix]->num_notebook_pages_cumulative = GLOBALS->num_notebook_pages_cumulative;
  2497.         (*GLOBALS->contexts)[ix]->dead_context = (*GLOBALS->contexts)[0]->dead_context; /* mirroring this is OK as page 0 always has value! */
  2498.         }
  2499.  
  2500.     gtk_notebook_set_show_tabs(GTK_NOTEBOOK(GLOBALS->notebook), ~0); /* then appear */
  2501.     gtk_notebook_set_show_border(GTK_NOTEBOOK(GLOBALS->notebook), ~0); /* then appear */
  2502.     gtk_notebook_set_scrollable(GTK_NOTEBOOK(GLOBALS->notebook), ~0);
  2503.     }
  2504.  
  2505. if(!GLOBALS->context_tabposition)
  2506.     {
  2507.     gtk_notebook_append_page(GTK_NOTEBOOK(GLOBALS->notebook), GLOBALS->toppanedwindow ? GLOBALS->toppanedwindow : panedwindow,
  2508.         gtk_label_new(GLOBALS->loaded_file_name));
  2509.     }
  2510.     else
  2511.     {
  2512.     char buf[40];
  2513.  
  2514.     sprintf(buf, "%d", GLOBALS->num_notebook_pages_cumulative);
  2515.  
  2516.     gtk_notebook_append_page(GTK_NOTEBOOK(GLOBALS->notebook), GLOBALS->toppanedwindow ? GLOBALS->toppanedwindow : panedwindow,
  2517.         gtk_label_new(buf));
  2518.     }
  2519.  
  2520. if(mainwindow_already_built)
  2521.     {
  2522.     gtk_notebook_set_current_page(GTK_NOTEBOOK(GLOBALS->notebook), GLOBALS->this_context_page);
  2523.     return(0);
  2524.     }
  2525.  
  2526. gtk_table_attach (GTK_TABLE (whole_table), GLOBALS->notebook, 0, 16, 1, 256,
  2527.                         GTK_FILL | GTK_EXPAND,
  2528.                         GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
  2529. gtk_widget_show(whole_table);
  2530. gtk_container_add (GTK_CONTAINER (main_vbox), whole_table);
  2531.  
  2532. if(GLOBALS->tims.marker != -1)
  2533.     {
  2534.     if(GLOBALS->tims.marker<GLOBALS->tims.first) GLOBALS->tims.marker=GLOBALS->tims.first;
  2535.     }
  2536. update_markertime(GLOBALS->tims.marker);
  2537.  
  2538. set_window_xypos(GLOBALS->initial_window_xpos, GLOBALS->initial_window_ypos);
  2539. GLOBALS->xy_ignore_main_c_1 = 1;
  2540.  
  2541. if(GLOBALS->logfile)
  2542.     {
  2543.     struct logfile_chain *lprev;
  2544.     char buf[50];
  2545.     int which = 1;
  2546.     while(GLOBALS->logfile)
  2547.         {
  2548.         sprintf(buf, "Logfile viewer [%d]", which++);
  2549.         logbox(buf, 480, GLOBALS->logfile->name);
  2550.         lprev = GLOBALS->logfile;
  2551.         GLOBALS->logfile = GLOBALS->logfile->next;
  2552.         free_2(lprev->name);
  2553.         free_2(lprev);
  2554.         }
  2555.     }
  2556.  
  2557. activate_stems_reader(GLOBALS->stems_name);
  2558.  
  2559. gtk_events_pending_gtk_main_iteration();
  2560.  
  2561. if(1)   /* here in order to calculate window manager delta if present... window is completely rendered by here */
  2562.     {
  2563.     int dummy_x, dummy_y;
  2564.     get_window_xypos(&dummy_x, &dummy_y);
  2565.     }
  2566.  
  2567. init_busy();
  2568.  
  2569. if(scriptfile
  2570. #if defined(HAVE_LIBTCL)
  2571.         && GLOBALS->interp
  2572. #endif
  2573. )
  2574.     {
  2575.     execute_script(scriptfile, 1); /* deallocate the name in the script because context might swap out from under us! */
  2576.     scriptfile=NULL;
  2577.     }
  2578.  
  2579. #if defined(WAVE_HAVE_GCONF) || defined(WAVE_HAVE_GSETTINGS)
  2580. if(GLOBALS->loaded_file_type != MISSING_FILE)
  2581.     {
  2582.     if(!chdir_cache) { wave_gconf_client_set_string("/current/pwd", getenv("PWD")); }
  2583.     wave_gconf_client_set_string("/current/dumpfile", GLOBALS->optimize_vcd ? GLOBALS->unoptimized_vcd_file_name : GLOBALS->loaded_file_name);
  2584.     wave_gconf_client_set_string("/current/optimized_vcd", GLOBALS->optimize_vcd ? "1" : "0");
  2585.     wave_gconf_client_set_string("/current/savefile", GLOBALS->filesel_writesave);
  2586.     }
  2587. #endif
  2588.  
  2589. #if !defined _MSC_VER
  2590. if(GLOBALS->dual_attach_id_main_c_1)
  2591.     {
  2592.     fprintf(stderr, "GTKWAVE | Attaching %08X as dual head session %d\n", GLOBALS->dual_attach_id_main_c_1, GLOBALS->dual_id);
  2593.  
  2594. #ifdef __MINGW32__
  2595.         {
  2596.         HANDLE hMapFile;
  2597.         char mapName[257];
  2598.  
  2599.         sprintf(mapName, "twinwave%d", GLOBALS->dual_attach_id_main_c_1);
  2600.         hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, mapName);
  2601.         if(hMapFile == NULL)
  2602.                 {
  2603.                 fprintf(stderr, "Could not attach shared memory map name '%s', exiting.\n", mapName);
  2604.                 exit(255);
  2605.                 }
  2606.         GLOBALS->dual_ctx = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 2 * sizeof(struct gtkwave_dual_ipc_t));
  2607.         if(GLOBALS->dual_ctx == NULL)
  2608.                 {
  2609.                 fprintf(stderr, "Could not map view of file '%s', exiting.\n", mapName);
  2610.                 exit(255);
  2611.                 }
  2612.         }
  2613. #else
  2614.     GLOBALS->dual_ctx = shmat(GLOBALS->dual_attach_id_main_c_1, NULL, 0);
  2615. #endif
  2616.     if(GLOBALS->dual_ctx)
  2617.         {
  2618.         if(memcmp(GLOBALS->dual_ctx[GLOBALS->dual_id].matchword, DUAL_MATCHWORD, 4))
  2619.             {
  2620.             fprintf(stderr, "Not a valid shared memory ID for dual head operation, exiting.\n");
  2621.             exit(255);
  2622.             }
  2623.  
  2624.         GLOBALS->dual_ctx[GLOBALS->dual_id].viewer_is_initialized = 1;
  2625.         for(;;)
  2626.             {
  2627.                 GtkAdjustment *hadj;
  2628.                 TimeType pageinc, gt;
  2629. #ifndef __MINGW32__
  2630.             struct timeval tv;
  2631. #endif
  2632.             if(GLOBALS->dual_ctx[1-GLOBALS->dual_id].use_new_times)
  2633.                 {
  2634.                 GLOBALS->dual_race_lock = 1;
  2635.  
  2636.                     gt = GLOBALS->dual_ctx[GLOBALS->dual_id].left_margin_time = GLOBALS->dual_ctx[1-GLOBALS->dual_id].left_margin_time;
  2637.  
  2638.                 GLOBALS->dual_ctx[GLOBALS->dual_id].marker = GLOBALS->dual_ctx[1-GLOBALS->dual_id].marker;
  2639.                 GLOBALS->dual_ctx[GLOBALS->dual_id].baseline = GLOBALS->dual_ctx[1-GLOBALS->dual_id].baseline;
  2640.                 GLOBALS->dual_ctx[GLOBALS->dual_id].zoom = GLOBALS->dual_ctx[1-GLOBALS->dual_id].zoom;
  2641.                 GLOBALS->dual_ctx[1-GLOBALS->dual_id].use_new_times = 0;
  2642.                 GLOBALS->dual_ctx[GLOBALS->dual_id].use_new_times = 0;
  2643.  
  2644.                 if(GLOBALS->dual_ctx[GLOBALS->dual_id].baseline != GLOBALS->tims.baseline)
  2645.                     {
  2646.                     if((GLOBALS->tims.marker != -1) && (GLOBALS->dual_ctx[GLOBALS->dual_id].marker == -1))
  2647.                         {
  2648.                             Trptr t;
  2649.  
  2650.                             for(t=GLOBALS->traces.first;t;t=t->t_next)
  2651.                                     {
  2652.                                     if(t->asciivalue) { free_2(t->asciivalue); t->asciivalue=NULL; }
  2653.                                     }
  2654.  
  2655.                             for(t=GLOBALS->traces.buffer;t;t=t->t_next)
  2656.                                     {
  2657.                                     if(t->asciivalue) { free_2(t->asciivalue); t->asciivalue=NULL; }
  2658.                                     }
  2659.                         }
  2660.  
  2661.                     GLOBALS->tims.marker = GLOBALS->dual_ctx[GLOBALS->dual_id].marker;
  2662.                     GLOBALS->tims.baseline = GLOBALS->dual_ctx[GLOBALS->dual_id].baseline;
  2663.                     update_basetime(GLOBALS->tims.baseline);
  2664.                     update_markertime(GLOBALS->tims.marker);
  2665.                     GLOBALS->signalwindow_width_dirty = 1;
  2666.                     button_press_release_common();
  2667.                     }
  2668.                 else
  2669.                 if(GLOBALS->dual_ctx[GLOBALS->dual_id].marker != GLOBALS->tims.marker)
  2670.                     {
  2671.                     if((GLOBALS->tims.marker != -1) && (GLOBALS->dual_ctx[GLOBALS->dual_id].marker == -1))
  2672.                         {
  2673.                             Trptr t;
  2674.  
  2675.                             for(t=GLOBALS->traces.first;t;t=t->t_next)
  2676.                                     {
  2677.                                     if(t->asciivalue) { free_2(t->asciivalue); t->asciivalue=NULL; }
  2678.                                     }
  2679.  
  2680.                             for(t=GLOBALS->traces.buffer;t;t=t->t_next)
  2681.                                     {
  2682.                                     if(t->asciivalue) { free_2(t->asciivalue); t->asciivalue=NULL; }
  2683.                                     }
  2684.                         }
  2685.  
  2686.                     GLOBALS->tims.marker = GLOBALS->dual_ctx[GLOBALS->dual_id].marker;
  2687.                     update_markertime(GLOBALS->tims.marker);
  2688.                     GLOBALS->signalwindow_width_dirty = 1;
  2689.                     button_press_release_common();
  2690.                     }
  2691.  
  2692.                 GLOBALS->tims.prevzoom=GLOBALS->tims.zoom;
  2693.                 GLOBALS->tims.zoom=GLOBALS->dual_ctx[GLOBALS->dual_id].zoom;
  2694.  
  2695.                     if(gt<GLOBALS->tims.first) gt=GLOBALS->tims.first;
  2696.                     else if(gt>GLOBALS->tims.last) gt=GLOBALS->tims.last;
  2697.  
  2698.                     hadj=GTK_ADJUSTMENT(GLOBALS->wave_hslider);
  2699.                     hadj->value=gt;
  2700.  
  2701.                     pageinc=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx);
  2702.                     if(gt<(GLOBALS->tims.last-pageinc+1))
  2703.                             GLOBALS->tims.timecache=gt;
  2704.                             else
  2705.                             {
  2706.                             GLOBALS->tims.timecache=GLOBALS->tims.last-pageinc+1;
  2707.                             if(GLOBALS->tims.timecache<GLOBALS->tims.first) GLOBALS->tims.timecache=GLOBALS->tims.first;
  2708.                             }
  2709.  
  2710.                     time_update();
  2711.                 }
  2712.  
  2713.             if(is_interactive)
  2714.                 {
  2715.                 kick_partial_vcd();
  2716.                 }
  2717.                 else
  2718.                 {
  2719.                 while (gtk_events_pending()) gtk_main_iteration();
  2720.                 }
  2721.  
  2722.             GLOBALS->dual_race_lock = 0;
  2723.  
  2724. #ifdef __MINGW32__
  2725.             Sleep(1000 / 25);
  2726. #else
  2727.             tv.tv_sec = 0;
  2728.                 tv.tv_usec = 1000000 / 25;
  2729.             select(0, NULL, NULL, NULL, &tv);
  2730. #endif
  2731.             }
  2732.         }
  2733.         else
  2734.         {
  2735.         fprintf(stderr, "Could not attach to %08X, exiting.\n", GLOBALS->dual_attach_id_main_c_1);
  2736.         exit(255);
  2737.         }
  2738.     }
  2739. else
  2740. #endif
  2741. if(is_interactive)
  2742.     {
  2743.     for(;;) { kick_partial_vcd(); }
  2744.     }
  2745.     else
  2746.     {
  2747. #if defined(HAVE_LIBTCL)
  2748.     if(is_wish)
  2749.       {
  2750.       char* argv_mod[1];
  2751.  
  2752.       set_globals_interp(argv[0], 1);
  2753.       addPidToExecutableName(1, argv, argv_mod);
  2754.       Tk_MainEx(1, argv_mod, gtkwaveInterpreterInit, GLOBALS->interp);
  2755.  
  2756.       /* note: for(kk=0;kk<argc;kk++) { free_2(argv_mod[kk]); } can't really be done here, doesn't matter anyway as context free will get it */
  2757.       }
  2758.       else
  2759.       {
  2760.       gtk_main();
  2761.           }
  2762. #else
  2763.       gtk_main();
  2764. #endif
  2765.     }
  2766.  
  2767. #ifdef MAC_INTEGRATION
  2768. exit(0); /* gtk_target_list_find crashes in OSX/Quartz is return instead of exit */
  2769. #else
  2770. return(0);
  2771. #endif
  2772. }
  2773.  
  2774. void
  2775. get_window_size (int *x, int *y)
  2776. {
  2777. #ifdef WAVE_USE_GTK2
  2778.   gtk_window_get_size (GTK_WINDOW (GLOBALS->mainwindow), x, y);
  2779. #else
  2780.   *x = GLOBALS->initial_window_x;
  2781.   *y = GLOBALS->initial_window_y;
  2782. #endif
  2783. }
  2784.  
  2785. void
  2786. set_window_size (int x, int y)
  2787. {
  2788.   if(GLOBALS->block_xy_update)
  2789.     {
  2790.       return;
  2791.     }
  2792.  
  2793.   if (GLOBALS->mainwindow == NULL)
  2794.     {
  2795.       GLOBALS->initial_window_width = x;
  2796.       GLOBALS->initial_window_height = y;
  2797.     }
  2798.   else
  2799.     {
  2800. #ifdef WAVE_USE_XID
  2801.       if(!GLOBALS->socket_xid)
  2802. #endif
  2803.     {
  2804. #ifdef MAC_INTEGRATION
  2805.         gtk_window_resize(GTK_WINDOW (GLOBALS->mainwindow), x, y);
  2806. #else
  2807.         gtk_window_set_default_size(GTK_WINDOW (GLOBALS->mainwindow), x, y);
  2808. #endif
  2809.     }
  2810.     }
  2811. }
  2812.  
  2813.  
  2814. void
  2815. get_window_xypos(int *root_x, int *root_y)
  2816. {
  2817. if(!GLOBALS->mainwindow) return;
  2818.  
  2819. #ifdef WAVE_USE_GTK2
  2820. gtk_window_get_position(GTK_WINDOW(GLOBALS->mainwindow), root_x, root_y);
  2821.  
  2822. if(!GLOBALS->initial_window_get_valid)
  2823.     {
  2824.     if((GLOBALS->mainwindow->window))
  2825.         {
  2826.         GLOBALS->initial_window_get_valid = 1;
  2827.         GLOBALS->initial_window_xpos_get = *root_x;
  2828.         GLOBALS->initial_window_ypos_get = *root_y;
  2829.  
  2830.         GLOBALS->xpos_delta = GLOBALS->initial_window_xpos_set - GLOBALS->initial_window_xpos_get;
  2831.         GLOBALS->ypos_delta = GLOBALS->initial_window_ypos_set - GLOBALS->initial_window_ypos_get;
  2832.         }
  2833.     }
  2834. #else
  2835. *root_x = *root_y = -1;
  2836. #endif
  2837. }
  2838.  
  2839. void
  2840. set_window_xypos(int root_x, int root_y)
  2841. {
  2842. #ifdef MAC_INTEGRATION
  2843. if(GLOBALS->num_notebook_pages > 1) return;
  2844. #else
  2845. if(GLOBALS->xy_ignore_main_c_1) return;
  2846. #endif
  2847.  
  2848. #if !defined __MINGW32__ && !defined _MSC_VER
  2849. GLOBALS->initial_window_xpos = root_x;
  2850. GLOBALS->initial_window_ypos = root_y;
  2851.  
  2852. if(!GLOBALS->mainwindow) return;
  2853. if((GLOBALS->initial_window_xpos>=0)||(GLOBALS->initial_window_ypos>=0))
  2854.     {
  2855.     if (GLOBALS->initial_window_xpos<0) { GLOBALS->initial_window_xpos = 0; }
  2856.     if (GLOBALS->initial_window_ypos<0) { GLOBALS->initial_window_ypos = 0; }
  2857. #ifdef WAVE_USE_GTK2
  2858.     gtk_window_move(GTK_WINDOW(GLOBALS->mainwindow), GLOBALS->initial_window_xpos, GLOBALS->initial_window_ypos);
  2859. #else
  2860.     gtk_window_reposition(GTK_WINDOW(GLOBALS->mainwindow), GLOBALS->initial_window_xpos, GLOBALS->initial_window_ypos);
  2861. #endif
  2862.  
  2863.     if(!GLOBALS->initial_window_set_valid)
  2864.         {
  2865.         GLOBALS->initial_window_set_valid = 1;
  2866.         GLOBALS->initial_window_xpos_set = GLOBALS->initial_window_xpos;
  2867.         GLOBALS->initial_window_ypos_set = GLOBALS->initial_window_ypos;
  2868.         }
  2869.     }
  2870. #endif
  2871. }
  2872.  
  2873.  
  2874. /*
  2875.  * bring up stems browser
  2876.  */
  2877. #if !defined _MSC_VER
  2878. int stems_are_active(void)
  2879. {
  2880. #ifdef __MINGW32__
  2881. if(GLOBALS->anno_ctx && GLOBALS->anno_ctx->browser_process)
  2882.     {
  2883.     /* nothing */
  2884.     return(1);
  2885.     }
  2886. #else
  2887. if(GLOBALS->anno_ctx && GLOBALS->anno_ctx->browser_process)
  2888.     {
  2889.     int mystat =0;
  2890.     pid_t pid = waitpid(GLOBALS->anno_ctx->browser_process, &mystat, WNOHANG);
  2891.     if(!pid)
  2892.         {
  2893.         status_text("Stems reader already active.\n");
  2894.         return(1);
  2895.         }
  2896.         else
  2897.         {
  2898.         shmdt((void *)GLOBALS->anno_ctx);
  2899.         GLOBALS->anno_ctx = NULL;
  2900.         }
  2901.     }
  2902. #endif
  2903. return(0);
  2904. }
  2905. #endif
  2906.  
  2907.  
  2908. void activate_stems_reader(char *stems_name)
  2909. {
  2910. #if !defined _MSC_VER
  2911.  
  2912. #ifdef __CYGWIN__
  2913. /* ajb : ok static as this is a one-time warning message... */
  2914. static int cyg_called = 0;
  2915. #endif
  2916.  
  2917. if(!stems_name) return;
  2918.  
  2919. #ifdef __CYGWIN__
  2920. if(GLOBALS->stems_type != WAVE_ANNO_NONE)
  2921.     {
  2922.     if(!cyg_called)
  2923.         {
  2924.         char *cygserver_env = getenv("CYGWIN");
  2925.         gboolean found = cygserver_env && (strstr(cygserver_env, "server") != NULL);
  2926.  
  2927.         if(!found)
  2928.             {
  2929.             fprintf(stderr, "GTKWAVE | =================================================================\n");
  2930.             fprintf(stderr, "GTKWAVE | If the viewer crashes with a Bad system call error,\n");
  2931.             fprintf(stderr, "GTKWAVE | make sure that Cygserver is enabled.\n");
  2932.             fprintf(stderr, "GTKWAVE | The Cygserver services are used by Cygwin applications only\n");
  2933.             fprintf(stderr, "GTKWAVE | if you set the environment variable CYGWIN to contain the\n");
  2934.             fprintf(stderr, "GTKWAVE | string \"server\". You must do this before starting this program.\n");
  2935.             fprintf(stderr, "GTKWAVE |\n");
  2936.             fprintf(stderr, "GTKWAVE | If this still does not work, you may have to enable the cygserver\n");
  2937.             fprintf(stderr, "GTKWAVE | by entering \"cygserver-config\" and answering \"yes\" followed by\n");
  2938.             fprintf(stderr, "GTKWAVE | \"net start cygserver\".\n");
  2939.             fprintf(stderr, "GTKWAVE | =================================================================\n");
  2940.             }
  2941.         cyg_called = 1;
  2942.         }
  2943.     }
  2944. #endif
  2945.  
  2946. if(GLOBALS->stems_type != WAVE_ANNO_NONE)
  2947.     {
  2948. #ifdef __MINGW32__
  2949.     int shmid = getpid();
  2950.     char mapName[257];
  2951.     HANDLE hMapFile;
  2952.         STARTUPINFO si;
  2953.         PROCESS_INFORMATION pi;
  2954.         BOOL rc;
  2955.  
  2956.         memset(&si, 0, sizeof(STARTUPINFO));
  2957.         memset(&pi, 0, sizeof(PROCESS_INFORMATION));
  2958.     si.cb = sizeof(si);
  2959.  
  2960.     sprintf(mapName, "rtlbrowse%d", shmid);
  2961.     hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(struct gtkwave_annotate_ipc_t), mapName);
  2962.     if(hMapFile != NULL)
  2963.             {
  2964.             GLOBALS->anno_ctx = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(struct gtkwave_annotate_ipc_t));
  2965.         if(GLOBALS->anno_ctx)
  2966.             {
  2967.             char mylist[257];
  2968.  
  2969.                         sprintf(mylist, "rtlbrowse.exe %08x", shmid);
  2970.  
  2971.             memset(GLOBALS->anno_ctx, 0, sizeof(struct gtkwave_annotate_ipc_t));
  2972.  
  2973.             memcpy(GLOBALS->anno_ctx->matchword, WAVE_MATCHWORD, 4);
  2974.             GLOBALS->anno_ctx->aet_type = GLOBALS->stems_type;
  2975.             strcpy(GLOBALS->anno_ctx->aet_name, GLOBALS->aet_name);
  2976.             strcpy(GLOBALS->anno_ctx->stems_name, stems_name);
  2977.  
  2978.             update_markertime(GLOBALS->tims.marker);
  2979.  
  2980.                         rc = CreateProcess(
  2981.                                         "rtlbrowse.exe",
  2982.                                         mylist,
  2983.                                         NULL,
  2984.                                         NULL,
  2985.                                         FALSE,
  2986.                                         0,
  2987.                                         NULL,
  2988.                                         NULL,
  2989.                                         &si,
  2990.                                         &pi);
  2991.  
  2992.                         if(!rc)
  2993.                             {
  2994.                 UnmapViewOfFile(GLOBALS->anno_ctx);
  2995.                 CloseHandle(hMapFile);
  2996.                 GLOBALS->anno_ctx = NULL;
  2997.                 GLOBALS->stems_type = WAVE_ANNO_NONE;
  2998.                                 }
  2999.                 else
  3000.                 {
  3001.                 GLOBALS->anno_ctx->browser_process = pi.hProcess;
  3002.                 }
  3003.             }
  3004.             else
  3005.             {
  3006.             CloseHandle(hMapFile);
  3007.             GLOBALS->stems_type = WAVE_ANNO_NONE;
  3008.             }
  3009.         }
  3010. #else
  3011.     int shmid = shmget(0, sizeof(struct gtkwave_annotate_ipc_t), IPC_CREAT | 0600 );
  3012.     if(shmid >=0)
  3013.         {
  3014.         struct shmid_ds ds;
  3015.  
  3016.         GLOBALS->anno_ctx = shmat(shmid, NULL, 0);
  3017.         if(GLOBALS->anno_ctx)
  3018.             {
  3019.             pid_t pid;
  3020.  
  3021.             memset(GLOBALS->anno_ctx, 0, sizeof(struct gtkwave_annotate_ipc_t));
  3022.  
  3023.             memcpy(GLOBALS->anno_ctx->matchword, WAVE_MATCHWORD, 4);
  3024.             GLOBALS->anno_ctx->aet_type = GLOBALS->stems_type;
  3025.             strcpy(GLOBALS->anno_ctx->aet_name, GLOBALS->aet_name);
  3026.             strcpy(GLOBALS->anno_ctx->stems_name, stems_name);
  3027.  
  3028.             GLOBALS->anno_ctx->gtkwave_process = getpid();
  3029.             update_markertime(GLOBALS->tims.marker);
  3030.  
  3031. #ifdef __linux__
  3032.             shmctl(shmid, IPC_RMID, &ds); /* mark for destroy */
  3033. #endif
  3034.  
  3035.                 pid=fork();
  3036.  
  3037.                 if(((int)pid) < 0)
  3038.                 {
  3039.                 /* can't do anything about this */
  3040.                 }
  3041.                 else
  3042.                 {
  3043.                     if(pid) /* parent==original server_pid */
  3044.                             {
  3045. #ifndef __CYGWIN__
  3046.                     static int kill_installed = 0;
  3047.  
  3048.                     if(!kill_installed)
  3049.                         {
  3050.                         kill_installed = 1;
  3051.                         atexit(kill_stems_browser);
  3052.                         }
  3053. #endif
  3054.                     GLOBALS->anno_ctx->browser_process = pid;
  3055. #ifndef __linux__
  3056.                     sleep(2);
  3057.                     shmctl(shmid, IPC_RMID, &ds); /* mark for destroy */
  3058. #endif
  3059.                             }
  3060.                     else
  3061.                     {
  3062.                     char buf[64];
  3063. #ifdef MAC_INTEGRATION
  3064.                     const gchar *p = gtkosx_application_get_executable_path();
  3065. #endif
  3066.                     sprintf(buf, "%08x", shmid);
  3067.  
  3068. #ifdef MAC_INTEGRATION
  3069.                     if(p && strstr(p, "Contents/"))
  3070.                         {
  3071.                         const char *xec = "../Resources/bin/rtlbrowse";
  3072.                         char *res = strdup_2(p);
  3073.                         char *slsh = strrchr(res, '/');
  3074.                         if(slsh)
  3075.                             {
  3076.                             *(slsh+1) = 0;
  3077.                             res = realloc_2(res, strlen(res) + strlen(xec) + 1);
  3078.                             strcat(res, xec);
  3079.                                 execlp(res, "rtlbrowse", buf, NULL);
  3080.                             fprintf(stderr, "GTKWAVE | Could not find '%s' in .app!\n", res);
  3081.                             free_2(res);
  3082.                             }
  3083.                         }
  3084. #endif
  3085.                         execlp("rtlbrowse", "rtlbrowse", buf, NULL);
  3086.                     fprintf(stderr, "GTKWAVE | Could not find rtlbrowse executable, exiting!\n");
  3087.                         exit(255); /* control never gets here if successful */
  3088.                     }
  3089.                 }
  3090.             }
  3091.             else
  3092.             {
  3093.             shmctl(shmid, IPC_RMID, &ds); /* actually destroy */
  3094.             GLOBALS->stems_type = WAVE_ANNO_NONE;
  3095.             }
  3096.         }
  3097. #endif
  3098.     }
  3099.     else
  3100.     {
  3101.     fprintf(stderr, "GTKWAVE | Unsupported dumpfile type for rtlbrowse.\n");
  3102.     }
  3103. #endif
  3104. }
  3105.  
  3106.  
  3107. #if !defined _MSC_VER && !defined __MINGW32__
  3108. void optimize_vcd_file(void) {
  3109.   if(!strcmp("-vcd", GLOBALS->unoptimized_vcd_file_name)) {
  3110. #ifdef __CYGWIN__
  3111.     char *buf = strdup_2("vcd2fst -- - vcd.fst");
  3112.     system(buf);
  3113.     free_2(buf);
  3114.     GLOBALS->loaded_file_name = strdup_2("vcd.fst");
  3115.     GLOBALS->is_optimized_stdin_vcd = 1;
  3116. #else
  3117.     pid_t pid;
  3118.     char *buf = malloc_2(strlen("vcd") + 4 + 1);
  3119.     sprintf(buf, "%s.fst", "vcd");
  3120.     pid = fork();
  3121.     if(((int)pid) < 0) {
  3122.       /* can't do anything about this */
  3123.     }
  3124.     else {
  3125.       if(pid) {
  3126.         int mystat;
  3127.         int rc = waitpid(pid, &mystat, 0);
  3128.     if(rc > 0) {
  3129.       free_2(GLOBALS->loaded_file_name);
  3130.       GLOBALS->loaded_file_name = buf;
  3131.       GLOBALS->is_optimized_stdin_vcd = 1;
  3132.     }
  3133.       }
  3134.       else {
  3135.         execlp("vcd2fst", "vcd2fst", "--", "-", buf, NULL);
  3136.     exit(255);
  3137.       }
  3138.     }
  3139. #endif
  3140.   }
  3141.   else {
  3142. #ifdef __CYGWIN__
  3143.     char *buf = malloc_2(9 + (strlen(GLOBALS->unoptimized_vcd_file_name) + 1) + (strlen(GLOBALS->unoptimized_vcd_file_name) + 4 + 1));
  3144.     sprintf(buf, "vcd2fst %s %s.fst", GLOBALS->unoptimized_vcd_file_name, GLOBALS->unoptimized_vcd_file_name);
  3145.     system(buf);
  3146.     free_2(buf);
  3147.     buf = malloc_2(strlen(GLOBALS->unoptimized_vcd_file_name) + 4 + 1);
  3148.     sprintf(buf, "%s.fst", GLOBALS->unoptimized_vcd_file_name);
  3149.     GLOBALS->loaded_file_name = buf;
  3150. #else
  3151.     pid_t pid;
  3152.     char *buf = malloc_2(strlen(GLOBALS->unoptimized_vcd_file_name) + 4 + 1);
  3153.     sprintf(buf, "%s.fst", GLOBALS->unoptimized_vcd_file_name);
  3154.     pid = fork();
  3155.     if(((int)pid) < 0) {
  3156.       /* can't do anything about this */
  3157.     }
  3158.     else {
  3159.       if(pid) {
  3160.     int mystat;
  3161.     int rc = waitpid(pid, &mystat, 0);
  3162.         if(rc > 0) {
  3163.           free_2(GLOBALS->loaded_file_name);
  3164.       GLOBALS->loaded_file_name = buf;
  3165.         }
  3166.       }
  3167.       else {
  3168. #ifdef MAC_INTEGRATION
  3169.     const gchar *p = gtkosx_application_get_executable_path();
  3170.     if(p && strstr(p, "Contents/"))
  3171.         {
  3172.         const char *xec = "../Resources/bin/vcd2fst";
  3173.         char *res = strdup_2(p);
  3174.         char *slsh = strrchr(res, '/');
  3175.         if(slsh)
  3176.             {
  3177.             *(slsh+1) = 0;
  3178.             res = realloc_2(res, strlen(res) + strlen(xec) + 1);
  3179.             strcat(res, xec);
  3180.                 execlp(res, "vcd2fst", GLOBALS->unoptimized_vcd_file_name, buf, NULL);
  3181.             fprintf(stderr, "GTKWAVE | Could not find '%s' in .app!\n", res);
  3182.             free_2(res);
  3183.             }
  3184.         }
  3185. #endif
  3186.         execlp("vcd2fst", "vcd2fst", GLOBALS->unoptimized_vcd_file_name, buf, NULL);
  3187.     fprintf(stderr, "GTKWAVE | Could not find vcd2fst executable, exiting!\n");
  3188.     exit(255);
  3189.       }
  3190.     }
  3191. #endif
  3192.   }
  3193. }
  3194. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement