set `sch_basename` and `path` global tcl vars when executing tclcommand launcher scripts

This commit is contained in:
stefan schippers 2026-08-06 15:24:35 +02:00
parent f583f47049
commit 9f740bf182
2 changed files with 23 additions and 0 deletions

View File

@ -1925,6 +1925,7 @@ void launcher(void)
if(url[0] || (program[0])) { /* open url with appropriate program */
tclvareval("launcher {", url, "} {", program, "}", NULL);
} else if(command && command[0]){
tcleval("set_xschem_vars");
dbg(1, "launcher(): command=%s\n", command);
if(Tcl_GlobalEval(interp, command) != TCL_OK) {
dbg(0, "%s\n", tclresult());

View File

@ -6900,6 +6900,28 @@ proc property_search {} {
return {}
}
# Sets some useful global vars to be sed in launcher scripts.
proc set_xschem_vars {} {
global path sch_basename
set raw_level [xschem get raw_level]
set netlist_type [xschem get netlist_type]
set path [string range [xschem get sch_path] 1 end]
set sch_basename [file tail [file rootname [xschem get current_name]]]
# skip hierarchy components above the level where raw file has been loaded.
# node path names to look up in raw file begin from there.
set skip 0
while { $skip < $raw_level } {
regsub {^[^.]*\.} $path {} path
incr skip
}
if { $netlist_type eq {spice} } {
# this is necessary if spiceprefix is being used in netlists
regsub {^([^xX])} $path {x\1} path
while { [regsub {\.([^xX])} $path {.x\1} path] } {}
}
}
#20171029
# allows to call TCL hooks from 'format' strings during netlisting
# example of symbol spice format definition: