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 |
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 |
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 |
register char *s; |
54 |
{ |
55 |
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 |
} |
66 |
|
67 |
|
68 |
char * |
69 |
fskip(s) /* skip float in string */ |
70 |
register char *s; |
71 |
{ |
72 |
register char *cp = s; |
73 |
|
74 |
while (isspace(*cp)) |
75 |
cp++; |
76 |
if (*cp == '-' || *cp == '+') |
77 |
cp++; |
78 |
s = cp; |
79 |
while (isdigit(*cp)) |
80 |
cp++; |
81 |
if (*cp == '.') { |
82 |
cp++; s++; |
83 |
while (isdigit(*cp)) |
84 |
cp++; |
85 |
} |
86 |
if (cp == s) |
87 |
return(NULL); |
88 |
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 |
return(cp != NULL && *cp == '\0'); |
101 |
} |
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 |
return(cp != NULL && strchr(ds, *cp) != NULL); |
111 |
} |
112 |
|
113 |
|
114 |
isflt(s) /* check float format */ |
115 |
char *s; |
116 |
{ |
117 |
register char *cp; |
118 |
|
119 |
cp = fskip(s); |
120 |
return(cp != NULL && *cp == '\0'); |
121 |
} |
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 |
return(cp != NULL && strchr(ds, *cp) != NULL); |
131 |
} |