fix 2 bugs in extra_rawfile(): xctx->extra_idx assignment in extra_rawfile "read" subcommand and return value if no command executed. Add "file_exists "procedure to be used in graph_edit_properties for rawentry resolution

This commit is contained in:
stefan schippers 2023-10-18 10:15:39 +02:00
parent a41a0bf9fd
commit cc5864e12f
2 changed files with 45 additions and 12 deletions

View File

@ -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"); dbg(0, "raw_read(): must clear current raw file before loading new\n");
return res; return res;
} }
dbg(1, "raw_read(): type=%s\n", type ? type : "NULL");
*rawptr = my_calloc(_ALLOC_ID_, 1, sizeof(Raw)); *rawptr = my_calloc(_ALLOC_ID_, 1, sizeof(Raw));
raw = *rawptr; raw = *rawptr;
raw->level = -1; 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_arr[xctx->extra_raw_n] = xctx->raw;
xctx->extra_raw_n++; 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); tclvareval("subst {", file, "}", NULL);
my_strncpy(f, tclresult(), S(f)); my_strncpy(f, tclresult(), S(f));
for(i = 0; i < xctx->extra_raw_n; i++) { 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); read_ret = raw_read(f, &xctx->raw, type);
if(read_ret) { if(read_ret) {
xctx->extra_raw_arr[xctx->extra_raw_n] = xctx->raw; xctx->extra_raw_arr[xctx->extra_raw_n] = xctx->raw;
xctx->extra_raw_n++;
xctx->extra_prev_idx = xctx->extra_idx; xctx->extra_prev_idx = xctx->extra_idx;
xctx->extra_idx = xctx->extra_raw_n; xctx->extra_idx = xctx->extra_raw_n;
xctx->extra_raw_n++;
} else { } else {
ret = 0; /* not found so did not switch */ 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->raw = save; /* restore */
xctx->extra_prev_idx = xctx->extra_idx; 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->extra_idx = i;
xctx->raw = xctx->extra_raw_arr[xctx->extra_idx]; xctx->raw = xctx->extra_raw_arr[xctx->extra_idx];
} }
} else if(what == 2) { /* switch */ /* **************** switch ************* */
} else if(what == 2) {
if(file && type) { if(file && type) {
tclvareval("subst {", file, "}", NULL); tclvareval("subst {", file, "}", NULL);
my_strncpy(f, tclresult(), S(f)); 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_prev_idx = xctx->extra_idx;
xctx->extra_idx = i; xctx->extra_idx = i;
} else { } 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; ret = 0;
} }
} else { /* switch to next */ } 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->extra_idx = (xctx->extra_idx + 1) % xctx->extra_raw_n;
} }
xctx->raw = xctx->extra_raw_arr[xctx->extra_idx]; xctx->raw = xctx->extra_raw_arr[xctx->extra_idx];
} else if(what == 5) { /* switch_back */ /* **************** switch back ************* */
} else if(what == 5) {
int tmp; 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; tmp = xctx->extra_idx;
xctx->extra_idx = xctx->extra_prev_idx; xctx->extra_idx = xctx->extra_prev_idx;
xctx->extra_prev_idx = tmp; xctx->extra_prev_idx = tmp;
xctx->raw = xctx->extra_raw_arr[xctx->extra_idx]; 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 */ if(!file) { /* clear all , keep only current */
for(i = 0; i < xctx->extra_raw_n; i++) { for(i = 0; i < xctx->extra_raw_n; i++) {
if(i == xctx->extra_idx) { 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 ret = 0; } else ret = 0;
} }
} else if(what == 4) { /* info */ /* **************** info ************* */
} else if(what == 4) {
if(xctx->raw) { if(xctx->raw) {
dbg(1, "extra_raw_n = %d\n", xctx->extra_raw_n); dbg(1, "extra_raw_n = %d\n", xctx->extra_raw_n);
Tcl_AppendResult(interp, my_itoa(xctx->extra_idx), " current\n", NULL); 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); xctx->extra_raw_arr[i]->sim_type ? xctx->extra_raw_arr[i]->sim_type : "NULL", "\n", NULL);
} }
} }
} else {
ret = 0;
} }
return ret; return ret;
} }

View File

@ -908,6 +908,29 @@ proc sim_is_xyce {} {
return 0 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 # wrapper to "xschem list_tokens" comand to handle non list results
# usually as a result of malformed input strings # usually as a result of malformed input strings
proc list_tokens {s} { proc list_tokens {s} {
@ -2045,7 +2068,7 @@ proc graph_edit_properties {n} {
if { [info tclversion] > 8.4} { if { [info tclversion] > 8.4} {
bind .graphdialog.center.right.list <<ComboboxSelected>> { bind .graphdialog.center.right.list <<ComboboxSelected>> {
xschem setprop rect 2 $graph_selected sim_type [.graphdialog.center.right.list get] fast 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 graph_fill_listbox
} }
} }
@ -2065,7 +2088,7 @@ proc graph_edit_properties {n} {
bind .graphdialog.center.right.list <KeyRelease> { bind .graphdialog.center.right.list <KeyRelease> {
xschem setprop rect 2 $graph_selected sim_type [.graphdialog.center.right.list get] fast 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 graph_fill_listbox
} }
} }
@ -2075,7 +2098,7 @@ proc graph_edit_properties {n} {
entry .graphdialog.center.right.rawentry -width 30 entry .graphdialog.center.right.rawentry -width 30
bind .graphdialog.center.right.rawentry <Leave> { bind .graphdialog.center.right.rawentry <Leave> {
xschem setprop rect 2 $graph_selected rawfile [.graphdialog.center.right.rawentry get] fast 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 graph_fill_listbox
} }
} }
@ -6101,7 +6124,7 @@ proc build_widgets { {topwin {} } } {
xschem redraw 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" \ $topwin.menubar.option.menu add command -label "Replace \[ and \] for buses in SPICE netlist" \
-command { -command {