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