1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
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 |
< |
* copymatch(pat, str) copy str into pat if glob match |
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) |
57 |
|
|
58 |
|
while (*cp) if (*cp++ != *s++) return(0); |
59 |
|
if (r == NULL) return(1); |
60 |
< |
while (*s) *r++ = *s++; |
60 |
> |
while (*s && !isspace(*s)) *r++ = *s++; |
61 |
|
*r = '\0'; |
62 |
|
return(1); |
63 |
|
} |
89 |
|
putc(quote, fp); |
90 |
|
} else |
91 |
|
fputs(*av++, fp); |
92 |
< |
putc(' ', fp); |
92 |
> |
putc(ac ? ' ' : '\n', fp); |
93 |
|
} |
94 |
– |
putc('\n', fp); |
94 |
|
} |
95 |
|
|
96 |
|
|
153 |
|
ungetc(buf[MAXLINE-2], fp); /* prevent false end */ |
154 |
|
buf[MAXLINE-2] = '\0'; |
155 |
|
} |
156 |
< |
if (f != NULL) |
157 |
< |
(*f)(buf, p); |
156 |
> |
if (f != NULL && (*f)(buf, p) < 0) |
157 |
> |
return(-1); |
158 |
|
} |
159 |
|
} |
160 |
|
|
175 |
|
} |
176 |
|
|
177 |
|
|
179 |
– |
/* |
180 |
– |
* Copymatch(pat,str) checks pat for wildcards, and |
181 |
– |
* copies str into pat if there is a match (returning true). |
182 |
– |
*/ |
183 |
– |
|
178 |
|
int |
179 |
< |
copymatch(pat, str) |
179 |
> |
globmatch(pat, str) /* check for glob match of str against pat */ |
180 |
|
char *pat, *str; |
181 |
|
{ |
188 |
– |
int docopy = 0; |
182 |
|
register char *p = pat, *s = str; |
183 |
|
|
184 |
|
do { |
186 |
|
case '?': /* match any character */ |
187 |
|
if (!*s++) |
188 |
|
return(0); |
196 |
– |
docopy++; |
189 |
|
break; |
190 |
|
case '*': /* match any string */ |
191 |
|
while (p[1] == '*') p++; |
192 |
|
do |
193 |
< |
if ( (p[1]=='?' || p[1]==*s) |
194 |
< |
&& copymatch(p+1,s) ) { |
203 |
< |
strcpy(pat, str); |
193 |
> |
if ( (p[1]=='?' || p[1]==*s) && |
194 |
> |
globmatch(p+1,s) ) |
195 |
|
return(1); |
205 |
– |
} |
196 |
|
while (*s++); |
197 |
|
return(0); |
198 |
|
case '\\': /* literal next */ |
205 |
|
break; |
206 |
|
} |
207 |
|
} while (*p++); |
218 |
– |
if (docopy) |
219 |
– |
strcpy(pat, str); |
208 |
|
return(1); |
209 |
|
} |
210 |
|
|
217 |
|
* if any input format is found (or there is an error), and 0 otherwise. |
218 |
|
* If fmt contains any '*' or '?' characters, then checkheader |
219 |
|
* does wildcard expansion and copies a matching result into fmt. |
220 |
< |
* Be sure that fmt is big enough to hold the match in such cases! |
220 |
> |
* Be sure that fmt is big enough to hold the match in such cases, |
221 |
> |
* and that it is not a static, read-only string! |
222 |
|
* The input header (minus any format lines) is copied to fout |
223 |
|
* if fout is not NULL. |
224 |
|
*/ |
230 |
|
FILE *fout; |
231 |
|
{ |
232 |
|
struct check cdat; |
233 |
+ |
register char *cp; |
234 |
|
|
235 |
|
cdat.fp = fout; |
236 |
|
cdat.fs[0] = '\0'; |
237 |
|
if (getheader(fin, mycheck, &cdat) < 0) |
238 |
|
return(-1); |
239 |
< |
if (cdat.fs[0] != '\0') |
240 |
< |
return(copymatch(fmt, cdat.fs) ? 1 : -1); |
241 |
< |
return(0); |
239 |
> |
if (!cdat.fs[0]) |
240 |
> |
return(0); |
241 |
> |
for (cp = fmt; *cp; cp++) /* check for globbing */ |
242 |
> |
if (*cp == '?' | *cp == '*') |
243 |
> |
if (globmatch(fmt, cdat.fs)) { |
244 |
> |
strcpy(fmt, cdat.fs); |
245 |
> |
return(1); |
246 |
> |
} else |
247 |
> |
return(-1); |
248 |
> |
return(strcmp(fmt, cdat.fs) ? -1 : 1); /* literal match */ |
249 |
|
} |