1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
3 |
#endif |
4 |
/* |
5 |
* Routines for recognizing and moving about words in strings. |
6 |
* |
7 |
* External symbols declared in standard.h |
8 |
*/ |
9 |
|
10 |
#include "copyright.h" |
11 |
|
12 |
#include <ctype.h> |
13 |
#include <string.h> |
14 |
|
15 |
#ifdef BSD |
16 |
#define strchr index |
17 |
#endif |
18 |
|
19 |
|
20 |
char * |
21 |
atos(rs, nb, s) /* get word from string, returning rs */ |
22 |
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 |
} |
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 |
} |
62 |
|
63 |
|
64 |
char * |
65 |
sskip(s) /* skip word in string, leaving on space */ |
66 |
register char *s; |
67 |
{ |
68 |
while (isspace(*s)) |
69 |
s++; |
70 |
while (*s && !isspace(*s)) |
71 |
s++; |
72 |
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 |
while (isspace(*s)) |
82 |
s++; |
83 |
while (n-- > 0) { |
84 |
while (*s && !isspace(*s)) |
85 |
s++; |
86 |
while (isspace(*s)) |
87 |
s++; |
88 |
} |
89 |
return(s); |
90 |
} |
91 |
|
92 |
|
93 |
char * |
94 |
iskip(s) /* skip integer in string */ |
95 |
register char *s; |
96 |
{ |
97 |
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 |
} |
108 |
|
109 |
|
110 |
char * |
111 |
fskip(s) /* skip float in string */ |
112 |
register char *s; |
113 |
{ |
114 |
register char *cp; |
115 |
|
116 |
while (isspace(*s)) |
117 |
s++; |
118 |
if (*s == '-' || *s == '+') |
119 |
s++; |
120 |
cp = s; |
121 |
while (isdigit(*cp)) |
122 |
cp++; |
123 |
if (*cp == '.') { |
124 |
cp++; s++; |
125 |
while (isdigit(*cp)) |
126 |
cp++; |
127 |
} |
128 |
if (cp == s) |
129 |
return(NULL); |
130 |
if (*cp == 'e' || *cp == 'E') |
131 |
return(iskip(cp+1)); |
132 |
return(cp); |
133 |
} |
134 |
|
135 |
|
136 |
int |
137 |
isint(s) /* check integer format */ |
138 |
char *s; |
139 |
{ |
140 |
register char *cp; |
141 |
|
142 |
cp = iskip(s); |
143 |
return(cp != NULL && *cp == '\0'); |
144 |
} |
145 |
|
146 |
|
147 |
int |
148 |
isintd(s, ds) /* check integer format with delimiter set */ |
149 |
char *s, *ds; |
150 |
{ |
151 |
register char *cp; |
152 |
|
153 |
cp = iskip(s); |
154 |
return(cp != NULL && strchr(ds, *cp) != NULL); |
155 |
} |
156 |
|
157 |
|
158 |
int |
159 |
isflt(s) /* check float format */ |
160 |
char *s; |
161 |
{ |
162 |
register char *cp; |
163 |
|
164 |
cp = fskip(s); |
165 |
return(cp != NULL && *cp == '\0'); |
166 |
} |
167 |
|
168 |
|
169 |
int |
170 |
isfltd(s, ds) /* check integer format with delimiter set */ |
171 |
char *s, *ds; |
172 |
{ |
173 |
register char *cp; |
174 |
|
175 |
cp = fskip(s); |
176 |
return(cp != NULL && strchr(ds, *cp) != NULL); |
177 |
} |