--- ray/src/common/words.c 2003/02/25 02:47:22 2.6 +++ ray/src/common/words.c 2019/12/28 18:05:14 2.12 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: words.c,v 2.6 2003/02/25 02:47:22 greg Exp $"; +static const char RCSid[] = "$Id: words.c,v 2.12 2019/12/28 18:05:14 greg Exp $"; #endif /* * Routines for recognizing and moving about words in strings. @@ -10,20 +10,13 @@ static const char RCSid[] = "$Id: words.c,v 2.6 2003/0 #include "copyright.h" #include -#include -#ifdef BSD -#define strchr index -#endif +#include "rtio.h" - char * -atos(rs, nb, s) /* get word from string, returning rs */ -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; + char *cp = rs; while (isspace(*s)) s++; @@ -35,10 +28,7 @@ register char *s; char * -nextword(cp, nb, s) /* get (quoted) word, returning new s */ -register char *cp; -register int nb; -register char *s; +nextword(char *cp, int nb, char *s) /* get (quoted) word, returning new s */ { int quote = 0; @@ -62,8 +52,7 @@ register char *s; char * -sskip(s) /* skip word in string, leaving on space */ -register char *s; +sskip(char *s) /* skip word in string, leaving on space */ { while (isspace(*s)) s++; @@ -74,9 +63,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++; @@ -91,12 +78,11 @@ register int n; char * -iskip(s) /* skip integer in string */ -register char *s; +iskip(char *s) /* skip integer in string */ { while (isspace(*s)) s++; - if (*s == '-' || *s == '+') + if ((*s == '-') | (*s == '+')) s++; if (!isdigit(*s)) return(NULL); @@ -108,14 +94,13 @@ register char *s; char * -fskip(s) /* skip float in string */ -register char *s; +fskip(char *s) /* skip float in string */ { - register char *cp; + char *cp; while (isspace(*s)) s++; - if (*s == '-' || *s == '+') + if ((*s == '-') | (*s == '+')) s++; cp = s; while (isdigit(*cp)) @@ -127,17 +112,16 @@ register char *s; } if (cp == s) return(NULL); - if (*cp == 'e' || *cp == 'E') - return(iskip(cp+1)); + if ((*cp == 'e') | (*cp == 'E')) + return(isspace(*++cp) ? NULL : iskip(cp)); return(cp); } int -isint(s) /* check integer format */ -char *s; +isint(char *s) /* check integer format */ { - register char *cp; + char *cp; cp = iskip(s); return(cp != NULL && *cp == '\0'); @@ -145,10 +129,9 @@ char *s; int -isintd(s, ds) /* check integer format with delimiter set */ -char *s, *ds; +isintd(char *s, char *ds) /* check integer format with delimiter set */ { - register char *cp; + char *cp; cp = iskip(s); return(cp != NULL && strchr(ds, *cp) != NULL); @@ -156,10 +139,9 @@ char *s, *ds; int -isflt(s) /* check float format */ -char *s; +isflt(char *s) /* check float format */ { - register char *cp; + char *cp; cp = fskip(s); return(cp != NULL && *cp == '\0'); @@ -167,11 +149,23 @@ char *s; int -isfltd(s, ds) /* check integer format with delimiter set */ -char *s, *ds; +isfltd(char *s, char *ds) /* check integer format with delimiter set */ { - register char *cp; + 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 */ }