Back to index

radiance  4R0+20100331
words.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: words.c,v 1.4 2003/03/11 17:08:55 greg Exp $";
00003 #endif
00004 /*
00005  * Routines for recognizing and moving about words in strings.
00006  */
00007 
00008 #include  <string.h>
00009 #include  <ctype.h>
00010 
00011 
00012 char *
00013 iskip(s)                    /* skip integer in string */
00014 register char  *s;
00015 {
00016        while (isspace(*s))
00017               s++;
00018        if (*s == '-' || *s == '+')
00019               s++;
00020        if (!isdigit(*s))
00021               return(NULL);
00022        do
00023               s++;
00024        while (isdigit(*s));
00025        return(s);
00026 }
00027 
00028 
00029 char *
00030 fskip(s)                    /* skip float in string */
00031 register char  *s;
00032 {
00033        register char  *cp;
00034 
00035        while (isspace(*s))
00036               s++;
00037        if (*s == '-' || *s == '+')
00038               s++;
00039        cp = s;
00040        while (isdigit(*cp))
00041               cp++;
00042        if (*cp == '.') {
00043               cp++; s++;
00044               while (isdigit(*cp))
00045                      cp++;
00046        }
00047        if (cp == s)
00048               return(NULL);
00049        if (*cp == 'e' || *cp == 'E')
00050               return(iskip(cp+1));
00051        return(cp);
00052 }
00053 
00054 
00055 int
00056 isint(s)                    /* check integer format */
00057 char  *s;
00058 {
00059        register char  *cp;
00060 
00061        cp = iskip(s);
00062        return(cp != NULL && *cp == '\0');
00063 }
00064 
00065 
00066 int
00067 isintd(s, ds)               /* check integer format with delimiter set */
00068 char  *s, *ds;
00069 {
00070        register char  *cp;
00071 
00072        cp = iskip(s);
00073        return(cp != NULL && strchr(ds, *cp) != NULL);
00074 }
00075 
00076 
00077 int
00078 isflt(s)                    /* check float format */
00079 char  *s;
00080 {
00081        register char  *cp;
00082 
00083        cp = fskip(s);
00084        return(cp != NULL && *cp == '\0');
00085 }
00086 
00087 
00088 int
00089 isfltd(s, ds)               /* check integer format with delimiter set */
00090 char  *s, *ds;
00091 {
00092        register char  *cp;
00093 
00094        cp = fskip(s);
00095        return(cp != NULL && strchr(ds, *cp) != NULL);
00096 }
00097 
00098 
00099 int
00100 isname(s)                   /* check for legal identifier name */
00101 register char  *s;
00102 {
00103        while (*s == '_')                  /* skip leading underscores */
00104               s++;
00105        if (!isascii(*s) || !isalpha(*s))  /* start with a letter */
00106               return(0);
00107        while (isascii(*++s) && isgraph(*s))      /* all visible characters */
00108               ;
00109        return(*s == '\0');                /* ending in nul */
00110 }