numparam/*, drop case conversions
inpcom.c is supposed to convert everything to lower case. Thus we can work case sensitive in numparam, which is easier compared to a whole set of local case conversions.
This commit is contained in:
parent
0200d5c7e9
commit
ea1b83698f
|
|
@ -10,14 +10,10 @@
|
|||
|
||||
|
||||
char *pscopy(SPICE_DSTRINGPTR s, const char *str, const char *stop);
|
||||
char *pscopy_up(SPICE_DSTRINGPTR s, const char *str, const char *stop);
|
||||
void scopyd(SPICE_DSTRINGPTR a, SPICE_DSTRINGPTR b);
|
||||
void scopys(SPICE_DSTRINGPTR a, const char *b);
|
||||
void scopy_up(SPICE_DSTRINGPTR a, const char *str);
|
||||
void scopy_lower(SPICE_DSTRINGPTR a, const char *str);
|
||||
void sadd(SPICE_DSTRINGPTR s, const char *t);
|
||||
void cadd(SPICE_DSTRINGPTR s, char c);
|
||||
bool ci_prefix(const char *p, const char *s);
|
||||
|
||||
bool alfa(char c);
|
||||
bool alfanum(char c);
|
||||
|
|
|
|||
|
|
@ -52,21 +52,6 @@ yes_or_no(void)
|
|||
}
|
||||
|
||||
|
||||
bool
|
||||
ci_prefix(const char *p, const char *s)
|
||||
{
|
||||
while (*p) {
|
||||
if ((isupper_c(*p) ? tolower_c(*p) : *p) !=
|
||||
(isupper_c(*s) ? tolower_c(*s) : *s))
|
||||
return (0);
|
||||
p++;
|
||||
s++;
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/******* Strings ************
|
||||
* are 0-terminated char arrays with a 2-byte trailer: max length.
|
||||
* the string mini-library is "overflow-safe" under these conditions:
|
||||
|
|
@ -129,44 +114,6 @@ scopys(SPICE_DSTRINGPTR s, const char *t) /* returns success flag */
|
|||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------
|
||||
* Create an upper case copy of a string and store it in a dynamic string.
|
||||
* Dynamic strings are always NULL * terminated.
|
||||
* ----------------------------------------------------------------- */
|
||||
void
|
||||
scopy_up(SPICE_DSTRINGPTR dstr_p, const char *str) /* returns success flag */
|
||||
{
|
||||
char up[2]; /* short string */
|
||||
const char *ptr; /* position in string */
|
||||
|
||||
spice_dstring_reinit(dstr_p);
|
||||
up[1] = '\0';
|
||||
for (ptr = str; ptr && *ptr; ptr++) {
|
||||
up[0] = toupper_c(*ptr);
|
||||
spice_dstring_append(dstr_p, up, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------
|
||||
* Create a lower case copy of a string and store it in a dynamic string.
|
||||
* Dynamic strings are always NULL * terminated.
|
||||
* ----------------------------------------------------------------- */
|
||||
void
|
||||
scopy_lower(SPICE_DSTRINGPTR dstr_p, const char *str) /* returns success flag */
|
||||
{
|
||||
char low[2]; /* short string */
|
||||
const char *ptr; /* position in string */
|
||||
|
||||
spice_dstring_reinit(dstr_p);
|
||||
low[1] = '\0';
|
||||
for (ptr = str; ptr && *ptr; ptr++) {
|
||||
low[0] = tolower_c(*ptr);
|
||||
spice_dstring_append(dstr_p, low, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
pscopy(SPICE_DSTRINGPTR dstr_p, const char *t, const char *stop)
|
||||
{
|
||||
|
|
@ -187,26 +134,6 @@ pscopy(SPICE_DSTRINGPTR dstr_p, const char *t, const char *stop)
|
|||
}
|
||||
|
||||
|
||||
char *
|
||||
pscopy_up(SPICE_DSTRINGPTR dstr_p, const char *t, const char *stop)
|
||||
{
|
||||
int i;
|
||||
char *s_p;
|
||||
|
||||
if (!stop)
|
||||
stop = strchr(t, '\0');
|
||||
|
||||
s_p = _spice_dstring_setlength(dstr_p, (int)(stop - t));
|
||||
|
||||
for (i = 0; t < stop;)
|
||||
s_p[i++] = toupper_c(*t++);
|
||||
|
||||
s_p[i] = '\0';
|
||||
|
||||
return s_p;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
alfa(char c)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ typedef struct entry_s {
|
|||
|
||||
|
||||
typedef struct { /* the input scanner data structure */
|
||||
SPICE_DSTRING lookup_buf; /* useful temp buffer for quick symbol lookup */
|
||||
int srcline;
|
||||
int oldline;
|
||||
int errcount;
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ findsubname(dico_t *dico, SPICE_DSTRINGPTR dstr_p)
|
|||
/* check for known subckt name */
|
||||
spice_dstring_reinit(&name);
|
||||
for (t = p; alfanum(*t); t++)
|
||||
cadd(&name, toupper_c(*t));
|
||||
cadd(&name, *t);
|
||||
entry = entrynb(dico, spice_dstring_value(&name));
|
||||
if (entry && (entry->tp == NUPA_SUBCKT)) {
|
||||
spice_dstring_setlength(dstr_p, (int) (p_end - s));
|
||||
|
|
@ -232,34 +232,29 @@ transform(dico_t *dico, SPICE_DSTRINGPTR dstr_p, bool incontrol)
|
|||
|
||||
if (s[0] == '.') {
|
||||
/* check PS parameter format */
|
||||
if (ci_prefix(".PARAM", s)) {
|
||||
if (prefix(".param", s)) {
|
||||
/* comment it out */
|
||||
/* s[0] = '*'; */
|
||||
category = 'P';
|
||||
} else if (ci_prefix(".SUBCKT", s)) {
|
||||
char *params, *t;
|
||||
SPICE_DSTRING tstr;
|
||||
spice_dstring_init(&tstr);
|
||||
scopy_up(&tstr, s);
|
||||
t = spice_dstring_value(&tstr);
|
||||
} else if (prefix(".subckt", s)) {
|
||||
char *params;
|
||||
/* split off any "params" tail */
|
||||
params = strstr(t, "PARAMS:");
|
||||
params = strstr(s, "params:");
|
||||
if (params)
|
||||
pscopy(dstr_p, s, s + (params - t));
|
||||
spice_dstring_free(&tstr);
|
||||
pscopy(dstr_p, s, params);
|
||||
category = 'S';
|
||||
} else if (ci_prefix(".CONTROL", s)) {
|
||||
} else if (prefix(".control", s)) {
|
||||
category = 'C';
|
||||
} else if (ci_prefix(".ENDC", s)) {
|
||||
} else if (prefix(".endc", s)) {
|
||||
category = 'E';
|
||||
} else if (ci_prefix(".ENDS", s)) {
|
||||
} else if (prefix(".ends", s)) {
|
||||
category = 'U';
|
||||
} else {
|
||||
category = '.';
|
||||
if (stripbraces(dstr_p) > 0)
|
||||
category = 'B'; /* priority category ! */
|
||||
}
|
||||
} else if (toupper_c(s[0]) == 'X') {
|
||||
} else if (s[0] == 'x') {
|
||||
/* strip actual parameters */
|
||||
findsubname(dico, dstr_p);
|
||||
category = 'X';
|
||||
|
|
@ -396,9 +391,8 @@ nupa_scan(struct card *card, int is_subckt)
|
|||
* Dump the contents of a symbol table.
|
||||
* ----------------------------------------------------------------- */
|
||||
static void
|
||||
dump_symbol_table(dico_t *dico, NGHASHPTR htable_p, FILE *fp)
|
||||
dump_symbol_table(NGHASHPTR htable_p, FILE *fp)
|
||||
{
|
||||
char *name; /* current symbol */
|
||||
entry_t *entry; /* current entry */
|
||||
NGHASHITER iter; /* hash iterator - thread safe */
|
||||
|
||||
|
|
@ -407,13 +401,8 @@ dump_symbol_table(dico_t *dico, NGHASHPTR htable_p, FILE *fp)
|
|||
entry;
|
||||
entry = (entry_t *) nghash_enumerateRE(htable_p, &iter))
|
||||
{
|
||||
if (entry->tp == NUPA_REAL) {
|
||||
spice_dstring_reinit(& dico->lookup_buf);
|
||||
scopy_lower(& dico->lookup_buf, entry->symbol);
|
||||
name = spice_dstring_value(& dico->lookup_buf);
|
||||
fprintf(fp, " ---> %s = %g\n", name, entry->vl);
|
||||
spice_dstring_free(& dico->lookup_buf);
|
||||
}
|
||||
if (entry->tp == NUPA_REAL)
|
||||
fprintf(fp, " ---> %s = %g\n", entry->symbol, entry->vl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -441,7 +430,7 @@ nupa_list_params(FILE *fp)
|
|||
fprintf(fp, " local symbol definitions for: %s\n", dico->inst_name[depth]);
|
||||
else
|
||||
fprintf(fp, " global symbol definitions:\n");
|
||||
dump_symbol_table(dico, htable_p, fp);
|
||||
dump_symbol_table(htable_p, fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -460,29 +449,20 @@ nupa_get_param(char *param_name, int *found)
|
|||
{
|
||||
dico_t *dico = dicoS; /* local copy for speed */
|
||||
int depth; /* nested subcircit depth */
|
||||
char *up_name; /* current parameter upper case */
|
||||
entry_t *entry; /* current entry */
|
||||
double result = 0; /* parameter value */
|
||||
|
||||
spice_dstring_reinit(& dico->lookup_buf);
|
||||
scopy_up(& dico->lookup_buf, param_name);
|
||||
up_name = spice_dstring_value(& dico->lookup_buf);
|
||||
|
||||
*found = 0;
|
||||
for (depth = dico->stack_depth; depth >= 0; depth--) {
|
||||
NGHASHPTR htable_p = dico->symbols[depth];
|
||||
if (htable_p) {
|
||||
entry = (entry_t *) nghash_find(htable_p, up_name);
|
||||
entry_t *entry = (entry_t *) nghash_find(htable_p, param_name);
|
||||
if (entry) {
|
||||
result = entry->vl;
|
||||
*found = 1;
|
||||
break;
|
||||
return entry->vl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spice_dstring_free(& dico->lookup_buf);
|
||||
return result;
|
||||
*found = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -490,33 +470,22 @@ void
|
|||
nupa_add_param(char *param_name, double value)
|
||||
{
|
||||
dico_t *dico = dicoS; /* local copy for speed */
|
||||
char *up_name; /* current parameter upper case */
|
||||
entry_t *entry; /* current entry */
|
||||
NGHASHPTR htable_p; /* hash table of interest */
|
||||
|
||||
/* -----------------------------------------------------------------
|
||||
* We use a dynamic string here because most of the time we will
|
||||
* be using short names and no memory allocation will occur.
|
||||
* ----------------------------------------------------------------- */
|
||||
spice_dstring_reinit(& dico->lookup_buf);
|
||||
scopy_up(& dico->lookup_buf, param_name);
|
||||
up_name = spice_dstring_value(& dico->lookup_buf);
|
||||
|
||||
/* can't be lazy anymore */
|
||||
if (!(dico->symbols[dico->stack_depth]))
|
||||
dico->symbols[dico->stack_depth] = nghash_init(NGHASH_MIN_SIZE);
|
||||
|
||||
htable_p = dico->symbols[dico->stack_depth];
|
||||
|
||||
entry = attrib(dico, htable_p, up_name, 'N');
|
||||
entry = attrib(dico, htable_p, param_name, 'N');
|
||||
if (entry) {
|
||||
entry->vl = value;
|
||||
entry->tp = NUPA_REAL;
|
||||
entry->ivl = 0;
|
||||
entry->sbbase = NULL;
|
||||
}
|
||||
|
||||
spice_dstring_free(& dico->lookup_buf);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -524,25 +493,18 @@ void
|
|||
nupa_add_inst_param(char *param_name, double value)
|
||||
{
|
||||
dico_t *dico = dicoS; /* local copy for speed */
|
||||
char *up_name; /* current parameter upper case */
|
||||
entry_t *entry; /* current entry */
|
||||
|
||||
spice_dstring_reinit(& dico->lookup_buf);
|
||||
scopy_up(& dico->lookup_buf, param_name);
|
||||
up_name = spice_dstring_value(& dico->lookup_buf);
|
||||
|
||||
if (!(dico->inst_symbols))
|
||||
dico->inst_symbols = nghash_init(NGHASH_MIN_SIZE);
|
||||
|
||||
entry = attrib(dico, dico->inst_symbols, up_name, 'N');
|
||||
entry = attrib(dico, dico->inst_symbols, param_name, 'N');
|
||||
if (entry) {
|
||||
entry->vl = value;
|
||||
entry->tp = NUPA_REAL;
|
||||
entry->ivl = 0;
|
||||
entry->sbbase = NULL;
|
||||
}
|
||||
|
||||
spice_dstring_free(& dico->lookup_buf);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -677,8 +639,6 @@ nupa_eval(struct card *card)
|
|||
char *inst_name = copy_substring(s, skip_non_ws(s));
|
||||
*inst_name = 'x';
|
||||
|
||||
strtoupper(inst_name);
|
||||
|
||||
idef = findsubckt(dicoS, s);
|
||||
if (idef > 0)
|
||||
nupa_subcktcall(dicoS, dicoS->dynrefptr[idef], dicoS->dynrefptr[linenum], inst_name);
|
||||
|
|
|
|||
|
|
@ -82,9 +82,9 @@ limit(double nominal_val, double abs_variation)
|
|||
|
||||
|
||||
static const char *fmathS = /* all math functions */
|
||||
"SQR SQRT SIN COS EXP LN ARCTAN ABS POW PWR MAX MIN INT LOG LOG10 SINH COSH"
|
||||
" TANH TERNARY_FCN AGAUSS SGN GAUSS UNIF AUNIF LIMIT CEIL FLOOR"
|
||||
" ASIN ACOS ATAN ASINH ACOSH ATANH TAN NINT";
|
||||
"sqr sqrt sin cos exp ln arctan abs pow pwr max min int log log10 sinh cosh"
|
||||
" tanh ternary_fcn agauss sgn gauss unif aunif limit ceil floor"
|
||||
" asin acos atan asinh acosh atanh tan nint";
|
||||
|
||||
|
||||
enum {
|
||||
|
|
@ -244,8 +244,6 @@ initdico(dico_t *dico)
|
|||
dico->srcline = -1;
|
||||
dico->errcount = 0;
|
||||
|
||||
spice_dstring_init(&(dico->lookup_buf));
|
||||
|
||||
dico->symbols = TMALLOC(NGHASHPTR, asize);
|
||||
dico->inst_name = TMALLOC(char*, asize);
|
||||
dico->max_stack_depth = asize;
|
||||
|
|
@ -532,7 +530,7 @@ defsubckt(dico_t *dico, struct card *card, nupa_type categ)
|
|||
if (s_end > s) {
|
||||
SPICE_DSTRING ustr; /* temp user string */
|
||||
spice_dstring_init(&ustr);
|
||||
pscopy_up(&ustr, s, s_end);
|
||||
pscopy(&ustr, s, s_end);
|
||||
err = nupa_define(dico, spice_dstring_value(&ustr), ' ', categ, 0.0, w, NULL);
|
||||
spice_dstring_free(&ustr);
|
||||
} else {
|
||||
|
|
@ -556,7 +554,7 @@ findsubckt(dico_t *dico, const char * const s)
|
|||
|
||||
spice_dstring_init(&ustr);
|
||||
|
||||
pscopy_up(&ustr, name_b, name_e);
|
||||
pscopy(&ustr, name_b, name_e);
|
||||
entry = entrynb(dico, spice_dstring_value(&ustr));
|
||||
|
||||
if (entry && (entry->tp == NUPA_SUBCKT)) {
|
||||
|
|
@ -581,7 +579,7 @@ keyword(const char *keys, const char *s, const char *s_end)
|
|||
|
||||
for (;;) {
|
||||
const char *p = s;
|
||||
while ((p < s_end) && (toupper_c(*p) == *keys))
|
||||
while ((p < s_end) && (*p == *keys))
|
||||
p++, keys++;
|
||||
if ((p >= s_end) && (*keys <= ' '))
|
||||
return j;
|
||||
|
|
@ -603,7 +601,7 @@ parseunit(const char *s)
|
|||
case 'T': return 1e12;
|
||||
case 'G': return 1e9;
|
||||
case 'K': return 1e3;
|
||||
case 'M': return ci_prefix("MEG", s) ? 1e6 : 1e-3;
|
||||
case 'M': return ciprefix("MEG", s) ? 1e6 : 1e-3;
|
||||
case 'U': return 1e-6;
|
||||
case 'N': return 1e-9;
|
||||
case 'P': return 1e-12;
|
||||
|
|
@ -956,7 +954,7 @@ formula(dico_t *dico, const char *s, const char *s_end, bool *perror)
|
|||
} else {
|
||||
spice_dstring_reinit(&tstr);
|
||||
while (s < s_next)
|
||||
cadd(&tstr, toupper_c(*s++));
|
||||
cadd(&tstr, *s++);
|
||||
u = fetchnumentry(dico, spice_dstring_value(&tstr), &error);
|
||||
state = S_atom;
|
||||
}
|
||||
|
|
@ -1214,7 +1212,7 @@ getword(const char *s, SPICE_DSTRINGPTR tstr_p)
|
|||
spice_dstring_reinit(tstr_p);
|
||||
|
||||
while ((s < s_end) && (alfa(*s) || isdigit_c(*s)))
|
||||
cadd(tstr_p, toupper_c(*s++));
|
||||
cadd(tstr_p, *s++);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1427,9 +1425,9 @@ nupa_subcktcall(dico_t *dico, char *s, char * const x, char * const inst_name)
|
|||
/***** first, analyze the subckt definition line */
|
||||
n = 0; /* number of parameters if any */
|
||||
|
||||
scopy_up(&tstr, s);
|
||||
scopys(&tstr, s);
|
||||
|
||||
const char *j2 = strstr(spice_dstring_value(&tstr), "SUBCKT");
|
||||
const char *j2 = strstr(spice_dstring_value(&tstr), "subckt");
|
||||
if (j2) {
|
||||
j2 = skip_ws(j2 + 6); /* skip subckt and whitespace */
|
||||
while (*j2 && (*j2 != ' '))
|
||||
|
|
@ -1438,7 +1436,7 @@ nupa_subcktcall(dico_t *dico, char *s, char * const x, char * const inst_name)
|
|||
err = message(dico, " ! a subckt line!\n");
|
||||
}
|
||||
|
||||
const char *i2 = strstr(spice_dstring_value(&tstr), "PARAMS:");
|
||||
const char *i2 = strstr(spice_dstring_value(&tstr), "params:");
|
||||
|
||||
if (i2) {
|
||||
const char *optr, *jptr;
|
||||
|
|
@ -1490,7 +1488,7 @@ nupa_subcktcall(dico_t *dico, char *s, char * const x, char * const inst_name)
|
|||
skip over instance name -- fixes bug where instance 'x1' is
|
||||
same name as subckt 'x1'
|
||||
*/
|
||||
scopy_up(&tstr, skip_non_ws(x));
|
||||
scopys(&tstr, skip_non_ws(x));
|
||||
|
||||
char * const t_p = spice_dstring_value(&tstr);
|
||||
char *jp = NULL;
|
||||
|
|
|
|||
Loading…
Reference in New Issue