| 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 |
|
/* |
| 223 |
|
* if fout is not NULL. |
| 224 |
|
*/ |
| 225 |
|
|
| 226 |
+ |
int |
| 227 |
|
checkheader(fin, fmt, fout) |
| 228 |
|
FILE *fin; |
| 229 |
|
char *fmt; |
| 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 |
|
} |