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

This commit is contained in:
rlar 2012-07-14 10:23:51 +02:00
parent d9ddaec784
commit 9655b9885a
19 changed files with 78 additions and 281 deletions

View File

@ -116,9 +116,7 @@ common(char *string, struct wordlist *wl, struct comm *command)
if ((buf = prompt(cp_in)) == NULL) /* prompt aborted */
return; /* don't execute command */
/* 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);
/* O.K. now call fn */

View File

@ -133,10 +133,7 @@ dohsubst(char *string)
break;
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;
return (wl);

View File

@ -1095,7 +1095,7 @@ com_alter_common(wordlist *wl, int do_model)
char *argument;
char **arglist;
int i=0, step=0, n, wlen, maxelem=3;
wordlist *wl2 = NULL, *wlin, *wleq;
wordlist *wl2 = NULL, *wlin, *rhs;
bool eqfound = FALSE, vecfound = FALSE;
if (!ft_curckt) {
@ -1207,18 +1207,9 @@ com_alter_common(wordlist *wl, int do_model)
return;
}
/* 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;
/* 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,
then move one step forward */
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 *
devexpand(char *name)
{
wordlist *wl, *devices, *tw;
wordlist *wl, *devices;
if (strchr(name, '*') || strchr(name, '[') || strchr(name, '?')) {
devices = cp_cctowl(ft_curckt->ci_devices);
for (wl = NULL; devices; devices = devices->wl_next)
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")) {
wl = cp_cctowl(ft_curckt->ci_devices);
} else {
wl = alloc(struct wordlist);
wl->wl_word = name;
wl = wl_cons(name, NULL);
}
wl_sort(wl);
return (wl);

View File

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

View File

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

View File

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

View File

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

View File

@ -127,9 +127,7 @@ com_meas(wordlist *wl) {
}
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);
wl_free(wl_let);
// fprintf(stdout, "in: %s\n", line_in);
@ -433,10 +431,7 @@ static wordlist *measure_parse_line( char *line )
txfree( extra_item ) ;
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) ;
} while( line && *line ) ;

View File

@ -119,13 +119,8 @@ inp_nutsource(FILE *fp, bool comfile, char *filename)
fprintf(cp_err,
"Warning: misplaced .endc line\n");
} 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))
wl->wl_word = copy(dd->li_line + 2);
else
@ -146,13 +141,7 @@ inp_nutsource(FILE *fp, bool comfile, char *filename)
eq(s, ".plot") ||
eq(s, ".print") ||
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;
tfree(dd->li_line);
tfree(dd);

View File

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

View File

@ -204,7 +204,7 @@ ccfilec(char *buf)
DIR *wdir;
char *lcomp, *dir;
struct direct *de;
wordlist *wl = NULL, *t;
wordlist *wl = NULL;
struct passwd *pw;
buf = copy(buf); /* Don't mangle anything... */
@ -217,18 +217,7 @@ ccfilec(char *buf)
buf++;
while ((pw = getpwent()) != NULL) {
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();
@ -249,18 +238,7 @@ ccfilec(char *buf)
while ((de = readdir(wdir)) != NULL)
if ((prefix(lcomp, de->d_name)) && (*lcomp ||
(*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);
@ -345,28 +323,16 @@ cp_ccom(wordlist *wlist, char *buf, bool esc)
static wordlist *
cctowl(struct ccom *cc, bool sib)
{
wordlist *wl, *end;
wordlist *wl;
if (!cc)
return (NULL);
wl = cctowl(cc->cc_child, TRUE);
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 (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);
}

View File

@ -115,11 +115,8 @@ brac1(char *string)
char *s;
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++) {
if (*s == cp_ocurl) {
nwl = brac2(s);
@ -141,10 +138,7 @@ brac1(char *string)
newwl = NULL;
for (wl = words; wl; wl = wl->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) strcat(nw->wl_word, w->wl_word);
newwl = wl_append(newwl, nw);

View File

@ -124,8 +124,7 @@ nloop: i = 0;
paren = 0;
bzero(linebuf, 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 (;;) {
if (string) {
c = *string++;

View File

@ -313,11 +313,8 @@ plotit(wordlist *wl, char *hcopy, char *devname)
wl = wl->wl_prev;
tw = NULL; /* Not used, so must be NULL */
} 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");

View File

@ -410,12 +410,8 @@ raw_read(char *name) {
skip(s);
nonl(s);
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
fprintf(cp_err,
"Error: misplaced Command: line\n");

View File

@ -202,11 +202,7 @@ dosim(
/* add "what" to beginning of wordlist wl, except "what" equals "run"
and a rawfile name is given (in wl) */
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 */
if (cp_getvar("filetype", CP_STRING, buf)) {

View File

@ -156,7 +156,6 @@ inp_subcktexpand(struct line *deck) {
int ok = 0;
char *t;
int i;
wordlist *wl;
wordlist *modnames = NULL;
if (!cp_getvar("substart", CP_STRING, start))
@ -222,12 +221,7 @@ inp_subcktexpand(struct line *deck) {
if (ciprefix(model, c->li_line)) {
s = c->li_line;
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 */
#ifdef TRACE
@ -1671,7 +1665,6 @@ modtranslate(struct line *deck, char *subname, wordlist **submod, wordlist ** co
{
struct line *c;
char *buffer, *name, *t, model[4 * BSIZE_SP];
wordlist *wl, *wlsub;
bool gotone;
(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 " */
tfree(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
/* 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
@ -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 */
t = c->li_line;
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
/* 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
}

View File

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

View File

@ -46,17 +46,7 @@ wl_copy(wordlist *wlist)
wordlist *wl, *nwl = NULL, *w = NULL;
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);
}
@ -119,19 +109,9 @@ wl_build(char **v)
{
wordlist *wlist = NULL;
wordlist *wl = NULL;
wordlist *cwl;
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++;
}
return (wlist);