diff --git a/src/actions.c b/src/actions.c index 68e561bb..7450f097 100644 --- a/src/actions.c +++ b/src/actions.c @@ -124,7 +124,7 @@ const char *get_text_floater(int i) } else { char *res = NULL; /* cache floater translated text to avoid re-evaluating every time schematic is drawn */ - my_strdup2(_ALLOC_ID_, &xctx->text[i].floater_ptr, translate(inst, xctx->text[i].txt_ptr, res)); + my_strdup2(_ALLOC_ID_, &xctx->text[i].floater_ptr, translate(inst, xctx->text[i].txt_ptr, &res)); my_free(_ALLOC_ID_, &res); txt_ptr = xctx->text[i].floater_ptr; } @@ -136,7 +136,7 @@ const char *get_text_floater(int i) if(strstr(txt_ptr, "tcleval(") == txt_ptr || strchr(txt_ptr, '@')) { char *res = NULL; /* my_strdup2(_ALLOC_ID_, &xctx->text[i].floater_ptr, tcl_hook2(xctx->text[i].txt_ptr)); */ - my_strdup2(_ALLOC_ID_, &xctx->text[i].floater_ptr, translate(-1, xctx->text[i].txt_ptr, res)); + my_strdup2(_ALLOC_ID_, &xctx->text[i].floater_ptr, translate(-1, xctx->text[i].txt_ptr, &res)); txt_ptr = xctx->text[i].floater_ptr; my_free(_ALLOC_ID_, &res); } @@ -1639,7 +1639,7 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot xctx->instances++;/* translate expects the correct balue of xctx->instances */ /* After having assigned prop_ptr to new instance translate symbol reference * to resolve @params --> res.tcl(@value\) --> res.tcl(100) */ - my_strncpy(name, translate(n, name, res), S(name)); + my_strncpy(name, translate(n, name, &res), S(name)); my_free(_ALLOC_ID_, &res); /* parameters like res.tcl(@value\) have been resolved, so reload symbol removing previous */ if(strcmp(name, name1)) { @@ -1906,11 +1906,11 @@ void launcher(void) } if(strchr(command, '@')) { char *res = NULL; - my_strdup2(_ALLOC_ID_, &command, translate3(command, 1, prop_ptr, NULL, NULL, NULL, res)); + my_strdup2(_ALLOC_ID_, &command, translate3(command, 1, prop_ptr, NULL, NULL, NULL, &res)); if(xctx->sel_array[0].type==ELEMENT) { xSymbol *sym = xctx->inst[n].ptr + xctx->sym; if(strchr(command, '@')) { - my_strdup2(_ALLOC_ID_, &command, translate3(command, 1, sym->prop_ptr, NULL, NULL, NULL, res)); + my_strdup2(_ALLOC_ID_, &command, translate3(command, 1, sym->prop_ptr, NULL, NULL, NULL, &res)); } } my_free(_ALLOC_ID_, &res); @@ -1957,7 +1957,7 @@ const char *get_sym_name(int inst, int ndir, int ext, int abs_path) my_strdup2(_ALLOC_ID_, &sch, get_tok_value(xctx->inst[inst].prop_ptr,"schematic", 6)); schematic_token_found = xctx->tok_size; if(sch && sch[0]) { - my_strdup2(_ALLOC_ID_, &sch, translate3(sch, 1, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, res)); + my_strdup2(_ALLOC_ID_, &sch, translate3(sch, 1, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, &res)); my_free(_ALLOC_ID_, &res); } if(sch && sch[0]) @@ -2203,7 +2203,7 @@ void get_additional_symbols(int what) dbg(1, "get_additional_symbols(): schematic=%s\n", sch); schematic_token_found = xctx->tok_size; - my_strdup2(_ALLOC_ID_, &sch, translate3(sch, 1, xctx->inst[i].prop_ptr, NULL, NULL, NULL, res)); + my_strdup2(_ALLOC_ID_, &sch, translate3(sch, 1, xctx->inst[i].prop_ptr, NULL, NULL, NULL, &res)); my_free(_ALLOC_ID_, &res); dbg(1, " get_additional_symbols(): sch=%s tok_size= %ld\n", sch, xctx->tok_size); @@ -2246,12 +2246,12 @@ void get_additional_symbols(int what) translate3(spice_sym_def, 1, xctx->inst[i].prop_ptr, symptr->templ, symname_attr, NULL, - res)); + &res)); my_strdup(_ALLOC_ID_, &spectre_sym_def, translate3(spectre_sym_def, 1, xctx->inst[i].prop_ptr, symptr->templ, symname_attr, NULL, - res)); + &res)); my_free(_ALLOC_ID_, &symname_attr); my_free(_ALLOC_ID_, &res); /* if instance symbol has default_schematic set to ignore copy the symbol anyway, since @@ -2355,7 +2355,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 */ my_strdup2(_ALLOC_ID_, &str_tmp, get_tok_value(xctx->inst[inst].prop_ptr,"schematic", 6)); if(str_tmp[0]) { - my_strdup2(_ALLOC_ID_, &str_tmp, translate3(str_tmp, 1, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, res)); + my_strdup2(_ALLOC_ID_, &str_tmp, translate3(str_tmp, 1, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, &res)); my_free(_ALLOC_ID_, &res); } /* diff --git a/src/draw.c b/src/draw.c index 09c6c077..c61bfa12 100644 --- a/src/draw.c +++ b/src/draw.c @@ -875,12 +875,12 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot, } #endif dbg(1, "draw_symbol(): drawing string: before translate(): text.txt_ptr=%s\n", text.txt_ptr); - my_strdup2(_ALLOC_ID_, &txtptr, translate(n, text.txt_ptr, res)); + my_strdup2(_ALLOC_ID_, &txtptr, translate(n, text.txt_ptr, &res)); /* do another round of substitutions if some @var are found, but if not found leave @var as is */ dbg(1, "draw_symbol(): drawing string: str=%s prop=%s\n", txtptr, text.prop_ptr ? text.prop_ptr : ""); my_strdup2(_ALLOC_ID_, &txtptr, translate3(txtptr, 0, xctx->inst[n].prop_ptr, - xctx->sym[xctx->inst[n].ptr].templ, NULL, NULL, res)); + xctx->sym[xctx->inst[n].ptr].templ, NULL, NULL, &res)); my_free(_ALLOC_ID_, &res); dbg(1, "draw_symbol(): after translate3: str=%s\n", txtptr); draw_string(textlayer, what, txtptr, @@ -1049,10 +1049,10 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,short tmp_flip, short rot #if HAS_CAIRO==1 customfont = set_text_custom_font(&text); #endif - my_strdup2(_ALLOC_ID_, &txtptr, translate(n, text.txt_ptr, res)); + my_strdup2(_ALLOC_ID_, &txtptr, translate(n, text.txt_ptr, &res)); /* 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, 0, xctx->inst[n].prop_ptr, - xctx->sym[xctx->inst[n].ptr].templ, NULL, NULL, res)); + xctx->sym[xctx->inst[n].ptr].templ, NULL, NULL, &res)); my_free(_ALLOC_ID_, &res); dbg(1, "draw_temp_symbol(): after translate3: str=%s\n", txtptr); if(txtptr[0]) draw_temp_string(gc, what, txtptr, diff --git a/src/editprop.c b/src/editprop.c index f2ef3fcb..6d9b3f67 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -1555,7 +1555,7 @@ int drc_check(int i) my_strdup(_ALLOC_ID_, &drc, get_tok_value(xctx->sym[xctx->inst[j].ptr].prop_ptr, "drc", 2)); if(drc) { my_strdup(_ALLOC_ID_, &res, translate3(drc, 1, - xctx->inst[j].prop_ptr, xctx->sym[xctx->inst[j].ptr].templ, NULL, NULL, res1)); + xctx->inst[j].prop_ptr, xctx->sym[xctx->inst[j].ptr].templ, NULL, NULL, &res1)); my_free(_ALLOC_ID_, &res1); dbg(1, "drc_check(): res = |%s|, drc=|%s|\n", res, drc); if(res) { @@ -1647,7 +1647,7 @@ static int update_symbol(const char *result, int x, int selected_inst) /* 20171220 calculate bbox before changes to correctly redraw areas */ /* must be recalculated as cairo text extents vary with zoom factor. */ symbol_bbox(*ii, &xctx->inst[*ii].x1, &xctx->inst[*ii].y1, &xctx->inst[*ii].x2, &xctx->inst[*ii].y2); - my_strdup2(_ALLOC_ID_, &old_translated_sym, translate(*ii, xctx->inst[*ii].name, res)); + my_strdup2(_ALLOC_ID_, &old_translated_sym, translate(*ii, xctx->inst[*ii].name, &res)); my_free(_ALLOC_ID_, &res); /* update property string from tcl dialog */ if(!no_change_props) @@ -1681,7 +1681,7 @@ static int update_symbol(const char *result, int x, int selected_inst) * to use for inst name (from symbol template) */ prefix = 0; sym_number = -1; - my_strdup2(_ALLOC_ID_, &translated_sym, translate(*ii, symbol, res)); + my_strdup2(_ALLOC_ID_, &translated_sym, translate(*ii, symbol, &res)); my_free(_ALLOC_ID_, &res); dbg(1, "update_symbol: %s -- %s\n", translated_sym, old_translated_sym); if(changed_symbol || diff --git a/src/psprint.c b/src/psprint.c index 52e43ffd..495fb285 100644 --- a/src/psprint.c +++ b/src/psprint.c @@ -1185,7 +1185,7 @@ static void ps_draw_symbol(int c, int n,int layer, int what, short tmp_flip, sho /* if(xscale*FONTWIDTH* xctx->mooz<1) continue; */ if(!xctx->show_hidden_texts && (text.flags & (HIDE_TEXT | HIDE_TEXT_INSTANTIATED))) continue; if( hide && text.txt_ptr && strcmp(text.txt_ptr, "@symname") && strcmp(text.txt_ptr, "@name") ) continue; - txtptr= translate(n, text.txt_ptr, res); + txtptr= translate(n, text.txt_ptr, &res); ROTATION(rot, flip, 0.0,0.0,text.x0,text.y0,x1,y1); textlayer = c_for_text; /* do not allow custom text color on hilighted instances */ diff --git a/src/save.c b/src/save.c index e53301ea..9fb567a8 100644 --- a/src/save.c +++ b/src/save.c @@ -3531,7 +3531,7 @@ void link_symbols_to_instances(int from) dbg(2, "link_symbols_to_instances(): inst=%d\n", i); dbg(2, "link_symbols_to_instances(): matching inst %d name=%s \n",i, xctx->inst[i].name); dbg(2, "link_symbols_to_instances(): -------\n"); - my_strdup2(_ALLOC_ID_, &name, tcl_hook2(translate(i, xctx->inst[i].name, res))); + my_strdup2(_ALLOC_ID_, &name, tcl_hook2(translate(i, xctx->inst[i].name, &res))); my_free(_ALLOC_ID_, &res); xctx->inst[i].ptr = match_symbol(name); my_free(_ALLOC_ID_, &name); @@ -4753,7 +4753,7 @@ int load_sym_def(const char *name, FILE *embed_fd) dbg(1, "l_s_d(): txt1: level=%d tt[i].txt_ptr=%s, i=%d\n", level, tt[i].txt_ptr, i); if (level>0) { char *res = NULL; - const char* tmp = translate2(lcc, level, tt[i].txt_ptr, res); + const char* tmp = translate2(lcc, level, tt[i].txt_ptr, &res); dbg(1, "l_s_d(): txt2: tt[i].txt_ptr=%s, i=%d\n", tt[i].txt_ptr, i); rot = lcc[level].rot; flip = lcc[level].flip; my_strdup2(_ALLOC_ID_, &tt[i].txt_ptr, tmp); @@ -5246,7 +5246,7 @@ int descend_symbol(void) if(ret == 0) clear_all_hilights(); if(ret == -1) return 0; /* user cancel */ } - my_snprintf(name, S(name), "%s", translate(n, xctx->inst[n].name, res)); + my_snprintf(name, S(name), "%s", translate(n, xctx->inst[n].name, &res)); my_free(_ALLOC_ID_, &res); /* dont allow descend in the default missing symbol */ if((xctx->inst[n].ptr+ xctx->sym)->type && diff --git a/src/scheduler.c b/src/scheduler.c index 3e716d09..0efe9b75 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -4920,7 +4920,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg hash_names(inst, XDELETE); set_inst_prop(inst); - my_strdup2(_ALLOC_ID_, &translated_sym, translate(inst, xctx->inst[inst].name, res)); + my_strdup2(_ALLOC_ID_, &translated_sym, translate(inst, xctx->inst[inst].name, &res)); my_free(_ALLOC_ID_, &res); sym_number=match_symbol(translated_sym); @@ -5873,7 +5873,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(old_name) { update_attached_floaters(old_name, inst, 0); } - my_strdup2(_ALLOC_ID_, &translated_sym, translate(inst, xctx->inst[inst].name, res)); + my_strdup2(_ALLOC_ID_, &translated_sym, translate(inst, xctx->inst[inst].name, &res)); my_free(_ALLOC_ID_, &res); sym_number=match_symbol(translated_sym); @@ -6536,7 +6536,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg Tcl_SetResult(interp, "xschem translate: instance not found", TCL_STATIC); return TCL_ERROR; } - my_strdup2(_ALLOC_ID_, &s, translate(i, argv[3], res)); + my_strdup2(_ALLOC_ID_, &s, translate(i, argv[3], &res)); my_free(_ALLOC_ID_, &res); Tcl_ResetResult(interp); Tcl_SetResult(interp, s, TCL_VOLATILE); @@ -6558,11 +6558,11 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;} 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], NULL, res)); + my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], argv[5], argv[6], NULL, &res)); else if(argc > 5) - my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], argv[5], NULL, NULL, res)); + my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], argv[5], NULL, NULL, &res)); else if(argc > 4) - my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], NULL, NULL, NULL, res)); + my_strdup2(_ALLOC_ID_, &s, translate3(argv[2], eat_escapes, argv[4], NULL, NULL, NULL, &res)); else { Tcl_SetResult(interp, "xschem translate3: missing arguments", TCL_STATIC); return TCL_ERROR; diff --git a/src/select.c b/src/select.c index 7b6790cb..ad3632d7 100644 --- a/src/select.c +++ b/src/select.c @@ -362,7 +362,7 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2) sym_flip = flip; sym_rot = rot; dbg(1, "symbol_bbox(): instance %d text n: %d text str=%s\n", i,j, text.txt_ptr? text.txt_ptr:""); - tmp_txt = translate(i, text.txt_ptr, res); + tmp_txt = translate(i, text.txt_ptr, &res); dbg(1, "symbol_bbox(): translated text: %s\n", tmp_txt); if(tmp_txt && !strncmp(tmp_txt, "@spice", 6)) continue; /* annotator texts not used in bbox */ ROTATION(rot, flip, 0.0,0.0,text.x0, text.y0,text_x0,text_y0); diff --git a/src/spectre_netlist.c b/src/spectre_netlist.c index 14263f16..d88e7932 100644 --- a/src/spectre_netlist.c +++ b/src/spectre_netlist.c @@ -114,14 +114,14 @@ static int spectre_netlist(FILE *fd, int spectre_stop ) /* hash device_model attribute if any */ my_strdup2(_ALLOC_ID_, &val, get_tok_value(xctx->inst[i].prop_ptr, "spectre_device_model", 2)); m = val; - if(strchr(val, '@')) m = translate(i, val, res); + if(strchr(val, '@')) m = translate(i, val, &res); else m = tcl_hook2(m); if(m[0]) str_hash_lookup(&spectre_model_table, spectre_model_name(m), m, XINSERT); else { my_strdup2(_ALLOC_ID_, &val, get_tok_value(xctx->sym[xctx->inst[i].ptr].prop_ptr, "spectre_device_model", 2)); m = val; - if(strchr(val, '@')) m = translate(i, val, res); + if(strchr(val, '@')) m = translate(i, val, &res); else m = tcl_hook2(m); if(m[0]) str_hash_lookup(&spectre_model_table, spectre_model_name(m), m, XINSERT); } @@ -556,7 +556,7 @@ int spectre_block_netlist(FILE *fd, int i, int alert) const char *translated_sym_def; char *res = 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, NULL, NULL, res); + translated_sym_def = translate3(sym_def, 1, xctx->sym[i].templ, symname_attr, NULL, NULL, &res); my_free(_ALLOC_ID_, &symname_attr); fprintf(fd, "%s\n", translated_sym_def); my_free(_ALLOC_ID_, &sym_def); diff --git a/src/spice_netlist.c b/src/spice_netlist.c index 73ac38c9..faaf3239 100644 --- a/src/spice_netlist.c +++ b/src/spice_netlist.c @@ -228,14 +228,14 @@ static int spice_netlist(FILE *fd, int spice_stop ) /* hash device_model attribute if any */ my_strdup2(_ALLOC_ID_, &val, get_tok_value(xctx->inst[i].prop_ptr, "device_model", 2)); m = val; - if(strchr(val, '@')) m = translate(i, val, res); + if(strchr(val, '@')) m = translate(i, val, &res); else m = tcl_hook2(m); if(m[0]) str_hash_lookup(&model_table, model_name(m), m, XINSERT); else { my_strdup2(_ALLOC_ID_, &val, get_tok_value(xctx->sym[xctx->inst[i].ptr].prop_ptr, "device_model", 2)); m = val; - if(strchr(val, '@')) m = translate(i, val, res); + if(strchr(val, '@')) m = translate(i, val, &res); else m = tcl_hook2(m); if(m[0]) str_hash_lookup(&model_table, model_name(m), m, XINSERT); } @@ -670,7 +670,7 @@ int spice_block_netlist(FILE *fd, int i, int alert) const char *translated_sym_def; char *res = 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, NULL, NULL, res); + translated_sym_def = translate3(sym_def, 1, xctx->sym[i].templ, symname_attr, NULL, NULL, &res); my_free(_ALLOC_ID_, &symname_attr); fprintf(fd, "%s\n", translated_sym_def); my_free(_ALLOC_ID_, &sym_def); diff --git a/src/svgdraw.c b/src/svgdraw.c index a203f322..021a5c9d 100644 --- a/src/svgdraw.c +++ b/src/svgdraw.c @@ -881,7 +881,7 @@ static void svg_draw_symbol(int c, int n,int layer,short tmp_flip, short rot, /* if(xscale*FONTWIDTH* xctx->mooz<1) continue; */ if(!xctx->show_hidden_texts && (symptr->text[j].flags & (HIDE_TEXT | HIDE_TEXT_INSTANTIATED))) continue; if( hide && text.txt_ptr && strcmp(text.txt_ptr, "@symname") && strcmp(text.txt_ptr, "@name") ) continue; - txtptr= translate(n, text.txt_ptr, res); + txtptr= translate(n, text.txt_ptr, &res); ROTATION(rot, flip, 0.0,0.0,text.x0,text.y0,x1,y1); textlayer = c_for_text; /* do not allow custom text color on hilighted instances */ diff --git a/src/token.c b/src/token.c index 9d54c742..7f0bb312 100644 --- a/src/token.c +++ b/src/token.c @@ -1043,14 +1043,14 @@ static void print_vhdl_primitive(FILE *fd, int inst) /* netlist primitives, 200 /* in hash table */ { char *res = NULL; - const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), res)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), &res)); my_mstrcat(_ALLOC_ID_, &result, s, NULL); my_free(_ALLOC_ID_, &res); } else if (strcmp(token,"@symname_ext")==0) { char *res = NULL; - const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 1, 0), res)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 1, 0), &res)); my_mstrcat(_ALLOC_ID_, &result, s, NULL); my_free(_ALLOC_ID_, &res); } @@ -1209,13 +1209,13 @@ static void print_vhdl_primitive(FILE *fd, int inst) /* netlist primitives, 200 if(strcmp(xctx->sym[xctx->inst[inst].ptr].type, "netlist_commands")) { char *res = NULL; my_strdup2(_ALLOC_ID_, &result, - translate3(result, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, NULL, NULL, res)); + translate3(result, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, NULL, NULL, &res)); /* can not put template in above translate3: -----------------------^^^^ * if instance has VHI=VHI, format string has VHI=@VHI, and symbol template has VHI=3 * we do not want token @VHI to resolve to 3, but stop at VHI as specified in instance */ if(strchr(result, '@')) { my_strdup2(_ALLOC_ID_, &result, - translate3(result, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, template, NULL, res)); + translate3(result, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, template, NULL, &res)); } my_free(_ALLOC_ID_, &res); } @@ -1542,11 +1542,11 @@ void print_vhdl_element(FILE *fd, int inst) dbg(2, "print_vhdl_element(): printing inst name & subcircuit name\n"); if( (lab = expandlabel(name, &tmp)) != NULL) { char *res = NULL; - fprintf(fd, "%d %s : %s\n", tmp, lab, sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), res)) ); + fprintf(fd, "%d %s : %s\n", tmp, lab, sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), &res)) ); my_free(_ALLOC_ID_, &res); } else { /* name in some strange format, probably an error */ char *res = NULL; - fprintf(fd, "1 %s : %s\n", name, sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), res)) ); + fprintf(fd, "1 %s : %s\n", name, sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), &res)) ); my_free(_ALLOC_ID_, &res); } dbg(2, "print_vhdl_element(): printing generics passed as properties\n"); @@ -1931,7 +1931,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); translated_sym_def = translate3(spice_sym_def, 1, xctx->inst[inst].prop_ptr, xctx->sym[symbol].templ, - symname_attr, NULL, res); + symname_attr, NULL, &res); dbg(1, "has_included_subcircuit(): translated_sym_def=%s\n", translated_sym_def); dbg(1, "has_included_subcircuit(): symname=%s\n", symname); @@ -2449,14 +2449,14 @@ int print_spice_element(FILE *fd, int inst) else if (strcmp(token,"@symname")==0) /* of course symname must not be present in attributes */ { char *res = NULL; - const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), res)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), &res)); my_mstrcat(_ALLOC_ID_, &result, s, NULL); my_free(_ALLOC_ID_, &res); } else if (strcmp(token,"@symname_ext")==0) /* of course symname_ext must not be present in attributes */ { char *res = NULL; - const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 1, 0), res)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 1, 0), &res)); my_mstrcat(_ALLOC_ID_, &result, s, NULL); my_free(_ALLOC_ID_, &res); } @@ -2634,26 +2634,26 @@ int print_spice_element(FILE *fd, int inst) */ my_strdup2(_ALLOC_ID_, &val, - translate3(token, 0, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, res)); + translate3(token, 0, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, &res)); /* can not put template in above translate3: ---------------------------^^^^ * if instance has VHI=VHI, format string has VHI=@VHI, and symbol template has VHI=3 * we do not want token @VHI to resolve to 3, but stop at VHI as specified in instance */ if(strchr(val, '@')) { my_strdup2(_ALLOC_ID_, &val, - translate3(val, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, template, NULL, res)); + translate3(val, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, template, NULL, &res)); } /* nmos instance format string: @model --> @modeln */ dbg(1, "print_spice_element(): 1st round: val: |%s|\n", val); if(strchr(val, '@')) { my_strdup2(_ALLOC_ID_, &val, - translate3(val, 1, schname_attr, xctx->inst[inst].prop_ptr, NULL, NULL, res)); + translate3(val, 1, schname_attr, xctx->inst[inst].prop_ptr, NULL, NULL, &res)); /* ............ --> replace @symname with symbol name */ dbg(1, "print_spice_element(): 2nd round: val: |%s|\n", val); /* normal passgate.sym placement, nmos instance format string: ad="expr('int((@nf + 1)/2) * @W / @nf * 0.29')" --> ad="expr('int((1 + 1)/2) * W_N/ 1 * 0.29')" */ if(strchr(val, '@')) { my_strdup2(_ALLOC_ID_, &val, - translate3(val, 0, xctx->inst[inst].prop_ptr, parent_templ, NULL, NULL, res)); + translate3(val, 0, xctx->inst[inst].prop_ptr, parent_templ, NULL, NULL, &res)); dbg(1, "print_spice_element(): 3nd round: val: |%s|\n", val); /* normal passgate.sym placement, nmos instance format string: * @modeln --> nfet_01v8 */ @@ -2834,14 +2834,14 @@ int print_spectre_element(FILE *fd, int inst) else if (strcmp(token,"@symname")==0) /* of course symname must not be present in attributes */ { char *res = NULL; - const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), res)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), &res)); my_mstrcat(_ALLOC_ID_, &result, s, NULL); my_free(_ALLOC_ID_, &res); } else if (strcmp(token,"@symname_ext")==0) /* of course symname_ext must not be present in attributes */ { char *res = NULL; - const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 1, 0), res)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 1, 0), &res)); my_mstrcat(_ALLOC_ID_, &result, s, NULL); my_free(_ALLOC_ID_, &res); } @@ -3018,25 +3018,25 @@ int print_spectre_element(FILE *fd, int inst) my_strdup2(_ALLOC_ID_, &val, - translate3(token, 0, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, res)); + translate3(token, 0, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, &res)); /* can not put template in above translate3: ---------------------------^^^^ * if instance has VHI=VHI, format string has VHI=@VHI, and symbol template has VHI=3 * we do not want token @VHI to resolve to 3, but stop at VHI as specified in instance */ if(strchr(val, '@')) { my_strdup2(_ALLOC_ID_, &val, - translate3(val, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, template, NULL, res)); + translate3(val, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, template, NULL, &res)); } /* nmos instance format string: @model --> @modeln */ dbg(1, "print_spectre_element(): 1st round: val: |%s|\n", val); if(strchr(val, '@')) { my_strdup2(_ALLOC_ID_, &val, - translate3(val, 0, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, res)); + translate3(val, 0, xctx->inst[inst].prop_ptr, NULL, NULL, NULL, &res)); dbg(1, "print_spectre_element(): 2nd round: val: |%s|\n", val); /* normal passgate.sym placement, nmos instance format string: ad="expr('int((@nf + 1)/2) * @W / @nf * 0.29')" --> ad="expr('int((1 + 1)/2) * W_N/ 1 * 0.29')" */ if(strchr(val, '@')) { my_strdup2(_ALLOC_ID_, &val, - translate3(val, 0, xctx->inst[inst].prop_ptr, parent_templ, NULL, NULL, res)); + translate3(val, 0, xctx->inst[inst].prop_ptr, parent_templ, NULL, NULL, &res)); dbg(1, "print_spectre_element(): 3nd round: val: |%s|\n", val); /* normal passgate.sym placement, nmos instance format string: * @modeln --> nfet_01v8 */ @@ -3180,7 +3180,7 @@ void print_tedax_element(FILE *fd, int inst) Int_hashtable table={NULL, 0}; subcircuit = 1; fprintf(fd, "__subcircuit__ %s %s\n", - sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), res)), xctx->inst[inst].instname); + sanitize(translate(inst, get_sym_name(inst, 0, 0, 0), &res)), xctx->inst[inst].instname); my_free(_ALLOC_ID_, &res); int_hash_init(&table, 37); for(i=0;isym[xctx->inst[inst].ptr].type, "netlist_commands")) { my_strdup2(_ALLOC_ID_, &result, - translate3(result, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, NULL, NULL, res)); + translate3(result, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, NULL, NULL, &res)); /* can not put template in above translate3: -----------------------^^^^ * if instance has VHI=VHI, format string has VHI=@VHI, and symbol template has VHI=3 * we do not want token @VHI to resolve to 3, but stop at VHI as specified in instance */ if(strchr(result, '@')) { my_strdup2(_ALLOC_ID_, &result, - translate3(result, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, template, NULL, res)); + translate3(result, 0, xctx->inst[inst].prop_ptr, parent_prop_ptr, template, NULL, &res)); } } if(res) my_free(_ALLOC_ID_, &res); @@ -4487,7 +4487,7 @@ char *get_fqdevice(const char *param, int modelparam, const char *instname) /* substitute given tokens in a string with their corresponding values */ /* ex.: name=@name w=@w l=@l ---> name=m112 w=3e-6 l=0.8e-6 */ /* if s==NULL return emty string */ -const char *translate(int inst, const char *s, char *result) +const char *translate(int inst, const char *s, char **result) { #ifdef __unix__ static regex_t *get_sp_cur = NULL; @@ -4553,8 +4553,8 @@ const char *translate(int inst, const char *s, char *result) /* sim_is_xyce = tcleval("sim_is_xyce")[0] == '1' ? 1 : 0; */ level = xctx->currsch; lcc = xctx->hier_attr; - STR_ALLOC(&result, result_pos, &size); - result[0]='\0'; + STR_ALLOC(result, result_pos, &size); + (*result)[0]='\0'; dbg(1, "translate(): substituting props in <%s>, instance <%s>\n", s ? s : "" , instname); @@ -4582,28 +4582,28 @@ const char *translate(int inst, const char *s, char *result) token[token_pos]='\0'; if(!strcmp(token, "@name")) { tmp = strlen(instname); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, instname, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, instname, tmp+1); result_pos+=tmp; } else if(inst >= 0 && strcmp(token,"@symref")==0) { tmp_sym_name = get_sym_name(inst, 9999, 1, 0); tmp_sym_name=tmp_sym_name ? tmp_sym_name : ""; tmp=strlen(tmp_sym_name); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,tmp_sym_name, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,tmp_sym_name, tmp+1); result_pos+=tmp; } else if(inst >= 0 && strcmp(token,"@lvs_ignore")==0) { char *lvs = tclgetboolvar("lvs_ignore") ? "1" : "0"; tmp = strlen(lvs); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, lvs, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, lvs, tmp+1); result_pos+=tmp; } else if(inst >= 0 && strcmp(token,"@symname")==0) { tmp_sym_name = get_sym_name(inst, 0, 0, 0); tmp_sym_name=tmp_sym_name ? tmp_sym_name : ""; tmp=strlen(tmp_sym_name); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,tmp_sym_name, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,tmp_sym_name, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@path")==0) { const char *path = xctx->sch_path[xctx->currsch] + 1; @@ -4617,15 +4617,15 @@ const char *translate(int inst, const char *s, char *result) } tmp=strlen(path); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, path, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, path, tmp+1); result_pos+=tmp; } else if(inst >= 0 && strcmp(token,"@symname_ext")==0) { tmp_sym_name = get_sym_name(inst, 0, 1, 0); tmp_sym_name=tmp_sym_name ? tmp_sym_name : ""; tmp=strlen(tmp_sym_name); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,tmp_sym_name, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,tmp_sym_name, tmp+1); result_pos+=tmp; /* recognize single pins 15112003 */ } else if(inst >= 0 && token[0]=='@' && token[1]=='@' && xctx->inst[inst].ptr >= 0) { @@ -4638,8 +4638,8 @@ const char *translate(int inst, const char *s, char *result) if(strboolcmp(get_tok_value(prop,"spice_ignore",0), "true")) { const char *str_ptr = net_name(inst,i, &multip, 0, 0); tmp = strlen(str_ptr); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,str_ptr, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,str_ptr, tmp+1); result_pos+=tmp; } break; @@ -4649,8 +4649,8 @@ const char *translate(int inst, const char *s, char *result) value = get_pin_attr(token, inst, engineering); if(value) { tmp=strlen(value); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, value, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, value, tmp+1); result_pos+=tmp; my_free(_ALLOC_ID_, &value); } @@ -4660,8 +4660,8 @@ const char *translate(int inst, const char *s, char *result) if(!stat(file_name , &time_buf)) { tm=localtime(&(time_buf.st_mtime) ); tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, date, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, date, tmp+1); result_pos+=tmp; } } else if(inst >= 0 && strcmp(token,"@sym_last_modified")==0) { @@ -4669,8 +4669,8 @@ const char *translate(int inst, const char *s, char *result) if(!stat(file_name , &time_buf)) { tm=localtime(&(time_buf.st_mtime) ); tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, date, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, date, tmp+1); result_pos+=tmp; } } else if(strcmp(token,"@time_last_modified")==0) { @@ -4678,34 +4678,34 @@ const char *translate(int inst, const char *s, char *result) if(!stat(file_name , &time_buf)) { tm=localtime(&(time_buf.st_mtime) ); tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, date, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, date, tmp+1); result_pos+=tmp; } } else if(strcmp(token,"@schname_ext")==0) { /* tmp=strlen(xctx->sch[xctx->currsch]);*/ tmp = strlen(xctx->current_name); - STR_ALLOC(&result, tmp + result_pos, &size); + STR_ALLOC(result, tmp + result_pos, &size); /* memcpy(result+result_pos,xctx->sch[xctx->currsch], tmp+1); */ - memcpy(result+result_pos, xctx->current_name, tmp+1); + memcpy(*result+result_pos, xctx->current_name, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@schname")==0) { const char *schname = get_cell(xctx->current_name, 0); tmp = strlen(schname); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, schname, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, schname, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@topschname")==0) { const char *topsch; topsch = get_trailing_path(xctx->sch[0], 0, 1); tmp = strlen(topsch); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, topsch, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, topsch, tmp+1); result_pos+=tmp; } else if(inst >= 0 && strcmp(token,"@prop_ptr")==0 && xctx->inst[inst].prop_ptr) { tmp=strlen(xctx->inst[inst].prop_ptr); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,xctx->inst[inst].prop_ptr, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,xctx->inst[inst].prop_ptr, tmp+1); result_pos+=tmp; } else if(inst >= 0 && strcmp(token,"@spice_get_voltage")==0 && xctx->inst[inst].ptr >= 0) @@ -4759,8 +4759,8 @@ const char *translate(int inst, const char *s, char *result) } if(len) { len = strlen(valstr); - STR_ALLOC(&result, len + result_pos, &size); - memcpy(result+result_pos, valstr, len+1); + STR_ALLOC(result, len + result_pos, &size); + memcpy(*result+result_pos, valstr, len+1); result_pos += len; } dbg(1, "inst %d, net=%s, fqnet=%s idx=%d valstr=%s\n", inst, net, fqnet, idx, valstr); @@ -4793,8 +4793,8 @@ const char *translate(int inst, const char *s, char *result) */ else if(strcmp(token,"@spice_get_node")==0 ) { - STR_ALLOC(&result, 15 + result_pos, &size); - memcpy(result+result_pos, token, 16); + STR_ALLOC(result, 15 + result_pos, &size); + memcpy(*result+result_pos, token, 16); result_pos += 15; } else if(strncmp(token,"@spice_get_voltage(", 19)==0 ) @@ -4861,8 +4861,8 @@ const char *translate(int inst, const char *s, char *result) } if(len) { len = strlen(valstr); - STR_ALLOC(&result, len + result_pos, &size); - memcpy(result+result_pos, valstr, len+1); + STR_ALLOC(result, len + result_pos, &size); + memcpy(*result+result_pos, valstr, len+1); result_pos += len; } dbg(1, "instname %s, net=%s, fqnet=%s idx=%d valstr=%s\n", instname, net, fqnet, idx, valstr); @@ -4963,8 +4963,8 @@ const char *translate(int inst, const char *s, char *result) } if(len) { len = strlen(valstr); - STR_ALLOC(&result, len + result_pos, &size); - memcpy(result+result_pos, valstr, len+1); + STR_ALLOC(result, len + result_pos, &size); + memcpy(*result+result_pos, valstr, len+1); result_pos += len; } dbg(1, "instname %s, dev=%s, fqdev=%s idx=%d valstr=%s\n", instname, dev, fqdev, idx, valstr); @@ -5030,8 +5030,8 @@ const char *translate(int inst, const char *s, char *result) } if(len) { len = strlen(valstr); - STR_ALLOC(&result, len + result_pos, &size); - memcpy(result+result_pos, valstr, len+1); + STR_ALLOC(result, len + result_pos, &size); + memcpy(*result+result_pos, valstr, len+1); result_pos += len; } dbg(1, "inst %d, fqnet1=%s fqnet2=%s idx1=%d idx2=%d, val1=%g val2=%g valstr=%s\n", @@ -5164,8 +5164,8 @@ const char *translate(int inst, const char *s, char *result) } if(len) { len = strlen(valstr); - STR_ALLOC(&result, len + result_pos, &size); - memcpy(result+result_pos, valstr, len+1); + STR_ALLOC(result, len + result_pos, &size); + memcpy(*result+result_pos, valstr, len+1); result_pos += len; } dbg(1, "instname %s, dev=%s, fqdev=%s idx=%d valstr=%s\n", instname, dev, fqdev, idx, valstr); @@ -5178,24 +5178,24 @@ const char *translate(int inst, const char *s, char *result) else if(strcmp(token,"@schvhdlprop")==0 && xctx->schvhdlprop) { tmp=strlen(xctx->schvhdlprop); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,xctx->schvhdlprop, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,xctx->schvhdlprop, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@schspectreprop")==0 && xctx->schspectreprop) { tmp=strlen(xctx->schspectreprop); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,xctx->schspectreprop, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,xctx->schspectreprop, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@schprop")==0 && xctx->schprop) { tmp=strlen(xctx->schprop); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,xctx->schprop, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,xctx->schprop, tmp+1); result_pos+=tmp; } /* /20100217 */ @@ -5203,16 +5203,16 @@ const char *translate(int inst, const char *s, char *result) else if(strcmp(token,"@schsymbolprop")==0 && xctx->schsymbolprop) { tmp=strlen(xctx->schsymbolprop); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,xctx->schsymbolprop, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,xctx->schsymbolprop, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@schtedaxprop")==0 && xctx->schtedaxprop) { tmp=strlen(xctx->schtedaxprop); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,xctx->schtedaxprop, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,xctx->schtedaxprop, tmp+1); result_pos+=tmp; } /* /20100217 */ @@ -5220,8 +5220,8 @@ const char *translate(int inst, const char *s, char *result) else if(strcmp(token,"@schverilogprop")==0 && xctx->schverilogprop) { tmp=strlen(xctx->schverilogprop); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos,xctx->schverilogprop, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos,xctx->schverilogprop, tmp+1); result_pos+=tmp; /* if spiceprefix==0 and token == @spiceprefix then set empty value */ } else if(!sp_prefix && !strcmp(token, "@spiceprefix")) { @@ -5240,9 +5240,9 @@ const char *translate(int inst, const char *s, char *result) if(token[0] =='%') { /* no definition found -> subst with token without leading % */ tmp=token_pos -1 ; /* we need token_pos -1 chars, ( strlen(token+1) ) , excluding leading '%' */ - STR_ALLOC(&result, tmp + result_pos, &size); + STR_ALLOC(result, tmp + result_pos, &size); /* dbg(2, "translate(): token=%s, token_pos = %d\n", token, token_pos); */ - memcpy(result+result_pos, token + 1, tmp+1); + memcpy(*result+result_pos, token + 1, tmp+1); result_pos+=tmp; } } else { @@ -5271,13 +5271,13 @@ const char *translate(int inst, const char *s, char *result) i--; } if(strchr(value1, '@')) { - my_strdup(_ALLOC_ID_, &value1, translate3(value1, 1, schname_attr, NULL, NULL, NULL, res)); + my_strdup(_ALLOC_ID_, &value1, translate3(value1, 1, schname_attr, NULL, NULL, NULL, &res)); } /* substitute remaing @params */ i = level; while(i > 0) { if(strchr(value1, '@')) { - my_strdup(_ALLOC_ID_, &value1, translate3(value1, 1, lcc[i-1].prop_ptr, NULL, NULL, NULL, res)); + my_strdup(_ALLOC_ID_, &value1, translate3(value1, 1, lcc[i-1].prop_ptr, NULL, NULL, NULL, &res)); dbg(1, "2 translate(): lcc[%d].prop_ptr=%s, value1=%s\n", i-1, lcc[i-1].prop_ptr, value1); } else break; i--; @@ -5287,15 +5287,15 @@ const char *translate(int inst, const char *s, char *result) i = level; while(i > 0) { if(strchr(value1, '@')) { - my_strdup(_ALLOC_ID_, &value1, translate3(value1, 1, lcc[i-1].templ, NULL, NULL, NULL, res)); + my_strdup(_ALLOC_ID_, &value1, translate3(value1, 1, lcc[i-1].templ, NULL, NULL, NULL, &res)); dbg(1, "2 translate(): lcc[%d].prop_ptr=%s, value1=%s\n", i-1, lcc[i-1].prop_ptr, value1); } else break; i--; } tmp=strlen(value1); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, value1, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, value1, tmp+1); result_pos+=tmp; my_free(_ALLOC_ID_, &value1); if(res) my_free(_ALLOC_ID_, &res); @@ -5304,43 +5304,43 @@ const char *translate(int inst, const char *s, char *result) token_pos = 0; if(c == '@' || c == '%') s--; else { - STR_ALLOC(&result, 1 + result_pos, &size); - result[result_pos++]=(char)c; + STR_ALLOC(result, 1 + result_pos, &size); + (*result)[result_pos++]=(char)c; } state=TOK_BEGIN; } /* else if(state==TOK_SEP) */ else if(state==TOK_BEGIN) { - STR_ALLOC(&result, 1 + result_pos, &size); - result[result_pos++]=(char)c; + STR_ALLOC(result, 1 + result_pos, &size); + (*result)[result_pos++]=(char)c; } if(c=='\0') { - STR_ALLOC(&result, 1 + result_pos, &size); - result[result_pos]='\0'; + STR_ALLOC(result, 1 + result_pos, &size); + (*result)[result_pos]='\0'; break; } } /* while(1) */ - dbg(2, "translate(): returning %s\n", result); + dbg(2, "translate(): returning %s\n", *result); my_free(_ALLOC_ID_, &token); /* resolve spice_get_node patterns. * if result is like: 'tcleval(some_string)' pass it thru tcl evaluation so expressions * can be calculated */ - my_strdup2(_ALLOC_ID_, &result, tcl_hook2(result)); - my_strdup2(_ALLOC_ID_, &result, spice_get_node(result)); + my_strdup2(_ALLOC_ID_, result, tcl_hook2(*result)); + my_strdup2(_ALLOC_ID_, result, spice_get_node(*result)); - if(is_expr(result) && inst >= 0) { + if(is_expr(*result) && inst >= 0) { char *res = NULL; - dbg(1, "translate(): expr():%s\n", result); - my_strdup2(_ALLOC_ID_, &result, eval_expr( - translate3(result, 1, xctx->inst[inst].prop_ptr, xctx->sym[xctx->inst[inst].ptr].templ, - NULL, NULL, res))); + dbg(1, "translate(): expr():%s\n", *result); + my_strdup2(_ALLOC_ID_, result, eval_expr( + translate3(*result, 1, xctx->inst[inst].prop_ptr, xctx->sym[xctx->inst[inst].ptr].templ, + NULL, NULL, &res))); my_free(_ALLOC_ID_, &res); } - return result; + return *result; } -const char *translate2(Lcc *lcc, int level, char* s, char *result) +const char *translate2(Lcc *lcc, int level, char* s, char **result) { static const char *empty=""; int i, escape = 0; @@ -5353,8 +5353,8 @@ const char *translate2(Lcc *lcc, int level, char* s, char *result) return empty; } size = CADCHUNKALLOC; - my_realloc(_ALLOC_ID_, &result, size); - result[0] = '\0'; + my_realloc(_ALLOC_ID_, result, size); + (*result)[0] = '\0'; dbg(1, "translate2(): s=%s, level=%d\n", s, level); while (1) { c = *s++; @@ -5369,7 +5369,7 @@ const char *translate2(Lcc *lcc, int level, char* s, char *result) if( state==TOK_BEGIN && (c=='@' || c=='%' ) ) state=TOK_TOKEN; else if(state==TOK_TOKEN && token_pos > 1 && ( ( (space || c == '%' || c == '@') ) || escape) ) state = TOK_SEP; - STR_ALLOC(&result, result_pos, &size); + STR_ALLOC(result, result_pos, &size); STR_ALLOC(&token, token_pos, &sizetok); if (state == TOK_TOKEN) token[token_pos++] = (char)c; else if (state == TOK_SEP) { @@ -5407,19 +5407,19 @@ const char *translate2(Lcc *lcc, int level, char* s, char *result) i--; } tmp = strlen(value); - STR_ALLOC(&result, tmp + 1 + result_pos, &size); /* +1 to add leading '%' */ + STR_ALLOC(result, tmp + 1 + result_pos, &size); /* +1 to add leading '%' */ /* prefix substituted token with a '%' so it will be recognized by translate() * for last level translation with instance placement prop_ptr attributes at * drawing/netlisting time. */ - memcpy(result + result_pos , "%", 1); - memcpy(result + result_pos + 1 , value, tmp + 1); + memcpy(*result + result_pos , "%", 1); + memcpy(*result + result_pos + 1 , value, tmp + 1); result_pos += tmp + 1; } else if (strncmp(token, "@spice_get_voltage", 18) == 0 || strncmp(token, "@spice_get_current", 18) == 0) { /* return unchanged */ tmp = strlen(token); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result + result_pos, token, tmp + 1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result + result_pos, token, tmp + 1); result_pos += tmp; } else if(strcmp(token,"@path")==0) { @@ -5436,40 +5436,40 @@ const char *translate2(Lcc *lcc, int level, char* s, char *result) } dbg(1, "path=%s\n", path); tmp=strlen(path); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, path, tmp+1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result+result_pos, path, tmp+1); my_free(_ALLOC_ID_, &path); result_pos+=tmp; } else if (strcmp(token, "@symname") == 0) { tmp_sym_name = lcc[level].symname ? get_cell(lcc[level].symname, 0) : ""; tmp = strlen(tmp_sym_name); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result + result_pos, tmp_sym_name, tmp + 1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result + result_pos, tmp_sym_name, tmp + 1); result_pos += tmp; } else if (strcmp(token, "@symname_ext") == 0) { tmp_sym_name = lcc[level].symname ? get_cell_w_ext(lcc[level].symname, 0) : ""; tmp = strlen(tmp_sym_name); - STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result + result_pos, tmp_sym_name, tmp + 1); + STR_ALLOC(result, tmp + result_pos, &size); + memcpy(*result + result_pos, tmp_sym_name, tmp + 1); result_pos += tmp; } if (c == '%' || c == '@') s--; /* push back to input for next token */ - else result[result_pos++] = (char)c; + else (*result)[result_pos++] = (char)c; state = TOK_BEGIN; } - else if (state == TOK_BEGIN) result[result_pos++] = (char)c; + else if (state == TOK_BEGIN) (*result)[result_pos++] = (char)c; if (c == '\0') { - result[result_pos] = '\0'; + (*result)[result_pos] = '\0'; break; } } /* while(1) */ my_free(_ALLOC_ID_, &token); my_free(_ALLOC_ID_, &value); - dbg(1, "translate2(): result=%s\n", result); + dbg(1, "translate2(): result=%s\n", *result); /* return tcl_hook2(result); */ - return result; + return *result; } @@ -5486,7 +5486,7 @@ const char *translate2(Lcc *lcc, int level, char* s, char *result) * == 1 --> return empty token if no definition found in s* strings */ const char *translate3(const char *s, int eat_escapes, const char *s1, - const char *s2, const char *s3, const char *s4, char *translated_tok) + const char *s2, const char *s3, const char *s4, char **translated_tok) { static const char *empty=""; char *result=NULL; /* safe to keep even with multiple schematics */ @@ -5584,9 +5584,10 @@ const char *translate3(const char *s, int eat_escapes, const char *s1, /* if result is like: 'tcleval(some_string)' pass it thru tcl evaluation so expressions * can be calculated */ dbg(1, "translate3(): result=|%s|\n", result); - my_strdup2(_ALLOC_ID_, &translated_tok, tcl_hook2(result)); + my_strdup2(_ALLOC_ID_, translated_tok, tcl_hook2(result)); + dbg(0, "translate3: %p\n", translated_tok); xctx->tok_size = found_value; if(result) my_free(_ALLOC_ID_, &result); - return translated_tok; + return *translated_tok; } diff --git a/src/verilog_netlist.c b/src/verilog_netlist.c index 8504b38f..8887158d 100644 --- a/src/verilog_netlist.c +++ b/src/verilog_netlist.c @@ -141,7 +141,7 @@ int global_verilog_netlist(int global, int alert) /* netlister driver */ str_tmp = get_tok_value(xctx->sym[xctx->inst[i].ptr].prop_ptr, "verilog_format", 2); my_strdup(_ALLOC_ID_, &tmp_string, str_tmp); - fprintf(fd, "%s\n", str_tmp ? translate(i, tmp_string, res) : ""); + fprintf(fd, "%s\n", str_tmp ? translate(i, tmp_string, &res) : ""); my_free(_ALLOC_ID_, &res); } } @@ -493,7 +493,7 @@ int verilog_block_netlist(FILE *fd, int i, int alert) if(!xctx->tok_size && strcmp(fmt_attr, "verilog_format")) str_tmp = get_tok_value(xctx->sym[xctx->inst[j].ptr].prop_ptr, "verilog_format", 2); my_strdup(_ALLOC_ID_, &tmp_string, str_tmp); - fprintf(fd, "%s\n", str_tmp ? translate(j, tmp_string, res) : ""); + fprintf(fd, "%s\n", str_tmp ? translate(j, tmp_string, &res) : ""); my_free(_ALLOC_ID_, &res); } } diff --git a/src/xschem.h b/src/xschem.h index c26f5a71..44752b24 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1657,10 +1657,10 @@ extern char *find_nth(const char *str, const char *sep, const char *quote, int k extern int isonlydigit(const char *s); extern char *spice_get_node(const char *token); extern char *get_fqdevice(const char *param, int modelparam, const char *instname); -extern const char *translate(int inst, const char* s, char *result); -extern const char* translate2(Lcc *lcc, int level, char* s, char *result); +extern const char *translate(int inst, const char* s, char **result); +extern const char* translate2(Lcc *lcc, int level, char* s, char **result); extern const char *translate3(const char* s, int eat_escapes, const char *s1, - const char *s2, const char *s3, const char *s4, char *translated_tok); + const char *s2, const char *s3, const char *s4, char **translated_tok); extern void print_tedax_element(FILE *fd, int inst); extern int print_spice_element(FILE *fd, int inst); extern void print_spice_subckt_nodes(FILE *fd, int symbol);