From 5af7f0ff78ced40e6a9b6f9f622a729a9485dd63 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Thu, 7 Jan 2021 13:41:11 +0100 Subject: [PATCH] sort instance list entries: RHS numbers (like nf=2) come first, expression then follow. --- src/frontend/numparam/xpressn.c | 37 ++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index c3cc60823..c153b4edd 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -31,6 +31,7 @@ extern long dynsubst; /* see inpcom.c */ #define S_unop 3 #define S_stop 4 +static char* sort_idlist(char *list); static double ternary_fcn(double conditional, double if_value, double else_value) @@ -1540,7 +1541,10 @@ nupa_subcktcall(dico_t *dico, const char *s, const char *x, /* ;} else { debugwarn(dico, idlist) */ } - err = nupa_assignment(dico, ds_get_buf(&idlist), 'N'); + /* sort the idlist, so that plain numerical entries like nf=2 move to the front */ + char* sortedlist = sort_idlist(ds_get_buf(&idlist)); + + err = nupa_assignment(dico, sortedlist, 'N'); ds_free(&subname); ds_free(&tstr); @@ -1548,6 +1552,8 @@ nupa_subcktcall(dico_t *dico, const char *s, const char *x, ds_free(&vstr); ds_free(&idlist); + tfree(sortedlist); + return err; } @@ -1567,3 +1573,32 @@ const struct nupa_type S_nupa_real = { "NUPA_REAL" }; const struct nupa_type S_nupa_string = { "NUPA_STRING" }; const struct nupa_type S_nupa_subckt = { "NUPA_SUBCKT" }; const struct nupa_type S_nupa_unknown = { "NUPA_UNKNOWN" }; + +/* get the instance line list, sort numerical entries (eg. nf=1) to the front */ +static char* sort_idlist(char* list) { + wordlist* wl = NULL, *wle = NULL; + bool start = TRUE; + char* cut_list = list; + while (*cut_list != '\0') { + int error; + char* token = gettok_char(&cut_list, ';', TRUE, FALSE); + char* eqstr = strchr(token, '='); + eqstr++; + INPevaluate(&eqstr, &error, 1); + /* num entry, prepend word */ + if (error == 0 && *eqstr == '\0') { + wle = wl_cons(token, wle); + if (start) + wl = wle; + start = FALSE; + } + /* expression, append word */ + else { + wl_append_word(&wl, &wl, token); + if (start) + wle = wl; + start = FALSE; + } + } + return wl_flatten(wle); +}