--- ray/src/common/words.c 1996/01/17 10:53:38 2.3 +++ ray/src/common/words.c 2011/02/18 00:40:25 2.10 @@ -1,29 +1,21 @@ -/* Copyright (c) 1996 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: words.c,v 2.10 2011/02/18 00:40:25 greg Exp $"; #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 +#include "rtio.h" -#define NULL 0 - -extern char *strchr(); - - char * -atos(rs, nb, s) /* get next word from string */ -char *rs; -register int nb; -register char *s; +atos(char *rs, int nb, char *s) /* get word from string, returning rs */ { register char *cp = rs; @@ -37,11 +29,34 @@ register char *s; char * -sskip(s) /* skip word in string, leaving on space */ -register char *s; +nextword(char *cp, int nb, char *s) /* get (quoted) word, returning new 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(char *s) /* skip word in string, leaving on space */ +{ + while (isspace(*s)) + s++; while (*s && !isspace(*s)) s++; return(s); @@ -49,9 +64,7 @@ register char *s; char * -sskip2(s, n) /* skip word(s) in string, leaving on word */ -register char *s; -register int n; +sskip2(char *s, int n) /* skip word(s) in string, leaving on word */ { while (isspace(*s)) s++; @@ -66,8 +79,7 @@ register int n; char * -iskip(s) /* skip integer in string */ -register char *s; +iskip(char *s) /* skip integer in string */ { while (isspace(*s)) s++; @@ -83,8 +95,7 @@ register char *s; char * -fskip(s) /* skip float in string */ -register char *s; +fskip(char *s) /* skip float in string */ { register char *cp; @@ -108,8 +119,8 @@ register char *s; } -isint(s) /* check integer format */ -char *s; +int +isint(char *s) /* check integer format */ { register char *cp; @@ -118,8 +129,8 @@ char *s; } -isintd(s, ds) /* check integer format with delimiter set */ -char *s, *ds; +int +isintd(char *s, char *ds) /* check integer format with delimiter set */ { register char *cp; @@ -128,8 +139,8 @@ char *s, *ds; } -isflt(s) /* check float format */ -char *s; +int +isflt(char *s) /* check float format */ { register char *cp; @@ -138,11 +149,24 @@ char *s; } -isfltd(s, ds) /* check integer format with delimiter set */ -char *s, *ds; +int +isfltd(char *s, char *ds) /* check integer format with delimiter set */ { register char *cp; cp = fskip(s); return(cp != NULL && strchr(ds, *cp) != NULL); +} + + +int +isname(char *s) /* check for legal identifier name */ +{ + while (*s == '_') /* skip leading underscores */ + s++; + if (!isascii(*s) || !isalpha(*s)) /* start with a letter */ + return(0); + while (isascii(*++s) && isgraph(*s)) /* all visible characters */ + ; + return(*s == '\0'); /* ending in nul */ }