From 2bd8a93889ca20600ae7f3266d4c0b17e9a3c8e5 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Tue, 1 Dec 2020 12:00:18 +0100 Subject: [PATCH] preserve backslashes in instance name after doing an editprop(). get_tok_value() fix: do not eat "\" if called with with_quotes=1 --- src/actions.c | 2 +- src/editprop.c | 3 ++- src/token.c | 28 ++++++++++------------------ xschem_library/pcb/74ls00-2.sym | 5 +++-- xschem_library/pcb/pcb_test2.sch | 7 ++++--- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/actions.c b/src/actions.c index d926920e..b1886786 100644 --- a/src/actions.c +++ b/src/actions.c @@ -805,7 +805,7 @@ void attach_labels_to_inst() /* offloaded from callback.c 20171005 */ rct=symbol->rect[PINLAYER]; for(i=0;i labname=%s\n", labname); pinx0 = (rct[i].x1+rct[i].x2)/2; diff --git a/src/editprop.c b/src/editprop.c index f6c5e5c7..fec71316 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -1044,7 +1044,8 @@ void update_symbol(const char *result, int x) } /* if symbol changed ensure instance name (with new prefix char) is unique */ - my_strdup(152, &name, get_tok_value(xctx->inst[i].prop_ptr, "name", 0)); + /* preserve backslashes in name ----------------------------------->. */ + my_strdup(152, &name, get_tok_value(xctx->inst[i].prop_ptr, "name", 1)); if(name && name[0] ) { dbg(1, "update_symbol(): prefix!='\\0', name=%s\n", name); /* 20110325 only modify prefix if prefix not NUL */ diff --git a/src/token.c b/src/token.c index 40b740c3..9a1e799d 100644 --- a/src/token.c +++ b/src/token.c @@ -493,20 +493,12 @@ const char *get_tok_value(const char *s,const char *tok, int with_quotes) get_tok_value_size = 0; return result; } - if(c=='"') { - if((with_quotes & 1) || escape) token[token_pos++]=c; - } - /* skip unescaped backslashes */ - else if( escape || c != '\\' ) token[token_pos++]=c; - } else if(state==TOK_VALUE) { - if(c=='"') { - if((with_quotes & 1) || escape) result[value_pos++]=c; - } - /* skip unescaped backslashes */ - else if( escape || c != '\\' ) result[value_pos++]=c; - } else if(state==TOK_ENDTOK || state==TOK_SEP) { + if(with_quotes || escape || (c != '\\' && c != '"')) token[token_pos++]=c; + } else if(state == TOK_VALUE) { + if(with_quotes || escape || (c != '\\' && c != '"')) result[value_pos++]=c; + } else if(state == TOK_ENDTOK || state == TOK_SEP) { if(token_pos) { - token[token_pos]='\0'; + token[token_pos] = '\0'; if( !(cmp = strcmp(token,tok)) ) { /* report back also token size, useful to check if requested token exists */ get_tok_size = token_pos; @@ -791,15 +783,15 @@ const char *subst_token(const char *s, const char *tok, const char *new_val) my_strdup2(458, &result, s); return result; } - /* quote new_val if it contains newlines */ + /* quote new_val if it contains newlines and not "name" token */ if(new_val) { new_val_len = strlen(new_val); - if(!is_quoted(new_val) && strpbrk(new_val, "\n \t")) { + if(strcmp(tok, "name") && !is_quoted(new_val) && strpbrk(new_val, "\n \t")) { new_val_copy = my_malloc(1210, new_val_len+3); my_snprintf(new_val_copy, new_val_len+3, "\"%s\"", new_val); - } - else my_strdup(1212, &new_val_copy, new_val); - } else new_val_copy = NULL; + } + else my_strdup(1212, &new_val_copy, new_val); + } else new_val_copy = NULL; dbg(1, "subst_token(): %s, %s, %s\n", s, tok, new_val); sizetok = size = CADCHUNKALLOC; my_realloc(1152, &result, size); diff --git a/xschem_library/pcb/74ls00-2.sym b/xschem_library/pcb/74ls00-2.sym index a0e30d86..20d576e9 100644 --- a/xschem_library/pcb/74ls00-2.sym +++ b/xschem_library/pcb/74ls00-2.sym @@ -1,5 +1,6 @@ -v {xschem version=2.9.5_RC5 file_version=1.1} -G {type=nand +v {xschem version=2.9.8 file_version=1.2} +G {} +K {type=nand verilog_format="nand #(@risedel , @falldel ) @name ( @#2 , @#0 , @#1 );" format="@name @pinlist @symname" tedax_format="footprint @name @footprint diff --git a/xschem_library/pcb/pcb_test2.sch b/xschem_library/pcb/pcb_test2.sch index f098731c..c6aad96b 100644 --- a/xschem_library/pcb/pcb_test2.sch +++ b/xschem_library/pcb/pcb_test2.sch @@ -1,12 +1,13 @@ -v {xschem version=2.9.5_RC5 file_version=1.1} +v {xschem version=2.9.8 file_version=1.2} G {} +K {} V {} S {} E {} C {title.sym} 160 -30 0 0 {name=l2 author="Stefan"} -C {74ls00-2.sym} 320 -280 0 0 {name=U\\ 5:3 +C {74ls00-2.sym} 320 -280 0 0 {name=U\\\\\\ 5:3 url="http://www.engrcs.com/components/74LS00.pdf"} -C {74ls00-2.sym} 230 -450 0 0 {name=U\\ 5:1 +C {74ls00-2.sym} 230 -450 0 0 {name=U\\\\\\ 5:1 pippo=ccc\\ ddd url="http://www.engrcs.com/components/74LS00.pdf" } C {lab_pin.sym} 280 -300 0 0 {name=p1 lab=U51_A}