1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
#include <math.h> |
15 |
+ |
#include <sys/types.h> |
16 |
|
#include <ctype.h> |
17 |
|
#include "color.h" |
18 |
|
#include "paths.h" |
109 |
|
float *lampcolor = defcolor; /* pointer to current lamp color */ |
110 |
|
double multiplier = 1.0; /* multiplier for all light sources */ |
111 |
|
char units[64] = "meters"; /* output units */ |
112 |
+ |
int out2stdout = 0; /* put out to stdout r.t. file */ |
113 |
|
int instantiate = 0; /* instantiate geometry */ |
114 |
|
double illumrad = 0.0; /* radius for illum sphere */ |
115 |
|
|
128 |
|
*filename(), *libname(), *fullname(), *malloc(), |
129 |
|
*getword(), *atos(); |
130 |
|
extern float *matchlamp(); |
131 |
+ |
extern time_t fdate(); |
132 |
|
|
133 |
|
#define scnint(fp,ip) cvtint(ip,getword(fp)) |
134 |
|
#define scnflt(fp,rp) cvtflt(rp,getword(fp)) |
206 |
|
case 'f': /* lamp data file */ |
207 |
|
lampdat = argv[++i]; |
208 |
|
break; |
209 |
< |
case 'o': /* output file name */ |
209 |
> |
case 'o': /* output file root name */ |
210 |
|
outfile = argv[++i]; |
211 |
|
break; |
212 |
+ |
case 's': /* output to stdout */ |
213 |
+ |
out2stdout = !out2stdout; |
214 |
+ |
break; |
215 |
|
case 'i': /* illum */ |
216 |
|
illumrad = atof(argv[++i]); |
217 |
|
break; |
247 |
|
exit(ies2rad(NULL, outfile) == 0 ? 0 : 1); |
248 |
|
else if (i == argc-1) |
249 |
|
exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1); |
250 |
< |
else { |
251 |
< |
fprintf(stderr, "%s: single input file required\n", |
246 |
< |
argv[0]); |
247 |
< |
exit(1); |
248 |
< |
} |
250 |
> |
else |
251 |
> |
goto needsingle; |
252 |
|
} else if (i >= argc) { |
253 |
|
fprintf(stderr, "%s: missing output file specification\n", |
254 |
|
argv[0]); |
255 |
|
exit(1); |
256 |
|
} |
257 |
+ |
if (out2stdout && i != argc-1) |
258 |
+ |
goto needsingle; |
259 |
|
status = 0; |
260 |
|
for ( ; i < argc; i++) { |
261 |
|
tailtrunc(strcpy(outname,filename(argv[i]))); |
263 |
|
status = 1; |
264 |
|
} |
265 |
|
exit(status); |
266 |
+ |
needsingle: |
267 |
+ |
fprintf(stderr, "%s: single input file required\n", argv[0]); |
268 |
+ |
exit(1); |
269 |
|
} |
270 |
|
|
271 |
|
|
472 |
|
perror(inpname); |
473 |
|
return(-1); |
474 |
|
} |
475 |
< |
if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { |
475 |
> |
if (out2stdout) |
476 |
> |
outfp = stdout; |
477 |
> |
else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { |
478 |
|
perror(buf); |
479 |
|
fclose(inpfp); |
480 |
|
return(-1); |
1050 |
|
strcpy(cp, "| oconv - > "); |
1051 |
|
cp += 12; |
1052 |
|
fullname(cp,outname,T_OCT); |
1053 |
< |
if (system(buf)) { /* create octree */ |
1053 |
> |
if (fdate(inpname) > fdate(outname) && |
1054 |
> |
system(buf)) { /* create octree */ |
1055 |
|
fclose(outfp); |
1056 |
|
return(-1); |
1057 |
|
} |
1065 |
|
fprintf(outfp, "0\n0\n"); |
1066 |
|
fclose(outfp); |
1067 |
|
} else { /* else append to luminaire file */ |
1057 |
– |
fclose(outfp); |
1068 |
|
if (!FEQ(meters2out, 1.0)) { /* apply scalefactor */ |
1069 |
|
sprintf(cp, "| xform -s %f ", meters2out); |
1070 |
|
cp += strlen(cp); |
1071 |
|
} |
1072 |
< |
strcpy(cp, ">> "); /* append works for DOS? */ |
1073 |
< |
cp += 3; |
1074 |
< |
fullname(cp,outname,T_RAD); |
1072 |
> |
if (!out2stdout) { |
1073 |
> |
fclose(outfp); |
1074 |
> |
strcpy(cp, ">> "); /* append works for DOS? */ |
1075 |
> |
cp += 3; |
1076 |
> |
fullname(cp,outname,T_RAD); |
1077 |
> |
} |
1078 |
|
if (system(buf)) |
1079 |
|
return(-1); |
1080 |
|
} |