preserve backslashes in instance name after doing an editprop(). get_tok_value() fix: do not eat "\" if called with with_quotes=1

This commit is contained in:
Stefan Frederik 2020-12-01 12:00:18 +01:00
parent 1055fdbf36
commit 2bd8a93889
5 changed files with 20 additions and 25 deletions

View File

@ -805,7 +805,7 @@ void attach_labels_to_inst() /* offloaded from callback.c 20171005 */
rct=symbol->rect[PINLAYER];
for(i=0;i<npin;i++) {
my_strdup(8, &labname,get_tok_value(rct[i].prop_ptr,"name",0));
my_strdup(8, &labname,get_tok_value(rct[i].prop_ptr,"name",1));
dbg(1,"attach_labels_to_inst(): 2 --> labname=%s\n", labname);
pinx0 = (rct[i].x1+rct[i].x2)/2;

View File

@ -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 */

View File

@ -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);

View File

@ -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

View File

@ -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}