--- ray/src/cv/ies2rad.c 1995/04/25 21:37:14 2.12 +++ ray/src/cv/ies2rad.c 1996/06/18 21:28:52 2.14 @@ -1,4 +1,4 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1996 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -12,6 +12,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include +#include #include #include "color.h" #include "paths.h" @@ -108,6 +109,7 @@ float defcolor[3] = {1.,1.,1.}; /* default lamp color float *lampcolor = defcolor; /* pointer to current lamp color */ double multiplier = 1.0; /* multiplier for all light sources */ char units[64] = "meters"; /* output units */ +int out2stdout = 0; /* put out to stdout r.t. file */ int instantiate = 0; /* instantiate geometry */ double illumrad = 0.0; /* radius for illum sphere */ @@ -126,6 +128,7 @@ extern char *strcpy(), *strcat(), *stradd(), *tailtrun *filename(), *libname(), *fullname(), *malloc(), *getword(), *atos(); extern float *matchlamp(); +extern time_t fdate(); #define scnint(fp,ip) cvtint(ip,getword(fp)) #define scnflt(fp,rp) cvtflt(rp,getword(fp)) @@ -203,9 +206,12 @@ char *argv[]; case 'f': /* lamp data file */ lampdat = argv[++i]; break; - case 'o': /* output file name */ + case 'o': /* output file root name */ outfile = argv[++i]; break; + case 's': /* output to stdout */ + out2stdout = !out2stdout; + break; case 'i': /* illum */ illumrad = atof(argv[++i]); break; @@ -241,16 +247,15 @@ char *argv[]; exit(ies2rad(NULL, outfile) == 0 ? 0 : 1); else if (i == argc-1) exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1); - else { - fprintf(stderr, "%s: single input file required\n", - argv[0]); - exit(1); - } + else + goto needsingle; } else if (i >= argc) { fprintf(stderr, "%s: missing output file specification\n", argv[0]); exit(1); } + if (out2stdout && i != argc-1) + goto needsingle; status = 0; for ( ; i < argc; i++) { tailtrunc(strcpy(outname,filename(argv[i]))); @@ -258,6 +263,9 @@ char *argv[]; status = 1; } exit(status); +needsingle: + fprintf(stderr, "%s: single input file required\n", argv[0]); + exit(1); } @@ -464,7 +472,9 @@ char *inpname, *outname; perror(inpname); return(-1); } - if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { + if (out2stdout) + outfp = stdout; + else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { perror(buf); fclose(inpfp); return(-1); @@ -1040,7 +1050,8 @@ FILE *outfp; /* close output file upon return */ strcpy(cp, "| oconv - > "); cp += 12; fullname(cp,outname,T_OCT); - if (system(buf)) { /* create octree */ + if (fdate(inpname) > fdate(outname) && + system(buf)) { /* create octree */ fclose(outfp); return(-1); } @@ -1054,14 +1065,16 @@ FILE *outfp; /* close output file upon return */ fprintf(outfp, "0\n0\n"); fclose(outfp); } else { /* else append to luminaire file */ - fclose(outfp); if (!FEQ(meters2out, 1.0)) { /* apply scalefactor */ sprintf(cp, "| xform -s %f ", meters2out); cp += strlen(cp); } - strcpy(cp, ">> "); /* append works for DOS? */ - cp += 3; - fullname(cp,outname,T_RAD); + if (!out2stdout) { + fclose(outfp); + strcpy(cp, ">> "); /* append works for DOS? */ + cp += 3; + fullname(cp,outname,T_RAD); + } if (system(buf)) return(-1); }