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) |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
– |
/* |
180 |
– |
* Copymatch(pat,str) checks pat for wildcards, and |
181 |
– |
* copies str into pat if there is a match (returning true). |
182 |
– |
*/ |
183 |
– |
|
179 |
|
int |
180 |
< |
copymatch(pat, str) |
180 |
> |
globmatch(pat, str) /* check for glob match of str against pat */ |
181 |
|
char *pat, *str; |
182 |
|
{ |
188 |
– |
int docopy = 0; |
183 |
|
register char *p = pat, *s = str; |
184 |
|
|
185 |
|
do { |
187 |
|
case '?': /* match any character */ |
188 |
|
if (!*s++) |
189 |
|
return(0); |
196 |
– |
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) ) { |
203 |
< |
strcpy(pat, str); |
194 |
> |
if ( (p[1]=='?' || p[1]==*s) && |
195 |
> |
globmatch(p+1,s) ) |
196 |
|
return(1); |
205 |
– |
} |
197 |
|
while (*s++); |
198 |
|
return(0); |
199 |
|
case '\\': /* literal next */ |
206 |
|
break; |
207 |
|
} |
208 |
|
} while (*p++); |
218 |
– |
if (docopy) |
219 |
– |
strcpy(pat, str); |
209 |
|
return(1); |
210 |
|
} |
211 |
|
|
235 |
|
cdat.fs[0] = '\0'; |
236 |
|
if (getheader(fin, mycheck, &cdat) < 0) |
237 |
|
return(-1); |
238 |
< |
if (cdat.fs[0] != '\0') |
239 |
< |
return(copymatch(fmt, cdat.fs) ? 1 : -1); |
240 |
< |
return(0); |
238 |
> |
if (!cdat.fs[0]) |
239 |
> |
return(0); |
240 |
> |
if (globmatch(fmt, cdat.fs)) { |
241 |
> |
strcpy(fmt, cdat.fs); |
242 |
> |
return(1); |
243 |
> |
} |
244 |
> |
return(-1); |
245 |
|
} |