diff --git a/doc/xschem_man/developer_info.html b/doc/xschem_man/developer_info.html index 69f9387e..9d9a65c9 100644 --- a/doc/xschem_man/developer_info.html +++ b/doc/xschem_man/developer_info.html @@ -481,7 +481,6 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns" -
  • abort_operation
  •     Resets UI state, unselect all and abort any pending operation 
  • add_symbol_pin
  • @@ -1073,14 +1072,18 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
        
  • snap_wire
  •     Start a GUI start snapped wire placement (click to start a
        wire to closest pin/net endpoint) 
    +
  • str_replace str rep with [escape]
  • +   replace 'rep' with 'with' in string 'str' 
    +   if rep not preceeded by an 'escape' character 
  • subst_tok str tok newval
  •     Return string 'str' with 'tok' attribute value replaced with 'newval' 
  • symbol_in_new_window [new_process]
  •     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 
    -
  • symbols
  • -   List all used symbols 
    +
  • symbols [n]
  • +   if 'n' given list symbol with name or number 'n', else 
    +   list all used symbols 
  • table_read [table_file]
  •     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 
    + + diff --git a/src/actions.c b/src/actions.c index ca53bb5f..cb7e52ed 100644 --- a/src/actions.c +++ b/src/actions.c @@ -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); diff --git a/src/editprop.c b/src/editprop.c index f68851b8..fc5432be 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -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; diff --git a/src/scheduler.c b/src/scheduler.c index 324ab2d5..33609dba 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -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; isymbols; ++i) { + if(argc > 2) { + i = get_symbol(argv[2]); + Tcl_AppendResult(interp, my_itoa(i), " {", xctx->sym[i].name, "}", NULL); + } else for(i=0; isymbols; ++i) { my_snprintf(n , S(n), "%d", i); Tcl_AppendResult(interp, " {", n, " ", "{", xctx->sym[i].name, "}", "}\n", NULL); } diff --git a/src/token.c b/src/token.c index 0b5e9b82..d1d9cdd7 100644 --- a/src/token.c +++ b/src/token.c @@ -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")) { diff --git a/src/xinit.c b/src/xinit.c index 40aea877..4e06c464 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -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 */ } diff --git a/src/xschem.h b/src/xschem.h index c7c64798..9b812c5d 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -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);