From 70c1e542b2f1f57e2f62d6556308b1105ddf2345 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Wed, 5 Feb 2025 18:20:36 +0100 Subject: [PATCH] attributes within expr(...) where expr() contains an infix arith expression will evaluate if possible. Otherwise the string within expr(...) will be returned unchanged. Changes done in translate() and print_spice_element() --- src/eval_expr.y | 2 +- src/token.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/eval_expr.y b/src/eval_expr.y index c7d14773..8a94444b 100644 --- a/src/eval_expr.y +++ b/src/eval_expr.y @@ -93,7 +93,7 @@ exp: NUM { $$ = $1;} static void get_expr(double x) { char xx[100]; - my_snprintf(xx, S(xx), "%.17g", x); + my_snprintf(xx, S(xx), "%.16g", x); my_mstrcat(_ALLOC_ID_, &ret, xx, NULL); strptr = str; } diff --git a/src/token.c b/src/token.c index a0aa55d5..7eb1576c 100644 --- a/src/token.c +++ b/src/token.c @@ -2246,6 +2246,13 @@ int print_spice_element(FILE *fd, int inst) if (!xctx->tok_size) value=get_tok_value(template, token+1, 0); token_exists = xctx->tok_size; + if(strstr(value, "expr(") == value) { + char *ptr; + my_strdup(_ALLOC_ID_, &val, value); + ptr = strrchr(val + 5, ')'); + *ptr = '\0'; + value = eval_expr(translate3(val + 5, 1, xctx->inst[inst].prop_ptr, template, NULL)); + } if(!strcmp("@savecurrent", token)) { token_exists = 0; /* processed later */ value = NULL; @@ -4479,6 +4486,13 @@ const char *translate(int inst, const char* s) dbg(1, "2 translate(): lcc[%d].prop_ptr=%s, value1=%s\n", i-1, lcc[i-1].prop_ptr, value1); i--; } + if(strstr(value1, "expr(") == value1) { + char *ptr = strrchr(value1 + 5, ')'); + dbg(0, "translate(): expr():%s\n", value1); + *ptr = '\0'; + my_strdup2(_ALLOC_ID_, &value1, eval_expr( + translate3(value1 + 5, 1, xctx->inst[inst].prop_ptr, xctx->sym[xctx->inst[inst].ptr].templ, NULL))); + } tmp=strlen(value1); STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos, value1, tmp+1);