1 |
greg |
2.1 |
#ifndef lint |
2 |
schorsch |
2.6 |
static const char RCSid[] = "$Id: duphead.c,v 2.5 2003/06/05 19:29:34 schorsch Exp $"; |
3 |
greg |
2.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Duplicate header on stdout. |
6 |
greg |
2.3 |
* |
7 |
|
|
* Externals declared in ray.h |
8 |
|
|
*/ |
9 |
|
|
|
10 |
greg |
2.4 |
#include "copyright.h" |
11 |
greg |
2.1 |
|
12 |
|
|
#include "standard.h" |
13 |
schorsch |
2.6 |
#include "platform.h" |
14 |
greg |
2.1 |
#include "paths.h" |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
int headismine = 1; /* true if header file belongs to me */ |
18 |
|
|
|
19 |
|
|
static char *headfname = NULL; /* temp file name */ |
20 |
|
|
static FILE *headfp = NULL; /* temp file pointer */ |
21 |
|
|
|
22 |
|
|
|
23 |
greg |
2.3 |
void |
24 |
greg |
2.1 |
headclean() /* remove header temp file (if one) */ |
25 |
|
|
{ |
26 |
greg |
2.3 |
if (headfname == NULL) |
27 |
|
|
return; |
28 |
|
|
if (headfp != NULL) |
29 |
|
|
fclose(headfp); |
30 |
|
|
if (headismine) |
31 |
|
|
unlink(headfname); |
32 |
greg |
2.1 |
} |
33 |
|
|
|
34 |
|
|
|
35 |
greg |
2.3 |
void |
36 |
greg |
2.1 |
openheader() /* save standard output to header file */ |
37 |
|
|
{ |
38 |
greg |
2.2 |
static char template[] = TEMPLATE; |
39 |
|
|
|
40 |
|
|
headfname = mktemp(template); |
41 |
greg |
2.1 |
if (freopen(headfname, "w", stdout) == NULL) { |
42 |
|
|
sprintf(errmsg, "cannot open header file \"%s\"", headfname); |
43 |
|
|
error(SYSTEM, errmsg); |
44 |
|
|
} |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
|
48 |
greg |
2.3 |
void |
49 |
greg |
2.1 |
dupheader() /* repeat header on standard output */ |
50 |
|
|
{ |
51 |
|
|
register int c; |
52 |
|
|
|
53 |
|
|
if (headfp == NULL) { |
54 |
|
|
if ((headfp = fopen(headfname, "r")) == NULL) |
55 |
|
|
error(SYSTEM, "error reopening header file"); |
56 |
schorsch |
2.5 |
SET_FILE_BINARY(headfp); |
57 |
greg |
2.1 |
} else if (fseek(headfp, 0L, 0) < 0) |
58 |
|
|
error(SYSTEM, "seek error on header file"); |
59 |
|
|
while ((c = getc(headfp)) != EOF) |
60 |
|
|
putchar(c); |
61 |
|
|
} |