17 |
|
* formatval(r,s) copy the format value in s to r |
18 |
|
* fputformat(s,fp) write "FORMAT=%s" to fp |
19 |
|
* getheader(fp,f,p) read header from fp, calling f(s,p) on each line |
20 |
+ |
* globmatch(pat, str) check for glob match of str against pat |
21 |
|
* checkheader(i,p,o) check header format from i against p and copy to o |
22 |
|
* |
23 |
|
* To copy header from input to output, use getheader(fin, fputs, fout) |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
+ |
int |
53 |
|
headidval(r,s) /* get header id (return true if is id) */ |
54 |
|
register char *r, *s; |
55 |
|
{ |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
+ |
int |
67 |
|
isheadid(s) /* check to see if line is header id */ |
68 |
|
char *s; |
69 |
|
{ |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
+ |
int |
99 |
|
formatval(r, s) /* get format value (return true if format) */ |
100 |
|
register char *r; |
101 |
|
register char *s; |
106 |
|
while (isspace(*s)) s++; |
107 |
|
if (!*s) return(0); |
108 |
|
if (r == NULL) return(1); |
109 |
< |
while(*s) *r++ = *s++; |
110 |
< |
while (isspace(r[-1])) r--; |
109 |
> |
do |
110 |
> |
*r++ = *s++; |
111 |
> |
while(*s && !isspace(*s)); |
112 |
|
*r = '\0'; |
113 |
|
return(1); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
+ |
int |
118 |
|
isformat(s) /* is line a format line? */ |
119 |
|
char *s; |
120 |
|
{ |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
+ |
int |
136 |
|
getheader(fp, f, p) /* get header from file */ |
137 |
|
FILE *fp; |
138 |
|
int (*f)(); |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
< |
/* |
180 |
< |
* Copymatch(pat,str) checks pat for wildcards, and |
174 |
< |
* copies str into pat if there is a match (returning true). |
175 |
< |
*/ |
176 |
< |
|
177 |
< |
#ifdef COPYMATCH |
178 |
< |
copymatch(pat, str) |
179 |
> |
int |
180 |
> |
globmatch(pat, str) /* check for glob match of str against pat */ |
181 |
|
char *pat, *str; |
182 |
|
{ |
181 |
– |
int docopy = 0; |
183 |
|
register char *p = pat, *s = str; |
184 |
|
|
185 |
|
do { |
187 |
|
case '?': /* match any character */ |
188 |
|
if (!*s++) |
189 |
|
return(0); |
189 |
– |
docopy++; |
190 |
|
break; |
191 |
|
case '*': /* match any string */ |
192 |
|
while (p[1] == '*') p++; |
193 |
|
do |
194 |
< |
if ( (p[1]=='?' || p[1]==*s) |
195 |
< |
&& copymatch(p+1,s) ) { |
196 |
< |
strcpy(pat, str); |
194 |
> |
if ( (p[1]=='?' || p[1]==*s) && |
195 |
> |
globmatch(p+1,s) ) |
196 |
|
return(1); |
198 |
– |
} |
197 |
|
while (*s++); |
198 |
|
return(0); |
199 |
|
case '\\': /* literal next */ |
206 |
|
break; |
207 |
|
} |
208 |
|
} while (*p++); |
211 |
– |
if (docopy) |
212 |
– |
strcpy(pat, str); |
209 |
|
return(1); |
210 |
|
} |
215 |
– |
#else |
216 |
– |
#define copymatch(pat, s) (!strcmp(pat, s)) |
217 |
– |
#endif |
211 |
|
|
212 |
|
|
213 |
|
/* |
218 |
|
* if any input format is found (or there is an error), and 0 otherwise. |
219 |
|
* If fmt contains any '*' or '?' characters, then checkheader |
220 |
|
* does wildcard expansion and copies a matching result into fmt. |
221 |
< |
* Be sure that fmt is big enough to hold the match in such cases! |
221 |
> |
* Be sure that fmt is big enough to hold the match in such cases, |
222 |
> |
* and that it is not a static, read-only string! |
223 |
|
* The input header (minus any format lines) is copied to fout |
224 |
|
* if fout is not NULL. |
225 |
|
*/ |
226 |
|
|
227 |
+ |
int |
228 |
|
checkheader(fin, fmt, fout) |
229 |
|
FILE *fin; |
230 |
|
char *fmt; |
231 |
|
FILE *fout; |
232 |
|
{ |
233 |
|
struct check cdat; |
234 |
+ |
register char *cp; |
235 |
|
|
236 |
|
cdat.fp = fout; |
237 |
|
cdat.fs[0] = '\0'; |
238 |
|
if (getheader(fin, mycheck, &cdat) < 0) |
239 |
|
return(-1); |
240 |
< |
if (cdat.fs[0] != '\0') |
241 |
< |
return(copymatch(fmt, cdat.fs) ? 1 : -1); |
242 |
< |
return(0); |
240 |
> |
if (!cdat.fs[0]) |
241 |
> |
return(0); |
242 |
> |
for (cp = fmt; *cp; cp++) /* check for globbing */ |
243 |
> |
if (*cp == '?' | *cp == '*') |
244 |
> |
if (globmatch(fmt, cdat.fs)) { |
245 |
> |
strcpy(fmt, cdat.fs); |
246 |
> |
return(1); |
247 |
> |
} else |
248 |
> |
return(-1); |
249 |
> |
return(strcmp(fmt, cdat.fs) ? -1 : 1); /* literal match */ |
250 |
|
} |