ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/words.c
Revision: 2.2
Committed: Wed Jan 10 21:04:21 1996 UTC (28 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +3 -1 lines
Log Message:
improved sskip() behavior

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 */
41 register char *s;
42 {
43 while (isspace(*s))
44 s++;
45 while (*s && !isspace(*s))
46 s++;
47 while (isspace(*s))
48 s++;
49 return(s);
50 }
51
52
53 char *
54 iskip(s) /* skip integer in string */
55 register char *s;
56 {
57 while (isspace(*s))
58 s++;
59 if (*s == '-' || *s == '+')
60 s++;
61 if (!isdigit(*s))
62 return(NULL);
63 do
64 s++;
65 while (isdigit(*s));
66 return(s);
67 }
68
69
70 char *
71 fskip(s) /* skip float in string */
72 register char *s;
73 {
74 register char *cp;
75
76 while (isspace(*s))
77 s++;
78 if (*s == '-' || *s == '+')
79 s++;
80 cp = s;
81 while (isdigit(*cp))
82 cp++;
83 if (*cp == '.') {
84 cp++; s++;
85 while (isdigit(*cp))
86 cp++;
87 }
88 if (cp == s)
89 return(NULL);
90 if (*cp == 'e' || *cp == 'E')
91 return(iskip(cp+1));
92 return(cp);
93 }
94
95
96 isint(s) /* check integer format */
97 char *s;
98 {
99 register char *cp;
100
101 cp = iskip(s);
102 return(cp != NULL && *cp == '\0');
103 }
104
105
106 isintd(s, ds) /* check integer format with delimiter set */
107 char *s, *ds;
108 {
109 register char *cp;
110
111 cp = iskip(s);
112 return(cp != NULL && strchr(ds, *cp) != NULL);
113 }
114
115
116 isflt(s) /* check float format */
117 char *s;
118 {
119 register char *cp;
120
121 cp = fskip(s);
122 return(cp != NULL && *cp == '\0');
123 }
124
125
126 isfltd(s, ds) /* check integer format with delimiter set */
127 char *s, *ds;
128 {
129 register char *cp;
130
131 cp = fskip(s);
132 return(cp != NULL && strchr(ds, *cp) != NULL);
133 }