ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/words.c
Revision: 2.3
Committed: Wed Jan 17 10:53:38 1996 UTC (28 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +16 -1 lines
Log Message:
replaced sskip() behavior and added new sskip2() function

File Contents

# Content
1 /* Copyright (c) 1996 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Routines for recognizing and moving about words in strings.
9 */
10
11 #include <ctype.h>
12
13 #ifdef BSD
14 #define strchr index
15 #endif
16
17 #define NULL 0
18
19 extern char *strchr();
20
21
22 char *
23 atos(rs, nb, s) /* get next word from string */
24 char *rs;
25 register int nb;
26 register char *s;
27 {
28 register char *cp = rs;
29
30 while (isspace(*s))
31 s++;
32 while (--nb > 0 && *s && !isspace(*s))
33 *cp++ = *s++;
34 *cp = '\0';
35 return(rs);
36 }
37
38
39 char *
40 sskip(s) /* skip word in string, leaving on space */
41 register char *s;
42 {
43 while (isspace(*s))
44 s++;
45 while (*s && !isspace(*s))
46 s++;
47 return(s);
48 }
49
50
51 char *
52 sskip2(s, n) /* skip word(s) in string, leaving on word */
53 register char *s;
54 register int n;
55 {
56 while (isspace(*s))
57 s++;
58 while (n-- > 0) {
59 while (*s && !isspace(*s))
60 s++;
61 while (isspace(*s))
62 s++;
63 }
64 return(s);
65 }
66
67
68 char *
69 iskip(s) /* skip integer in string */
70 register char *s;
71 {
72 while (isspace(*s))
73 s++;
74 if (*s == '-' || *s == '+')
75 s++;
76 if (!isdigit(*s))
77 return(NULL);
78 do
79 s++;
80 while (isdigit(*s));
81 return(s);
82 }
83
84
85 char *
86 fskip(s) /* skip float in string */
87 register char *s;
88 {
89 register char *cp;
90
91 while (isspace(*s))
92 s++;
93 if (*s == '-' || *s == '+')
94 s++;
95 cp = s;
96 while (isdigit(*cp))
97 cp++;
98 if (*cp == '.') {
99 cp++; s++;
100 while (isdigit(*cp))
101 cp++;
102 }
103 if (cp == s)
104 return(NULL);
105 if (*cp == 'e' || *cp == 'E')
106 return(iskip(cp+1));
107 return(cp);
108 }
109
110
111 isint(s) /* check integer format */
112 char *s;
113 {
114 register char *cp;
115
116 cp = iskip(s);
117 return(cp != NULL && *cp == '\0');
118 }
119
120
121 isintd(s, ds) /* check integer format with delimiter set */
122 char *s, *ds;
123 {
124 register char *cp;
125
126 cp = iskip(s);
127 return(cp != NULL && strchr(ds, *cp) != NULL);
128 }
129
130
131 isflt(s) /* check float format */
132 char *s;
133 {
134 register char *cp;
135
136 cp = fskip(s);
137 return(cp != NULL && *cp == '\0');
138 }
139
140
141 isfltd(s, ds) /* check integer format with delimiter set */
142 char *s, *ds;
143 {
144 register char *cp;
145
146 cp = fskip(s);
147 return(cp != NULL && strchr(ds, *cp) != NULL);
148 }