one more argument to translate3()

This commit is contained in:
stefan schippers 2025-02-07 14:39:21 +01:00
parent 0024dc2759
commit 0b3db90f19
8 changed files with 24 additions and 18 deletions

View File

@ -1994,7 +1994,7 @@ void get_additional_symbols(int what)
/* resolve schematic=generator.tcl( @n ) where n=11 is defined in instance attrs */ /* resolve schematic=generator.tcl( @n ) where n=11 is defined in instance attrs */
my_strdup2(_ALLOC_ID_, &sch, my_strdup2(_ALLOC_ID_, &sch,
translate3(get_tok_value(xctx->inst[i].prop_ptr,"schematic", 6), 1, translate3(get_tok_value(xctx->inst[i].prop_ptr,"schematic", 6), 1,
xctx->inst[i].prop_ptr, NULL, NULL)); xctx->inst[i].prop_ptr, NULL, NULL, NULL));
dbg(1, "sch=%s\n", sch); dbg(1, "sch=%s\n", sch);
my_strdup2(_ALLOC_ID_, &sch, tcl_hook2( my_strdup2(_ALLOC_ID_, &sch, tcl_hook2(
@ -2034,7 +2034,7 @@ void get_additional_symbols(int what)
my_strdup(_ALLOC_ID_, &spice_sym_def, my_strdup(_ALLOC_ID_, &spice_sym_def,
translate3(spice_sym_def, 1, xctx->inst[i].prop_ptr, translate3(spice_sym_def, 1, xctx->inst[i].prop_ptr,
symptr->templ, symptr->templ,
symname_attr)); symname_attr, NULL));
dbg(1, "get_additional_symbols(): spice_sym_def=%s\n", spice_sym_def); dbg(1, "get_additional_symbols(): spice_sym_def=%s\n", spice_sym_def);
my_free(_ALLOC_ID_, &symname_attr); my_free(_ALLOC_ID_, &symname_attr);
/* if instance symbol has default_schematic set to ignore copy the symbol anyway, since /* if instance symbol has default_schematic set to ignore copy the symbol anyway, since
@ -2128,7 +2128,7 @@ void get_sch_from_sym(char *filename, xSymbol *sym, int inst, int fallback)
/* resolve schematic=generator.tcl( @n ) where n=11 is defined in instance attrs */ /* resolve schematic=generator.tcl( @n ) where n=11 is defined in instance attrs */
if(inst >=0 ) { if(inst >=0 ) {
my_strdup(_ALLOC_ID_, &str_tmp, translate3(get_tok_value(xctx->inst[inst].prop_ptr,"schematic", 6), my_strdup(_ALLOC_ID_, &str_tmp, translate3(get_tok_value(xctx->inst[inst].prop_ptr,"schematic", 6),
1, xctx->inst[inst].prop_ptr, NULL, NULL)); 1, xctx->inst[inst].prop_ptr, NULL, NULL, NULL));
} }
if(!str_tmp) my_strdup2(_ALLOC_ID_, &str_tmp, get_tok_value(sym->prop_ptr, "schematic", 6)); if(!str_tmp) my_strdup2(_ALLOC_ID_, &str_tmp, get_tok_value(sym->prop_ptr, "schematic", 6));
if(str_tmp[0]) { /* schematic attribute in symbol or instance was given */ if(str_tmp[0]) { /* schematic attribute in symbol or instance was given */

View File

@ -736,7 +736,7 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot,
dbg(1, "draw_symbol(): drawing string: str=%s prop=%s\n", dbg(1, "draw_symbol(): drawing string: str=%s prop=%s\n",
txtptr, text.prop_ptr ? text.prop_ptr : "<NULL>"); txtptr, text.prop_ptr ? text.prop_ptr : "<NULL>");
my_strdup2(_ALLOC_ID_, &txtptr, translate3(txtptr, 1, xctx->inst[n].prop_ptr, my_strdup2(_ALLOC_ID_, &txtptr, translate3(txtptr, 1, xctx->inst[n].prop_ptr,
xctx->sym[xctx->inst[n].ptr].templ, NULL )); xctx->sym[xctx->inst[n].ptr].templ, NULL, NULL));
dbg(1, "draw_symbol(): after translate3: str=%s\n", txtptr); dbg(1, "draw_symbol(): after translate3: str=%s\n", txtptr);
draw_string(textlayer, what, txtptr, draw_string(textlayer, what, txtptr,
(text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3, (text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3,
@ -906,7 +906,7 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,short tmp_flip, short rot
my_strdup2(_ALLOC_ID_, &txtptr, translate(n, text.txt_ptr)); my_strdup2(_ALLOC_ID_, &txtptr, translate(n, text.txt_ptr));
/* do another round of substitutions if some @var are found, but if not found leave @var as is */ /* do another round of substitutions if some @var are found, but if not found leave @var as is */
my_strdup2(_ALLOC_ID_, &txtptr, translate3(txtptr, 1, xctx->inst[n].prop_ptr, my_strdup2(_ALLOC_ID_, &txtptr, translate3(txtptr, 1, xctx->inst[n].prop_ptr,
xctx->sym[xctx->inst[n].ptr].templ, NULL )); xctx->sym[xctx->inst[n].ptr].templ, NULL, NULL));
dbg(1, "draw_temp_symbol(): after translate3: str=%s\n", txtptr); dbg(1, "draw_temp_symbol(): after translate3: str=%s\n", txtptr);
if(txtptr[0]) draw_temp_string(gc, what, txtptr, if(txtptr[0]) draw_temp_string(gc, what, txtptr,
(text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3, (text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3,

View File

@ -1475,7 +1475,7 @@ int drc_check(int i)
my_strdup(_ALLOC_ID_, &drc, get_tok_value(xctx->sym[xctx->inst[j].ptr].prop_ptr, "drc", 2)); my_strdup(_ALLOC_ID_, &drc, get_tok_value(xctx->sym[xctx->inst[j].ptr].prop_ptr, "drc", 2));
if(drc) { if(drc) {
my_strdup(_ALLOC_ID_, &res, translate3(drc, 1, my_strdup(_ALLOC_ID_, &res, translate3(drc, 1,
xctx->inst[j].prop_ptr, xctx->sym[xctx->inst[j].ptr].templ, NULL)); xctx->inst[j].prop_ptr, xctx->sym[xctx->inst[j].ptr].templ, NULL, NULL));
dbg(1, "drc_check(): res = |%s|, drc=|%s|\n", res, drc); dbg(1, "drc_check(): res = |%s|, drc=|%s|\n", res, drc);
if(res) { if(res) {
const char *result; const char *result;

View File

@ -6068,9 +6068,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
int eat_escapes = 0; int eat_escapes = 0;
if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;} if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
if(argc > 3) eat_escapes = atoi(argv[3]); if(argc > 3) eat_escapes = atoi(argv[3]);
if(argc > 6) my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], argv[5], argv[6])); if(argc > 6) my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], argv[5], argv[6], NULL));
else if(argc > 5) my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], argv[5], NULL)); else if(argc > 5) my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], argv[5], NULL, NULL));
else if(argc > 4) my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], NULL, NULL)); else if(argc > 4) my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], NULL, NULL, NULL));
else { else {
Tcl_SetResult(interp, "xschem translate3: missing arguments", TCL_STATIC); Tcl_SetResult(interp, "xschem translate3: missing arguments", TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;

View File

@ -645,7 +645,7 @@ int spice_block_netlist(FILE *fd, int i, int alert)
char *symname_attr = NULL; char *symname_attr = NULL;
const char *translated_sym_def; const char *translated_sym_def;
my_mstrcat(_ALLOC_ID_, &symname_attr, "symname=", get_cell(name, 0), NULL); my_mstrcat(_ALLOC_ID_, &symname_attr, "symname=", get_cell(name, 0), NULL);
translated_sym_def = translate3(sym_def, 1, "", xctx->sym[i].templ, symname_attr); translated_sym_def = translate3(sym_def, 1, xctx->sym[i].templ, symname_attr, NULL, NULL);
my_free(_ALLOC_ID_, &symname_attr); my_free(_ALLOC_ID_, &symname_attr);
fprintf(fd, "%s\n", translated_sym_def); fprintf(fd, "%s\n", translated_sym_def);
my_free(_ALLOC_ID_, &sym_def); my_free(_ALLOC_ID_, &sym_def);

View File

@ -1887,7 +1887,7 @@ static int has_included_subcircuit(int inst, int symbol, char **result)
my_mstrcat(_ALLOC_ID_, &symname_attr, " symref=", get_sym_name(inst, 9999, 1, 1), NULL); my_mstrcat(_ALLOC_ID_, &symname_attr, " symref=", get_sym_name(inst, 9999, 1, 1), NULL);
translated_sym_def = translate3(spice_sym_def, 1, xctx->inst[inst].prop_ptr, translated_sym_def = translate3(spice_sym_def, 1, xctx->inst[inst].prop_ptr,
xctx->sym[symbol].templ, xctx->sym[symbol].templ,
symname_attr); symname_attr, NULL);
dbg(1, "has_included_subcircuit(): translated_sym_def=%s\n", translated_sym_def); dbg(1, "has_included_subcircuit(): translated_sym_def=%s\n", translated_sym_def);
dbg(1, "has_included_subcircuit(): symname=%s\n", symname); dbg(1, "has_included_subcircuit(): symname=%s\n", symname);
@ -2397,7 +2397,7 @@ int print_spice_element(FILE *fd, int inst)
parent_templ = xctx->hier_attr[xctx->currsch - 1].templ; parent_templ = xctx->hier_attr[xctx->currsch - 1].templ;
} }
dbg(1, "print_spice_element(): before translate3(): value=%s\n", value); dbg(1, "print_spice_element(): before translate3(): value=%s\n", value);
value = translate3(val, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, parent_templ); value = translate3(val, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, parent_templ, NULL);
dbg(1, "print_spice_element(): after translate3(): value=%s\n", value); dbg(1, "print_spice_element(): after translate3(): value=%s\n", value);
} }
tok_val_len = strlen(value); tok_val_len = strlen(value);
@ -2412,7 +2412,7 @@ int print_spice_element(FILE *fd, int inst)
if(strstr(value, "expr(") ) { if(strstr(value, "expr(") ) {
my_strdup2(_ALLOC_ID_, &val, value); my_strdup2(_ALLOC_ID_, &val, value);
value = eval_expr(translate3(val, 1, xctx->inst[inst].prop_ptr, template, NULL)); value = eval_expr(translate3(val, 1, xctx->inst[inst].prop_ptr, template, NULL, NULL));
} }
/* token=%xxxx and xxxx is not defined in prop_ptr or template: return xxxx */ /* token=%xxxx and xxxx is not defined in prop_ptr or template: return xxxx */
if(!token_exists && token[0] =='%') { if(!token_exists && token[0] =='%') {
@ -4493,7 +4493,8 @@ const char *translate(int inst, const char* s)
if(strstr(result, "expr(")) { if(strstr(result, "expr(")) {
dbg(1, "translate(): expr():%s\n", result); dbg(1, "translate(): expr():%s\n", result);
my_strdup2(_ALLOC_ID_, &result, eval_expr( my_strdup2(_ALLOC_ID_, &result, eval_expr(
translate3(result, 1, xctx->inst[inst].prop_ptr, xctx->sym[xctx->inst[inst].ptr].templ, NULL))); translate3(result, 1, xctx->inst[inst].prop_ptr, xctx->sym[xctx->inst[inst].ptr].templ,
NULL, NULL)));
} }
return result; return result;
} }
@ -4640,7 +4641,8 @@ const char *translate2(Lcc *lcc, int level, char* s)
/* using s1, s2, s3 in turn to resolve @tokens */ /* using s1, s2, s3 in turn to resolve @tokens */
/* if no definition for @token is found return @token as is in s */ /* if no definition for @token is found return @token as is in s */
/* if s==NULL return emty string */ /* if s==NULL return emty string */
const char *translate3(const char *s, int eat_escapes, const char *s1, const char *s2, const char *s3) const char *translate3(const char *s, int eat_escapes, const char *s1,
const char *s2, const char *s3, const char *s4)
{ {
static const char *empty=""; static const char *empty="";
static char *translated_tok = NULL; static char *translated_tok = NULL;
@ -4659,7 +4661,7 @@ const char *translate3(const char *s, int eat_escapes, const char *s1, const cha
my_free(_ALLOC_ID_, &translated_tok); my_free(_ALLOC_ID_, &translated_tok);
return empty; return empty;
} }
dbg(2, "translate3():\n s=%s\n s1=%s\n s2=%s\n s3=%s\n", s, s1, s2, s3); dbg(2, "translate3():\n s=%s\n s1=%s\n s2=%s\n s3=%s s4=%s\n", s, s1, s2, s3, s4);
my_strdup2(_ALLOC_ID_, &result, ""); my_strdup2(_ALLOC_ID_, &result, "");
while(1) { while(1) {
@ -4696,6 +4698,9 @@ const char *translate3(const char *s, int eat_escapes, const char *s1, const cha
if(!xctx->tok_size && s3) { if(!xctx->tok_size && s3) {
value=get_tok_value(s3, token+1, 0); value=get_tok_value(s3, token+1, 0);
} }
if(!xctx->tok_size) { /* above lines did not find a value for token */ if(!xctx->tok_size) { /* above lines did not find a value for token */
/* no definition found -> keep token */ /* no definition found -> keep token */
my_strcat(_ALLOC_ID_, &result, token); my_strcat(_ALLOC_ID_, &result, token);

View File

@ -946,7 +946,7 @@ static void xwin_exit(void)
list_tokens(NULL, 0); /* clear static data in function */ list_tokens(NULL, 0); /* clear static data in function */
translate(-1, NULL); /* clear static data in function */ translate(-1, NULL); /* clear static data in function */
translate2(NULL, 0, NULL); /* clear static data in function */ translate2(NULL, 0, NULL); /* clear static data in function */
translate3(NULL, 0, NULL, NULL, NULL); /* clear static data in function */ translate3(NULL, 0, NULL, NULL, NULL, NULL); /* clear static data in function */
subst_token(NULL, NULL, NULL); /* clear static data in function */ subst_token(NULL, NULL, NULL); /* clear static data in function */
find_nth(NULL, "", "", 0, 0); /* clear static data in function */ find_nth(NULL, "", "", 0, 0); /* clear static data in function */
trim_chars(NULL, ""); /* clear static data in function */ trim_chars(NULL, ""); /* clear static data in function */

View File

@ -1609,7 +1609,8 @@ extern int isonlydigit(const char *s);
extern const char *spice_get_node(const char *token); extern const char *spice_get_node(const char *token);
extern const char *translate(int inst, const char* s); extern const char *translate(int inst, const char* s);
extern const char* translate2(Lcc *lcc, int level, char* s); extern const char* translate2(Lcc *lcc, int level, char* s);
extern const char *translate3(const char* s, int eat_escapes, const char *s1, const char *s2, const char *s3); extern const char *translate3(const char* s, int eat_escapes, const char *s1,
const char *s2, const char *s3, const char *s4);
extern void print_tedax_element(FILE *fd, int inst); extern void print_tedax_element(FILE *fd, int inst);
extern int print_spice_element(FILE *fd, int inst); extern int print_spice_element(FILE *fd, int inst);
extern void print_spice_subckt_nodes(FILE *fd, int symbol); extern void print_spice_subckt_nodes(FILE *fd, int symbol);