From baea7ab745d1773ad56f51090607b149c37f11bc Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Wed, 6 Sep 2023 08:30:40 +0200 Subject: [PATCH] xschem switch command return exit status depending if switch context was successfull or not --- src/scheduler.c | 5 +++-- src/xinit.c | 30 +++++++++++++++++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/scheduler.c b/src/scheduler.c index 88cd8700..3c1d2b8b 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -3833,8 +3833,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg */ else if(!strcmp(argv[1], "switch")) { - if(argc > 2) new_schematic("switch", argv[2], NULL); - Tcl_SetResult(interp, my_itoa(get_window_count()), TCL_VOLATILE); + int r; + if(argc > 2) r = new_schematic("switch", argv[2], NULL); + Tcl_SetResult(interp, my_itoa(r), TCL_VOLATILE); } /* symbols [n] diff --git a/src/xinit.c b/src/xinit.c index e913180b..5d79f2dd 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1386,21 +1386,21 @@ int check_loaded(const char *f, char *win_path) return found; } -static void switch_window(int *window_count, const char *win_path, int tcl_ctx) +static int switch_window(int *window_count, const char *win_path, int tcl_ctx) { int n; char my_win_path[80]; Tk_Window tkwin=NULL; if(!win_path) { dbg(0, "switch_window(): no filename or window path given\n"); - return; + return 1; } - if(!strcmp(win_path, xctx->current_win_path)) return; /* already there */ + if(!strcmp(win_path, xctx->current_win_path)) return 1; /* already there */ if(*window_count) { n = get_tab_or_window_number(win_path); if(n == -1) { dbg(0, "new_schematic(\"switch\"...): no window to switch to found: %s\n", win_path); - return; + return 1; } /* build my_win_path since win_path can also be a filename */ if(n == 0) my_snprintf(my_win_path, S(my_win_path), ".drw"); @@ -1419,27 +1419,31 @@ static void switch_window(int *window_count, const char *win_path, int tcl_ctx) tclvareval("housekeeping_ctx", NULL); if(tcl_ctx && has_x) tclvareval("reconfigure_layers_button {}", NULL); set_modify(-1); /* sets window title */ + return 0; } + } else { + dbg(0, "No additional windows are present\n"); } + return 1; } -static void switch_tab(int *window_count, const char *win_path) +static int switch_tab(int *window_count, const char *win_path) { int n; dbg(1, "switch_tab(): win_path=%s\n", win_path); - if(xctx->semaphore) return; /* some editing operation ongoing. do nothing */ + if(xctx->semaphore) return 1; /* some editing operation ongoing. do nothing */ if(!win_path) { dbg(0, "switch_tab(): no filename or window path given\n"); - return; + return 1; } - if(!strcmp(win_path, xctx->current_win_path)) return; /* already there */ + if(!strcmp(win_path, xctx->current_win_path)) return 1; /* already there */ if(*window_count) { dbg(1, "new_schematic() switch_tab: %s\n", win_path); n = get_tab_or_window_number(win_path); if(n == -1) { dbg(0, "new_schematic(\"switch_tab\"...): no tab to switch to found: %s\n", win_path); - return; + return 1; } /* if no matching tab found --> do nothing */ if(n >= 0 && n < MAX_NEW_WINDOWS) { @@ -1452,8 +1456,12 @@ static void switch_tab(int *window_count, const char *win_path) resetwin(1, 1, 1, 0, 0); set_modify(-1); /* sets window title */ draw(); + return 0; } + } else { + dbg(0, "No tabs are present\n"); } + return 1; } /* non NULL and not empty noconfirm is used to avoid warning for duplicated filenames */ @@ -1908,8 +1916,8 @@ int new_schematic(const char *what, const char *win_path, const char *fname) destroy_all_tabs(&window_count, (win_path && win_path[0]) ? 1 : 0); } } else if(!strcmp(what, "switch")) { - if(tabbed_interface) switch_tab(&window_count, win_path); - else switch_window(&window_count, win_path, 1); + if(tabbed_interface) return switch_tab(&window_count, win_path); + else return switch_window(&window_count, win_path, 1); } else if(!strcmp(what, "switch_no_tcl_ctx") && !tabbed_interface) { switch_window(&window_count, win_path, 0); }