add expr_eng(...) in addition to expr(...) to return result in engineering notation (like 3.2u)
This commit is contained in:
parent
b4283563d0
commit
96d2e56b53
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
static const char *str, *strptr;
|
||||
static char *ret = NULL;
|
||||
|
||||
static int engineering = 0;
|
||||
static int dbglev = 1;
|
||||
|
||||
/* Data type for links in the chain of functions. */
|
||||
|
|
@ -128,7 +128,11 @@ static void get_expr(double x)
|
|||
{
|
||||
char xx[100];
|
||||
dbg(dbglev,"get_expr(): x=%g\n", x);
|
||||
my_snprintf(xx, S(xx), "%.15g", x);
|
||||
if(engineering) {
|
||||
my_snprintf(xx, S(xx), "%s", dtoa_eng(x));
|
||||
} else {
|
||||
my_snprintf(xx, S(xx), "%.15g", x);
|
||||
}
|
||||
my_mstrcat(_ALLOC_ID_, &ret, xx, NULL);
|
||||
strptr = str;
|
||||
}
|
||||
|
|
@ -149,6 +153,10 @@ static void remove_expr(char *s)
|
|||
ptr += 5;
|
||||
plev++;
|
||||
}
|
||||
else if(strstr(ptr, "expr_eng(") == ptr) {
|
||||
ptr += 9;
|
||||
plev++;
|
||||
}
|
||||
if(*ptr == '(') plev++;
|
||||
if(*ptr == ')') {
|
||||
plev--;
|
||||
|
|
@ -226,8 +234,18 @@ static int kklex()
|
|||
lex_state = 1;
|
||||
str += 5;
|
||||
dbg(dbglev, "lex(): EXPR\n");
|
||||
engineering = 0;
|
||||
return EXPR;
|
||||
}
|
||||
|
||||
else if(strstr(str, "expr_eng(") == str) {
|
||||
lex_state = 1;
|
||||
str += 9;
|
||||
dbg(dbglev, "lex(): EXPR_ENG\n");
|
||||
engineering = 1;
|
||||
return EXPR;
|
||||
}
|
||||
|
||||
if(!lex_state) {
|
||||
c = *str++;
|
||||
if(c) {
|
||||
|
|
|
|||
21
src/token.c
21
src/token.c
|
|
@ -920,6 +920,17 @@ int xis_quoted(const char *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char *is_expr(const char *str)
|
||||
{
|
||||
char *ret = NULL;
|
||||
if(str) {
|
||||
ret = strstr(str, "expr(");
|
||||
if(!ret) ret = strstr(str, "expr_eng(");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void print_vhdl_primitive(FILE *fd, int inst) /* netlist primitives, 20071217 */
|
||||
{
|
||||
int i=0, multip, tmp;
|
||||
|
|
@ -1199,7 +1210,7 @@ static void print_vhdl_primitive(FILE *fd, int inst) /* netlist primitives, 200
|
|||
}
|
||||
}
|
||||
my_strdup2(_ALLOC_ID_, &result, tcl_hook2(result)); /* tcl evaluation if tcleval(....) */
|
||||
if(result && strstr(result, "expr(")) {
|
||||
if(is_expr(result)) {
|
||||
my_strdup2(_ALLOC_ID_, &result, eval_expr(result));
|
||||
}
|
||||
dbg(1, "print_vhdl_primitive(): after translate3() result=%s\n", result);
|
||||
|
|
@ -2491,7 +2502,7 @@ int print_spice_element(FILE *fd, int inst)
|
|||
value = spiceprefixtag;
|
||||
}
|
||||
|
||||
if(value && strstr(value, "expr(")) {
|
||||
if(is_expr(value)) {
|
||||
value = eval_expr(value);
|
||||
}
|
||||
/* token=%xxxx and xxxx is not defined in prop_ptr or template: return xxxx */
|
||||
|
|
@ -2546,7 +2557,7 @@ int print_spice_element(FILE *fd, int inst)
|
|||
if(result) {
|
||||
my_strdup(_ALLOC_ID_, &result, tcl_hook2(result));
|
||||
}
|
||||
if(result && strstr(result, "expr(")) {
|
||||
if(is_expr(result)) {
|
||||
my_strdup2(_ALLOC_ID_, &result, eval_expr(result));
|
||||
}
|
||||
if(result) fprintf(fd, "%s", result);
|
||||
|
|
@ -3183,7 +3194,7 @@ static void print_verilog_primitive(FILE *fd, int inst) /* netlist switch level
|
|||
}
|
||||
}
|
||||
my_strdup2(_ALLOC_ID_, &result, tcl_hook2(result)); /* tcl evaluation if tcleval(....) */
|
||||
if(result && strstr(result, "expr(")) {
|
||||
if(is_expr(result)) {
|
||||
my_strdup2(_ALLOC_ID_, &result, eval_expr(result));
|
||||
}
|
||||
dbg(1, "print_verilog_primitive(): after translate3() result=%s\n", result);
|
||||
|
|
@ -4681,7 +4692,7 @@ const char *translate(int inst, const char* s)
|
|||
* can be calculated */
|
||||
my_strdup2(_ALLOC_ID_, &result, spice_get_node(tcl_hook2(result)));
|
||||
|
||||
if(result && strstr(result, "expr(")) {
|
||||
if(is_expr(result)) {
|
||||
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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue