correctly mangle generator calls with parameters containing forbidden characters. Transliterate to get valid SPICE identifiers

This commit is contained in:
stefan schippers 2025-01-20 17:54:06 +01:00
parent 724c264c9d
commit 7523c0015c
3 changed files with 5 additions and 2 deletions

View File

@ -1797,6 +1797,7 @@ const char *get_sym_name(int inst, int ndir, int ext, int abs_path)
sch = tcl_hook2(str_replace(get_tok_value(xctx->inst[inst].prop_ptr,"schematic", 6), "@symname",
get_cell(xctx->inst[inst].name, 0), '\\', -1));
dbg(1, "get_sym_name(): sch=%s\n", sch);
if(xctx->tok_size) { /* token exists */
if(abs_path)
sym = abs_sym_path(sch, ".sym");

View File

@ -653,7 +653,7 @@ int spice_block_netlist(FILE *fd, int i, int alert)
fprintf(fd, "%s\n", translated_sym_def);
my_free(_ALLOC_ID_, &sym_def);
} else {
const char *s = sanitize(get_cell(name, 0));
const char *s = get_cell(sanitize(name), 0);
fprintf(fd, "** sch_path: %s\n", sanitized_abs_sym_path(filename, ""));
fprintf(fd, ".subckt %s ", s);
print_spice_subckt_nodes(fd, i);

View File

@ -120,9 +120,11 @@ const char *sanitize(const char *name)
my_free(_ALLOC_ID_, &s);
return empty;
}
tclvareval("regsub -all { *[(),] *} {", name, "} _", NULL);
dbg(1, "sanitize(): name=%s\n", name);
tclvareval("regsub -all { *[.(),] *} {", name, "} _", NULL);
tclvareval("regsub {_$} {", tclresult(), "} {}", NULL);
my_strdup2(_ALLOC_ID_, &s, tclresult());
dbg(1, "sanitize(): s=%s\n", s);
return s;
}