diff --git a/src/save.c b/src/save.c index 227acbbd..163d3ade 100644 --- a/src/save.c +++ b/src/save.c @@ -783,6 +783,7 @@ int raw_read(const char *f, Raw **rawptr, const char *type) dbg(0, "raw_read(): must clear current raw file before loading new\n"); return res; } + dbg(1, "raw_read(): type=%s\n", type ? type : "NULL"); *rawptr = my_calloc(_ALLOC_ID_, 1, sizeof(Raw)); raw = *rawptr; raw->level = -1; @@ -833,7 +834,8 @@ int extra_rawfile(int what, const char *file, const char *type) xctx->extra_raw_arr[xctx->extra_raw_n] = xctx->raw; xctx->extra_raw_n++; } - if(what == 1 && xctx->extra_raw_n < MAX_RAW_N && file && type) { /* read */ + /* **************** read ************* */ + if(what == 1 && xctx->extra_raw_n < MAX_RAW_N && file && type) { tclvareval("subst {", file, "}", NULL); my_strncpy(f, tclresult(), S(f)); for(i = 0; i < xctx->extra_raw_n; i++) { @@ -850,12 +852,12 @@ int extra_rawfile(int what, const char *file, const char *type) read_ret = raw_read(f, &xctx->raw, type); if(read_ret) { xctx->extra_raw_arr[xctx->extra_raw_n] = xctx->raw; - xctx->extra_raw_n++; xctx->extra_prev_idx = xctx->extra_idx; xctx->extra_idx = xctx->extra_raw_n; + xctx->extra_raw_n++; } else { ret = 0; /* not found so did not switch */ - dbg(0, "extra_rawfile() read: %s %s not found\n", f, type); + dbg(0, "extra_rawfile() read: %s not found or no %s analysis\n", f, type); xctx->raw = save; /* restore */ xctx->extra_prev_idx = xctx->extra_idx; } @@ -865,7 +867,8 @@ int extra_rawfile(int what, const char *file, const char *type) xctx->extra_idx = i; xctx->raw = xctx->extra_raw_arr[xctx->extra_idx]; } - } else if(what == 2) { /* switch */ + /* **************** switch ************* */ + } else if(what == 2) { if(file && type) { tclvareval("subst {", file, "}", NULL); my_strncpy(f, tclresult(), S(f)); @@ -881,7 +884,7 @@ int extra_rawfile(int what, const char *file, const char *type) xctx->extra_prev_idx = xctx->extra_idx; xctx->extra_idx = i; } else { - dbg(0, "extra_rawfile() switch: %s %s not found\n", f, type); + dbg(0, "extra_rawfile() switch: %s not found or no %s analysis\n", f, type); ret = 0; } } else { /* switch to next */ @@ -889,13 +892,17 @@ int extra_rawfile(int what, const char *file, const char *type) xctx->extra_idx = (xctx->extra_idx + 1) % xctx->extra_raw_n; } xctx->raw = xctx->extra_raw_arr[xctx->extra_idx]; - } else if(what == 5) { /* switch_back */ + /* **************** switch back ************* */ + } else if(what == 5) { int tmp; + dbg(1, "extra_rawfile() switch back: extra_idx=%d, extra_prev_idx=%d\n", + xctx->extra_idx, xctx->extra_prev_idx); tmp = xctx->extra_idx; xctx->extra_idx = xctx->extra_prev_idx; xctx->extra_prev_idx = tmp; xctx->raw = xctx->extra_raw_arr[xctx->extra_idx]; - } else if(what == 3) { /* clear */ + /* **************** clear ************* */ + } else if(what == 3) { if(!file) { /* clear all , keep only current */ for(i = 0; i < xctx->extra_raw_n; i++) { if(i == xctx->extra_idx) { @@ -929,7 +936,8 @@ int extra_rawfile(int what, const char *file, const char *type) } else ret = 0; } else ret = 0; } - } else if(what == 4) { /* info */ + /* **************** info ************* */ + } else if(what == 4) { if(xctx->raw) { dbg(1, "extra_raw_n = %d\n", xctx->extra_raw_n); Tcl_AppendResult(interp, my_itoa(xctx->extra_idx), " current\n", NULL); @@ -938,6 +946,8 @@ int extra_rawfile(int what, const char *file, const char *type) xctx->extra_raw_arr[i]->sim_type ? xctx->extra_raw_arr[i]->sim_type : "NULL", "\n", NULL); } } + } else { + ret = 0; } return ret; } diff --git a/src/xschem.tcl b/src/xschem.tcl index ac97795e..e38c29ac 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -908,6 +908,29 @@ proc sim_is_xyce {} { return 0 } +# tests if file f exists. One level of global scope 'subst' is done on f +# to expand global variables / commands catching errors. +# example: +# % set b {$env(HOME)/.bashrc} +# $env(HOME)/.bashrc +# % file_exists $b +# 1 +# % +# % +# % set b {$env(HOMExx)/.bashrc} +# $env(HOMExx)/.bashrc +# % file_exists $b +# 0 +# % +proc file_exists {f} { + set ret 0 + set r [catch "uplevel #0 {subst $f}" res] + if {$r == 0} { + if {[file exists $res]} { set ret 1} + } + return $ret +} + # wrapper to "xschem list_tokens" comand to handle non list results # usually as a result of malformed input strings proc list_tokens {s} { @@ -2045,7 +2068,7 @@ proc graph_edit_properties {n} { if { [info tclversion] > 8.4} { bind .graphdialog.center.right.list <> { xschem setprop rect 2 $graph_selected sim_type [.graphdialog.center.right.list get] fast - if {[file exists [subst [.graphdialog.center.right.rawentry get]]]} { + if {[file_exists [.graphdialog.center.right.rawentry get]]} { graph_fill_listbox } } @@ -2065,7 +2088,7 @@ proc graph_edit_properties {n} { bind .graphdialog.center.right.list { xschem setprop rect 2 $graph_selected sim_type [.graphdialog.center.right.list get] fast - if {[file exists [subst [.graphdialog.center.right.rawentry get]]]} { + if {[file_exists [.graphdialog.center.right.rawentry get]]} { graph_fill_listbox } } @@ -2075,7 +2098,7 @@ proc graph_edit_properties {n} { entry .graphdialog.center.right.rawentry -width 30 bind .graphdialog.center.right.rawentry { xschem setprop rect 2 $graph_selected rawfile [.graphdialog.center.right.rawentry get] fast - if {[file exists [subst [.graphdialog.center.right.rawentry get]]]} { + if {[file_exists [.graphdialog.center.right.rawentry get]]} { graph_fill_listbox } } @@ -6101,7 +6124,7 @@ proc build_widgets { {topwin {} } } { xschem redraw } } - $topwin.menubar.option.menu add checkbutton -label "Persistet wire/line place command" -variable persistent_command + $topwin.menubar.option.menu add checkbutton -label "Persistent wire/line place command" -variable persistent_command $topwin.menubar.option.menu add command -label "Replace \[ and \] for buses in SPICE netlist" \ -command {