From c7b9e8206f7219f350b0c90677bfeaa360b36870 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Sat, 15 Jan 2022 23:35:37 +0100 Subject: [PATCH] various checks to prevent multiple file loading if no X or -x option used, put xpm header in icon.c so it can be opened by image viewers --- src/icon.c | 2 +- src/scheduler.c | 21 ++++++++++++--------- src/track_memory.awk | 2 +- src/xinit.c | 9 +++++---- src/xschem.tcl | 8 ++++++++ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/icon.c b/src/icon.c index b2b2f507..10191eee 100644 --- a/src/icon.c +++ b/src/icon.c @@ -1,3 +1,4 @@ +/* XPM */ /* File: icon.c * * This file is part of XSCHEM, @@ -20,7 +21,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* XPM */ char *cad_icon[] = { /* columns rows colors chars-per-pixel */ "56 42 6 1 ", diff --git a/src/scheduler.c b/src/scheduler.c index a3fc0ad4..987dc752 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1591,17 +1591,20 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1],"load_new_window") ) { char fullname[PATH_MAX]; - cmd_found = 1; - if(argc>=3) { - my_snprintf(fullname, S(fullname),"%s", argv[2]); + if(has_x) { + if(argc>=3) { + my_snprintf(fullname, S(fullname),"%s", argv[2]); + } else { + tcleval("load_file_dialog {Load file} .sch.sym INITIALLOADDIR"); + my_snprintf(fullname, S(fullname),"%s", tclresult()); + } + if( fullname[0] ) { + new_schematic("create", NULL, fullname); + tclvareval("update_recent_file {", fullname, "}", NULL); + } } else { - tcleval("load_file_dialog {Load file} .sch.sym INITIALLOADDIR"); - my_snprintf(fullname, S(fullname),"%s", tclresult()); - } - if( fullname[0] ) { - new_schematic("create", NULL, fullname); - tclvareval("update_recent_file {", fullname, "}", NULL); + Tcl_ResetResult(interp); } } else if(!strcmp(argv[1],"log")) diff --git a/src/track_memory.awk b/src/track_memory.awk index 5eca8f0b..c6643b58 100755 --- a/src/track_memory.awk +++ b/src/track_memory.awk @@ -75,7 +75,7 @@ END{ leak+= address[i] print " address[ " i ", " idx[i] " ]= " address[i] if(show_source) { - pipe = "egrep -n 'my_(malloc|calloc|realloc|free|strdup|strdup2)\(" idx[i] ",' *.c xschem.h" + pipe = "egrep -n 'my_(malloc|calloc|realloc|free|strdup|strdup2)\\(" idx[i] ",' *.c xschem.h" while( pipe | getline a) print " " a close(pipe) } diff --git a/src/xinit.c b/src/xinit.c index 215f891c..fa259299 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -693,13 +693,13 @@ void xwin_exit(void) my_free(1143, &xschem_executable); record_global_node(2, NULL, NULL); /* delete global node array */ 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(errfp!=stderr) fclose(errfp); + errfp=stderr; if(!detach) printf("\n"); init_done=0; /* 20150409 to avoid multiple calls */ } @@ -1421,6 +1421,7 @@ int new_schematic(const char *what, const char *win_path, const char *fname) int tabbed_interface; const char *tmp; + if(!has_x) return 0; tabbed_interface = 0; if((tmp = tclgetvar("tabbed_interface"))) { if(tmp[0] == '1') tabbed_interface = 1; @@ -1999,7 +2000,7 @@ int Tcl_AppInit(Tcl_Interp *inter) { pixdata[i]=my_calloc(642, 32, sizeof(char)); } - pixmap=my_calloc(636, cadlayers, sizeof(Pixmap)); + if(has_x) pixmap=my_calloc(636, cadlayers, sizeof(Pixmap)); my_strncpy(xctx->plotfile, cli_opt_plotfile, S(xctx->plotfile)); xctx->draw_window = tclgetintvar("draw_window"); @@ -2343,7 +2344,7 @@ int Tcl_AppInit(Tcl_Interp *inter) /* load additional files */ - for(i = 2; i < cli_opt_argc; i++) { + if(has_x) for(i = 2; i < cli_opt_argc; i++) { tclvareval("xschem load_new_window ", cli_opt_argv[i], NULL); } diff --git a/src/xschem.tcl b/src/xschem.tcl index c594cba7..b2e12ce0 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -3961,6 +3961,8 @@ set tctx::global_array_list { } proc delete_ctx {context} { + global has_x + if {![info exists $has_x]} {return} set tctx::tctx $context uplevel #0 { # puts "delete_ctx $tctx::tctx" @@ -3975,6 +3977,8 @@ proc delete_ctx {context} { proc restore_ctx {context} { # puts "restoring tcl context $context : semaphore=[xschem get semaphore]" + global has_x + if {![info exists $has_x]} {return} set tctx::tctx $context array unset ::sim uplevel #0 { @@ -3998,6 +4002,8 @@ proc restore_ctx {context} { proc save_ctx {context} { # puts "saving tcl context $context : semaphore=[xschem get semaphore]" + global has_x + if {![info exists $has_x]} {return} set tctx::tctx $context uplevel #0 { # puts "save_ctx $tctx::tctx" @@ -4015,6 +4021,8 @@ proc save_ctx {context} { } proc housekeeping_ctx {} { + global has_x + if {![info exists $has_x]} {return} uplevel #0 { # puts housekeeping_ctx }