12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
|
15 |
+ |
#define MAXLINE 512 |
16 |
|
|
17 |
+ |
char FMTSTR[] = "FORMAT="; |
18 |
+ |
int FMTSTRL = 7; |
19 |
+ |
|
20 |
+ |
|
21 |
|
printargs(ac, av, fp) /* print arguments to a file */ |
22 |
|
int ac; |
23 |
|
char **av; |
31 |
|
} |
32 |
|
|
33 |
|
|
34 |
< |
#define MAXLINE 512 |
34 |
> |
isformat(s) /* is line a format line? */ |
35 |
> |
char *s; |
36 |
> |
{ |
37 |
> |
return(!strncmp(s,FMTSTR,FMTSTRL)); |
38 |
> |
} |
39 |
|
|
40 |
< |
getheader(fp, f) /* get header from file */ |
40 |
> |
|
41 |
> |
formatval(r, s) /* return format value */ |
42 |
> |
register char *r; |
43 |
> |
register char *s; |
44 |
> |
{ |
45 |
> |
s += FMTSTRL; |
46 |
> |
while (*s && *s != '\n') |
47 |
> |
*r++ = *s++; |
48 |
> |
*r = '\0'; |
49 |
> |
} |
50 |
> |
|
51 |
> |
|
52 |
> |
fputformat(s, fp) /* put out a format value */ |
53 |
> |
char *s; |
54 |
|
FILE *fp; |
55 |
+ |
{ |
56 |
+ |
fputs(FMTSTR, fp); |
57 |
+ |
fputs(s, fp); |
58 |
+ |
putc('\n', fp); |
59 |
+ |
} |
60 |
+ |
|
61 |
+ |
|
62 |
+ |
getheader(fp, f, p) /* get header from file */ |
63 |
+ |
FILE *fp; |
64 |
|
int (*f)(); |
65 |
+ |
char *p; |
66 |
|
{ |
67 |
|
char buf[MAXLINE]; |
68 |
|
|
77 |
|
buf[MAXLINE-2] = '\0'; |
78 |
|
} |
79 |
|
if (f != NULL) |
80 |
< |
(*f)(buf); |
80 |
> |
(*f)(buf, p); |
81 |
|
} |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
< |
static FILE *outfp; |
85 |
> |
struct check { |
86 |
> |
FILE *fp; |
87 |
> |
char fs[32]; |
88 |
> |
}; |
89 |
|
|
90 |
+ |
|
91 |
|
static |
92 |
< |
myputs(s) |
92 |
> |
mycheck(s, cp) /* check a header line for format info. */ |
93 |
|
char *s; |
94 |
+ |
register struct check *cp; |
95 |
|
{ |
96 |
< |
fputs(s, outfp); |
96 |
> |
if (!strncmp(s,FMTSTR,FMTSTRL)) |
97 |
> |
formatval(cp->fs, s); |
98 |
> |
else if (cp->fp != NULL) /* don't copy format info. */ |
99 |
> |
fputs(s, cp->fp); |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
< |
copyheader(fin, fout) /* copy file header */ |
104 |
< |
FILE *fin, *fout; |
103 |
> |
checkheader(fin, fmt, fout) /* check data format in header */ |
104 |
> |
FILE *fin; |
105 |
> |
char *fmt; |
106 |
> |
FILE *fout; |
107 |
|
{ |
108 |
< |
outfp = fout; |
109 |
< |
return(getheader(fin, myputs)); |
108 |
> |
struct check cdat; |
109 |
> |
|
110 |
> |
cdat.fp = fout; |
111 |
> |
cdat.fs[0] = '\0'; |
112 |
> |
if (getheader(fin, mycheck, &cdat) < 0) |
113 |
> |
return(-1); |
114 |
> |
if (fmt != NULL && cdat.fs[0] != '\0') |
115 |
> |
return(strcmp(fmt, cdat.fs) ? -1 : 1); |
116 |
> |
return(0); |
117 |
|
} |