From 2438d0fa95a8d21c7f1df5dce86c5875caa4ef9c Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 2 May 2023 23:21:20 +0200 Subject: [PATCH] translate2(): better handle %xxx tokens in LCC symbols (propagate %xxx to upper level if not assigned to anything in instance) --- src/save.c | 2 +- src/token.c | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/save.c b/src/save.c index c881b03e..e34ae2da 100644 --- a/src/save.c +++ b/src/save.c @@ -4043,7 +4043,7 @@ void descend_symbol(void) "/xschem_web/", get_cell_w_ext(name, 0), NULL); load_schematic(1, sympath, 1, 1); } else { - dbg(0, "descend_symbol(): sympath=%s\n", sympath); + dbg(1, "descend_symbol(): sympath=%s\n", sympath); load_schematic(1, sympath, 1, 1); } my_free(_ALLOC_ID_, &sympath); diff --git a/src/token.c b/src/token.c index 609d7c01..0f2e9469 100644 --- a/src/token.c +++ b/src/token.c @@ -3568,13 +3568,13 @@ const char *translate2(Lcc *lcc, int level, char* s) } else escape = 0; space = SPACE(c); - if (state == TOK_BEGIN && c == '@' && !escape) state = TOK_TOKEN; + if( state==TOK_BEGIN && (c=='@' || c=='%' ) && !escape ) state=TOK_TOKEN; else if(state==TOK_TOKEN && token_pos > 1 && ( - ( (space || c == '@') && !escape ) || - ( (!space && c != '@') && escape ) - ) - ) state=TOK_SEP; + ( (space || c == '%' || c == '@') && !escape ) || + ( (!space && c != '%' && c != '@') && escape ) + ) + ) state = TOK_SEP; STR_ALLOC(&result, result_pos, &size); STR_ALLOC(&token, token_pos, &sizetok); if (state == TOK_TOKEN) token[token_pos++] = (char)c; @@ -3592,6 +3592,11 @@ const char *translate2(Lcc *lcc, int level, char* s) xctx->tok_size = 0; } else { my_strdup2(_ALLOC_ID_, &value, get_tok_value(lcc[level].prop_ptr, token + 1, 0)); + /* propagate %xxx tokens to upper levels if no value found */ + if(!value[0] && token[0] == '%') { + my_strdup2(_ALLOC_ID_, &value, token + 1); + xctx->tok_size = 1; /* just to tell %xxx token was found */ + } dbg(1, "translate2(): lcc[%d].prop_ptr=%s value=%s\n", level, lcc[level].prop_ptr, value); } if(xctx->tok_size && value[0]) { @@ -3655,7 +3660,7 @@ const char *translate2(Lcc *lcc, int level, char* s) memcpy(result + result_pos, tmp_sym_name, tmp + 1); result_pos += tmp; } - if (c == '@') s--; /* push back to input for next token */ + if (c == '%' || c == '@') s--; /* push back to input for next token */ else result[result_pos++] = (char)c; state = TOK_BEGIN; }