Allow netlist lines to grow during parameter substitution,
removing a 25-character limit on the size of string parameters.
This commit is contained in:
parent
1876e59aaf
commit
3f3c4dc6aa
|
|
@ -60,7 +60,7 @@ int donedico(dico_t *);
|
||||||
void dico_free_entry(entry_t *);
|
void dico_free_entry(entry_t *);
|
||||||
bool defsubckt(dico_t *, const struct card *);
|
bool defsubckt(dico_t *, const struct card *);
|
||||||
int findsubckt(dico_t *, const char *s);
|
int findsubckt(dico_t *, const char *s);
|
||||||
bool nupa_substitute(dico_t *, const char *s, char *r);
|
bool nupa_substitute(dico_t *, const char *s, char **lp);
|
||||||
bool nupa_assignment(dico_t *, const char *s, char mode);
|
bool nupa_assignment(dico_t *, const char *s, char mode);
|
||||||
bool nupa_subcktcall(dico_t *, const char *s, const char *x,
|
bool nupa_subcktcall(dico_t *, const char *s, const char *x,
|
||||||
char *inst_name);
|
char *inst_name);
|
||||||
|
|
|
||||||
|
|
@ -676,10 +676,12 @@ nupa_eval(struct card *card)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (c == 'P') { /* evaluate parameters */
|
if (c == 'P') { /* evaluate parameters */
|
||||||
// err = nupa_substitute(dico, dico->dynrefptr[linenum], s);
|
|
||||||
nupa_assignment(dicoS, dicoS->dynrefptr[linenum], 'N');
|
nupa_assignment(dicoS, dicoS->dynrefptr[linenum], 'N');
|
||||||
} else if (c == 'B') { /* substitute braces line */
|
} else if (c == 'B') { /* substitute braces line */
|
||||||
err = nupa_substitute(dicoS, dicoS->dynrefptr[linenum], s);
|
/* nupa_substitute() may reallocate line buffer. */
|
||||||
|
|
||||||
|
err = nupa_substitute(dicoS, dicoS->dynrefptr[linenum], &card->line);
|
||||||
|
s = card->line;
|
||||||
} else if (c == 'X') {
|
} else if (c == 'X') {
|
||||||
/* compute args of subcircuit, if required */
|
/* compute args of subcircuit, if required */
|
||||||
char *inst_name = copy_substring(s, skip_non_ws(s));
|
char *inst_name = copy_substring(s, skip_non_ws(s));
|
||||||
|
|
|
||||||
|
|
@ -1201,27 +1201,48 @@ evaluate_expr(dico_t *dico, DSTRINGPTR qstr_p, const char *t, const char * const
|
||||||
|
|
||||||
/********* interface functions for spice3f5 extension ***********/
|
/********* interface functions for spice3f5 extension ***********/
|
||||||
|
|
||||||
static char *
|
static bool
|
||||||
insertnumber(dico_t *dico, char * const s, DSTRINGPTR ustr_p)
|
insertnumber(dico_t *dico, char **lp, DSTRINGPTR ustr_p)
|
||||||
/* insert u in string s in place of the next placeholder number */
|
/* insert *ustr_p in string *lp in place of the next placeholder number */
|
||||||
{
|
{
|
||||||
const char *u = ds_get_buf(ustr_p);
|
const char *u = ds_get_buf(ustr_p);
|
||||||
|
char *s = *lp; // Point to line contents
|
||||||
char buf[ACT_CHARACTS+1];
|
long id;
|
||||||
|
int n;
|
||||||
long id = 0;
|
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
char *p = strstr(s, "numparm__________");
|
char *p = strstr(s, "numparm__________");
|
||||||
|
|
||||||
if (p &&
|
if (p &&
|
||||||
(1 == sscanf(p, "numparm__________%8lx%n", &id, &n)) &&
|
(1 == sscanf(p, "numparm__________%8lx%n", &id, &n)) &&
|
||||||
(n == ACT_CHARACTS) &&
|
(n == ACT_CHARACTS) &&
|
||||||
(id > 0) && (id < dynsubst + 1) &&
|
(id > 0) && (id < dynsubst + 1)) {
|
||||||
(snprintf(buf, sizeof(buf), "%-25s", u) == ACT_CHARACTS))
|
/* Found a target for substitution. */
|
||||||
{
|
|
||||||
memcpy(p, buf, ACT_CHARACTS);
|
n = ds_get_length(ustr_p);
|
||||||
return p + ACT_CHARACTS;
|
if (n <= ACT_CHARACTS) {
|
||||||
|
char buf[ACT_CHARACTS + 1];
|
||||||
|
|
||||||
|
/* Replace in place. */
|
||||||
|
|
||||||
|
snprintf(buf, sizeof buf, "%-*s", ACT_CHARACTS, u);
|
||||||
|
memcpy(p, buf, ACT_CHARACTS);
|
||||||
|
} else {
|
||||||
|
char *newline;
|
||||||
|
|
||||||
|
/* Requires reallocation. */
|
||||||
|
|
||||||
|
newline = malloc((p - s) + n + strlen(p + ACT_CHARACTS) + 1);
|
||||||
|
if (!newline) {
|
||||||
|
message(dico, "nupa_substitute failed: no memory\n");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
memcpy(newline, s, (p - s));
|
||||||
|
memcpy(newline + (p - s), u, n);
|
||||||
|
strcpy(newline + (p - s) + n, p + ACT_CHARACTS);
|
||||||
|
free(*lp);
|
||||||
|
*lp = newline;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
message
|
message
|
||||||
|
|
@ -1229,18 +1250,15 @@ insertnumber(dico_t *dico, char * const s, DSTRINGPTR ustr_p)
|
||||||
"insertnumber: fails.\n"
|
"insertnumber: fails.\n"
|
||||||
" s = \"%s\" u=\"%s\" id=%ld\n",
|
" s = \"%s\" u=\"%s\" id=%ld\n",
|
||||||
s, u, id);
|
s, u, id);
|
||||||
|
return TRUE;
|
||||||
/* swallow everything on failure */
|
|
||||||
return s + strlen(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
nupa_substitute(dico_t *dico, const char *s, char *r)
|
nupa_substitute(dico_t *dico, const char *s, char **lp)
|
||||||
/* s: pointer to original source line.
|
/* s: pointer to original source line.
|
||||||
r: pointer to result line, already heavily modified wrt s
|
lp: pointer to result line pointer, line already heavily modified wrt s:
|
||||||
anywhere we find a 10-char numstring in r, substitute it.
|
anywhere we find a 25-char numstring in *lp, substitute it.
|
||||||
bug: wont flag overflow!
|
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
const char * const s_end = s + strlen(s);
|
const char * const s_end = s + strlen(s);
|
||||||
|
|
@ -1248,9 +1266,7 @@ nupa_substitute(dico_t *dico, const char *s, char *r)
|
||||||
|
|
||||||
DS_CREATE(qstr, 200); /* temp result dynamic string */
|
DS_CREATE(qstr, 200); /* temp result dynamic string */
|
||||||
|
|
||||||
|
|
||||||
while (s < s_end) {
|
while (s < s_end) {
|
||||||
|
|
||||||
char c = *s++;
|
char c = *s++;
|
||||||
|
|
||||||
if (c == '{') {
|
if (c == '{') {
|
||||||
|
|
@ -1289,14 +1305,14 @@ nupa_substitute(dico_t *dico, const char *s, char *r)
|
||||||
}
|
}
|
||||||
|
|
||||||
s = kptr + 1;
|
s = kptr + 1;
|
||||||
r = insertnumber(dico, r, &qstr);
|
err = insertnumber(dico, lp, &qstr);
|
||||||
|
if (err)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Lend:
|
Lend:
|
||||||
ds_free(&qstr);
|
ds_free(&qstr);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue