1 |
/* Copyright (c) 1993 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* Duplicate header on stdout. |
9 |
*/ |
10 |
|
11 |
#include "standard.h" |
12 |
#include "paths.h" |
13 |
|
14 |
|
15 |
int headismine = 1; /* true if header file belongs to me */ |
16 |
|
17 |
static char *headfname = NULL; /* temp file name */ |
18 |
static FILE *headfp = NULL; /* temp file pointer */ |
19 |
|
20 |
|
21 |
headclean() /* remove header temp file (if one) */ |
22 |
{ |
23 |
if (headfname != NULL) { |
24 |
if (headfp != NULL) |
25 |
fclose(headfp); |
26 |
if (headismine) |
27 |
unlink(headfname); |
28 |
} |
29 |
} |
30 |
|
31 |
|
32 |
openheader() /* save standard output to header file */ |
33 |
{ |
34 |
headfname = mktemp(TEMPLATE); |
35 |
if (freopen(headfname, "w", stdout) == NULL) { |
36 |
sprintf(errmsg, "cannot open header file \"%s\"", headfname); |
37 |
error(SYSTEM, errmsg); |
38 |
} |
39 |
} |
40 |
|
41 |
|
42 |
dupheader() /* repeat header on standard output */ |
43 |
{ |
44 |
register int c; |
45 |
|
46 |
if (headfp == NULL) { |
47 |
if ((headfp = fopen(headfname, "r")) == NULL) |
48 |
error(SYSTEM, "error reopening header file"); |
49 |
#ifdef MSDOS |
50 |
setmode(fileno(headfp), O_BINARY); |
51 |
#endif |
52 |
} else if (fseek(headfp, 0L, 0) < 0) |
53 |
error(SYSTEM, "seek error on header file"); |
54 |
while ((c = getc(headfp)) != EOF) |
55 |
putchar(c); |
56 |
} |