--- ray/src/common/words.c 1991/07/30 13:47:29 1.4 +++ ray/src/common/words.c 1999/01/29 11:18:23 2.4 @@ -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,7 +20,7 @@ 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,13 +37,57 @@ 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); +} + + +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); }