numparam/*, drop "old style" '&' syntax
Probably an artefact of the external preprocessor implementation of numparam. This syntax seems to have been a non spice macro expansion facility.
This commit is contained in:
parent
8022aa09a6
commit
0200d5c7e9
|
|
@ -9,9 +9,6 @@
|
||||||
|
|
||||||
/***** numparam internals ********/
|
/***** numparam internals ********/
|
||||||
|
|
||||||
typedef enum {Intro = '&'} _nIntro; /* Introduces preprocessor tokens */
|
|
||||||
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------
|
/* -----------------------------------------------------------------
|
||||||
* I believe the entry_t should be a union of type but I need more info.
|
* I believe the entry_t should be a union of type but I need more info.
|
||||||
* ----------------------------------------------------------------- */
|
* ----------------------------------------------------------------- */
|
||||||
|
|
|
||||||
|
|
@ -198,63 +198,6 @@ findsubname(dico_t *dico, SPICE_DSTRINGPTR dstr_p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
modernizeex(SPICE_DSTRINGPTR dstr_p)
|
|
||||||
/* old style expressions &(..) and &id --> new style with braces. */
|
|
||||||
{
|
|
||||||
int i, state, ls;
|
|
||||||
char c, d;
|
|
||||||
char *s; /* current string */
|
|
||||||
SPICE_DSTRING t; /* temporary dyna string */
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
state = 0;
|
|
||||||
ls = spice_dstring_length(dstr_p);
|
|
||||||
s = spice_dstring_value(dstr_p);
|
|
||||||
|
|
||||||
/* check if string might need modernizing */
|
|
||||||
if (!memchr(s, Intro, (size_t) ls))
|
|
||||||
return;
|
|
||||||
|
|
||||||
spice_dstring_init(&t);
|
|
||||||
|
|
||||||
while (i < ls) {
|
|
||||||
c = s[i];
|
|
||||||
d = s[i + 1];
|
|
||||||
if ((!state) && (c == Intro) && (i > 0)) {
|
|
||||||
if (d == '(') {
|
|
||||||
state = 1;
|
|
||||||
i++;
|
|
||||||
c = '{';
|
|
||||||
} else if (alfa(d)) {
|
|
||||||
cadd(&t, '{');
|
|
||||||
i++;
|
|
||||||
while (alfanum(s[i])) {
|
|
||||||
cadd(&t, s[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
c = '}';
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
} else if (state) {
|
|
||||||
if (c == '(')
|
|
||||||
state++;
|
|
||||||
else if (c == ')')
|
|
||||||
state--;
|
|
||||||
|
|
||||||
if (!state) /* replace--) by terminator */
|
|
||||||
c = '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
cadd(&t, c);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
scopyd(dstr_p, &t);
|
|
||||||
spice_dstring_free(&t);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char
|
static char
|
||||||
transform(dico_t *dico, SPICE_DSTRINGPTR dstr_p, bool incontrol)
|
transform(dico_t *dico, SPICE_DSTRINGPTR dstr_p, bool incontrol)
|
||||||
/* line s is categorized and crippled down to basic Spice
|
/* line s is categorized and crippled down to basic Spice
|
||||||
|
|
@ -284,7 +227,6 @@ transform(dico_t *dico, SPICE_DSTRINGPTR dstr_p, bool incontrol)
|
||||||
char *s; /* dstring value of dstr_p */
|
char *s; /* dstring value of dstr_p */
|
||||||
char category;
|
char category;
|
||||||
stripsomespace(dstr_p, incontrol);
|
stripsomespace(dstr_p, incontrol);
|
||||||
modernizeex(dstr_p); /* required for stripbraces count */
|
|
||||||
|
|
||||||
s = spice_dstring_value(dstr_p);
|
s = spice_dstring_value(dstr_p);
|
||||||
|
|
||||||
|
|
@ -317,10 +259,6 @@ transform(dico_t *dico, SPICE_DSTRINGPTR dstr_p, bool incontrol)
|
||||||
if (stripbraces(dstr_p) > 0)
|
if (stripbraces(dstr_p) > 0)
|
||||||
category = 'B'; /* priority category ! */
|
category = 'B'; /* priority category ! */
|
||||||
}
|
}
|
||||||
} else if (s[0] == Intro) {
|
|
||||||
/* private style preprocessor line */
|
|
||||||
s[0] = '*';
|
|
||||||
category = 'P';
|
|
||||||
} else if (toupper_c(s[0]) == 'X') {
|
} else if (toupper_c(s[0]) == 'X') {
|
||||||
/* strip actual parameters */
|
/* strip actual parameters */
|
||||||
findsubname(dico, dstr_p);
|
findsubname(dico, dstr_p);
|
||||||
|
|
|
||||||
|
|
@ -1081,44 +1081,6 @@ double_to_string(SPICE_DSTRINGPTR qstr_p, double value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* expand parameter in string `t' to result `q' */
|
|
||||||
static bool
|
|
||||||
evaluate_variable(dico_t *dico, SPICE_DSTRINGPTR qstr_p, const char * const t, const char * const t_end)
|
|
||||||
{
|
|
||||||
entry_t *entry;
|
|
||||||
|
|
||||||
spice_dstring_reinit(qstr_p);
|
|
||||||
|
|
||||||
char *tx = copy_substring(t, t_end);
|
|
||||||
strtoupper(tx);
|
|
||||||
entry = entrynb(dico, tx);
|
|
||||||
tfree(tx);
|
|
||||||
|
|
||||||
if (!entry)
|
|
||||||
return message(dico,
|
|
||||||
"\"%.*s\" not evaluated. Lookup failure.\n", (int) (t_end - t), t);
|
|
||||||
|
|
||||||
if (entry->tp == NUPA_REAL) {
|
|
||||||
double_to_string(qstr_p, entry->vl);
|
|
||||||
}
|
|
||||||
else if (entry->tp == NUPA_STRING) {
|
|
||||||
/* suppose source text "..." at */
|
|
||||||
int j = entry->ivl + 1;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
char c = entry->sbbase[j++];
|
|
||||||
|
|
||||||
if ((c == '\"') || (c < ' '))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
cadd(qstr_p, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* transform exression in string `t' to result q */
|
/* transform exression in string `t' to result q */
|
||||||
static bool
|
static bool
|
||||||
evaluate_expr(dico_t *dico, SPICE_DSTRINGPTR qstr_p, const char *t, const char * const t_end)
|
evaluate_expr(dico_t *dico, SPICE_DSTRINGPTR qstr_p, const char *t, const char * const t_end)
|
||||||
|
|
@ -1231,69 +1193,6 @@ nupa_substitute(dico_t *dico, const char *s, char *r)
|
||||||
s = kptr + 1;
|
s = kptr + 1;
|
||||||
r = insertnumber(dico, r, &qstr);
|
r = insertnumber(dico, r, &qstr);
|
||||||
|
|
||||||
} else if (c == Intro) {
|
|
||||||
/* skip "&&" which may occur in B source */
|
|
||||||
|
|
||||||
if ((s < s_end - 1) && (*s == Intro)) {
|
|
||||||
s++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((s < s_end - 1) && (*s <= ' '))
|
|
||||||
s++;
|
|
||||||
|
|
||||||
if (*s == '(') {
|
|
||||||
/* sub-formula */
|
|
||||||
const char *kptr = s + 1;
|
|
||||||
int level = 1;
|
|
||||||
|
|
||||||
for (; *kptr; kptr++) {
|
|
||||||
|
|
||||||
char d = *kptr;
|
|
||||||
|
|
||||||
if (d == '(')
|
|
||||||
level++;
|
|
||||||
else if (d == ')')
|
|
||||||
level--;
|
|
||||||
|
|
||||||
if ((d == ')') && (level <= 0))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*kptr == '\0') {
|
|
||||||
err = message(dico, "Closing \")\" not found.\n");
|
|
||||||
goto Lend;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = evaluate_expr(dico, &qstr, s + 1, kptr);
|
|
||||||
if (err) {
|
|
||||||
message(dico, "Cannot compute &(expression)\n");
|
|
||||||
goto Lend;
|
|
||||||
}
|
|
||||||
|
|
||||||
s = kptr + 1;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/* simple identifier may also be string? */
|
|
||||||
|
|
||||||
/* fixme, kptr might point behind the terminating '\0' here
|
|
||||||
* causing serious troubles in evaluate_variable()
|
|
||||||
* and/or when updating s
|
|
||||||
*/
|
|
||||||
const char *kptr = s + 1;
|
|
||||||
for (; kptr < s_end; kptr++)
|
|
||||||
if (*kptr <= ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
err = evaluate_variable(dico, &qstr, s, kptr);
|
|
||||||
if (err) {
|
|
||||||
message(dico, "Cannot compute &identifier\n");
|
|
||||||
goto Lend;
|
|
||||||
}
|
|
||||||
s = kptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = insertnumber(dico, r, &qstr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1425,9 +1324,6 @@ nupa_assignment(dico_t *dico, const char * const s, char mode)
|
||||||
while ((p < s_end) && (*p <= ' '))
|
while ((p < s_end) && (*p <= ' '))
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
if (*p == Intro)
|
|
||||||
p++;
|
|
||||||
|
|
||||||
if (*p == '.') /* skip any dot keyword */
|
if (*p == '.') /* skip any dot keyword */
|
||||||
while (*p > ' ')
|
while (*p > ' ')
|
||||||
p++;
|
p++;
|
||||||
|
|
@ -1624,31 +1520,6 @@ nupa_subcktcall(dico_t *dico, char *s, char * const x, char * const inst_name)
|
||||||
char *kp = jp;
|
char *kp = jp;
|
||||||
spice_dstring_reinit(&ustr);
|
spice_dstring_reinit(&ustr);
|
||||||
|
|
||||||
if (*kp == Intro) {
|
|
||||||
|
|
||||||
/* handle historical syntax... */
|
|
||||||
if (alfa(kp[1])) {
|
|
||||||
kp++;
|
|
||||||
} else if (kp[1] == '(') {
|
|
||||||
/* transform to braces... */
|
|
||||||
kp++;
|
|
||||||
*kp = '{';
|
|
||||||
char *gp = kp;
|
|
||||||
int nest = 1;
|
|
||||||
|
|
||||||
while ((nest > 0) && *gp) {
|
|
||||||
gp++;
|
|
||||||
if (*gp == '(')
|
|
||||||
nest++;
|
|
||||||
else if (*gp == ')')
|
|
||||||
nest--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*gp && (nest == 0))
|
|
||||||
*gp = '}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alfanum(*kp) || *kp == '.') {
|
if (alfanum(*kp) || *kp == '.') {
|
||||||
/* number, identifier */
|
/* number, identifier */
|
||||||
jp = skip_non_ws(kp);
|
jp = skip_non_ws(kp);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue