Back to index

radiance  4R0+20100331
duphead.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: duphead.c,v 2.7 2003/10/22 02:06:35 greg Exp $";
00003 #endif
00004 /*
00005  * Duplicate header on stdout.
00006  *
00007  * Externals declared in ray.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include  "platform.h"
00013 #include  "standard.h"
00014 #include  "paths.h"
00015 
00016 
00017 int  headismine = 1;        /* true if header file belongs to me */
00018 
00019 static char  *headfname = NULL;    /* temp file name */
00020 static FILE  *headfp = NULL;       /* temp file pointer */
00021 
00022 
00023 void
00024 headclean()                 /* remove header temp file (if one) */
00025 {
00026        if (headfname == NULL)
00027               return;
00028        if (headfp != NULL)
00029               fclose(headfp);
00030        if (headismine)
00031               unlink(headfname);
00032 }
00033 
00034 
00035 void
00036 openheader()                /* save standard output to header file */
00037 {
00038        static char  template[] = TEMPLATE;
00039 
00040        headfname = mktemp(template);
00041        if (freopen(headfname, "w", stdout) == NULL) {
00042               sprintf(errmsg, "cannot open header file \"%s\"", headfname);
00043               error(SYSTEM, errmsg);
00044        }
00045 }
00046 
00047 
00048 void
00049 dupheader()                 /* repeat header on standard output */
00050 {
00051        register int  c;
00052 
00053        if (headfp == NULL) {
00054               if ((headfp = fopen(headfname, "r")) == NULL)
00055                      error(SYSTEM, "error reopening header file");
00056               SET_FILE_BINARY(headfp);
00057        } else if (fseek(headfp, 0L, 0) < 0)
00058               error(SYSTEM, "seek error on header file");
00059        while ((c = getc(headfp)) != EOF)
00060               putchar(c);
00061 }