print_spice_subckt_nodes(): use (improved to handle escape chars) str_replace() to substitute @symname, added xschem str_replace, improved xschem symbols

This commit is contained in:
stefan schippers 2023-04-18 00:20:40 +02:00
parent 88fdc83b34
commit a5492be752
7 changed files with 42 additions and 21 deletions

View File

@ -481,7 +481,6 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
<li><kbd> abort_operation</kbd></li><pre>
Resets UI state, unselect all and abort any pending operation </pre>
<li><kbd> add_symbol_pin</kbd></li><pre>
@ -1073,14 +1072,18 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
<li><kbd> snap_wire </kbd></li><pre>
Start a GUI start snapped wire placement (click to start a
wire to closest pin/net endpoint) </pre>
<li><kbd> str_replace str rep with [escape]</kbd></li><pre>
replace 'rep' with 'with' in string 'str'
if rep not preceeded by an 'escape' character </pre>
<li><kbd> subst_tok str tok newval</kbd></li><pre>
Return string 'str' with 'tok' attribute value replaced with 'newval' </pre>
<li><kbd> symbol_in_new_window [new_process]</kbd></li><pre>
When a symbol is selected edit it in a new tab/window if not already open.
If nothing selected open another window of the second schematic (issues a warning).
if 'new_process' is given start a new xschem process </pre>
<li><kbd> symbols</kbd></li><pre>
List all used symbols </pre>
<li><kbd> symbols [n]</kbd></li><pre>
if 'n' given list symbol with name or number 'n', else
list all used symbols </pre>
<li><kbd> table_read [table_file]</kbd></li><pre>
If a simulation raw file is lodaded unload from memory.
else read a tabular file 'table_file'
@ -1159,6 +1162,8 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
Zoom to selection </pre>
</ul>
<!-- TCL global variables -->

View File

@ -1269,7 +1269,6 @@ void get_sch_from_sym(char *filename, xSymbol *sym, int inst)
{
char *sch = NULL;
char *str_tmp = NULL;
char *ptr;
int web_url = 0;
struct stat buf;
@ -1282,15 +1281,7 @@ void get_sch_from_sym(char *filename, xSymbol *sym, int inst)
if(!str_tmp) my_strdup2(_ALLOC_ID_, &str_tmp, get_tok_value(sym->prop_ptr, "schematic", 2));
if(str_tmp[0]) {
/* @symname in schematic attribute will be replaced with symbol name */
if( (ptr = strstr(str_tmp, "@symname")) && ( ptr == str_tmp || *(ptr - 1) != '\\') ) {
*ptr = '\0';
my_strdup2(_ALLOC_ID_, &sch, str_tmp);
my_strcat(_ALLOC_ID_, &sch, sym->name);
ptr += 8;
my_strcat(_ALLOC_ID_, &sch, ptr);
} else {
my_strdup2(_ALLOC_ID_, &sch, str_tmp);
}
my_strdup(_ALLOC_ID_, &sch, str_replace(str_tmp, "@symname", skip_dir(sym->name), '\\'));
dbg(1, "get_sch_from_sym(): sch=%s\n", sch);
my_strdup2(_ALLOC_ID_, &sch, tcl_hook2(&sch));
dbg(1, "get_sch_from_sym(): after tcl_hook2 sch=%s\n", sch);

View File

@ -1507,13 +1507,15 @@ void change_elem_order(void)
}
}
char *str_replace(const char *s, const char *rep, const char *with)
char *str_replace(const char *str, const char *rep, const char *with, int escape)
{
static char *result = NULL;
static size_t size=0;
size_t result_pos = 0;
size_t rep_len;
size_t with_len;
const char *s = str;
int cond;
if(s==NULL || rep == NULL || with == NULL || rep[0] == '\0') {
my_free(_ALLOC_ID_, &result);
@ -1529,7 +1531,9 @@ char *str_replace(const char *s, const char *rep, const char *with)
}
while(*s) {
STR_ALLOC(&result, result_pos + with_len + 1, &size);
if(!strncmp(s, rep, rep_len)) {
cond = ((s == str) || ((*(s - 1) != escape))) && (!strncmp(s, rep, rep_len));
if(cond) {
my_strncpy(result + result_pos, with, with_len + 1);
result_pos += with_len;
s += rep_len;

View File

@ -3506,6 +3506,21 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
xctx->ui_state |= MENUSTARTSNAPWIRE;
}
/* str_replace str rep with [escape]
* replace 'rep' with 'with' in string 'str'
* if rep not preceeded by an 'escape' character */
else if(!strcmp(argv[1], "str_replace"))
{
int escape = 0;
if(argc > 5) escape = argv[5][0];
if(argc > 4) {
Tcl_AppendResult(interp, str_replace(argv[2], argv[3], argv[4], escape), NULL);
} else {
Tcl_SetResult(interp, "Missing arguments", TCL_STATIC);
return TCL_ERROR;
}
}
/* subst_tok str tok newval
* Return string 'str' with 'tok' attribute value replaced with 'newval' */
else if(!strcmp(argv[1], "subst_tok"))
@ -3529,13 +3544,17 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
Tcl_ResetResult(interp);
}
/* symbols
* List all used symbols */
/* symbols [n]
* if 'n' given list symbol with name or number 'n', else
* list all used symbols */
else if(!strcmp(argv[1], "symbols"))
{
int i;
char n[100];
for(i=0; i<xctx->symbols; ++i) {
if(argc > 2) {
i = get_symbol(argv[2]);
Tcl_AppendResult(interp, my_itoa(i), " {", xctx->sym[i].name, "}", NULL);
} else for(i=0; i<xctx->symbols; ++i) {
my_snprintf(n , S(n), "%d", i);
Tcl_AppendResult(interp, " {", n, " ", "{", xctx->sym[i].name, "}", "}\n", NULL);
}

View File

@ -72,7 +72,7 @@ const char *tcl_hook2(char **res)
return empty;
}
if(strstr(*res, "tcleval(") == *res) {
unescaped_res = str_replace(*res, "\\}", "}");
unescaped_res = str_replace(*res, "\\}", "}", 0);
tclvareval("tclpropeval2 {", unescaped_res, "}" , NULL);
my_strdup2(_ALLOC_ID_, &result, tclresult());
/* dbg(0, "tcl_hook2: return: %s\n", result);*/
@ -1526,6 +1526,8 @@ void print_spice_subckt_nodes(FILE *fd, int symbol)
if(!xctx->tok_size && strcmp(fmt_attr, "format") )
my_strdup(_ALLOC_ID_, &format1, get_tok_value(xctx->sym[symbol].prop_ptr, "format", 2));
dbg(1, "print_spice_subckt(): format1=%s\n", format1);
my_strdup(_ALLOC_ID_, &format1, str_replace(format1, "@symname", skip_dir(xctx->sym[symbol].name), '\\'));
if(format1 && strstr(format1, "tcleval(") == format1) {
tclres = tcl_hook2(&format1);
if(!strcmp(tclres, "?\n")) {

View File

@ -664,7 +664,7 @@ static void delete_schematic_data(int delete_pixmap)
/* delete instances, wires, lines, rects, arcs, polys, texts, hash_inst, hash_wire,
* inst & wire .node fields, instance name hash */
remove_symbols();
str_replace(NULL, NULL, NULL);
str_replace(NULL, NULL, NULL, 0);
free_rawfile(0);
free_xschem_data(); /* delete the xctx struct */
}

View File

@ -1479,7 +1479,7 @@ extern void hilight_parent_pins(void);
extern void hilight_net_pin_mismatches(void);
extern Node_hashentry **get_node_table_ptr(void);
extern void change_elem_order(void);
extern char *str_replace(const char *s, const char *rep, const char *with);
extern char *str_replace(const char *str, const char *rep, const char *with, int escape);
extern int set_different_token(char **s,const char *new, const char *old);
extern void print_hilight_net(int show);
extern void list_hilights(void);