--- ray/src/common/words.c 1991/07/23 11:36:42 1.2 +++ ray/src/common/words.c 2003/03/10 17:26:26 2.7 @@ -1,26 +1,20 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id"; #endif - /* * Routines for recognizing and moving about words in strings. + * + * External symbols declared in standard.h */ +#include "copyright.h" + #include +#include -#ifdef BSD -#define strchr index -#endif -#define NULL 0 - -extern char *strchr(); - - char * -atos(rs, nb, s) /* get next word from string */ +atos(rs, nb, s) /* get word from string, returning rs */ char *rs; register int nb; register char *s; @@ -37,11 +31,38 @@ register char *s; char * -sskip(s) /* skip word in string */ +nextword(cp, nb, s) /* get (quoted) word, returning new s */ +register char *cp; +register int nb; register char *s; { + int quote = 0; + + if (s == NULL) return(NULL); while (isspace(*s)) s++; + switch (*s) { + case '\0': + return(NULL); + case '"': + case '\'': + quote = *s++; + } + while (--nb > 0 && *s && (quote ? *s!=quote : !isspace(*s))) + *cp++ = *s++; + *cp = '\0'; + if (quote && *s==quote) + s++; + return(s); +} + + +char * +sskip(s) /* skip word in string, leaving on space */ +register char *s; +{ + while (isspace(*s)) + s++; while (*s && !isspace(*s)) s++; return(s); @@ -49,6 +70,23 @@ register char *s; char * +sskip2(s, n) /* skip word(s) in string, leaving on word */ +register char *s; +register int n; +{ + while (isspace(*s)) + s++; + while (n-- > 0) { + while (*s && !isspace(*s)) + s++; + while (isspace(*s)) + s++; + } + return(s); +} + + +char * iskip(s) /* skip integer in string */ register char *s; { @@ -69,13 +107,13 @@ char * fskip(s) /* skip float in string */ register char *s; { - register char *cp = s; + register char *cp; - while (isspace(*cp)) - cp++; - if (*cp == '-' || *cp == '+') - cp++; - s = cp; + while (isspace(*s)) + s++; + if (*s == '-' || *s == '+') + s++; + cp = s; while (isdigit(*cp)) cp++; if (*cp == '.') { @@ -91,6 +129,7 @@ register char *s; } +int isint(s) /* check integer format */ char *s; { @@ -101,16 +140,18 @@ char *s; } +int isintd(s, ds) /* check integer format with delimiter set */ char *s, *ds; { register char *cp; cp = iskip(s); - return(cp != NULL && strchr(*cp, ds) != NULL); + return(cp != NULL && strchr(ds, *cp) != NULL); } +int isflt(s) /* check float format */ char *s; { @@ -121,11 +162,12 @@ char *s; } +int isfltd(s, ds) /* check integer format with delimiter set */ char *s, *ds; { register char *cp; cp = fskip(s); - return(cp != NULL && strchr(*cp, ds) != NULL); + return(cp != NULL && strchr(ds, *cp) != NULL); }