| 1 | 
#ifndef lint | 
| 2 | 
static const char       RCSid[] = "$Id: words.c,v 1.4 2003/03/11 17:08:55 greg Exp $"; | 
| 3 | 
#endif | 
| 4 | 
/* | 
| 5 | 
 * Routines for recognizing and moving about words in strings. | 
| 6 | 
 */ | 
| 7 | 
 | 
| 8 | 
#include  <string.h> | 
| 9 | 
#include  <ctype.h> | 
| 10 | 
 | 
| 11 | 
 | 
| 12 | 
char * | 
| 13 | 
iskip(s)                        /* skip integer in string */ | 
| 14 | 
register char  *s; | 
| 15 | 
{ | 
| 16 | 
        while (isspace(*s)) | 
| 17 | 
                s++; | 
| 18 | 
        if (*s == '-' || *s == '+') | 
| 19 | 
                s++; | 
| 20 | 
        if (!isdigit(*s)) | 
| 21 | 
                return(NULL); | 
| 22 | 
        do | 
| 23 | 
                s++; | 
| 24 | 
        while (isdigit(*s)); | 
| 25 | 
        return(s); | 
| 26 | 
} | 
| 27 | 
 | 
| 28 | 
 | 
| 29 | 
char * | 
| 30 | 
fskip(s)                        /* skip float in string */ | 
| 31 | 
register char  *s; | 
| 32 | 
{ | 
| 33 | 
        register char  *cp; | 
| 34 | 
 | 
| 35 | 
        while (isspace(*s)) | 
| 36 | 
                s++; | 
| 37 | 
        if (*s == '-' || *s == '+') | 
| 38 | 
                s++; | 
| 39 | 
        cp = s; | 
| 40 | 
        while (isdigit(*cp)) | 
| 41 | 
                cp++; | 
| 42 | 
        if (*cp == '.') { | 
| 43 | 
                cp++; s++; | 
| 44 | 
                while (isdigit(*cp)) | 
| 45 | 
                        cp++; | 
| 46 | 
        } | 
| 47 | 
        if (cp == s) | 
| 48 | 
                return(NULL); | 
| 49 | 
        if (*cp == 'e' || *cp == 'E') | 
| 50 | 
                return(iskip(cp+1)); | 
| 51 | 
        return(cp); | 
| 52 | 
} | 
| 53 | 
 | 
| 54 | 
 | 
| 55 | 
int | 
| 56 | 
isint(s)                        /* check integer format */ | 
| 57 | 
char  *s; | 
| 58 | 
{ | 
| 59 | 
        register char  *cp; | 
| 60 | 
 | 
| 61 | 
        cp = iskip(s); | 
| 62 | 
        return(cp != NULL && *cp == '\0'); | 
| 63 | 
} | 
| 64 | 
 | 
| 65 | 
 | 
| 66 | 
int | 
| 67 | 
isintd(s, ds)                   /* check integer format with delimiter set */ | 
| 68 | 
char  *s, *ds; | 
| 69 | 
{ | 
| 70 | 
        register char  *cp; | 
| 71 | 
 | 
| 72 | 
        cp = iskip(s); | 
| 73 | 
        return(cp != NULL && strchr(ds, *cp) != NULL); | 
| 74 | 
} | 
| 75 | 
 | 
| 76 | 
 | 
| 77 | 
int | 
| 78 | 
isflt(s)                        /* check float format */ | 
| 79 | 
char  *s; | 
| 80 | 
{ | 
| 81 | 
        register char  *cp; | 
| 82 | 
 | 
| 83 | 
        cp = fskip(s); | 
| 84 | 
        return(cp != NULL && *cp == '\0'); | 
| 85 | 
} | 
| 86 | 
 | 
| 87 | 
 | 
| 88 | 
int | 
| 89 | 
isfltd(s, ds)                   /* check integer format with delimiter set */ | 
| 90 | 
char  *s, *ds; | 
| 91 | 
{ | 
| 92 | 
        register char  *cp; | 
| 93 | 
 | 
| 94 | 
        cp = fskip(s); | 
| 95 | 
        return(cp != NULL && strchr(ds, *cp) != NULL); | 
| 96 | 
} | 
| 97 | 
 | 
| 98 | 
 | 
| 99 | 
int | 
| 100 | 
isname(s)                       /* check for legal identifier name */ | 
| 101 | 
register char  *s; | 
| 102 | 
{ | 
| 103 | 
        while (*s == '_')                       /* skip leading underscores */ | 
| 104 | 
                s++; | 
| 105 | 
        if (!isascii(*s) || !isalpha(*s))       /* start with a letter */ | 
| 106 | 
                return(0); | 
| 107 | 
        while (isascii(*++s) && isgraph(*s))    /* all visible characters */ | 
| 108 | 
                ; | 
| 109 | 
        return(*s == '\0');                     /* ending in nul */ | 
| 110 | 
} |