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