1 |
greg |
1.1 |
/* Copyright (c) 1988 Regents of the University of California */ |
2 |
|
|
|
3 |
|
|
#ifndef lint |
4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
|
#endif |
6 |
|
|
|
7 |
|
|
/* |
8 |
|
|
* header.c - routines for reading and writing information headers. |
9 |
|
|
* |
10 |
|
|
* 8/19/88 |
11 |
|
|
*/ |
12 |
|
|
|
13 |
|
|
#include <stdio.h> |
14 |
|
|
|
15 |
|
|
|
16 |
|
|
printargs(ac, av, fp) /* print arguments to a file */ |
17 |
|
|
int ac; |
18 |
|
|
char **av; |
19 |
|
|
FILE *fp; |
20 |
|
|
{ |
21 |
|
|
while (ac-- > 0) { |
22 |
|
|
fputs(*av++, fp); |
23 |
|
|
putc(' ', fp); |
24 |
|
|
} |
25 |
|
|
putc('\n', fp); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
|
29 |
|
|
#define MAXLINE 512 |
30 |
|
|
|
31 |
|
|
getheader(fp, f) /* get header from file */ |
32 |
|
|
FILE *fp; |
33 |
|
|
int (*f)(); |
34 |
|
|
{ |
35 |
|
|
char buf[MAXLINE]; |
36 |
|
|
|
37 |
|
|
for ( ; ; ) { |
38 |
|
|
buf[MAXLINE-2] = '\n'; |
39 |
|
|
if (fgets(buf, sizeof(buf), fp) == NULL) |
40 |
|
|
return(-1); |
41 |
|
|
if (buf[0] == '\n') |
42 |
|
|
return(0); |
43 |
|
|
if (buf[MAXLINE-2] != '\n') { |
44 |
|
|
ungetc(buf[MAXLINE-2], fp); /* prevent false end */ |
45 |
|
|
buf[MAXLINE-2] = '\0'; |
46 |
|
|
} |
47 |
|
|
if (f != NULL) |
48 |
|
|
(*f)(buf); |
49 |
|
|
} |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
static FILE *outfp; |
54 |
|
|
|
55 |
|
|
static |
56 |
|
|
myputs(s) |
57 |
|
|
char *s; |
58 |
|
|
{ |
59 |
|
|
fputs(s, outfp); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
copyheader(fin, fout) /* copy file header */ |
64 |
|
|
FILE *fin, *fout; |
65 |
|
|
{ |
66 |
|
|
outfp = fout; |
67 |
|
|
return(getheader(fin, myputs)); |
68 |
|
|
} |