skip-ws, #3/6, use TEMPORARY macros, obj-invariant

This commit is contained in:
rlar 2016-03-21 15:22:51 +01:00
parent 6d1171ad6f
commit a86f2068c8
14 changed files with 46 additions and 91 deletions

View File

@ -113,8 +113,7 @@ com_let(wordlist *wl)
free_pnode(names); /* frees also t, if pnode `names' is simple value */ free_pnode(names); /* frees also t, if pnode `names' is simple value */
s = q; s = q;
for (; *s && isspace_c(*s); s++) TEMPORARY_SKIP_WS_X0(s);
;
} }
} }
/* vector name at p */ /* vector name at p */

View File

@ -246,8 +246,7 @@ ft_cpinit(void)
/* jump over leading spaces */ /* jump over leading spaces */
for (copys = s = cp_tildexpand(Lib_Path); copys && *copys; ) { for (copys = s = cp_tildexpand(Lib_Path); copys && *copys; ) {
while (isspace_c(*s)) TEMPORARY_SKIP_WS_X1(s);
s++;
/* copy s into buf until space is seen, r is the actual position */ /* copy s into buf until space is seen, r is the actual position */
for (r = buf; *s && !isspace_c(*s); r++, s++) for (r = buf; *s && !isspace_c(*s); r++, s++)
*r = *s; *r = *s;

View File

@ -133,13 +133,11 @@ atodims(char *p, int *data, int *outlength)
return 0; return 0;
} }
while (*p && isspace_c(*p)) TEMPORARY_SKIP_WS_X0(p);
p++;
if (*p == '[') { if (*p == '[') {
p++; p++;
while (*p && isspace_c(*p)) TEMPORARY_SKIP_WS_X0(p);
p++;
needbracket = 1; needbracket = 1;
} }
@ -186,8 +184,7 @@ atodims(char *p, int *data, int *outlength)
break; break;
} }
while (*p && isspace_c(*p)) TEMPORARY_SKIP_WS_X0(p);
p++;
} }
*outlength = length; *outlength = length;

View File

@ -74,8 +74,7 @@ hlp_thandle(topic **parent)
} }
s = buf; s = buf;
for (; *s && isspace_c(*s); s++) TEMPORARY_SKIP_WS_X0(s);
;
switch (*s) { switch (*s) {
case '?': case '?':
fprintf(cp_out, fprintf(cp_out,

View File

@ -396,8 +396,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
/* get temp from deck */ /* get temp from deck */
if (ciprefix(".temp", dd->li_line)) { if (ciprefix(".temp", dd->li_line)) {
s = dd->li_line + 5; s = dd->li_line + 5;
while (isspace_c(*s)) TEMPORARY_SKIP_WS_X1(s);
s++;
if (temperature) if (temperature)
txfree(temperature); txfree(temperature);
temperature = strdup(s); temperature = strdup(s);
@ -405,8 +404,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
/* Ignore comment lines, but not lines begining with '*#', /* Ignore comment lines, but not lines begining with '*#',
but remove them, if they are in a .control ... .endc section */ but remove them, if they are in a .control ... .endc section */
s = dd->li_line; s = dd->li_line;
while (isspace_c(*s)) TEMPORARY_SKIP_WS_X1(s);
s++;
if ((*s == '*') && ((s != dd->li_line) || (s[1] != '#'))) { if ((*s == '*') && ((s != dd->li_line) || (s[1] != '#'))) {
if (commands) { if (commands) {
/* Remove comment lines in control sections, so they don't /* Remove comment lines in control sections, so they don't
@ -422,11 +420,9 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
/* Put the first token from line into s */ /* Put the first token from line into s */
strncpy(name, dd->li_line, BSIZE_SP); strncpy(name, dd->li_line, BSIZE_SP);
s = name; s = name;
for (; *s && isspace_c(*s); s++) TEMPORARY_SKIP_WS_X0(s);
;
t = s; t = s;
for (; *t && !isspace_c(*t); t++) TEMPORARY_SKIP_NON_WS_X0(t);
;
*t = '\0'; *t = '\0';
if (ciprefix(".control", dd->li_line)) { if (ciprefix(".control", dd->li_line)) {
@ -570,8 +566,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
s = dd->li_line; s = dd->li_line;
*s = '*'; *s = '*';
s = dd->li_line + 8; s = dd->li_line + 8;
while (isspace_c(*s)) TEMPORARY_SKIP_WS_X1(s);
s++;
cstoken[0] = gettok_char(&s, '=', FALSE, FALSE); cstoken[0] = gettok_char(&s, '=', FALSE, FALSE);
cstoken[1] = gettok_char(&s, '=', TRUE, FALSE); cstoken[1] = gettok_char(&s, '=', TRUE, FALSE);
cstoken[2] = gettok(&s); cstoken[2] = gettok(&s);
@ -811,8 +806,7 @@ inp_dodeck(
struct line *opt_beg = options; struct line *opt_beg = options;
for (; options; options = options->li_next) { for (; options; options = options->li_next) {
s = options->li_line; s = options->li_line;
for (; *s && !isspace_c(*s); s++) TEMPORARY_SKIP_NON_WS_X0(s);
;
ii = cp_interactive; ii = cp_interactive;
cp_interactive = FALSE; cp_interactive = FALSE;
@ -993,8 +987,7 @@ inp_dodeck(
/* /*
* for (; options; options = options->li_next) { * for (; options; options = options->li_next) {
* s = options->li_line; * s = options->li_line;
* for (; *s && !isspace_c(*s); s++) * TEMPORARY_SKIP_NON_WS_X0(s);
* ;
* ii = cp_interactive; * ii = cp_interactive;
* cp_interactive = FALSE; * cp_interactive = FALSE;
* wl = cp_lexer(s); * wl = cp_lexer(s);

View File

@ -80,8 +80,7 @@ com_reshape(wordlist *wl)
wlast = wlast->wl_next; wlast = wlast->wl_next;
} }
while (*p && isspace_c(*p)) TEMPORARY_SKIP_WS_X0(p);
p++;
switch (state) { switch (state) {
case 0: /* p just at or before a number */ case 0: /* p just at or before a number */
@ -132,8 +131,7 @@ com_reshape(wordlist *wl)
} }
} }
while (*p && isspace_c(*p)) TEMPORARY_SKIP_WS_X0(p);
p++;
} while (state < 3); } while (state < 3);

View File

@ -832,8 +832,7 @@ nupa_eval(char *s, int linenum, int orig_linenum)
} else if (c == 'X') { } else if (c == 'X') {
/* compute args of subcircuit, if required */ /* compute args of subcircuit, if required */
ptr = s; ptr = s;
while (*ptr && !isspace_c(*ptr)) TEMPORARY_SKIP_NON_WS_X0(ptr);
ptr++;
keep = *ptr; keep = *ptr;
*ptr = '\0'; *ptr = '\0';
nupa_inst_name = strdup(s); nupa_inst_name = strdup(s);

View File

@ -95,11 +95,9 @@ inp_nutsource(FILE *fp, bool comfile, char *filename)
} }
(void) strncpy(name, dd->li_line, BSIZE_SP); (void) strncpy(name, dd->li_line, BSIZE_SP);
s = name; s = name;
for (; *s && isspace_c(*s); s++) TEMPORARY_SKIP_WS_X0(s);
;
t = s; t = s;
for (; *t && !isspace_c(*t); t++) TEMPORARY_SKIP_NON_WS_X0(t);
;
*t = '\0'; *t = '\0';
if (ciprefix(".control", dd->li_line)) { if (ciprefix(".control", dd->li_line)) {

View File

@ -1036,8 +1036,7 @@ readtics(char *string)
for (k = 0; *words && k < MAXTICS; words = worde) { for (k = 0; *words && k < MAXTICS; words = worde) {
while (isspace_c(*words)) TEMPORARY_SKIP_WS_X1(words);
words++;
worde = words; worde = words;
while (isalpha_c(*worde) || isdigit_c(*worde)) while (isalpha_c(*worde) || isdigit_c(*worde))

View File

@ -153,11 +153,9 @@ collect_global_nodes(struct line *c)
txfree(gettok(&s)); txfree(gettok(&s));
while (*s) { while (*s) {
char *t = s; char *t = s;
for (; *s && !isspace_c(*s); s++) TEMPORARY_SKIP_NON_WS_X0(s);
;
global_nodes[num_global_nodes++] = copy_substring(t, s); global_nodes[num_global_nodes++] = copy_substring(t, s);
while (isspace_c(*s)) TEMPORARY_SKIP_WS_X1(s);
s++;
} }
c->li_line[0] = '*'; /* comment it out */ c->li_line[0] = '*'; /* comment it out */
} }
@ -323,10 +321,8 @@ inp_subcktexpand(struct line *deck) {
} else if (*s == '.') { } else if (*s == '.') {
continue; /* skip .commands */ continue; /* skip .commands */
} else { /* any other line . . . */ } else { /* any other line . . . */
while (*s && !isspace_c(*s)) /* skip first token */ TEMPORARY_SKIP_NON_WS_X0(s);
s++; TEMPORARY_SKIP_WS_X0(s);
while (*s && isspace_c(*s)) /* skip whitespace */
s++;
if (*s == '(') { if (*s == '(') {
int level = 0; int level = 0;
@ -496,12 +492,10 @@ doit(struct line *deck, wordlist *modnames) {
/* count the number of args in the .subckt line */ /* count the number of args in the .subckt line */
sss->su_numargs = 0; sss->su_numargs = 0;
for (;;) { for (;;) {
while (isspace_c(*s)) TEMPORARY_SKIP_WS_X1(s);
s++;
if (*s == '\0') if (*s == '\0')
break; break;
while (*s && !isspace_c(*s)) TEMPORARY_SKIP_NON_WS_X0(s);
s++;
sss->su_numargs ++; sss->su_numargs ++;
} }
} }
@ -1316,8 +1310,7 @@ finishLine(struct bxx_buffer *t, char *src, char *scname)
continue; continue;
} }
s = src + 1; s = src + 1;
for (; *s && isspace_c(*s); s++) TEMPORARY_SKIP_WS_X0(s);
;
if (!*s || (*s != '(')) { if (!*s || (*s != '(')) {
lastwasalpha = isalpha_c(*src); lastwasalpha = isalpha_c(*src);
bxx_putc(t, *src++); bxx_putc(t, *src++);
@ -1327,8 +1320,7 @@ finishLine(struct bxx_buffer *t, char *src, char *scname)
bxx_putc(t, which = *src); bxx_putc(t, which = *src);
src = s; src = s;
bxx_putc(t, *src++); bxx_putc(t, *src++);
while (isspace_c(*src)) TEMPORARY_SKIP_WS_X1(src);
src++;
for (buf = src; *src && !isspace_c(*src) && *src != ',' && *src != ')'; ) for (buf = src; *src && !isspace_c(*src) && *src != ',' && *src != ')'; )
src++; src++;
buf_end = src; buf_end = src;
@ -1475,8 +1467,7 @@ numnodes(char *name, struct subs *subs, wordlist const *modnames)
const wordlist *wl; const wordlist *wl;
int n, i, gotit; int n, i, gotit;
while (*name && isspace_c(*name)) TEMPORARY_SKIP_WS_X0(name);
name++;
c = *name; c = *name;
if (isupper_c(c)) if (isupper_c(c))
@ -1506,10 +1497,8 @@ numnodes(char *name, struct subs *subs, wordlist const *modnames)
int nodes = -2; int nodes = -2;
for (s = buf; *s; ) { for (s = buf; *s; ) {
nodes++; nodes++;
while (*s && !isspace_c(*s)) TEMPORARY_SKIP_NON_WS_X0(s);
s++; TEMPORARY_SKIP_WS_X1(s);
while (isspace_c(*s))
s++;
} }
return (nodes); return (nodes);
} }
@ -1582,8 +1571,7 @@ static int
numdevs(char *s) numdevs(char *s)
{ {
while (*s && isspace_c(*s)) TEMPORARY_SKIP_WS_X0(s);
s++;
switch (*s) { switch (*s) {
case 'K': case 'K':
case 'k': case 'k':
@ -1692,8 +1680,7 @@ devmodtranslate(struct line *s, char *subname, wordlist * const orig_modnames)
printf("In devmodtranslate, examining line %s.\n", t); printf("In devmodtranslate, examining line %s.\n", t);
#endif #endif
while (*t && isspace_c(*t)) TEMPORARY_SKIP_WS_X0(t);
t++;
c = *t; /* set c to first char in line. . . . */ c = *t; /* set c to first char in line. . . . */
if (isupper_c(c)) if (isupper_c(c))
c = tolower_c(c); c = tolower_c(c);

View File

@ -939,8 +939,7 @@ vec_basename(struct dvec *v)
strtolower(buf); strtolower(buf);
t = buf; t = buf;
for (; isspace_c(*t); t++) TEMPORARY_SKIP_WS_X1(t);
;
s = t; s = t;
for (t = s; *t; t++) for (t = s; *t; t++)
; ;

View File

@ -283,8 +283,7 @@ gettok(char **s)
char *beg, *token ; /* return token */ char *beg, *token ; /* return token */
paren = 0; paren = 0;
while (isspace_c(**s)) TEMPORARY_SKIP_WS_X1(*s);
(*s)++;
if (!**s) if (!**s)
return (NULL); return (NULL);
beg = *s ; beg = *s ;
@ -358,8 +357,7 @@ gettok_noparens(char **s)
char c; char c;
char *beg, *token ; /* return token */ char *beg, *token ; /* return token */
while ( isspace_c(**s) ) TEMPORARY_SKIP_WS_X1(*s);
(*s)++; /* iterate over whitespace */
if (!**s) if (!**s)
return (NULL); /* return NULL if we come to end of line */ return (NULL); /* return NULL if we come to end of line */
@ -377,8 +375,7 @@ gettok_noparens(char **s)
token = copy_substring(beg, *s) ; token = copy_substring(beg, *s) ;
/* Now iterate up to next non-whitespace char */ /* Now iterate up to next non-whitespace char */
while ( isspace_c(**s) ) TEMPORARY_SKIP_WS_X1(*s);
(*s)++;
return ( token ) ; return ( token ) ;
} }
@ -389,8 +386,7 @@ gettok_instance(char **s)
char c; char c;
char *beg, *token ; /* return token */ char *beg, *token ; /* return token */
while ( isspace_c(**s) ) TEMPORARY_SKIP_WS_X1(*s);
(*s)++; /* iterate over whitespace */
if (!**s) if (!**s)
return (NULL); /* return NULL if we come to end of line */ return (NULL); /* return NULL if we come to end of line */
@ -407,8 +403,7 @@ gettok_instance(char **s)
token = copy_substring(beg, *s) ; token = copy_substring(beg, *s) ;
/* Now iterate up to next non-whitespace char */ /* Now iterate up to next non-whitespace char */
while ( isspace_c(**s) ) TEMPORARY_SKIP_WS_X1(*s);
(*s)++;
return ( token ) ; return ( token ) ;
} }
@ -425,8 +420,7 @@ gettok_char(char **s, char p, bool inc_p, bool nested)
char c; char c;
char *beg, *token ; /* return token */ char *beg, *token ; /* return token */
while ( isspace_c(**s) ) TEMPORARY_SKIP_WS_X1(*s);
(*s)++; /* iterate over whitespace */
if (!**s) if (!**s)
return (NULL); /* return NULL if we come to end of line */ return (NULL); /* return NULL if we come to end of line */
@ -473,8 +467,7 @@ gettok_char(char **s, char p, bool inc_p, bool nested)
token = copy_substring(beg, *s) ; token = copy_substring(beg, *s) ;
/* Now iterate up to next non-whitespace char */ /* Now iterate up to next non-whitespace char */
while ( isspace_c(**s) ) TEMPORARY_SKIP_WS_X1(*s);
(*s)++;
return ( token ) ; return ( token ) ;
} }
@ -671,7 +664,7 @@ get_comma_separated_values( char *values[], char *str ) {
values[count++] = strdup(str); values[count++] = strdup(str);
*ptr = keep; *ptr = keep;
str = comma_ptr + 1; str = comma_ptr + 1;
while ( isspace_c(*str) ) str++; TEMPORARY_SKIP_WS_X1(str);
} }
values[count++] = strdup(str); values[count++] = strdup(str);
return count; return count;

View File

@ -43,8 +43,7 @@ tildexpand(char *string)
if (!string) if (!string)
return NULL; return NULL;
while (*string && isspace_c(*string)) TEMPORARY_SKIP_WS_X0(string);
string++;
if (*string != '~') if (*string != '~')
return copy(string); return copy(string);

View File

@ -86,8 +86,7 @@ void INP2R(CKTcircuit *ckt, INPtables * tab, card * current)
s += 2; s += 2;
/* skip any white space */ /* skip any white space */
while(isspace_c(*s)) TEMPORARY_SKIP_WS_X1(s);
s++;
/* reject if not '=' */ /* reject if not '=' */
if(*s != '=') if(*s != '=')
@ -96,8 +95,7 @@ void INP2R(CKTcircuit *ckt, INPtables * tab, card * current)
s++; s++;
/* skip any white space */ /* skip any white space */
while(isspace_c(*s)) TEMPORARY_SKIP_WS_X1(s);
s++;
/* if we now have +, - or a decimal digit then assume we have a number, /* if we now have +, - or a decimal digit then assume we have a number,
otherwise reject */ otherwise reject */
@ -105,14 +103,12 @@ void INP2R(CKTcircuit *ckt, INPtables * tab, card * current)
continue; continue;
/* look for next white space or null */ /* look for next white space or null */
while(*s && !isspace_c(*s)) TEMPORARY_SKIP_NON_WS_X0(s);
s++;
left_length = (size_t) (s - current->line); left_length = (size_t) (s - current->line);
/* skip any additional white space */ /* skip any additional white space */
while(isspace_c(*s)) TEMPORARY_SKIP_WS_X1(s);
s++;
/* if we now have +, - or a decimal digit then assume we have the /* if we now have +, - or a decimal digit then assume we have the
second number, otherwise reject */ second number, otherwise reject */