From 9f740bf182b25324fa21104df1c5eba567337e22 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Thu, 6 Aug 2026 15:24:35 +0200 Subject: [PATCH] set `sch_basename` and `path` global tcl vars when executing tclcommand launcher scripts --- src/actions.c | 1 + src/xschem.tcl | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/actions.c b/src/actions.c index 960cba46..ca73ca87 100644 --- a/src/actions.c +++ b/src/actions.c @@ -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()); diff --git a/src/xschem.tcl b/src/xschem.tcl index d3d7c9f3..3fc6cdc5 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -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: