From 3f017074be8659737e258d3a4fbd5312e7d0197f Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Sat, 15 Jan 2022 13:19:06 +0100 Subject: [PATCH] load multiple files from command line, in tabbed or foating windows mode --- src/globals.c | 2 ++ src/main.c | 43 ++++++++++++++----------------------------- src/xinit.c | 14 +++++++++++++- src/xschem.h | 2 ++ 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/globals.c b/src/globals.c index 280081ca..fb61e655 100644 --- a/src/globals.c +++ b/src/globals.c @@ -195,6 +195,8 @@ const char fopen_read_mode[] = "r"; /* ---------------------------------------------------------- */ /* Cmdline options (used at xinit, and then not used anymore) */ /* ---------------------------------------------------------- */ +int cli_opt_argc; +char **cli_opt_argv = NULL; int cli_opt_netlist_type = 0; int cli_opt_flat_netlist = 0; char cli_opt_plotfile[PATH_MAX] = ""; diff --git a/src/main.c b/src/main.c index 8024d57e..60e6c9c3 100644 --- a/src/main.c +++ b/src/main.c @@ -68,6 +68,7 @@ void child_handler(int signum) int main(int argc, char **argv) { + int i; my_strdup(45, &xschem_executable, argv[0]); signal(SIGINT, sig_handler); signal(SIGSEGV, sig_handler); @@ -81,40 +82,24 @@ int main(int argc, char **argv) #ifdef __unix__ if(!getenv("DISPLAY") || !getenv("DISPLAY")[0]) has_x=0; #endif - process_options(argc, argv); + argc = process_options(argc, argv); if(debug_var>=1 && !has_x) fprintf(errfp, "main(): no DISPLAY set, assuming no X available\n"); - - -#if 0 -/* detach from console (fork a child and close std file descriptors) */ - if(detach) { -#ifdef __unix__ - pid_t pid = fork(); - if(pid < 0) { - fprintf(errfp, "main(): fork() failed\n"); - exit(EXIT_FAILURE); - } - if(pid == 0) { - /* The child becomes the daemon. */ - /* Detach all standard I/O descriptors */ - close(0); /* stdin */ - close(1); /* stdout */ - close(2); /* stderr */ - setsid(); /* new session */ - /* Ok, now detached */ - } - else { - /* terminate parent */ - exit(0); - } -#endif - } -#endif - /* if detach is 1 no interactive command shell is created ... * using detach if no windowing exists (has_x == 0) is non sense so do nothing */ + + + + cli_opt_argc = argc; + cli_opt_argv = my_malloc(291, cli_opt_argc * sizeof(char *)); + for(i = 0; i < cli_opt_argc; i++) { + cli_opt_argv[i] = NULL; + my_strdup(374, &cli_opt_argv[i], argv[i]); + } + + + if(detach && has_x) { Tcl_FindExecutable(argv[0]); /* tcl stores executable name for its internal usage */ interp = Tcl_CreateInterp(); /* create the tcl interpreter */ diff --git a/src/xinit.c b/src/xinit.c index 5d0acf01..215f891c 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -695,6 +695,11 @@ void xwin_exit(void) dbg(1, "xwin_exit(): deleted undo buffer\n"); if(errfp!=stderr) fclose(errfp); errfp=stderr; + /* delete cmdline stuff */ + for(i = 0 ; i < cli_opt_argc; i++) { + my_free(1141, &cli_opt_argv[i]); + } + my_free(1464, &cli_opt_argv); if(!detach) printf("\n"); init_done=0; /* 20150409 to avoid multiple calls */ } @@ -1213,7 +1218,7 @@ static void destroy_window(int *window_count, const char *win_path) savectx = xctx; if(*window_count) { int close = 0; - dbg(0, "new_schematic() destroy {%s}\n", win_path); + dbg(1, "new_schematic() destroy {%s}\n", win_path); if(xctx->modified && has_x) { tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] -message \"" "[get_cell [xschem get schname] 0]" @@ -2336,6 +2341,13 @@ int Tcl_AppInit(Tcl_Interp *inter) tcleval("exit"); } + + /* load additional files */ + for(i = 2; i < cli_opt_argc; i++) { + tclvareval("xschem load_new_window ", cli_opt_argv[i], NULL); + } + + /* */ /* END PROCESSING USER OPTIONS */ /* */ diff --git a/src/xschem.h b/src/xschem.h index 5a37c224..f572f239 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -997,6 +997,8 @@ extern int detach; /* no TCL console */ extern const char fopen_read_mode[]; /* "r" on unix, "rb" on windows */ /*********** Cmdline options (used at xinit, and then not used anymore) ***********/ +extern int cli_opt_argc; +extern char **cli_opt_argv; extern int cli_opt_netlist_type; extern int cli_opt_flat_netlist; extern char cli_opt_plotfile[PATH_MAX];