sort instance list entries: RHS numbers (like nf=2) come first,

expression then follow.
This commit is contained in:
Holger Vogt 2021-01-07 13:41:11 +01:00
parent 4a6fff05b6
commit 5af7f0ff78
1 changed files with 36 additions and 1 deletions

View File

@ -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);
}