gettok_nc(&line): like gettok(), move pointer beyond next token in line, but without returning a string, without TMALLOC. Replaces constructs like tfree(gettok(&line)).
This commit is contained in:
parent
dca877ca69
commit
268a22e36f
|
|
@ -57,7 +57,7 @@ void
|
||||||
ft_dotsaves(void)
|
ft_dotsaves(void)
|
||||||
{
|
{
|
||||||
wordlist *iline, *wl = NULL;
|
wordlist *iline, *wl = NULL;
|
||||||
char *s, *fr;
|
char *s;
|
||||||
|
|
||||||
if (!ft_curckt) /* Shouldn't happen. */
|
if (!ft_curckt) /* Shouldn't happen. */
|
||||||
return;
|
return;
|
||||||
|
|
@ -66,8 +66,7 @@ ft_dotsaves(void)
|
||||||
if (ciprefix(".save", iline->wl_word)) {
|
if (ciprefix(".save", iline->wl_word)) {
|
||||||
s = iline->wl_word;
|
s = iline->wl_word;
|
||||||
/* skip .save */
|
/* skip .save */
|
||||||
fr = gettok(&s);
|
gettok_nc(&s);
|
||||||
tfree(fr);
|
|
||||||
wl = wl_append(wl, gettoks(s));
|
wl = wl_append(wl, gettoks(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +111,7 @@ ft_savedotargs(void)
|
||||||
isaplot = 0;
|
isaplot = 0;
|
||||||
|
|
||||||
if (isaplot || ciprefix(".print", s)) {
|
if (isaplot || ciprefix(".print", s)) {
|
||||||
(void) gettok(&s);
|
gettok_nc(&s);
|
||||||
name = gettok(&s);
|
name = gettok(&s);
|
||||||
|
|
||||||
if ((w = gettoks(s)) == NULL) {
|
if ((w = gettoks(s)) == NULL) {
|
||||||
|
|
@ -138,8 +137,8 @@ ft_savedotargs(void)
|
||||||
com_save2(w, name);
|
com_save2(w, name);
|
||||||
}
|
}
|
||||||
} else if (ciprefix(".four", s)) {
|
} else if (ciprefix(".four", s)) {
|
||||||
(void) gettok(&s);
|
gettok_nc(&s);
|
||||||
(void) gettok(&s);
|
gettok_nc(&s);
|
||||||
if ((w = gettoks(s)) == NULL) {
|
if ((w = gettoks(s)) == NULL) {
|
||||||
fprintf(cp_err, "Warning: no nodes given: %s\n", iline->wl_word);
|
fprintf(cp_err, "Warning: no nodes given: %s\n", iline->wl_word);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1473,8 +1473,7 @@ inp_parse_temper(struct line *card)
|
||||||
if (prefix(".model", curr_line)) {
|
if (prefix(".model", curr_line)) {
|
||||||
struct pt_temper *modtlistnew = NULL;
|
struct pt_temper *modtlistnew = NULL;
|
||||||
/* remove '.model' */
|
/* remove '.model' */
|
||||||
str_ptr = gettok(&curr_line);
|
gettok_nc(&curr_line);
|
||||||
tfree(str_ptr);
|
|
||||||
devmodname = gettok(&curr_line);
|
devmodname = gettok(&curr_line);
|
||||||
beg_tstr = curr_line;
|
beg_tstr = curr_line;
|
||||||
while ((end_tstr = beg_tstr = strstr(beg_tstr, "temper")) != NULL) {
|
while ((end_tstr = beg_tstr = strstr(beg_tstr, "temper")) != NULL) {
|
||||||
|
|
|
||||||
|
|
@ -5392,14 +5392,14 @@ replace_token(char *string, char *token, int wherereplace, int total)
|
||||||
|
|
||||||
/* get total number of tokens */
|
/* get total number of tokens */
|
||||||
while (*actstring) {
|
while (*actstring) {
|
||||||
txfree(gettok(&actstring));
|
gettok_nc(&actstring);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
/* If total number of tokens correct */
|
/* If total number of tokens correct */
|
||||||
if (count == total) {
|
if (count == total) {
|
||||||
actstring = string;
|
actstring = string;
|
||||||
for (i = 1; i < wherereplace; i++)
|
for (i = 1; i < wherereplace; i++)
|
||||||
txfree(gettok(&actstring));
|
gettok_nc(&actstring);
|
||||||
/* If token to be replaced at right position */
|
/* If token to be replaced at right position */
|
||||||
if (ciprefix(token, actstring)) {
|
if (ciprefix(token, actstring)) {
|
||||||
actstring[0] = ' ';
|
actstring[0] = ' ';
|
||||||
|
|
@ -5873,9 +5873,9 @@ inp_poly_err(struct line *card)
|
||||||
if ((ciprefix("e", curr_line)) || (ciprefix("g", curr_line)) ||
|
if ((ciprefix("e", curr_line)) || (ciprefix("g", curr_line)) ||
|
||||||
(ciprefix("f", curr_line)) || (ciprefix("h", curr_line)))
|
(ciprefix("f", curr_line)) || (ciprefix("h", curr_line)))
|
||||||
{
|
{
|
||||||
txfree(gettok(&curr_line));
|
gettok_nc(&curr_line);
|
||||||
txfree(gettok(&curr_line));
|
gettok_nc(&curr_line);
|
||||||
txfree(gettok(&curr_line));
|
gettok_nc(&curr_line);
|
||||||
if (ciprefix("poly", curr_line)) {
|
if (ciprefix("poly", curr_line)) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\nError: XSPICE is required to run the 'poly' option in line %d\n",
|
"\nError: XSPICE is required to run the 'poly' option in line %d\n",
|
||||||
|
|
@ -6143,7 +6143,7 @@ inp_fix_temper_in_param(struct line *deck)
|
||||||
/* if we have inserted into a .param line, convert to .func */
|
/* if we have inserted into a .param line, convert to .func */
|
||||||
if (prefix(".param", new_str)) {
|
if (prefix(".param", new_str)) {
|
||||||
char *new_tmp_str = new_str;
|
char *new_tmp_str = new_str;
|
||||||
txfree(gettok(&new_tmp_str));
|
gettok_nc(&new_tmp_str);
|
||||||
funcname = gettok_char(&new_tmp_str, '=', FALSE, FALSE);
|
funcname = gettok_char(&new_tmp_str, '=', FALSE, FALSE);
|
||||||
funcbody = copy(new_tmp_str + 1);
|
funcbody = copy(new_tmp_str + 1);
|
||||||
*funcs_tail_ptr =
|
*funcs_tail_ptr =
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,7 @@ do_measure(
|
||||||
for (meas_card = ft_curckt->ci_meas; meas_card != NULL; meas_card = meas_card->li_next) {
|
for (meas_card = ft_curckt->ci_meas; meas_card != NULL; meas_card = meas_card->li_next) {
|
||||||
line = meas_card->li_line;
|
line = meas_card->li_line;
|
||||||
|
|
||||||
txfree(gettok(&line)); /* discard .meas */
|
gettok_nc(&line); /* discard .meas */
|
||||||
|
|
||||||
an_type = gettok(&line);
|
an_type = gettok(&line);
|
||||||
resname = gettok(&line);
|
resname = gettok(&line);
|
||||||
|
|
@ -359,7 +359,7 @@ do_measure(
|
||||||
for (meas_card = ft_curckt->ci_meas; meas_card != NULL; meas_card = meas_card->li_next) {
|
for (meas_card = ft_curckt->ci_meas; meas_card != NULL; meas_card = meas_card->li_next) {
|
||||||
line = meas_card->li_line;
|
line = meas_card->li_line;
|
||||||
|
|
||||||
txfree(gettok(&line)); /* discard .meas */
|
gettok_nc(&line); /* discard .meas */
|
||||||
|
|
||||||
an_type = gettok(&line);
|
an_type = gettok(&line);
|
||||||
resname = gettok(&line);
|
resname = gettok(&line);
|
||||||
|
|
@ -466,7 +466,7 @@ measure_parse_line(char *line)
|
||||||
char *extra_item; /* extra item */
|
char *extra_item; /* extra item */
|
||||||
|
|
||||||
wl = NULL;
|
wl = NULL;
|
||||||
txfree(gettok(&line));
|
gettok_nc(&line);
|
||||||
do {
|
do {
|
||||||
item = gettok(&line);
|
item = gettok(&line);
|
||||||
if (!(item))
|
if (!(item))
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ inp_getoptsc(char *in_line, struct line *com_options)
|
||||||
|
|
||||||
/* option -> .options */
|
/* option -> .options */
|
||||||
/* skip option */
|
/* skip option */
|
||||||
gettok(&in_line);
|
gettok_nc(&in_line);
|
||||||
line = tprintf(".options %s", in_line);
|
line = tprintf(".options %s", in_line);
|
||||||
|
|
||||||
next = TMALLOC(struct line, 1);
|
next = TMALLOC(struct line, 1);
|
||||||
|
|
|
||||||
|
|
@ -474,7 +474,7 @@ raw_read(char *name) {
|
||||||
(void) fgets(buf, BSIZE_SP, fp);
|
(void) fgets(buf, BSIZE_SP, fp);
|
||||||
s = buf;
|
s = buf;
|
||||||
}
|
}
|
||||||
(void) gettok(&s); /* The strchr field. */
|
gettok_nc(&s); /* The strchr field. */
|
||||||
if ((t = gettok(&s)) != NULL) {
|
if ((t = gettok(&s)) != NULL) {
|
||||||
v->v_name = t;
|
v->v_name = t;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ collect_global_nodes(struct line *c)
|
||||||
for (; c; c = c->li_next)
|
for (; c; c = c->li_next)
|
||||||
if (ciprefix(".global", c->li_line)) {
|
if (ciprefix(".global", c->li_line)) {
|
||||||
char *s = c->li_line;
|
char *s = c->li_line;
|
||||||
txfree(gettok(&s));
|
gettok_nc(&s);
|
||||||
while (*s) {
|
while (*s) {
|
||||||
char *t = skip_non_ws(s);
|
char *t = skip_non_ws(s);
|
||||||
global_nodes[num_global_nodes++] = copy_substring(s, t);
|
global_nodes[num_global_nodes++] = copy_substring(s, t);
|
||||||
|
|
@ -267,7 +267,7 @@ inp_subcktexpand(struct line *deck) {
|
||||||
|
|
||||||
if (ciprefix(model, c->li_line)) {
|
if (ciprefix(model, c->li_line)) {
|
||||||
char *s = c->li_line;
|
char *s = c->li_line;
|
||||||
txfree(gettok(&s)); /* discard the model keyword */
|
gettok_nc(&s); /* discard the model keyword */
|
||||||
modnames = wl_cons(gettok(&s), modnames);
|
modnames = wl_cons(gettok(&s), modnames);
|
||||||
} /* model name finding routine */
|
} /* model name finding routine */
|
||||||
}
|
}
|
||||||
|
|
@ -479,7 +479,7 @@ doit(struct line *deck, wordlist *modnames) {
|
||||||
|
|
||||||
sss = TMALLOC(struct subs, 1);
|
sss = TMALLOC(struct subs, 1);
|
||||||
|
|
||||||
txfree(gettok(&s));
|
gettok_nc(&s);
|
||||||
|
|
||||||
sss->su_name = gettok(&s);
|
sss->su_name = gettok(&s);
|
||||||
sss->su_args = copy(s);
|
sss->su_args = copy(s);
|
||||||
|
|
@ -612,7 +612,7 @@ doit(struct line *deck, wordlist *modnames) {
|
||||||
/* prepend the translated model names to the list `modnames' */
|
/* prepend the translated model names to the list `modnames' */
|
||||||
modnames = modtranslate(su_deck, scname, modnames);
|
modnames = modtranslate(su_deck, scname, modnames);
|
||||||
|
|
||||||
txfree(gettok(&t)); /* Throw out the subcircuit refdes */
|
gettok_nc(&t); /* Throw out the subcircuit refdes */
|
||||||
|
|
||||||
/* now invoke translate, which handles the remainder of the
|
/* now invoke translate, which handles the remainder of the
|
||||||
* translation.
|
* translation.
|
||||||
|
|
@ -1544,7 +1544,7 @@ numnodes(char *name, struct subs *subs, wordlist const *modnames)
|
||||||
i = 0;
|
i = 0;
|
||||||
s = buf;
|
s = buf;
|
||||||
gotit = 0;
|
gotit = 0;
|
||||||
txfree(gettok(&s)); /* Skip component name */
|
gettok_nc(&s); /* Skip component name */
|
||||||
while ((i < n) && (*s) && !gotit) {
|
while ((i < n) && (*s) && !gotit) {
|
||||||
t = gettok_node(&s); /* get nodenames . . . */
|
t = gettok_node(&s); /* get nodenames . . . */
|
||||||
for (wl = modnames; wl; wl = wl->wl_next)
|
for (wl = modnames; wl; wl = wl->wl_next)
|
||||||
|
|
@ -1571,7 +1571,7 @@ numnodes(char *name, struct subs *subs, wordlist const *modnames)
|
||||||
return (n);
|
return (n);
|
||||||
|
|
||||||
for (s = buf, i = 0; *s && (i < 4); i++)
|
for (s = buf, i = 0; *s && (i < 4); i++)
|
||||||
txfree(gettok(&s));
|
gettok_nc(&s);
|
||||||
|
|
||||||
if (i == 3)
|
if (i == 3)
|
||||||
return (3);
|
return (3);
|
||||||
|
|
@ -1650,7 +1650,7 @@ modtranslate(struct line *c, char *subname, wordlist *new_modnames)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* swallow ".model" */
|
/* swallow ".model" */
|
||||||
txfree(gettok(&t));
|
gettok_nc(&t);
|
||||||
|
|
||||||
model_name = gettok(&t);
|
model_name = gettok(&t);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,7 @@ extern double x_atanh(double);
|
||||||
extern char *gettok_noparens(char **s);
|
extern char *gettok_noparens(char **s);
|
||||||
extern char *gettok_node(char **s);
|
extern char *gettok_node(char **s);
|
||||||
extern char *gettok_iv(char **s);
|
extern char *gettok_iv(char **s);
|
||||||
|
extern int gettok_nc(char **s);
|
||||||
extern int get_l_paren(char **s);
|
extern int get_l_paren(char **s);
|
||||||
extern int get_r_paren(char **s);
|
extern int get_r_paren(char **s);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -306,6 +306,40 @@ gettok(char **s)
|
||||||
return ( token ) ;
|
return ( token ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------*
|
||||||
|
* gettok_nc skips over whitespaces and the next token in s, but does not
|
||||||
|
* use TMALLOC or not return anything * but 1 for empty s and 0 if o.k. .
|
||||||
|
* It replaces constructs like txfree(gettok(&actstring)) by
|
||||||
|
* gettok_nc(&actstring). This is derived from the original gettok version.
|
||||||
|
* It does not "do the right thing" when
|
||||||
|
* you have parens or commas anywhere in the nodelist.
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
gettok_nc(char **s)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
int paren;
|
||||||
|
|
||||||
|
paren = 0;
|
||||||
|
*s = skip_ws(*s);
|
||||||
|
if (!**s)
|
||||||
|
return (1);
|
||||||
|
while ((c = **s) != '\0' && !isspace_c(c)) {
|
||||||
|
if (c == '(')
|
||||||
|
paren += 1;
|
||||||
|
else if (c == ')')
|
||||||
|
paren -= 1;
|
||||||
|
else if (c == ',' && paren < 1)
|
||||||
|
break;
|
||||||
|
(*s)++;
|
||||||
|
}
|
||||||
|
while (isspace_c(**s) || **s == ',')
|
||||||
|
(*s)++;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*
|
/*-------------------------------------------------------------------------*
|
||||||
* gettok skips over whitespaces or '=' and returns the next token found,
|
* gettok skips over whitespaces or '=' and returns the next token found,
|
||||||
* if the token is something like i(xxx), v(yyy), or v(xxx,yyy)
|
* if the token is something like i(xxx), v(yyy), or v(xxx,yyy)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue