Browse Source

cleanup, use wl_cons(), wl_append_word() and wl_chop_rest()

rlar 14 years ago
parent
commit
9655b9885a
  1. 4
      src/frontend/arg.c
  2. 5
      src/frontend/com_history.c
  3. 29
      src/frontend/device.c
  4. 24
      src/frontend/dotcards.c
  5. 11
      src/frontend/help/readhelp.c
  6. 34
      src/frontend/inp.c
  7. 52
      src/frontend/inpcom.c
  8. 9
      src/frontend/measure.c
  9. 17
      src/frontend/nutinp.c
  10. 4
      src/frontend/parser/backq.c
  11. 50
      src/frontend/parser/complete.c
  12. 12
      src/frontend/parser/glob.c
  13. 3
      src/frontend/parser/lexical.c
  14. 7
      src/frontend/plotting/plotit.c
  15. 8
      src/frontend/rawfile.c
  16. 6
      src/frontend/runcoms.c
  17. 28
      src/frontend/subckt.c
  18. 32
      src/frontend/variable.c
  19. 24
      src/misc/wlist.c

4
src/frontend/arg.c

@ -116,9 +116,7 @@ common(char *string, struct wordlist *wl, struct comm *command)
if ((buf = prompt(cp_in)) == NULL) /* prompt aborted */ if ((buf = prompt(cp_in)) == NULL) /* prompt aborted */
return; /* don't execute command */ return; /* don't execute command */
/* do something with the wordlist */ /* do something with the wordlist */
w = alloc(struct wordlist);
w->wl_word = buf;
w->wl_next = NULL;
w = wl_cons(buf, NULL);
w = process(w); w = process(w);
/* O.K. now call fn */ /* O.K. now call fn */

5
src/frontend/com_history.c

@ -133,10 +133,7 @@ dohsubst(char *string)
break; break;
case '\0': /* Maybe this should be cp_event. */ case '\0': /* Maybe this should be cp_event. */
wl = alloc(struct wordlist);
wl->wl_word = copy("!");
wl->wl_next = NULL;
wl->wl_prev = NULL;
wl = wl_cons(copy("!"), NULL);
cp_didhsubst = FALSE; cp_didhsubst = FALSE;
return (wl); return (wl);

29
src/frontend/device.c

@ -1095,7 +1095,7 @@ com_alter_common(wordlist *wl, int do_model)
char *argument; char *argument;
char **arglist; char **arglist;
int i=0, step=0, n, wlen, maxelem=3; int i=0, step=0, n, wlen, maxelem=3;
wordlist *wl2 = NULL, *wlin, *wleq;
wordlist *wl2 = NULL, *wlin, *rhs;
bool eqfound = FALSE, vecfound = FALSE; bool eqfound = FALSE, vecfound = FALSE;
if (!ft_curckt) { if (!ft_curckt) {
@ -1207,18 +1207,9 @@ com_alter_common(wordlist *wl, int do_model)
return; return;
} }
/* add the '=' */ /* add the '=' */
/* create wordlist with '=' */
wleq = TMALLOC(wordlist, 1);
wleq->wl_word = copy("=");
/* add the last element (the value of the param - value pair) */
wleq->wl_next = wlin;
/* move back one element to place equal sign */
wlin = wlin->wl_prev; wlin = wlin->wl_prev;
/* add ' = value' */
wlin->wl_next = wleq;
wleq->wl_prev = wlin;
if(wleq->wl_next)
wleq->wl_next->wl_prev = wleq;
rhs = wl_chop_rest(wlin);
wlin = wl_append(wlin, wl_cons(copy("="), rhs));
/* step back until 'alter' or 'altermod' is found, /* step back until 'alter' or 'altermod' is found,
then move one step forward */ then move one step forward */
while (!ciprefix("alter",wlin->wl_word)) //while (!ciprefix(wlin->wl_word,"alter")) while (!ciprefix("alter",wlin->wl_word)) //while (!ciprefix(wlin->wl_word,"alter"))
@ -1353,26 +1344,18 @@ com_alter_common(wordlist *wl, int do_model)
static wordlist * static wordlist *
devexpand(char *name) devexpand(char *name)
{ {
wordlist *wl, *devices, *tw;
wordlist *wl, *devices;
if (strchr(name, '*') || strchr(name, '[') || strchr(name, '?')) { if (strchr(name, '*') || strchr(name, '[') || strchr(name, '?')) {
devices = cp_cctowl(ft_curckt->ci_devices); devices = cp_cctowl(ft_curckt->ci_devices);
for (wl = NULL; devices; devices = devices->wl_next) for (wl = NULL; devices; devices = devices->wl_next)
if (cp_globmatch(name, devices->wl_word)) { if (cp_globmatch(name, devices->wl_word)) {
tw = alloc(struct wordlist);
if (wl) {
wl->wl_prev = tw;
tw->wl_next = wl;
wl = tw;
} else
wl = tw;
wl->wl_word = devices->wl_word;
wl = wl_cons(devices->wl_word, wl);
} }
} else if (cieq(name, "all")) { } else if (cieq(name, "all")) {
wl = cp_cctowl(ft_curckt->ci_devices); wl = cp_cctowl(ft_curckt->ci_devices);
} else { } else {
wl = alloc(struct wordlist);
wl->wl_word = name;
wl = wl_cons(name, NULL);
} }
wl_sort(wl); wl_sort(wl);
return (wl); return (wl);

24
src/frontend/dotcards.c

@ -438,17 +438,10 @@ fixdotplot(wordlist *wl)
d2 = *d; d2 = *d;
tfree(wl->wl_word); tfree(wl->wl_word);
wl->wl_word = copy("xlimit"); wl->wl_word = copy("xlimit");
wl->wl_next = alloc(struct wordlist);
wl->wl_next->wl_prev = wl;
wl = wl->wl_next;
printnum(numbuf, d1); printnum(numbuf, d1);
wl->wl_word = copy(numbuf);
wl->wl_next = alloc(struct wordlist);
wl->wl_next->wl_prev = wl;
wl = wl->wl_next;
wl_append_word(NULL, &wl, copy(numbuf));
printnum(numbuf, d2); printnum(numbuf, d2);
wl->wl_word = copy(numbuf);
wl_append_word(NULL, &wl, copy(numbuf));
} }
wl = wl->wl_next; wl = wl->wl_next;
} }
@ -544,8 +537,7 @@ gettoks(char *s)
continue; continue;
l =strrchr(t, '('/*)*/); l =strrchr(t, '('/*)*/);
if (!l) { if (!l) {
wl = alloc(struct wordlist);
wl->wl_word = copy(t);
wl = wl_cons(copy(t), NULL);
*prevp = wl; *prevp = wl;
prevp = &wl->wl_next; prevp = &wl->wl_next;
continue; continue;
@ -560,7 +552,9 @@ gettoks(char *s)
if (c) if (c)
*c = 0; *c = 0;
wl = alloc(struct wordlist);
wl = wl_cons(NULL, NULL);
*prevp = wl;
prevp = &wl->wl_next;
if (*(l - 1) == 'i' || *(l - 1) == 'I') { if (*(l - 1) == 'i' || *(l - 1) == 'I') {
char buf[513]; char buf[513];
@ -570,13 +564,9 @@ gettoks(char *s)
} else } else
wl->wl_word = copy(l + 1); wl->wl_word = copy(l + 1);
*prevp = wl;
prevp = &wl->wl_next;
if (c != r) { if (c != r) {
*r = 0; *r = 0;
wl = alloc(struct wordlist);
wl->wl_word = copy(c + 1);
wl = wl_cons(copy(c + 1), NULL);
*prevp = wl; *prevp = wl;
prevp = &wl->wl_next; prevp = &wl->wl_next;
} }

11
src/frontend/help/readhelp.c

@ -64,7 +64,7 @@ hlp_read(fplace *place)
topic *top = alloc(topic); topic *top = alloc(topic);
toplink *topiclink; toplink *topiclink;
toplink *tl, *tend = NULL; toplink *tl, *tend = NULL;
wordlist *wl, *end = NULL;
wordlist *end = NULL;
int i, fchanges; int i, fchanges;
char *s; char *s;
bool mof = FALSE; bool mof = FALSE;
@ -104,14 +104,7 @@ hlp_read(fplace *place)
((s[0] == '_') && (s[1] == '\b'))) ((s[0] == '_') && (s[1] == '\b')))
fchanges++; fchanges++;
*s = '\0'; *s = '\0';
wl = alloc(wordlist);
wl->wl_word = copy(&buf[6]);
if (end)
end->wl_next = wl;
else
top->text = wl;
wl->wl_prev = end;
end = wl;
wl_append_word(&(top->text), &end, copy(&buf[6]));
top->numlines++; top->numlines++;
i = (int) strlen(&buf[6]) - fchanges; i = (int) strlen(&buf[6]) - fchanges;
if (top->maxcols < i) if (top->maxcols < i)

34
src/frontend/inp.c

@ -442,24 +442,18 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
else else
fprintf(cp_err, "Warning: misplaced .endc card\n"); fprintf(cp_err, "Warning: misplaced .endc card\n");
} else if (commands || prefix("*#", dd->li_line)) { } else if (commands || prefix("*#", dd->li_line)) {
wl = alloc(struct wordlist);
if (controls) {
wl->wl_next = controls;
controls->wl_prev = wl;
controls = wl;
} else
controls = wl;
/* more control lines */ /* more control lines */
if (prefix("*#", dd->li_line)) if (prefix("*#", dd->li_line))
wl->wl_word = copy(dd->li_line + 2);
s = copy(dd->li_line + 2);
else { else {
wl->wl_word = dd->li_line;
s = dd->li_line;
dd->li_line = 0; /* SJB - prevent line_free() freeing the string (now pointed at by wl->wl_word) */ dd->li_line = 0; /* SJB - prevent line_free() freeing the string (now pointed at by wl->wl_word) */
} }
controls = wl_cons(s, controls);
wl = controls;
/* Look for set or unset numparams. /* Look for set or unset numparams.
If either are found then we evaluate these lines immediately If either are found then we evaluate these lines immediately
so they take effect before netlist parsing */ so they take effect before netlist parsing */
s = wl->wl_word;
while(isspace(*s)) s++; /* step past any white space */ while(isspace(*s)) s++; /* step past any white space */
if(ciprefix("set", s)) { if(ciprefix("set", s)) {
s+=3; s+=3;
@ -492,13 +486,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
|| eq(s, ".op") || eq(s, ".op")
|| ciprefix(".meas", s) || ciprefix(".meas", s)
|| eq(s, ".tf")) { || eq(s, ".tf")) {
if (end) {
end->wl_next = alloc(struct wordlist);
end->wl_next->wl_prev = end;
end = end->wl_next;
} else
wl_first = end = alloc(struct wordlist);
end->wl_word = copy(dd->li_line);
wl_append_word(&wl_first, &end, copy(dd->li_line));
if (!eq(s, ".op") && !eq(s, ".tf") && !ciprefix(".meas", s)) { if (!eq(s, ".op") && !eq(s, ".tf") && !ciprefix(".meas", s)) {
ld->li_next = dd->li_next; ld->li_next = dd->li_next;
@ -561,7 +549,6 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
if ( ciprefix(".csparam", dd->li_line) ) { if ( ciprefix(".csparam", dd->li_line) ) {
wordlist *wlist = NULL; wordlist *wlist = NULL;
wordlist *wl = NULL; wordlist *wl = NULL;
wordlist *cwl;
char *cstoken[3]; char *cstoken[3];
int i; int i;
s = dd->li_line; s = dd->li_line;
@ -572,16 +559,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
cstoken[1]=gettok_char(&s, '=', TRUE); cstoken[1]=gettok_char(&s, '=', TRUE);
cstoken[2]=gettok(&s); cstoken[2]=gettok(&s);
for (i=0; i<3;i++) { for (i=0; i<3;i++) {
cwl = alloc(struct wordlist);
cwl->wl_prev = wl;
if (wl)
wl->wl_next = cwl;
else {
wlist = cwl;
cwl->wl_next = NULL;
}
cwl->wl_word = cstoken[i];
wl = cwl;
wl_append_word(&wlist, &wl, cstoken[i]);
} }
com_let(wlist); com_let(wlist);
wl_free(wlist); wl_free(wlist);

52
src/frontend/inpcom.c

@ -2990,7 +2990,7 @@ inp_fix_param_values( struct line *deck )
char *line, *beg_of_str, *end_of_str, *old_str, *equal_ptr, *new_str; char *line, *beg_of_str, *end_of_str, *old_str, *equal_ptr, *new_str;
char *vec_str, *natok, *buffer, *newvec, *whereisgt; char *vec_str, *natok, *buffer, *newvec, *whereisgt;
bool control_section = FALSE; bool control_section = FALSE;
wordlist *wl, *nwl;
wordlist *nwl;
int parens; int parens;
while ( c != NULL ) { while ( c != NULL ) {
@ -3097,7 +3097,6 @@ inp_fix_param_values( struct line *deck )
for (;;) { for (;;) {
natok = gettok(&vec_str); natok = gettok(&vec_str);
if (!natok) break; if (!natok) break;
wl = alloc(struct wordlist);
buffer = TMALLOC(char, strlen(natok) + 4); buffer = TMALLOC(char, strlen(natok) + 4);
if ( isdigit(*natok) || *natok == '{' || *natok == '.' || if ( isdigit(*natok) || *natok == '{' || *natok == '.' ||
@ -3130,12 +3129,8 @@ inp_fix_param_values( struct line *deck )
(void) sprintf(buffer, "{%s}", natok); (void) sprintf(buffer, "{%s}", natok);
} }
tfree(natok); tfree(natok);
wl->wl_word = copy(buffer);
nwl = wl_cons(copy(buffer), nwl);
tfree(buffer); tfree(buffer);
wl->wl_next = nwl;
if (nwl)
nwl->wl_prev = wl;
nwl = wl;
} }
nwl = wl_reverse(nwl); nwl = wl_reverse(nwl);
/* new vector elements */ /* new vector elements */
@ -3165,7 +3160,6 @@ inp_fix_param_values( struct line *deck )
for (;;) { for (;;) {
natok = gettok(&vec_str); natok = gettok(&vec_str);
if (!natok) break; if (!natok) break;
wl = alloc(struct wordlist);
buffer = TMALLOC(char, strlen(natok) + 4); buffer = TMALLOC(char, strlen(natok) + 4);
if ( isdigit(*natok) || *natok == '{' || *natok == '.' || if ( isdigit(*natok) || *natok == '{' || *natok == '.' ||
@ -3176,12 +3170,8 @@ inp_fix_param_values( struct line *deck )
(void) sprintf(buffer, "{%s}", natok); (void) sprintf(buffer, "{%s}", natok);
} }
tfree(natok); tfree(natok);
wl->wl_word = copy(buffer);
nwl = wl_cons(copy(buffer), nwl);
tfree(buffer); tfree(buffer);
wl->wl_next = nwl;
if (nwl)
nwl->wl_prev = wl;
nwl = wl;
} }
nwl = wl_reverse(nwl); nwl = wl_reverse(nwl);
/* new elements of complex variable */ /* new elements of complex variable */
@ -4959,7 +4949,7 @@ static void inp_bsource_compat(struct line *deck)
char *equal_ptr, *str_ptr, *tmp_char, *new_str, *final_str; char *equal_ptr, *str_ptr, *tmp_char, *new_str, *final_str;
char actchar, prevchar = ' '; char actchar, prevchar = ' ';
struct line *card, *new_line, *tmp_ptr; struct line *card, *new_line, *tmp_ptr;
wordlist *wl = NULL, *wlist = NULL, *cwl;
wordlist *wl = NULL, *wlist = NULL;
char buf[512]; char buf[512];
size_t i, xlen, ustate = 0; size_t i, xlen, ustate = 0;
int skip_control = 0; int skip_control = 0;
@ -5008,14 +4998,7 @@ static void inp_bsource_compat(struct line *deck)
str_ptr++; str_ptr++;
if (*str_ptr == '\0') break; if (*str_ptr == '\0') break;
actchar = *str_ptr; actchar = *str_ptr;
cwl = alloc(struct wordlist);
cwl->wl_prev = wl;
if (wl)
wl->wl_next = cwl;
else {
wlist = cwl;
cwl->wl_next = NULL;
}
wl_append_word(&wlist, &wl, NULL);
if ((actchar == ',') || (actchar == '(') || (actchar == ')') if ((actchar == ',') || (actchar == '(') || (actchar == ')')
|| (actchar == '*') || (actchar == '/') || (actchar == '^') || (actchar == '*') || (actchar == '/') || (actchar == '^')
|| (actchar == '+') || (actchar == '?') || (actchar == ':')) { || (actchar == '+') || (actchar == '?') || (actchar == ':')) {
@ -5025,7 +5008,7 @@ static void inp_bsource_compat(struct line *deck)
} }
buf[0] = actchar; buf[0] = actchar;
buf[1] = '\0'; buf[1] = '\0';
cwl->wl_word = copy(buf);
wl->wl_word = copy(buf);
str_ptr++; str_ptr++;
if (actchar == ')') ustate = 0; if (actchar == ')') ustate = 0;
else ustate = 1; /* we have an operator */ else ustate = 1; /* we have an operator */
@ -5035,22 +5018,22 @@ static void inp_bsource_compat(struct line *deck)
char *beg = str_ptr++; char *beg = str_ptr++;
if ((*str_ptr == '=') || (*str_ptr == '<') || (*str_ptr == '>')) if ((*str_ptr == '=') || (*str_ptr == '<') || (*str_ptr == '>'))
str_ptr++; str_ptr++;
cwl->wl_word = copy_substring(beg, str_ptr);
wl->wl_word = copy_substring(beg, str_ptr);
ustate = 1; /* we have an operator */ ustate = 1; /* we have an operator */
} else if ((actchar == '|') || (actchar == '&')) { } else if ((actchar == '|') || (actchar == '&')) {
char *beg = str_ptr++; char *beg = str_ptr++;
if ((*str_ptr == '|') || (*str_ptr == '&')) if ((*str_ptr == '|') || (*str_ptr == '&'))
str_ptr++; str_ptr++;
cwl->wl_word = copy_substring(beg, str_ptr);
wl->wl_word = copy_substring(beg, str_ptr);
ustate = 1; /* we have an operator */ ustate = 1; /* we have an operator */
} else if ((actchar == '-') && (ustate == 0)) { } else if ((actchar == '-') && (ustate == 0)) {
buf[0] = actchar; buf[0] = actchar;
buf[1] = '\0'; buf[1] = '\0';
cwl->wl_word = copy(buf);
wl->wl_word = copy(buf);
str_ptr++; str_ptr++;
ustate = 1; /* we have an operator */ ustate = 1; /* we have an operator */
} else if ((actchar == '-') && (ustate == 1)) { } else if ((actchar == '-') && (ustate == 1)) {
cwl->wl_word = copy("");
wl->wl_word = copy("");
str_ptr++; str_ptr++;
ustate = 2; /* place a '-' in front of token */ ustate = 2; /* place a '-' in front of token */
} else if (isalpha(actchar)) { } else if (isalpha(actchar)) {
@ -5068,7 +5051,7 @@ static void inp_bsource_compat(struct line *deck)
} }
buf[i] = *str_ptr; buf[i] = *str_ptr;
buf[i+1] = '\0'; buf[i+1] = '\0';
cwl->wl_word = copy(buf);
wl->wl_word = copy(buf);
str_ptr++; str_ptr++;
} else { } else {
while (isalnum(*str_ptr) || (*str_ptr == '!') || (*str_ptr == '#') while (isalnum(*str_ptr) || (*str_ptr == '!') || (*str_ptr == '#')
@ -5138,7 +5121,7 @@ static void inp_bsource_compat(struct line *deck)
str_ptr++; str_ptr++;
} }
*/ */
cwl->wl_word = copy(buf);
wl->wl_word = copy(buf);
} }
else if (cieq(buf, "tc1") || cieq(buf, "tc2") || cieq(buf, "reciproctc")) { else if (cieq(buf, "tc1") || cieq(buf, "tc2") || cieq(buf, "reciproctc")) {
while (isspace(*str_ptr)) while (isspace(*str_ptr))
@ -5148,13 +5131,13 @@ static void inp_bsource_compat(struct line *deck)
buf[i++] = '='; buf[i++] = '=';
buf[i] = '\0'; buf[i] = '\0';
str_ptr++; str_ptr++;
cwl->wl_word = copy(buf);
wl->wl_word = copy(buf);
} }
else { else {
xlen = strlen(buf); xlen = strlen(buf);
tmp_char = TMALLOC(char, xlen + 3); tmp_char = TMALLOC(char, xlen + 3);
sprintf(tmp_char, "{%s}", buf); sprintf(tmp_char, "{%s}", buf);
cwl->wl_word = tmp_char;
wl->wl_word = tmp_char;
} }
} }
/* {} around all other tokens */ /* {} around all other tokens */
@ -5162,7 +5145,7 @@ static void inp_bsource_compat(struct line *deck)
xlen = strlen(buf); xlen = strlen(buf);
tmp_char = TMALLOC(char, xlen + 3); tmp_char = TMALLOC(char, xlen + 3);
sprintf(tmp_char, "{%s}", buf); sprintf(tmp_char, "{%s}", buf);
cwl->wl_word = tmp_char;
wl->wl_word = tmp_char;
} }
} }
ustate = 0; /* we have a number */ ustate = 0; /* we have a number */
@ -5174,7 +5157,7 @@ static void inp_bsource_compat(struct line *deck)
if (ustate == 2) if (ustate == 2)
dvalue *= -1; dvalue *= -1;
sprintf(cvalue,"%18.10e", dvalue); sprintf(cvalue,"%18.10e", dvalue);
cwl->wl_word = copy(cvalue);
wl->wl_word = copy(cvalue);
ustate = 0; /* we have a number */ ustate = 0; /* we have a number */
/* skip the `unit', FIXME INPevaluate() should do this */ /* skip the `unit', FIXME INPevaluate() should do this */
while(isalpha(*str_ptr)) while(isalpha(*str_ptr))
@ -5183,10 +5166,9 @@ static void inp_bsource_compat(struct line *deck)
printf("Preparing B line for numparam\nWhat is this?\n%s\n", str_ptr); printf("Preparing B line for numparam\nWhat is this?\n%s\n", str_ptr);
buf[0] = *str_ptr; buf[0] = *str_ptr;
buf[1] = '\0'; buf[1] = '\0';
cwl->wl_word = copy(buf);
wl->wl_word = copy(buf);
str_ptr++; str_ptr++;
} }
wl = cwl;
prevchar = actchar; prevchar = actchar;
} }

9
src/frontend/measure.c

@ -127,9 +127,7 @@ com_meas(wordlist *wl) {
} }
sprintf(newvec, "%s = %e", outvar, result); sprintf(newvec, "%s = %e", outvar, result);
wl_let = alloc(struct wordlist);
wl_let->wl_next = NULL;
wl_let->wl_word = copy(newvec);
wl_let = wl_cons(copy(newvec), NULL);
com_let(wl_let); com_let(wl_let);
wl_free(wl_let); wl_free(wl_let);
// fprintf(stdout, "in: %s\n", line_in); // fprintf(stdout, "in: %s\n", line_in);
@ -433,10 +431,7 @@ static wordlist *measure_parse_line( char *line )
txfree( extra_item ) ; txfree( extra_item ) ;
item = long_str ; item = long_str ;
} }
new_item = alloc(struct wordlist) ;
new_item->wl_word = item ;
new_item->wl_next = NULL ;
new_item->wl_prev = NULL ;
new_item = wl_cons(item, NULL);
wl = wl_append(wl, new_item) ; wl = wl_append(wl, new_item) ;
} while( line && *line ) ; } while( line && *line ) ;

17
src/frontend/nutinp.c

@ -119,13 +119,8 @@ inp_nutsource(FILE *fp, bool comfile, char *filename)
fprintf(cp_err, fprintf(cp_err,
"Warning: misplaced .endc line\n"); "Warning: misplaced .endc line\n");
} else if (commands || prefix("*#", dd->li_line)) { } else if (commands || prefix("*#", dd->li_line)) {
wl = alloc(struct wordlist);
if (controls) {
wl->wl_next = controls;
controls->wl_prev = wl;
controls = wl;
} else
controls = wl;
controls = wl_cons(NULL, controls);
wl = controls;
if (prefix("*#", dd->li_line)) if (prefix("*#", dd->li_line))
wl->wl_word = copy(dd->li_line + 2); wl->wl_word = copy(dd->li_line + 2);
else else
@ -146,13 +141,7 @@ inp_nutsource(FILE *fp, bool comfile, char *filename)
eq(s, ".plot") || eq(s, ".plot") ||
eq(s, ".print") || eq(s, ".print") ||
eq(s, ".save")) { eq(s, ".save")) {
if (end) {
end->wl_next = alloc(struct wordlist);
end->wl_next->wl_prev = end;
end = end->wl_next;
} else
wl = end = alloc(struct wordlist);
end->wl_word = copy(dd->li_line);
wl_append_word(&wl, &end, copy(dd->li_line));
ld->li_next = dd->li_next; ld->li_next = dd->li_next;
tfree(dd->li_line); tfree(dd->li_line);
tfree(dd); tfree(dd);

4
src/frontend/parser/backq.c

@ -107,9 +107,7 @@ backeval(char *string)
(void) pclose(proc); (void) pclose(proc);
return (wl); return (wl);
#else #else
wordlist *wl = alloc(struct wordlist);
wl->wl_word = copy(string);
wordlist *wl = wl_cons(copy(string), NULL);
return (wl); return (wl);
#endif #endif
} }

50
src/frontend/parser/complete.c

@ -204,7 +204,7 @@ ccfilec(char *buf)
DIR *wdir; DIR *wdir;
char *lcomp, *dir; char *lcomp, *dir;
struct direct *de; struct direct *de;
wordlist *wl = NULL, *t;
wordlist *wl = NULL;
struct passwd *pw; struct passwd *pw;
buf = copy(buf); /* Don't mangle anything... */ buf = copy(buf); /* Don't mangle anything... */
@ -217,18 +217,7 @@ ccfilec(char *buf)
buf++; buf++;
while ((pw = getpwent()) != NULL) { while ((pw = getpwent()) != NULL) {
if (prefix(buf, pw->pw_name)) { if (prefix(buf, pw->pw_name)) {
if (wl == NULL) {
wl = alloc(struct wordlist);
wl->wl_next = NULL;
wl->wl_prev = NULL;
} else {
t = wl;
wl = alloc(struct wordlist);
wl->wl_prev = NULL;
wl->wl_next = t;
t->wl_prev = wl;
}
wl->wl_word = copy(pw->pw_name);
wl = wl_cons(copy(pw->pw_name), wl);
} }
} }
(void) endpwent(); (void) endpwent();
@ -249,18 +238,7 @@ ccfilec(char *buf)
while ((de = readdir(wdir)) != NULL) while ((de = readdir(wdir)) != NULL)
if ((prefix(lcomp, de->d_name)) && (*lcomp || if ((prefix(lcomp, de->d_name)) && (*lcomp ||
(*de->d_name != '.'))) { (*de->d_name != '.'))) {
if (wl == NULL) {
wl = alloc(struct wordlist);
wl->wl_next = NULL;
wl->wl_prev = NULL;
} else {
t = wl;
wl = alloc(struct wordlist);
wl->wl_next = t;
t->wl_prev = wl;
wl->wl_prev = NULL;
}
wl->wl_word = copy(de->d_name);
wl = wl_cons(copy(de->d_name), wl);
} }
(void) closedir(wdir); (void) closedir(wdir);
@ -345,28 +323,16 @@ cp_ccom(wordlist *wlist, char *buf, bool esc)
static wordlist * static wordlist *
cctowl(struct ccom *cc, bool sib) cctowl(struct ccom *cc, bool sib)
{ {
wordlist *wl, *end;
wordlist *wl;
if (!cc) if (!cc)
return (NULL); return (NULL);
wl = cctowl(cc->cc_child, TRUE);
if (!cc->cc_invalid) { if (!cc->cc_invalid) {
wl = alloc(struct wordlist);
wl->wl_word = copy(cc->cc_name);
wl->wl_prev = NULL;
wl->wl_next = cctowl(cc->cc_child, TRUE);
if (wl->wl_next)
wl->wl_next->wl_prev = wl;
} else
wl = cctowl(cc->cc_child, TRUE);
wl = wl_cons(copy(cc->cc_name), wl);
}
if (sib) { if (sib) {
if (wl) {
for (end = wl; end->wl_next; end = end->wl_next)
;
end->wl_next = cctowl(cc->cc_sibling, TRUE);
if (end->wl_next)
end->wl_next->wl_prev = end;
} else
wl = cctowl(cc->cc_sibling, TRUE);
wl = wl_append(wl, cctowl(cc->cc_sibling, TRUE));
} }
return (wl); return (wl);
} }

12
src/frontend/parser/glob.c

@ -115,11 +115,8 @@ brac1(char *string)
char *s; char *s;
int nb; int nb;
words = alloc(struct wordlist);
words->wl_word = TMALLOC(char, BSIZE_SP);
words->wl_word[0] = 0;
words->wl_next = NULL;
words->wl_prev = NULL;
words = wl_cons(TMALLOC(char, BSIZE_SP), NULL);
words->wl_word[0] = '\0';
for (s = string; *s; s++) { for (s = string; *s; s++) {
if (*s == cp_ocurl) { if (*s == cp_ocurl) {
nwl = brac2(s); nwl = brac2(s);
@ -141,10 +138,7 @@ brac1(char *string)
newwl = NULL; newwl = NULL;
for (wl = words; wl; wl = wl->wl_next) for (wl = words; wl; wl = wl->wl_next)
for (w = nwl; w; w = w->wl_next) { for (w = nwl; w; w = w->wl_next) {
nw = alloc(struct wordlist);
nw->wl_next = NULL;
nw->wl_prev = NULL;
nw->wl_word = TMALLOC(char, BSIZE_SP);
nw = wl_cons(TMALLOC(char, BSIZE_SP), NULL);
(void) strcpy(nw->wl_word, wl->wl_word); (void) strcpy(nw->wl_word, wl->wl_word);
(void) strcat(nw->wl_word, w->wl_word); (void) strcat(nw->wl_word, w->wl_word);
newwl = wl_append(newwl, nw); newwl = wl_append(newwl, nw);

3
src/frontend/parser/lexical.c

@ -124,8 +124,7 @@ nloop: i = 0;
paren = 0; paren = 0;
bzero(linebuf, NEW_BSIZE_SP); bzero(linebuf, NEW_BSIZE_SP);
bzero(buf, NEW_BSIZE_SP); bzero(buf, NEW_BSIZE_SP);
wlist = cw = alloc(struct wordlist);
cw->wl_next = cw->wl_prev = NULL;
wlist = cw = wl_cons(NULL, NULL);
for (;;) { for (;;) {
if (string) { if (string) {
c = *string++; c = *string++;

7
src/frontend/plotting/plotit.c

@ -313,11 +313,8 @@ plotit(wordlist *wl, char *hcopy, char *devname)
wl = wl->wl_prev; wl = wl->wl_prev;
tw = NULL; /* Not used, so must be NULL */ tw = NULL; /* Not used, so must be NULL */
} else { } else {
tw = alloc(struct wordlist);
wl->wl_prev = tw;
tw->wl_next = wl;
wl = tw;
tw->wl_word = "";
wl = wl_cons("", wl);
tw = wl;
} }
sameflag = getflag(wl, "samep"); sameflag = getflag(wl, "samep");

8
src/frontend/rawfile.c

@ -410,12 +410,8 @@ raw_read(char *name) {
skip(s); skip(s);
nonl(s); nonl(s);
if (curpl) { if (curpl) {
wl = alloc(struct wordlist);
wl->wl_word = copy(s);
wl->wl_next = curpl->pl_commands;
if (curpl->pl_commands)
curpl->pl_commands->wl_prev = wl;
curpl->pl_commands = wl;
curpl->pl_commands = wl_cons(copy(s), curpl->pl_commands);
wl = curpl->pl_commands;
} else } else
fprintf(cp_err, fprintf(cp_err,
"Error: misplaced Command: line\n"); "Error: misplaced Command: line\n");

6
src/frontend/runcoms.c

@ -202,11 +202,7 @@ dosim(
/* add "what" to beginning of wordlist wl, except "what" equals "run" /* add "what" to beginning of wordlist wl, except "what" equals "run"
and a rawfile name is given (in wl) */ and a rawfile name is given (in wl) */
if (!dofile) { if (!dofile) {
ww = alloc(struct wordlist);
ww->wl_next = wl;
if (wl)
wl->wl_prev = ww;
ww->wl_word = copy(what);
ww = wl_cons(copy(what), wl);
} }
/* reset output file type according to variable given in spinit */ /* reset output file type according to variable given in spinit */
if (cp_getvar("filetype", CP_STRING, buf)) { if (cp_getvar("filetype", CP_STRING, buf)) {

28
src/frontend/subckt.c

@ -156,7 +156,6 @@ inp_subcktexpand(struct line *deck) {
int ok = 0; int ok = 0;
char *t; char *t;
int i; int i;
wordlist *wl;
wordlist *modnames = NULL; wordlist *modnames = NULL;
if (!cp_getvar("substart", CP_STRING, start)) if (!cp_getvar("substart", CP_STRING, start))
@ -222,12 +221,7 @@ inp_subcktexpand(struct line *deck) {
if (ciprefix(model, c->li_line)) { if (ciprefix(model, c->li_line)) {
s = c->li_line; s = c->li_line;
txfree(gettok(&s)); /* discard the model keyword */ txfree(gettok(&s)); /* discard the model keyword */
wl = alloc(struct wordlist);
wl->wl_next = modnames;
if (modnames)
modnames->wl_prev = wl;
modnames = wl;
wl->wl_word = gettok(&s); /* wl->wl_word now holds name of model */
modnames = wl_cons(gettok(&s), modnames);
} /* model name finding routine */ } /* model name finding routine */
#ifdef TRACE #ifdef TRACE
@ -1671,7 +1665,6 @@ modtranslate(struct line *deck, char *subname, wordlist **submod, wordlist ** co
{ {
struct line *c; struct line *c;
char *buffer, *name, *t, model[4 * BSIZE_SP]; char *buffer, *name, *t, model[4 * BSIZE_SP];
wordlist *wl, *wlsub;
bool gotone; bool gotone;
(void) strcpy(model, ".model"); (void) strcpy(model, ".model");
@ -1691,16 +1684,10 @@ modtranslate(struct line *deck, char *subname, wordlist **submod, wordlist ** co
(void) sprintf(buffer, "%s ", name); /* at this point, buffer = ".model " */ (void) sprintf(buffer, "%s ", name); /* at this point, buffer = ".model " */
tfree(name); tfree(name);
name = gettok(&t); /* name now holds model name */ name = gettok(&t); /* name now holds model name */
wlsub = alloc(struct wordlist);
wlsub->wl_next = *submod;
if (*submod)
(*submod)->wl_prev = wlsub;
/* here's where we insert the model name into the model name list */
*submod = wlsub;
wlsub->wl_word = name;
*submod = wl_cons(name, *submod);
#ifdef TRACE #ifdef TRACE
/* SDB debug statement */ /* SDB debug statement */
printf("In modtranslate, sticking model name %s into submod\n", wlsub->wl_word);
printf("In modtranslate, sticking model name %s into submod\n", (*submod)->wl_word);
#endif #endif
@ -1719,16 +1706,11 @@ modtranslate(struct line *deck, char *subname, wordlist **submod, wordlist ** co
/* this looks like it tries to stick the translated model name into the list of model names */ /* this looks like it tries to stick the translated model name into the list of model names */
t = c->li_line; t = c->li_line;
txfree(gettok(&t)); txfree(gettok(&t));
wl = alloc(struct wordlist);
wl->wl_next = *modnames;
if (*modnames)
(*modnames)->wl_prev = wl;
(*modnames) = wl;
wl->wl_word = gettok(&t);
*modnames = wl_cons(gettok(&t), *modnames);
#ifdef TRACE #ifdef TRACE
/* SDB debug statement */ /* SDB debug statement */
printf("In modtranslate, sticking model name %s into modnames\n", wl->wl_word);
printf("In modtranslate, sticking model name %s into modnames\n", (*modnames)->wl_word);
#endif #endif
} }

32
src/frontend/variable.c

@ -76,9 +76,7 @@ cp_varwl(struct variable *var)
var->va_type); var->va_type);
return (NULL); return (NULL);
} }
wl = alloc(struct wordlist);
wl->wl_next = wl->wl_prev = NULL;
wl->wl_word = copy(buf);
wl = wl_cons(copy(buf), NULL);
return (wl); return (wl);
} }
@ -689,11 +687,10 @@ cp_variablesubst(wordlist *wlist)
if (nwl) { if (nwl) {
(void) strcat(buf, nwl->wl_word); (void) strcat(buf, nwl->wl_word);
tfree(nwl->wl_word); tfree(nwl->wl_word);
nwl->wl_word = copy(buf);
} else { } else {
nwl = alloc(struct wordlist);
nwl->wl_next = nwl->wl_prev = NULL;
nwl = wl_cons(copy(buf), NULL);
} }
nwl->wl_word = copy(buf);
} }
(void) strcpy(tbuf, t); /* MW. Save t*/ (void) strcpy(tbuf, t); /* MW. Save t*/
@ -742,13 +739,8 @@ vareval(char *string)
switch (*string) { switch (*string) {
case '$': case '$':
wl = alloc(struct wordlist);
wl->wl_next = wl->wl_prev = NULL;
(void) sprintf(buf, "%d", getpid()); (void) sprintf(buf, "%d", getpid());
wl->wl_word = copy(buf);
wl = wl_cons(copy(buf), NULL);
tfree(oldstring); tfree(oldstring);
return (wl); return (wl);
@ -769,21 +761,17 @@ vareval(char *string)
return (wl); return (wl);
case '?': case '?':
wl = alloc(struct wordlist);
wl->wl_next = wl->wl_prev = NULL;
string++; string++;
for (v = variables; v; v = v->va_next) for (v = variables; v; v = v->va_next)
if (eq(v->va_name, string)) if (eq(v->va_name, string))
break; break;
if (!v) if (!v)
v = cp_enqvar(string); v = cp_enqvar(string);
wl->wl_word = copy(v ? "1" : "0");
wl = wl_cons(copy(v ? "1" : "0"), NULL);
tfree(oldstring); tfree(oldstring);
return (wl); return (wl);
case '#': case '#':
wl = alloc(struct wordlist);
wl->wl_next = wl->wl_prev = NULL;
string++; string++;
for (v = variables; v; v = v->va_next) for (v = variables; v; v = v->va_next)
if (eq(v->va_name, string)) if (eq(v->va_name, string))
@ -802,14 +790,12 @@ vareval(char *string)
else else
i = (v->va_type != CP_BOOL); i = (v->va_type != CP_BOOL);
(void) sprintf(buf, "%d", i); (void) sprintf(buf, "%d", i);
wl->wl_word = copy(buf);
wl = wl_cons(copy(buf), NULL);
tfree(oldstring); tfree(oldstring);
return (wl); return (wl);
case '\0': case '\0':
wl = alloc(struct wordlist);
wl->wl_next = wl->wl_prev = NULL;
wl->wl_word = copy("$");
wl = wl_cons(copy("$"), NULL);
tfree(oldstring); tfree(oldstring);
return (wl); return (wl);
} }
@ -833,9 +819,7 @@ vareval(char *string)
v = cp_enqvar(string); v = cp_enqvar(string);
} }
if (!v && (s = getenv(string)) != NULL) { if (!v && (s = getenv(string)) != NULL) {
wl = alloc(struct wordlist);
wl->wl_next = wl->wl_prev = NULL;
wl->wl_word = copy(s);
wl = wl_cons(copy(s), NULL);
tfree(oldstring); tfree(oldstring);
return (wl); return (wl);
} }

24
src/misc/wlist.c

@ -46,17 +46,7 @@ wl_copy(wordlist *wlist)
wordlist *wl, *nwl = NULL, *w = NULL; wordlist *wl, *nwl = NULL, *w = NULL;
for (wl = wlist; wl; wl = wl->wl_next) { for (wl = wlist; wl; wl = wl->wl_next) {
if (nwl == NULL) {
nwl = w = alloc(struct wordlist);
w->wl_prev = NULL;
w->wl_next = NULL;
} else {
w->wl_next = alloc(struct wordlist);
w->wl_next->wl_prev = w;
w = w->wl_next;
w->wl_next = NULL;
}
w->wl_word = copy(wl->wl_word);
wl_append_word(&nwl, &w, copy(wl->wl_word));
} }
return (nwl); return (nwl);
} }
@ -119,19 +109,9 @@ wl_build(char **v)
{ {
wordlist *wlist = NULL; wordlist *wlist = NULL;
wordlist *wl = NULL; wordlist *wl = NULL;
wordlist *cwl;
while (*v) { while (*v) {
cwl = alloc(struct wordlist);
cwl->wl_prev = wl;
if (wl)
wl->wl_next = cwl;
else {
wlist = cwl;
cwl->wl_next = NULL;
}
cwl->wl_word = copy(*v);
wl = cwl;
wl_append_word(&wlist, &wl, copy(*v));
v++; v++;
} }
return (wlist); return (wlist);

Loading…
Cancel
Save