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()

This commit is contained in:
stefan schippers 2025-02-05 18:20:36 +01:00
parent 4db384a671
commit 70c1e542b2
2 changed files with 15 additions and 1 deletions

View File

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

View File

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