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