allow to pass down to tcl evaluation (via tcleval( ....) wrap) instance parameters: example of a mos transistor : name=m1 w=2 l=0.13 model=net ad="tcleval([expr @W * 0.29])" --> in netlist: m1 d g s b nfet w=2 l=0.13 ... ad=0.58

This commit is contained in:
Stefan Frederik 2020-11-20 18:46:27 +01:00
parent 759c44078e
commit 0d59d01170
5 changed files with 48 additions and 17 deletions

View File

@ -18,9 +18,6 @@
/* Define to 1 if popen(3) is not available but fork(2) and pipe(2) are available */
/*#undef HAS_PIPE */
#ifndef XSCHEM_LIBRARY_PATH
#define XSCHEM_LIBRARY_PATH "C:/Program Files/XSchem/xschem_library;C:/Program Files/XSchem/xschem_library/devices;C:/Program Files/XSchem/xschem_library/examples;C:/Program Files/XSchem/xschem_library/ngspice;C:/Program Files/XSchem/xschem_library/logic;C:/Program Files/XSchem/xschem_library/binto7seg;C:/Program Files/XSchem/xschem_library/pcb;C:/Program Files/XSchem/xschem_library/rom8k"
#endif
#define USER_CONF_DIR "userConf"
/* Extra includes required by the detected libs (may be empty): */

View File

@ -223,6 +223,7 @@ void print_image()
}
#ifdef HAS_CAIRO
void set_cairo_color(int layer)
{
cairo_set_source_rgb(cairo_ctx,
@ -235,7 +236,6 @@ void set_cairo_color(int layer)
(double)xcolor_array[layer].blue/65535.0);
}
#ifdef HAS_CAIRO
/* remember to call cairo_restore(cairo_ctx) when done !! */
int set_text_custom_font(xText *txt) /* 20171122 for correct text_bbox calculation */
{

View File

@ -281,7 +281,7 @@ static void svg_draw_string(int layer, const char *str, int rot, int flip, int h
if(rot == 3 && flip == 1 ) { x=textx1;}
}
llength=0;
my_strdup2(73, &sss, str);
my_strdup2(434, &sss, str);
tt=ss=sss;
for(;;) {
c=*ss;
@ -298,7 +298,7 @@ static void svg_draw_string(int layer, const char *str, int rot, int flip, int h
}
ss++;
}
my_free(1157, &sss);
my_free(1154, &sss);
}

View File

@ -1431,6 +1431,7 @@ void print_spice_element(FILE *fd, int inst)
register int c, state=TOK_BEGIN, space;
char *template=NULL,*format=NULL,*s, *name=NULL, *token=NULL;
const char *lab, *value = NULL;
char *translatedvalue = NULL;
int pin_number;
int sizetok=0;
int token_pos=0, escape=0;
@ -1500,10 +1501,14 @@ void print_spice_element(FILE *fd, int inst)
} else {
dbg(1, "print_spice_element(): token: |%s|\n", token);
value = get_tok_value(xctx->inst[inst].prop_ptr, token+1, 2);
if (value[0] == '\0')
value=get_tok_value(template, token+1, 0);
if (value[0] == '\0') value=get_tok_value(template, token+1, 0);
if (!strncmp(value,"tcleval(", 8)) {
my_strdup2(62, &translatedvalue, translate(inst, value));
value = translatedvalue;
}
}
if(!get_tok_size && token[0] =='$') {
if(!value[0] && token[0] =='$') {
tmp = strlen(token + 1) +100 ; /* always make room for some extra chars
@ -1663,6 +1668,13 @@ void print_spice_element(FILE *fd, int inst)
my_strdup(22, &result, translate(inst, result));
dbg(1, "print_spice_element(): after translate()result=%s\n", result);
}
/* can't remember what the f**k this is supposed to do.
why eval( and not tcleval( ?
disable until some regression pops out
*/
#if 0
/* do a second round of substitutions, but without calling tcl */
if(result && strstr(result, "eval(") == result) {
char *c = strrchr(result, ')');
@ -1673,12 +1685,16 @@ void print_spice_element(FILE *fd, int inst)
}
my_strdup2(88, &result, translate(inst, result+5));
}
#endif
fprintf(fd, "%s", result);
my_free(1019, &template);
my_free(1020, &format);
my_free(1021, &name);
my_free(1022, &token);
my_free(1194, &result);
my_free(63, &translatedvalue);
}
void print_tedax_element(FILE *fd, int inst)

View File

@ -981,10 +981,18 @@ int Tcl_AppInit(Tcl_Interp *inter)
my_snprintf(user_conf_dir, S(user_conf_dir), "%s", tclresult());
tclsetvar("USER_CONF_DIR", user_conf_dir);
#else
my_snprintf(tmp, S(tmp),"regsub -all {~/} {.;%s} {%s/}", XSCHEM_LIBRARY_PATH, home_dir);
tcleval(tmp);
tclsetvar("XSCHEM_LIBRARY_PATH", tclresult());
char install_dir[MAX_PATH];
char install_dir[MAX_PATH]="";
char *up_hier=NULL, *win_xschem_library_path=NULL;
#define WIN_XSCHEM_LIBRARY_PATH_NUM 8
const char *WIN_XSCHEM_LIBRARY_PATH[WIN_XSCHEM_LIBRARY_PATH_NUM] = {
/*1*/ "xschem_library",
/*2*/ "xschem_library/devices",
/*3*/ "xschem_library/examples",
/*4*/ "xschem_library/ngspice",
/*5*/ "xschem_library/logic",
/*6*/ "xschem_library/binto7seg",
/*7*/ "xschem_library/pcb",
/*8*/ "xschem_library/rom8k"};
GetModuleFileNameA(NULL, install_dir, MAX_PATH);
change_to_unix_fn(install_dir);
int dir_len=strlen(install_dir);
@ -996,11 +1004,21 @@ int Tcl_AppInit(Tcl_Interp *inter)
if (atoi(tclresult()) == 0)
{
running_in_src_dir = 1; /* no bin, so it's running in Visual studio source directory*/
my_snprintf(tmp, S(tmp), "subst [regsub {\\w+/\\w+/\\w+$} \"%s\" {}]xschem_library/devices", install_dir);
tcleval(tmp);
my_snprintf(tmp, S(tmp), ".;%s", tclresult());
tclsetvar("XSCHEM_LIBRARY_PATH", tmp);
my_strdup(62, &up_hier, "../../..");
}
else my_strdup(63, &up_hier, "..");
my_strcat(415, &win_xschem_library_path, ".");
for (i = 0; i < WIN_XSCHEM_LIBRARY_PATH_NUM; ++i) {
my_snprintf(tmp, S(tmp),"%s/%s/%s", install_dir, up_hier, WIN_XSCHEM_LIBRARY_PATH[i]);
my_strcat(416, &win_xschem_library_path, "\;");
my_strcat(431, &win_xschem_library_path, tmp);
}
my_snprintf(tmp, S(tmp), "set tmp2 \"%s\"; while {[regsub {([^/]*\\.*[^./]+[^/]*)/\\.\\./?} $tmp2 {} tmp2]} {}; ", win_xschem_library_path);
const char *result2 = tcleval(tmp);
const char *win_xschem_library_path_clean = tclgetvar("tmp2");
tclsetvar("XSCHEM_LIBRARY_PATH", win_xschem_library_path_clean);
my_free(432, &win_xschem_library_path);
my_free(441, &up_hier);
char* gxschem_library=NULL, *xschem_sharedir=NULL;
if ((xschem_sharedir=getenv("XSCHEM_SHAREDIR")) != NULL) {
if (!stat(xschem_sharedir, &buf)) {