--- ray/src/common/words.c 1991/07/22 14:34:27 1.1 +++ ray/src/common/words.c 1996/01/10 21:04:21 2.2 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1996 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -20,6 +20,23 @@ extern char *strchr(); char * +atos(rs, nb, s) /* get next word from string */ +char *rs; +register int nb; +register char *s; +{ + register char *cp = rs; + + while (isspace(*s)) + s++; + while (--nb > 0 && *s && !isspace(*s)) + *cp++ = *s++; + *cp = '\0'; + return(rs); +} + + +char * sskip(s) /* skip word in string */ register char *s; { @@ -27,43 +44,49 @@ register char *s; s++; while (*s && !isspace(*s)) s++; + while (isspace(*s)) + s++; return(s); } char * iskip(s) /* skip integer in string */ -char *s; +register char *s; { - register char *cp = s; - - while (isspace(*cp)) - cp++; - if (*cp == '-' || *cp == '+') - cp++; - while (isdigit(*cp)) - cp++; - return(cp); + while (isspace(*s)) + s++; + if (*s == '-' || *s == '+') + s++; + if (!isdigit(*s)) + return(NULL); + do + s++; + while (isdigit(*s)); + return(s); } char * fskip(s) /* skip float in string */ -char *s; +register char *s; { - register char *cp = s; + register char *cp; - while (isspace(*cp)) - cp++; - if (*cp == '-' || *cp == '+') - cp++; + while (isspace(*s)) + s++; + if (*s == '-' || *s == '+') + s++; + cp = s; while (isdigit(*cp)) cp++; if (*cp == '.') { - cp++; + cp++; s++; while (isdigit(*cp)) cp++; } + if (cp == s) + return(NULL); if (*cp == 'e' || *cp == 'E') return(iskip(cp+1)); return(cp); @@ -76,7 +99,7 @@ char *s; register char *cp; cp = iskip(s); - return(cp > s && *cp == '\0'); + return(cp != NULL && *cp == '\0'); } @@ -86,7 +109,7 @@ char *s, *ds; register char *cp; cp = iskip(s); - return(cp > s && strchr(*cp, ds) != NULL); + return(cp != NULL && strchr(ds, *cp) != NULL); } @@ -96,7 +119,7 @@ char *s; register char *cp; cp = fskip(s); - return(cp > s && *cp == '\0'); + return(cp != NULL && *cp == '\0'); } @@ -106,5 +129,5 @@ char *s, *ds; register char *cp; cp = fskip(s); - return(cp > s && strchr(*cp, ds) != NULL); + return(cp != NULL && strchr(ds, *cp) != NULL); }