From 0edfbef782095730704ec139e34e88339474634f Mon Sep 17 00:00:00 2001 From: mhx Date: Mon, 2 Jan 2017 16:24:36 +0100 Subject: [PATCH] $.xxx can now read strings defined by .param. Fixed the string handling facilities of nupa. Strings are entered as .param `xxx` (note backquotes). --- src/frontend/numparam/numpaif.h | 2 +- src/frontend/numparam/spicenum.c | 20 +++++++++++++------- src/frontend/numparam/xpressn.c | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/frontend/numparam/numpaif.h b/src/frontend/numparam/numpaif.h index bf570d2a6..fcc2be422 100644 --- a/src/frontend/numparam/numpaif.h +++ b/src/frontend/numparam/numpaif.h @@ -18,7 +18,7 @@ extern int nupa_eval(char *s, int linenum, int orig_linenum); extern int nupa_signal(int sig, char *info); extern void nupa_scan(char * s, int linenum, int is_subckt, struct nscope *level); extern void nupa_list_params(FILE *cp_out); -extern double nupa_get_param(char *param_name, int *found); +extern double nupa_get_param(char *param_name, int *found, char **text); extern void nupa_add_param(char *param_name, double value); extern void nupa_add_inst_param(char *param_name, double value); extern void nupa_copy_inst_dico(void); diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index c38466c76..0427dff6f 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -563,11 +563,14 @@ dump_symbol_table(dico_t *dico, NGHASHPTR htable_p, FILE *fp) entry; entry = (entry_t *) nghash_enumerateRE(htable_p, &iter)) { - if (entry->tp == 'R') { + if (entry->tp == 'R' || entry->tp == 'S') { 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); + fprintf(fp, " ---> %s = ", name); + if(entry->tp == 'R') + fprintf(fp, "%g\n", entry->vl); + else fprintf(fp, "%s\n", entry->sbbase); spice_dstring_free(& dico->lookup_buf); } } @@ -613,7 +616,7 @@ nupa_list_params(FILE *fp) * table. * ----------------------------------------------------------------- */ double -nupa_get_param(char *param_name, int *found) +nupa_get_param(char *param_name, int *found, char **text) { int depth; /* nested subcircit depth */ char *up_name; /* current parameter upper case */ @@ -632,10 +635,13 @@ nupa_get_param(char *param_name, int *found) if (htable_p) { entry = (entry_t *) nghash_find(htable_p, up_name); if (entry) { - result = entry->vl; - *found = 1; - break; - } + switch (entry->tp) { + case 'S': result = 1; *found = 'S'; *text = entry->sbbase; break; + case 'R': result = entry->vl; *found = 'R'; break; + default: *found = 0; fprintf(cp_err, "ERROR: nupa found an unrecognized type (%c).\n", entry->tp); + } + break; + } } } diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index 0ebefe6cf..af140f6b4 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -998,8 +998,8 @@ formula(dico_t *dico, const char *s, const char *s_end, bool *perror) int ix; for (ix = 2; ix < argi; ix++) /* mhx */ if (arg[ix] > s) { wx[ix] = formula(dico, s, arg[ix] - 1, &error); s = arg[ix]; } - u = formula(dico, s, kptr - 1, &error); - v = wx[2]; w = wx[3]; wx[argi] = u; /* mhx */ + u = formula(dico, s, kptr - 1, &error); + v = wx[2]; w = wx[3]; wx[argi] = u; /* mhx */ state = S_atom; if (fu > 0) { if ((fu == XFU_TERNARY_FCN)) @@ -1552,6 +1552,9 @@ nupa_assignment(dico_t *dico, char *s, char mode) error = message(dico, " Identifier expected\n"); if (!error) { + int ix; + char *strptr = NULL; + /* assignment expressions */ while ((i <= ls) && (s[i - 1] != '=')) i++; @@ -1559,7 +1562,12 @@ nupa_assignment(dico_t *dico, char *s, char mode) if (i > ls) error = message(dico, " = sign expected.\n"); - dtype = getexpress(s, &ustr, &i); + for (ix = i; ix < ls - 1; ix++) { /* change delimiters {` and `} to double quotes */ + if (s[ix] == '{' && s[ix + 1] == '`') { s[ix] = ' '; s[ix + 1] = '"'; strptr = &s[ix + 1]; } + if (s[ix] == '`' && s[ix + 1] == '}') { s[ix] = '"'; s[ix + 1] = '\0'; } + } + + dtype = getexpress(s, &ustr, &i); if (dtype == 'R') { const char *tmp = spice_dstring_value(&ustr); @@ -1573,7 +1581,7 @@ nupa_assignment(dico_t *dico, char *s, char mode) } err = nupa_define(dico, spice_dstring_value(&tstr), mode /* was ' ' */ , - dtype, rval, wval, NULL, NULL); + dtype, rval, wval, strptr, NULL); error = error || err; }