From e449543805e7a795efdc35aec87618fc99e7be32 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Sun, 5 Dec 2021 12:39:05 +0100 Subject: [PATCH] tclvareval() wrapper --- src/actions.c | 24 ++++++++++++------------ src/callback.c | 38 +++++++++++++++++++------------------- src/draw.c | 4 ++-- src/hilight.c | 38 +++++++++++++++++++------------------- src/in_memory_undo.c | 6 +++--- src/psprint.c | 4 ++-- src/save.c | 18 +++++++++--------- src/scheduler.c | 39 ++++++++++++++++++++++++++++++--------- src/svgdraw.c | 4 ++-- src/token.c | 2 +- src/xinit.c | 22 +++++++++++----------- src/xschem.h | 1 + 12 files changed, 111 insertions(+), 89 deletions(-) diff --git a/src/actions.c b/src/actions.c index 930a16bf..25125b30 100644 --- a/src/actions.c +++ b/src/actions.c @@ -41,11 +41,11 @@ void set_modify(int mod) xctx->prev_set_modify = mod; if(has_x && strcmp(get_cell(xctx->sch[xctx->currsch],1), "systemlib/font")) { if(mod == 1) { - Tcl_VarEval(interp, "wm title ", top_path, " \"xschem - [file tail [xschem get schname]]*\"", NULL); - Tcl_VarEval(interp, "wm iconname ", top_path, " \"xschem - [file tail [xschem get schname]]*\"", NULL); + tclvareval("wm title ", top_path, " \"xschem - [file tail [xschem get schname]]*\"", NULL); + tclvareval("wm iconname ", top_path, " \"xschem - [file tail [xschem get schname]]*\"", NULL); } else { - Tcl_VarEval(interp, "wm title ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); - Tcl_VarEval(interp, "wm iconname ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); + tclvareval("wm title ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); + tclvareval("wm iconname ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); } } } @@ -120,9 +120,9 @@ void set_snap(double newsnap) /* 20161212 set new snap factor and just notify n } cs = newsnap ? newsnap : default_snap; if(cs == default_snap) { - Tcl_VarEval(interp, xctx->top_path, ".statusbar.3 configure -background PaleGreen", NULL); + tclvareval(xctx->top_path, ".statusbar.3 configure -background PaleGreen", NULL); } else { - Tcl_VarEval(interp, xctx->top_path, ".statusbar.3 configure -background OrangeRed", NULL); + tclvareval(xctx->top_path, ".statusbar.3 configure -background OrangeRed", NULL); } tclsetdoublevar("cadsnap", cs); } @@ -140,9 +140,9 @@ void set_grid(double newgrid) cg = newgrid ? newgrid : default_grid; dbg(1, "set_grid(): default_grid = %.16g, cadgrid=%.16g\n", default_grid, cg); if(cg == default_grid) { - Tcl_VarEval(interp, xctx->top_path, ".statusbar.5 configure -background PaleGreen", NULL); + tclvareval(xctx->top_path, ".statusbar.5 configure -background PaleGreen", NULL); } else { - Tcl_VarEval(interp, xctx->top_path, ".statusbar.5 configure -background OrangeRed", NULL); + tclvareval(xctx->top_path, ".statusbar.5 configure -background OrangeRed", NULL); } tclsetdoublevar("cadgrid", cg); } @@ -389,7 +389,7 @@ void saveas(const char *f, int type) /* changed name from ask_save_file to save if(!res[0]) return; dbg(1, "saveas(): res = %s\n", res); save_schematic(res); - Tcl_VarEval(interp, "update_recent_file {", res,"}", NULL); + tclvareval("update_recent_file {", res,"}", NULL); my_strncpy(xctx->current_name, rel_sym_path(res), S(xctx->current_name)); return; @@ -415,7 +415,7 @@ void ask_new_file(void) unselect_all(); remove_symbols(); load_schematic(1, fullname,1); /* 20180925.1 */ - Tcl_VarEval(interp, "update_recent_file {", fullname, "}", NULL); + tclvareval("update_recent_file {", fullname, "}", NULL); my_strdup(1, &xctx->sch_path[xctx->currsch],"."); xctx->sch_path_hash[xctx->currsch] = 0; xctx->sch_inst_number[xctx->currsch] = 1; @@ -983,7 +983,7 @@ void launcher(void) url = get_tok_value(xctx->inst[n].prop_ptr,"url",0); /* handle backslashes */ dbg(1, "launcher(): url=%s\n", url); if(url[0] || (program[0])) { /* open url with appropriate program */ - Tcl_VarEval(interp, "launcher {", url, "} {", program, "}", NULL); + tclvareval("launcher {", url, "} {", program, "}", NULL); } else { my_strncpy(program, get_tok_value(xctx->inst[n].prop_ptr,"tclcommand",0), S(program)); if(program[0]) { /* execute tcl command */ @@ -1071,7 +1071,7 @@ void descend_schematic(int instnumber) if(instnumber <= 0 ) { const char *inum; - Tcl_VarEval(interp, "input_line ", "{input instance number (leftmost = 1) to descend into:\n" + tclvareval("input_line ", "{input instance number (leftmost = 1) to descend into:\n" "negative numbers select instance starting\nfrom the right (rightmost = -1)}" " {} 1 6", NULL); inum = tclresult(); diff --git a/src/callback.c b/src/callback.c index b7cf64ea..0754b95b 100644 --- a/src/callback.c +++ b/src/callback.c @@ -84,7 +84,7 @@ void start_place_symbol(double mx, double my) xctx->last_command = 0; rebuild_selected_array(); if(xctx->lastsel && xctx->sel_array[0].type==ELEMENT) { - Tcl_VarEval(interp, "set INITIALINSTDIR [file dirname {", + tclvareval("set INITIALINSTDIR [file dirname {", abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""), "}]", NULL); } unselect_all(); @@ -157,28 +157,28 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, #ifndef __unix__ if(cstate & 0x0001) { /* caps lock */ - Tcl_VarEval(interp, xctx->top_path, ".statusbar.8 configure -state active -text {CAPS LOCK SET! }", NULL); + tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {CAPS LOCK SET! }", NULL); } else if (nstate & 0x0001) { /* num lock */ - Tcl_VarEval(interp, xctx->top_path, ".statusbar.8 configure -state active -text {NUM LOCK SET! }", NULL); + tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {NUM LOCK SET! }", NULL); } else { /* normal state */ - Tcl_VarEval(interp, xctx->top_path, ".statusbar.8 configure -state normal -text {}", NULL); + tclvareval(xctx->top_path, ".statusbar.8 configure -state normal -text {}", NULL); } #else XGetKeyboardControl(display, &kbdstate); if(kbdstate.led_mask & 1) { /* caps lock */ - Tcl_VarEval(interp, xctx->top_path, ".statusbar.8 configure -state active -text {CAPS LOCK SET! }", NULL); + tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {CAPS LOCK SET! }", NULL); } else if(kbdstate.led_mask & 2) { /* num lock */ - Tcl_VarEval(interp, xctx->top_path, ".statusbar.8 configure -state active -text {NUM LOCK SET! }", NULL); + tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {NUM LOCK SET! }", NULL); } else { /* normal state */ - Tcl_VarEval(interp, xctx->top_path, ".statusbar.8 configure -state normal -text {}", NULL); + tclvareval(xctx->top_path, ".statusbar.8 configure -state normal -text {}", NULL); } #endif - Tcl_VarEval(interp, xctx->top_path, ".statusbar.7 configure -text $netlist_type", NULL); - Tcl_VarEval(interp, xctx->top_path, ".statusbar.3 delete 0 end;", + tclvareval(xctx->top_path, ".statusbar.7 configure -text $netlist_type", NULL); + tclvareval(xctx->top_path, ".statusbar.3 delete 0 end;", xctx->top_path, ".statusbar.3 insert 0 $cadsnap", NULL); - Tcl_VarEval(interp, xctx->top_path, ".statusbar.5 delete 0 end;", + tclvareval(xctx->top_path, ".statusbar.5 delete 0 end;", xctx->top_path, ".statusbar.5 insert 0 $cadgrid", NULL); @@ -196,9 +196,9 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, redraw_only = 1; } else { dbg(1, "callback(): switching window context: %s --> %s\n", old_winpath, winpath); - if(old_winpath[0]) Tcl_VarEval(interp, "save_ctx ", old_winpath, NULL); - Tcl_VarEval(interp, "restore_ctx ", winpath, NULL); - Tcl_VarEval(interp, "housekeeping_ctx", NULL); + if(old_winpath[0]) tclvareval("save_ctx ", old_winpath, NULL); + tclvareval("restore_ctx ", winpath, NULL); + tclvareval("housekeeping_ctx", NULL); } new_schematic("switch", xctx->top_path, winpath, ""); } @@ -687,12 +687,12 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, char n[30]; xctx->rectcolor = key - '0'+4; my_snprintf(n, S(n), "%d", xctx->rectcolor); - Tcl_VarEval(interp, "xschem set rectcolor ", n, NULL); + tclvareval("xschem set rectcolor ", n, NULL); if(!strcmp(winpath, ".drw")) { - Tcl_VarEval(interp, "reconfigure_layers_button {}", NULL); + tclvareval("reconfigure_layers_button {}", NULL); } else { - Tcl_VarEval(interp, "reconfigure_layers_button [winfo parent ", winpath, "]", NULL); + tclvareval("reconfigure_layers_button [winfo parent ", winpath, "]", NULL); } dbg(1, "callback(): new color: %d\n",xctx->color_index[xctx->rectcolor]); break; @@ -747,7 +747,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } } else { /* xschem new_schematic destroy asks user confirmation if schematic changed */ - Tcl_VarEval(interp, "xschem new_schematic destroy ", top_path, " ", winpath," {}" , NULL); + tclvareval("xschem new_schematic destroy ", top_path, " ", winpath," {}" , NULL); /* ================================================================ */ /* We must return here, since current schematic is no more existing */ /* ================================================================ */ @@ -900,7 +900,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } if(key=='O' && (state == (ControlMask|ShiftMask)) ) /* load most recent tile */ { - Tcl_VarEval(interp, "xschem load [lindex $recentfile 0]", NULL); + tclvareval("xschem load [lindex $recentfile 0]", NULL); break; } if(key=='O' && state == ShiftMask) /* toggle light/dark colorscheme 20171113 */ @@ -1554,7 +1554,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, merge_file(2,".sch"); break; case 9: /* load most recent file */ - Tcl_VarEval(interp, "xschem load [lindex $recentfile 0]", NULL); + tclvareval("xschem load [lindex $recentfile 0]", NULL); break; case 10: /* edit attributes */ edit_property(0); diff --git a/src/draw.c b/src/draw.c index 2ed63992..19218f95 100644 --- a/src/draw.c +++ b/src/draw.c @@ -55,12 +55,12 @@ void print_image() if(!has_x) return ; if(!lastdir[0]) my_strncpy(lastdir, pwd_dir, S(lastdir)); if(!xctx->plotfile[0]) { - Tcl_VarEval(interp, "tk_getSaveFile -title {Select destination file} -initialfile {", + tclvareval("tk_getSaveFile -title {Select destination file} -initialfile {", get_cell(xctx->sch[xctx->currsch], 0) , ".png} -initialdir {", lastdir, "}", NULL); r = tclresult(); if(r[0]) { my_strncpy(xctx->plotfile, r, S(xctx->plotfile)); - Tcl_VarEval(interp, "file dirname {", xctx->plotfile, "}", NULL); + tclvareval("file dirname {", xctx->plotfile, "}", NULL); my_strncpy(lastdir, tclresult(), S(lastdir)); } else return; diff --git a/src/hilight.c b/src/hilight.c index 45e0d03b..968d3de1 100644 --- a/src/hilight.c +++ b/src/hilight.c @@ -312,7 +312,7 @@ void create_plot_cmd(void) my_strdup(1273, &t, tok); my_strdup2(1274, &p, (entry->path)+1); if(simtype == 0 ) { /* spice */ - Tcl_VarEval(interp, "puts $gaw_fd {copyvar v(", strtolower(p), strtolower(t), + tclvareval("puts $gaw_fd {copyvar v(", strtolower(p), strtolower(t), ") sel #", color_str, "}\nvwait gaw_fd\n", NULL); } else { /* Xyce */ char *c=p; @@ -320,7 +320,7 @@ void create_plot_cmd(void) if(*c == '.') *c = ':'; /* Xyce uses : as path separator */ c++; } - Tcl_VarEval(interp, "puts $gaw_fd {copyvar ", strtoupper(p), strtoupper(t), + tclvareval("puts $gaw_fd {copyvar ", strtoupper(p), strtoupper(t), " sel #", color_str, "}\nvwait gaw_fd\n", NULL); } my_free(1275, &p); @@ -334,7 +334,7 @@ void create_plot_cmd(void) my_strdup2(245, &p, (entry->path)+1); if(simtype == 0 ) { /* spice */ - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{set_curve_style \"", rawfile, @@ -342,7 +342,7 @@ void create_plot_cmd(void) ")\" \"solid_line\" \"no symbol\" 1 ", color_str, "}", NULL); - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{add_curve_to_plot \"", rawfile, "\" \"v(", strtolower(p), strtolower(t), ")\" \"\"}", @@ -353,7 +353,7 @@ void create_plot_cmd(void) if(*c == '.') *c = ':'; /* Xyce uses : as path separator */ c++; } - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{set_curve_style \"", rawfile, @@ -361,7 +361,7 @@ void create_plot_cmd(void) "\" \"solid_line\" \"no symbol\" 1 ", color_str, "}", NULL); - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{add_curve_to_plot \"", rawfile, "\" \"", strtoupper(p), strtoupper(t), "\" \"\"}", @@ -858,7 +858,7 @@ static void send_net_to_bespice(int simtype, const char *node) my_strdup(1277, &t, find_nth(expanded_tok, ',', k)); my_strdup2(1278, &p, xctx->sch_path[xctx->currsch]+1); if(simtype == 0 ) { /* spice */ - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{set_curve_style \"", rawfile, @@ -866,7 +866,7 @@ static void send_net_to_bespice(int simtype, const char *node) ")\" \"solid_line\" \"no symbol\" 1 ", color_str, "}", NULL); - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{add_curve_to_plot \"", rawfile, "\" \"v(", strtolower(p), strtolower(t), ")\" \"\"}", @@ -877,7 +877,7 @@ static void send_net_to_bespice(int simtype, const char *node) if(*c == '.') *c = ':'; /* Xyce uses : as path separator */ c++; } - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{set_curve_style \"", rawfile, @@ -885,7 +885,7 @@ static void send_net_to_bespice(int simtype, const char *node) "\" \"solid_line\" \"no symbol\" 1 ", color_str, "}", NULL); - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{add_curve_to_plot \"", rawfile, "\" \"", strtoupper(p), strtoupper(t), "\" \"\"}", @@ -920,7 +920,7 @@ static void send_net_to_gaw(int simtype, const char *node) my_strdup(246, &t, find_nth(expanded_tok, ',', k)); my_strdup2(254, &p, xctx->sch_path[xctx->currsch]+1); if(simtype == 0 ) { /* spice */ - Tcl_VarEval(interp, "puts $gaw_fd {copyvar v(", strtolower(p), strtolower(t), + tclvareval("puts $gaw_fd {copyvar v(", strtolower(p), strtolower(t), ") sel #", color_str, "}\nvwait gaw_fd\n", NULL); } else { /* Xyce */ char *c=p; @@ -928,7 +928,7 @@ static void send_net_to_gaw(int simtype, const char *node) if(*c == '.') *c = ':'; /* Xyce uses : as path separator */ c++; } - Tcl_VarEval(interp, "puts $gaw_fd {copyvar ", strtoupper(p), strtoupper(t), + tclvareval("puts $gaw_fd {copyvar ", strtoupper(p), strtoupper(t), " sel #", color_str, "}\nvwait gaw_fd\n", NULL); } } @@ -960,7 +960,7 @@ static void send_current_to_bespice(int simtype, const char *node) my_strdup(1281, &t, find_nth(expanded_tok, ',', k)); my_strdup2(1282, &p, xctx->sch_path[xctx->currsch]+1); if(!simtype) { /* spice */ - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{set_curve_style \"", rawfile, @@ -969,7 +969,7 @@ static void send_current_to_bespice(int simtype, const char *node) ")\" \"solid_line\" \"no symbol\" 1 ", color_str, "}", NULL); - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{add_curve_to_plot \"", rawfile, "\" \"i(", xctx->currsch>0 ? "v." : "", strtolower(p), strtolower(t), @@ -982,7 +982,7 @@ static void send_current_to_bespice(int simtype, const char *node) c++; } - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{set_curve_style \"", rawfile, @@ -991,7 +991,7 @@ static void send_current_to_bespice(int simtype, const char *node) "\" \"solid_line\" \"no symbol\" 1 ", color_str, "}", NULL); - Tcl_VarEval(interp, + tclvareval( "puts $bespice_server_getdata(sock) ", "{add_curve_to_plot \"", rawfile, "\" \"", xctx->currsch>0 ? "V:" : "", strtoupper(p), strtoupper( xctx->currsch>0 ? t+1 : t), "#branch", @@ -1023,7 +1023,7 @@ static void send_current_to_gaw(int simtype, const char *node) my_strdup(1179, &t, find_nth(expanded_tok, ',', k)); my_strdup2(1180, &p, xctx->sch_path[xctx->currsch]+1); if(!simtype) { /* spice */ - Tcl_VarEval(interp, "puts $gaw_fd {copyvar i(", xctx->currsch>0 ? "v." : "", + tclvareval("puts $gaw_fd {copyvar i(", xctx->currsch>0 ? "v." : "", strtolower(p), strtolower(t), ") sel #", color_str, "}\nvwait gaw_fd\n", NULL); } else { /* Xyce */ @@ -1032,7 +1032,7 @@ static void send_current_to_gaw(int simtype, const char *node) if(*c == '.') *c = ':'; /* Xyce uses : as path separator */ c++; } - Tcl_VarEval(interp, "puts $gaw_fd {copyvar ", xctx->currsch>0 ? "V:" : "", + tclvareval("puts $gaw_fd {copyvar ", xctx->currsch>0 ? "V:" : "", strtoupper(p), strtoupper( xctx->currsch>0 ? t+1 : t ), "#branch", " sel #", color_str, "}\nvwait gaw_fd\n", NULL); } @@ -1460,7 +1460,7 @@ void propagate_logic() } if(!found) break; /* get out from infinite loops (circuit is oscillating) */ - Tcl_VarEval(interp, "update; if {$::tclstop == 1} {return 1} else {return 0}", NULL); + tclvareval("update; if {$::tclstop == 1} {return 1} else {return 0}", NULL); if( tclresult()[0] == '1') break; iter++; } /* while(1) */ diff --git a/src/in_memory_undo.c b/src/in_memory_undo.c index f3a4c105..31c27e67 100644 --- a/src/in_memory_undo.c +++ b/src/in_memory_undo.c @@ -190,11 +190,11 @@ static void free_undo_symbols(int slot) xctx->uslot[slot].symbols = 0; } -static void init_undo(void) +static void mem_init_undo(void) { int slot; - dbg(1, "init_undo(): undo_initialized = %d\n", xctx->undo_initialized); + dbg(1, "mem_init_undo(): undo_initialized = %d\n", xctx->undo_initialized); if(!xctx->undo_initialized) { for(slot = 0;slotuslot[slot].lines = my_calloc(165, cadlayers, sizeof(int)); @@ -258,7 +258,7 @@ void mem_push_undo(void) int j; if(xctx->no_undo)return; - init_undo(); + mem_init_undo(); slot = xctx->cur_undo_ptr%MAX_UNDO; my_strdup(173, &xctx->uslot[slot].gptr, xctx->schvhdlprop); diff --git a/src/psprint.c b/src/psprint.c index e546553d..aa72070f 100644 --- a/src/psprint.c +++ b/src/psprint.c @@ -887,12 +887,12 @@ int ps_draw(int what) if(what & 1) { /* prolog */ if(!lastdir[0]) my_strncpy(lastdir, pwd_dir, S(lastdir)); if(!xctx->plotfile[0]) { - Tcl_VarEval(interp, "tk_getSaveFile -title {Select destination file} -initialfile {", + tclvareval("tk_getSaveFile -title {Select destination file} -initialfile {", get_cell(xctx->sch[xctx->currsch], 0) , ".pdf} -initialdir {", lastdir, "}", NULL); r = tclresult(); if(r[0]) { my_strncpy(xctx->plotfile, r, S(xctx->plotfile)); - Tcl_VarEval(interp, "file dirname {", xctx->plotfile, "}", NULL); + tclvareval("file dirname {", xctx->plotfile, "}", NULL); my_strncpy(lastdir, tclresult(), S(lastdir)); } else return 0; diff --git a/src/save.c b/src/save.c index 0cebe159..47981533 100644 --- a/src/save.c +++ b/src/save.c @@ -981,13 +981,13 @@ int save_schematic(const char *schname) /* 20171020 added return value */ dbg(1, "save_schematic(): abs_sym_path=%s\n", abs_sym_path(xctx->sch[xctx->currsch], "")); my_strncpy(name, xctx->sch[xctx->currsch], S(name)); if(has_x) { - Tcl_VarEval(interp, "wm title ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); - Tcl_VarEval(interp, "wm iconname ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); + tclvareval("wm title ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); + tclvareval("wm iconname ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); } if(!stat(name, &buf)) { if(xctx->time_last_modify && xctx->time_last_modify != buf.st_mtime) { - Tcl_VarEval(interp, "ask_save \"Schematic file: ", name, + tclvareval("ask_save \"Schematic file: ", name, "\nHas been changed since opening.\nSave anyway?\" 0", NULL); if(strcmp(tclresult(), "yes") ) return 0; } @@ -1102,7 +1102,7 @@ void load_schematic(int load_symbols, const char *filename, int reset_undo) /* 2 dbg(2, "load_schematic(): loaded file:wire=%d inst=%d\n",xctx->wires , xctx->instances); if(load_symbols) link_symbols_to_instances(-1); if(reset_undo) { - Tcl_VarEval(interp, "is_xschem_file {", xctx->sch[xctx->currsch], "}", NULL); + tclvareval("is_xschem_file {", xctx->sch[xctx->currsch], "}", NULL); if(!strcmp(tclresult(), "SYMBOL")) { xctx->save_netlist_type = xctx->netlist_type; xctx->netlist_type = CAD_SYMBOL_ATTRS; @@ -1211,7 +1211,7 @@ void push_undo(void) if(!(diff_fd=freopen(diff_name,"w", stdout))) /* redirect stdout to file diff_name */ { dbg(1, "push_undo(): problems opening file %s \n",diff_name); - Tcl_Eval(interp, "exit"); + tcleval("exit"); } /* the following 2 statements are a replacement for dup2() which is not c89 @@ -1226,7 +1226,7 @@ void push_undo(void) execlp("gzip", "gzip", "--fast", "-c", NULL); /* replace current process with comand */ /* never gets here */ fprintf(errfp, "push_undo(): problems with execlp\n"); - Tcl_Eval(interp, "exit"); + tcleval("exit"); } close(pd[0]); /* close read side of pipe */ fd=fdopen(pd[1],"w"); @@ -1311,7 +1311,7 @@ void pop_undo(int redo, int set_modify_status) if(!(diff_fd=freopen(diff_name,"r", stdin))) /* redirect stdin from file name */ { dbg(1, "pop_undo(): problems opening file %s \n",diff_name); - Tcl_Eval(interp, "exit"); + tcleval("exit"); } /* connect write side of pipe to stdout */ #if HAS_DUP2 @@ -1323,7 +1323,7 @@ void pop_undo(int redo, int set_modify_status) execlp("gzip", "gzip", "-d", "-c", NULL); /* replace current process with command */ /* never gets here */ dbg(1, "pop_undo(): problems with execlp\n"); - Tcl_Eval(interp, "exit"); + tcleval("exit"); } close(pd[1]); /* close write side of pipe */ fd=fdopen(pd[0],"r"); @@ -2290,7 +2290,7 @@ void create_sch_from_sym(void) my_strncpy(schname, add_ext(abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""), ".sch"), S(schname)); } if( !stat(schname, &buf) ) { - Tcl_VarEval(interp, "ask_save \"Create schematic file: ", schname, + tclvareval("ask_save \"Create schematic file: ", schname, "?\nWARNING: This schematic file already exists, it will be overwritten\"", NULL); if(strcmp(tclresult(), "yes") ) { return; diff --git a/src/scheduler.c b/src/scheduler.c index 923d82d2..92adc49c 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -36,7 +36,7 @@ void statusmsg(char str[],int n) tcleval("infowindow"); } else { - Tcl_VarEval(interp, xctx->top_path, ".statusbar.1 configure -text $infowindow_text", NULL); + tclvareval(xctx->top_path, ".statusbar.1 configure -text $infowindow_text", NULL); dbg(3, "statusmsg(str, %d): -> $infowindow_text = %s\n", n, tclgetvar("infowindow_text")); } } @@ -455,8 +455,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(has_x) { char *top_path; top_path = xctx->top_path[0] ? xctx->top_path : "."; - Tcl_VarEval(interp, "wm title ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); - Tcl_VarEval(interp, "wm iconname ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); + tclvareval("wm title ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); + tclvareval("wm iconname ", top_path, " \"xschem - [file tail [xschem get schname]]\"", NULL); } } Tcl_ResetResult(interp); @@ -636,7 +636,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } else tcleval("exit"); /* if has_x == 0 there are no additional windows to close */ } else { - Tcl_VarEval(interp, "xschem new_schematic destroy ", top_path, " ", xctx->top_path, ".drw {}" , NULL); + tclvareval("xschem new_schematic destroy ", top_path, " ", xctx->top_path, ".drw {}" , NULL); } Tcl_ResetResult(interp); } @@ -1120,6 +1120,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg #ifdef XSCHEM_LIBRARY_PATH my_snprintf(res, S(res), "XSCHEM_LIBRARY_PATH=%s\n", XSCHEM_LIBRARY_PATH); Tcl_AppendResult(interp, res, NULL); #endif + #ifdef HAS_SNPRINTF + my_snprintf(res, S(res), "HAS_SNPRINTF=%s\n", HAS_SNPRINTF); Tcl_AppendResult(interp, res, NULL); + #endif } else if(!strcmp(argv[1],"go_back")) @@ -1474,7 +1477,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg unselect_all(); remove_symbols(); load_schematic(1, abs_sym_path(argv[2], ""), 1); - Tcl_VarEval(interp, "update_recent_file {", abs_sym_path(argv[2], ""), "}", NULL); + tclvareval("update_recent_file {", abs_sym_path(argv[2], ""), "}", NULL); my_strdup(375, &xctx->sch_path[xctx->currsch],"."); xctx->sch_path_hash[xctx->currsch] = 0; xctx->sch_inst_number[xctx->currsch] = 1; @@ -1497,8 +1500,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg my_snprintf(fullname, S(fullname),"%s", tclresult()); } if( fullname[0] ) { - Tcl_VarEval(interp, "new_window create {", fullname, "}", NULL); - Tcl_VarEval(interp, "update_recent_file {", fullname, "}", NULL); + tclvareval("new_window create {", fullname, "}", NULL); + tclvareval("update_recent_file {", fullname, "}", NULL); } } @@ -1736,7 +1739,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg xctx->last_command = 0; rebuild_selected_array(); if(xctx->lastsel && xctx->sel_array[0].type==ELEMENT) { - Tcl_VarEval(interp, "set INITIALINSTDIR [file dirname {", + tclvareval("set INITIALINSTDIR [file dirname {", abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""), "}]", NULL); } ret = place_symbol(-1,NULL,xctx->mousex_snap, xctx->mousey_snap, 0, 0, NULL, 4, 1, 1/*to_push_undo*/); @@ -1799,7 +1802,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg return TCL_ERROR; } if(argc >= 4) { - Tcl_VarEval(interp, "file normalize {", argv[3], "}", NULL); + tclvareval("file normalize {", argv[3], "}", NULL); my_strncpy(xctx->plotfile, Tcl_GetStringResult(interp), S(xctx->plotfile)); } @@ -2793,4 +2796,22 @@ void tclsetboolvar(const char *s, const int value) } } +/* Replacement for Tcl_VarEval, which despite being very useful is deprecated */ +int tclvareval(const char *script, ...) +{ + char *str = NULL; + int return_code; + size_t size; + const char *p; + va_list args; + va_start(args, script); + size = my_strcat(1379, &str, script); + while( (p = va_arg(args, const char *)) ) { + size = my_strcat(1380, &str, p); + } + return_code = Tcl_EvalEx(interp, str, size, TCL_EVAL_GLOBAL); + va_end(args); + my_free(1381, &p); + return return_code; +} diff --git a/src/svgdraw.c b/src/svgdraw.c index 536d15ad..ea35e370 100644 --- a/src/svgdraw.c +++ b/src/svgdraw.c @@ -564,12 +564,12 @@ void svg_draw(void) if(!lastdir[0]) my_strncpy(lastdir, pwd_dir, S(lastdir)); if(!xctx->plotfile[0]) { - Tcl_VarEval(interp, "tk_getSaveFile -title {Select destination file} -initialfile {", + tclvareval("tk_getSaveFile -title {Select destination file} -initialfile {", get_cell(xctx->sch[xctx->currsch], 0) , ".svg} -initialdir {", lastdir, "}", NULL); r = tclresult(); if(r[0]) { my_strncpy(xctx->plotfile, r, S(xctx->plotfile)); - Tcl_VarEval(interp, "file dirname {", xctx->plotfile, "}", NULL); + tclvareval("file dirname {", xctx->plotfile, "}", NULL); my_strncpy(lastdir, tclresult(), S(lastdir)); } else return; diff --git a/src/token.c b/src/token.c index ab6e3588..fbcb9c1a 100644 --- a/src/token.c +++ b/src/token.c @@ -152,7 +152,7 @@ const char *tcl_hook2(char **res) return empty; } if(strstr(*res, "tcleval(") == *res) { - Tcl_VarEval(interp, "tclpropeval2 {", *res, "}" , NULL); + tclvareval("tclpropeval2 {", *res, "}" , NULL); my_strdup2(1286, &result, tclresult()); return result; } else { diff --git a/src/xinit.c b/src/xinit.c index c9775a8f..d7623e2a 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -167,7 +167,7 @@ void windowid(const char *winpath) framewindow_nchildren =0; mainwindow=Tk_MainWindow(interp); display = Tk_Display(mainwindow); - Tcl_VarEval(interp, "winfo id ", winpath, NULL); + tclvareval("winfo id ", winpath, NULL); sscanf(tclresult(), "0x%x", (unsigned int *) &ww); framewin = ww; XQueryTree(display, framewin, &rootwindow, &parent_of_topwindow, &framewin_child_ptr, &framewindow_nchildren); @@ -792,7 +792,7 @@ void toggle_fullscreen(const char *topwin) tcleval( "winfo id ."); sscanf(tclresult(), "0x%x", (unsigned int *) &topwin_id); } else { - Tcl_VarEval(interp, "winfo id ", xctx->top_path, NULL); + tclvareval("winfo id ", xctx->top_path, NULL); sscanf(tclresult(), "0x%x", (unsigned int *) &topwin_id); } XQueryTree(display, topwin_id, &rootwindow, &parent_id, &framewin_child_ptr, &framewindow_nchildren); @@ -804,11 +804,11 @@ void toggle_fullscreen(const char *topwin) dbg(1, "toggle_fullscreen(): fullscreen=%d\n", fs); if(fs==2) { - Tcl_VarEval(interp, "pack forget ", xctx->top_path, ".menubar ", xctx->top_path, ".statusbar; update", NULL); + tclvareval("pack forget ", xctx->top_path, ".menubar ", xctx->top_path, ".statusbar; update", NULL); xctx->menu_removed = 1; } if(fs !=2 && xctx->menu_removed) { - Tcl_VarEval(interp, "pack ", xctx->top_path, + tclvareval("pack ", xctx->top_path, ".menubar -anchor n -side top -fill x -before ", xctx->top_path, ".drw; pack ", xctx->top_path, ".statusbar -after ", xctx->top_path, ".drw -anchor sw -fill x; update", NULL); xctx->menu_removed=0; @@ -1024,12 +1024,12 @@ void new_schematic(const char *what, const char *top_path, const char *tk_win_pa xctx = save_xctx[n]; delete_schematic_data(); save_xctx[n] = NULL; - Tcl_VarEval(interp, "winfo toplevel ", tk_win_path, NULL); + tclvareval("winfo toplevel ", tk_win_path, NULL); Tk_DestroyWindow(tknew_window[n]); - Tcl_VarEval(interp, "destroy ", tclresult(), NULL); + tclvareval("destroy ", tclresult(), NULL); tknew_window[n] = NULL; /* delete Tcl context of deleted schematic window */ - Tcl_VarEval(interp, "delete_ctx ", tk_win_path, "; incr tctx::cnt -1", NULL); + tclvareval("delete_ctx ", tk_win_path, "; incr tctx::cnt -1", NULL); cnt--; } } @@ -1567,9 +1567,9 @@ int Tcl_AppInit(Tcl_Interp *inter) cadlayers=atoi(tclgetvar("cadlayers")); if(debug_var==-10) debug_var=0; my_snprintf(tmp, S(tmp), "%.16g",CADGRID); - Tcl_VarEval(interp, "set_ne cadgrid ", tmp, NULL); + tclvareval("set_ne cadgrid ", tmp, NULL); my_snprintf(tmp, S(tmp), "%.16g",CADSNAP); - Tcl_VarEval(interp, "set_ne cadsnap ", tmp, NULL); + tclvareval("set_ne cadsnap ", tmp, NULL); cairo_vert_correct = tclgetdoublevar("cairo_vert_correct"); nocairo_vert_correct = tclgetdoublevar("nocairo_vert_correct"); cairo_font_scale = tclgetdoublevar("cairo_font_scale"); @@ -1826,7 +1826,7 @@ int Tcl_AppInit(Tcl_Interp *inter) /* if do_netlist=1 call load_schematic with 'reset_undo=0' avoiding call to tcl is_xschem_file that could change xctx->netlist_type to symbol */ load_schematic(1, f, !do_netlist); - Tcl_VarEval(interp, "update_recent_file {", f, "}", NULL); + tclvareval("update_recent_file {", f, "}", NULL); } else if(!tcl_script[0]) { char * tmp; char filename[PATH_MAX]; @@ -1915,7 +1915,7 @@ int Tcl_AppInit(Tcl_Interp *inter) /* source tcl file given on command line with --script */ if(tcl_script[0]) { - Tcl_VarEval(interp, "update; source {", tcl_script, "}", NULL); + tclvareval("update; source {", tcl_script, "}", NULL); } if(quit) { diff --git a/src/xschem.h b/src/xschem.h index 0f39b32f..7129757f 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1113,6 +1113,7 @@ extern void tclsetvar(const char *s, const char *value); extern void tclsetdoublevar(const char *s, const double value); extern void tclsetboolvar(const char *s, const int value); extern void tclsetintvar(const char *s, const int value); +extern int tclvareval(const char *script, ...); extern const char *tcl_hook2(char **res); extern void statusmsg(char str[],int n); extern int place_text(int draw_text, double mx, double my);