ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/words.c
Revision: 2.8
Committed: Thu Jul 17 09:21:29 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.7: +1 -0 lines
Log Message:
Added prototypes and includes from patch by Randolph Fritz.
Added more required includes and reduced other compile warnings.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.7 static const char RCSid[] = "$Id";
3 greg 1.1 #endif
4     /*
5     * Routines for recognizing and moving about words in strings.
6 greg 2.5 *
7     * External symbols declared in standard.h
8     */
9    
10 greg 2.6 #include "copyright.h"
11 greg 1.1
12     #include <ctype.h>
13 greg 2.5 #include <string.h>
14 greg 1.1
15 schorsch 2.8 #include "rtio.h"
16 greg 1.1
17     char *
18 gwlarson 2.4 atos(rs, nb, s) /* get word from string, returning rs */
19 greg 1.2 char *rs;
20     register int nb;
21     register char *s;
22     {
23     register char *cp = rs;
24    
25     while (isspace(*s))
26     s++;
27     while (--nb > 0 && *s && !isspace(*s))
28     *cp++ = *s++;
29     *cp = '\0';
30     return(rs);
31 gwlarson 2.4 }
32    
33    
34     char *
35     nextword(cp, nb, s) /* get (quoted) word, returning new s */
36     register char *cp;
37     register int nb;
38     register char *s;
39     {
40     int quote = 0;
41    
42     if (s == NULL) return(NULL);
43     while (isspace(*s))
44     s++;
45     switch (*s) {
46     case '\0':
47     return(NULL);
48     case '"':
49     case '\'':
50     quote = *s++;
51     }
52     while (--nb > 0 && *s && (quote ? *s!=quote : !isspace(*s)))
53     *cp++ = *s++;
54     *cp = '\0';
55     if (quote && *s==quote)
56     s++;
57     return(s);
58 greg 1.2 }
59    
60    
61     char *
62 greg 2.3 sskip(s) /* skip word in string, leaving on space */
63 greg 1.1 register char *s;
64     {
65     while (isspace(*s))
66     s++;
67     while (*s && !isspace(*s))
68 greg 2.2 s++;
69 greg 2.3 return(s);
70     }
71    
72    
73     char *
74     sskip2(s, n) /* skip word(s) in string, leaving on word */
75     register char *s;
76     register int n;
77     {
78 greg 2.2 while (isspace(*s))
79 greg 1.1 s++;
80 greg 2.3 while (n-- > 0) {
81     while (*s && !isspace(*s))
82     s++;
83     while (isspace(*s))
84     s++;
85     }
86 greg 1.1 return(s);
87     }
88    
89    
90     char *
91     iskip(s) /* skip integer in string */
92 greg 1.2 register char *s;
93 greg 1.1 {
94 greg 1.2 while (isspace(*s))
95     s++;
96     if (*s == '-' || *s == '+')
97     s++;
98     if (!isdigit(*s))
99     return(NULL);
100     do
101     s++;
102     while (isdigit(*s));
103     return(s);
104 greg 1.1 }
105    
106    
107     char *
108     fskip(s) /* skip float in string */
109 greg 1.2 register char *s;
110 greg 1.1 {
111 greg 1.4 register char *cp;
112 greg 1.1
113 greg 1.4 while (isspace(*s))
114     s++;
115     if (*s == '-' || *s == '+')
116     s++;
117     cp = s;
118 greg 1.1 while (isdigit(*cp))
119     cp++;
120     if (*cp == '.') {
121 greg 1.2 cp++; s++;
122 greg 1.1 while (isdigit(*cp))
123     cp++;
124     }
125 greg 1.2 if (cp == s)
126     return(NULL);
127 greg 1.1 if (*cp == 'e' || *cp == 'E')
128     return(iskip(cp+1));
129     return(cp);
130     }
131    
132    
133 greg 2.5 int
134 greg 1.1 isint(s) /* check integer format */
135     char *s;
136     {
137     register char *cp;
138    
139     cp = iskip(s);
140 greg 1.2 return(cp != NULL && *cp == '\0');
141 greg 1.1 }
142    
143    
144 greg 2.5 int
145 greg 1.1 isintd(s, ds) /* check integer format with delimiter set */
146     char *s, *ds;
147     {
148     register char *cp;
149    
150     cp = iskip(s);
151 greg 1.3 return(cp != NULL && strchr(ds, *cp) != NULL);
152 greg 1.1 }
153    
154    
155 greg 2.5 int
156 greg 1.1 isflt(s) /* check float format */
157     char *s;
158     {
159     register char *cp;
160    
161     cp = fskip(s);
162 greg 1.2 return(cp != NULL && *cp == '\0');
163 greg 1.1 }
164    
165    
166 greg 2.5 int
167 greg 1.1 isfltd(s, ds) /* check integer format with delimiter set */
168     char *s, *ds;
169     {
170     register char *cp;
171    
172     cp = fskip(s);
173 greg 1.3 return(cp != NULL && strchr(ds, *cp) != NULL);
174 greg 1.1 }