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