ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/words.c
Revision: 1.3
Committed: Fri Feb 28 20:11:30 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -6 lines
Log Message:
Updates for 3.5 release

File Contents

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