1 |
greg |
2.2 |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
greg |
1.1 |
|
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 |
greg |
1.2 |
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 |
greg |
2.3 |
sskip(s) /* skip word in string, leaving on space */ |
41 |
greg |
1.1 |
register char *s; |
42 |
|
|
{ |
43 |
|
|
while (isspace(*s)) |
44 |
|
|
s++; |
45 |
|
|
while (*s && !isspace(*s)) |
46 |
greg |
2.2 |
s++; |
47 |
greg |
2.3 |
return(s); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
|
51 |
|
|
char * |
52 |
|
|
sskip2(s, n) /* skip word(s) in string, leaving on word */ |
53 |
|
|
register char *s; |
54 |
|
|
register int n; |
55 |
|
|
{ |
56 |
greg |
2.2 |
while (isspace(*s)) |
57 |
greg |
1.1 |
s++; |
58 |
greg |
2.3 |
while (n-- > 0) { |
59 |
|
|
while (*s && !isspace(*s)) |
60 |
|
|
s++; |
61 |
|
|
while (isspace(*s)) |
62 |
|
|
s++; |
63 |
|
|
} |
64 |
greg |
1.1 |
return(s); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
|
68 |
|
|
char * |
69 |
|
|
iskip(s) /* skip integer in string */ |
70 |
greg |
1.2 |
register char *s; |
71 |
greg |
1.1 |
{ |
72 |
greg |
1.2 |
while (isspace(*s)) |
73 |
|
|
s++; |
74 |
|
|
if (*s == '-' || *s == '+') |
75 |
|
|
s++; |
76 |
|
|
if (!isdigit(*s)) |
77 |
|
|
return(NULL); |
78 |
|
|
do |
79 |
|
|
s++; |
80 |
|
|
while (isdigit(*s)); |
81 |
|
|
return(s); |
82 |
greg |
1.1 |
} |
83 |
|
|
|
84 |
|
|
|
85 |
|
|
char * |
86 |
|
|
fskip(s) /* skip float in string */ |
87 |
greg |
1.2 |
register char *s; |
88 |
greg |
1.1 |
{ |
89 |
greg |
1.4 |
register char *cp; |
90 |
greg |
1.1 |
|
91 |
greg |
1.4 |
while (isspace(*s)) |
92 |
|
|
s++; |
93 |
|
|
if (*s == '-' || *s == '+') |
94 |
|
|
s++; |
95 |
|
|
cp = s; |
96 |
greg |
1.1 |
while (isdigit(*cp)) |
97 |
|
|
cp++; |
98 |
|
|
if (*cp == '.') { |
99 |
greg |
1.2 |
cp++; s++; |
100 |
greg |
1.1 |
while (isdigit(*cp)) |
101 |
|
|
cp++; |
102 |
|
|
} |
103 |
greg |
1.2 |
if (cp == s) |
104 |
|
|
return(NULL); |
105 |
greg |
1.1 |
if (*cp == 'e' || *cp == 'E') |
106 |
|
|
return(iskip(cp+1)); |
107 |
|
|
return(cp); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
|
111 |
|
|
isint(s) /* check integer format */ |
112 |
|
|
char *s; |
113 |
|
|
{ |
114 |
|
|
register char *cp; |
115 |
|
|
|
116 |
|
|
cp = iskip(s); |
117 |
greg |
1.2 |
return(cp != NULL && *cp == '\0'); |
118 |
greg |
1.1 |
} |
119 |
|
|
|
120 |
|
|
|
121 |
|
|
isintd(s, ds) /* check integer format with delimiter set */ |
122 |
|
|
char *s, *ds; |
123 |
|
|
{ |
124 |
|
|
register char *cp; |
125 |
|
|
|
126 |
|
|
cp = iskip(s); |
127 |
greg |
1.3 |
return(cp != NULL && strchr(ds, *cp) != NULL); |
128 |
greg |
1.1 |
} |
129 |
|
|
|
130 |
|
|
|
131 |
|
|
isflt(s) /* check float format */ |
132 |
|
|
char *s; |
133 |
|
|
{ |
134 |
|
|
register char *cp; |
135 |
|
|
|
136 |
|
|
cp = fskip(s); |
137 |
greg |
1.2 |
return(cp != NULL && *cp == '\0'); |
138 |
greg |
1.1 |
} |
139 |
|
|
|
140 |
|
|
|
141 |
|
|
isfltd(s, ds) /* check integer format with delimiter set */ |
142 |
|
|
char *s, *ds; |
143 |
|
|
{ |
144 |
|
|
register char *cp; |
145 |
|
|
|
146 |
|
|
cp = fskip(s); |
147 |
greg |
1.3 |
return(cp != NULL && strchr(ds, *cp) != NULL); |
148 |
greg |
1.1 |
} |