From 4aed813422245e0308885b7907e16df7a02cd14a Mon Sep 17 00:00:00 2001 From: mhx Date: Sat, 7 Jan 2017 23:46:44 +0100 Subject: [PATCH] Enabled NUPA's capability to recognize quoted strings. NUPA has an options string ( dico->option that must be set to SPICE-3. When not, recognized strings are uppercased before being returned. Facilitated .PARAM to recognize strings in two ways: by sharps #xxx# and now also by quotes "xxx". --- src/frontend/inp.c | 10 ++++++---- src/frontend/numparam/xpressn.c | 24 ++++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index b6a1f4bf8..e6f6bb3b2 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -589,8 +589,11 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) /* lines .width, .four, .plot, .print, .save added to wl_first, removed from deck */ /* lines .op, .meas, .tf added to wl_first */ inp_casefix(s); /* s: first token from line */ - inp_casefix(dd->li_line); - if (eq(s, ".width") || + if (!ciprefix(".param", s)) + /* mhx: casefix strips quotes(!?), and .PARAM therefore does not see them. */ + /* maybe .func shold also be allowed? */ + inp_casefix(dd->li_line); + if (eq(s, ".width") || ciprefix(".four", s) || eq(s, ".plot") || eq(s, ".print") || @@ -1382,8 +1385,7 @@ com_alterparam(wordlist *wl) curr_line = dd->li_line; char *start = gettok_char(&curr_line, '=', TRUE, FALSE); tfree(dd->li_line); - /* mhx: re-inserted braces. It works/ed (sometimes) without them. */ - dd->li_line = tprintf("%s{%s}", start, pval); + dd->li_line = tprintf("%s%s", start, pval); found = TRUE; tfree(start); } diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index a3e822187..6d9ce29ad 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -251,8 +251,9 @@ initdico(dico_t *dico) int asize = NESTINGDEPTH; /* default allocation depth of the synbol stack */ COMPATMODE_T compat_mode; - spice_dstring_init(&(dico->option)); - spice_dstring_init(&(dico->srcfile)); + spice_dstring_init (&(dico->option)); + spice_dstring_value (&dico->option) = "spice-3"; /* mhx: If not, nupa uppercases quoted strings */ + spice_dstring_init (&(dico->srcfile)); dico->srcline = -1; dico->errcount = 0; @@ -1539,6 +1540,10 @@ nupa_assignment(dico_t *dico, char *s, char mode) SPICE_DSTRING tstr; /* temporary dstring */ SPICE_DSTRING ustr; /* temporary dstring */ +#define SHARP(x) (s[x] == '#' || s[x] == '"') +#define LBRAC(x) (s[x] == '{') +#define RBRAC(x) (s[x] == '}') + spice_dstring_init(&tstr); spice_dstring_init(&ustr); ls = length(s); @@ -1573,14 +1578,10 @@ nupa_assignment(dico_t *dico, char *s, char mode) if (i > ls) error = message(dico, " = sign expected.\n"); - for (ix = i; ix < ls - 1; ix++) { /* change delimiters {# and #} to double quotes */ - int ssharp = 0; - 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'; } - if (s[ix] == '#' && !s[ix + 1] == '}') { - s[ix] = '"'; ssharp++; - if (ssharp == 2) { s[ix + 1] = '\0'; ssharp = 0; } - } + strptr = strchr(&s[i], '\"'); /* mhx: maybe this is a quoted string already; .param x = "hello" */ + for (ix = i; ix < ls - 1; ix++) { /* change possible delimiters {# and #} to double quotes */ + if (LBRAC(ix) && SHARP(ix + 1)) { s[ix] = ' '; s[ix + 1] = '"'; strptr = &s[ix + 1]; } + if (SHARP(ix) && RBRAC(ix + 1)) { s[ix] = '"'; s[ix + 1] = '\0'; } } dtype = getexpress(s, &ustr, &i); @@ -1611,6 +1612,9 @@ nupa_assignment(dico_t *dico, char *s, char mode) spice_dstring_free(&ustr); return error; +#undef SHARP +#undef RBRAC +#undef LBRAC }