5 |
|
* Take BSDF XML file and generate a referencing Radiance object |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "rtio.h" |
9 |
|
#include "paths.h" |
10 |
|
#include "bsdf.h" |
11 |
|
|
12 |
|
int do_stdout = 0; /* send Radiance object to stdout? */ |
13 |
|
int do_instance = 0; /* produce instance/octree pairs? */ |
14 |
|
|
15 |
+ |
char *progname; /* global argv[0] */ |
16 |
|
|
17 |
|
/* Return appropriate suffix for Z offset */ |
18 |
|
static const char * |
54 |
|
char command[SDnameLn+64]; |
55 |
|
int fd; |
56 |
|
/* write MGF to temp file */ |
57 |
< |
fd = open(mktemp(strcpy(tmpfile,TEMPLATE)), O_WRONLY|O_CREAT|O_EXCL); |
57 |
> |
fd = open(mktemp(strcpy(tmpfile,TEMPLATE)), O_WRONLY|O_CREAT|O_EXCL, 0600); |
58 |
|
if (fd < 0) { |
59 |
|
fprintf(stderr, "Cannot open temp file '%s'\n", tmpfile); |
60 |
|
return(0); |
61 |
|
} |
62 |
< |
write(fd, bsp->mgf, strlen(bsp->mgf)); |
62 |
> |
(void)write(fd, bsp->mgf, strlen(bsp->mgf)); |
63 |
|
close(fd); |
64 |
|
/* set up command */ |
65 |
|
if (do_instance) { |
84 |
|
|
85 |
|
/* Load a BSDF XML file and produce a corresponding Radiance object */ |
86 |
|
static int |
87 |
< |
cvtBSDF(const char *fname) |
87 |
> |
cvtBSDF(char *fname) |
88 |
|
{ |
89 |
|
int retOK; |
90 |
|
SDData myBSDF; |
91 |
< |
/* load the XML file */ |
91 |
> |
char *pname, *fnbeg; |
92 |
> |
/* find and load the XML file */ |
93 |
|
retOK = strlen(fname); |
94 |
< |
if (retOK < 5 || strcmp(fname+retOK-4, ".xml")) { |
94 |
> |
if (retOK < 5 || strcasecmp(fname+retOK-4, ".xml")) { |
95 |
|
fprintf(stderr, "%s: input does not end in '.xml'\n", fname); |
96 |
|
return(0); |
97 |
|
} |
98 |
+ |
pname = getpath(fname, getrlibpath(), R_OK); |
99 |
+ |
if (pname == NULL) { |
100 |
+ |
fprintf(stderr, "%s: cannot find BSDF file\n", fname); |
101 |
+ |
return(0); |
102 |
+ |
} |
103 |
+ |
fnbeg = strrchr(fname, DIRSEP); |
104 |
+ |
if (fnbeg != NULL) /* eliminate directory */ |
105 |
+ |
fname = fnbeg+1; |
106 |
|
SDclearBSDF(&myBSDF, fname); |
107 |
< |
if (SDreportEnglish(SDloadFile(&myBSDF, fname), stderr)) |
107 |
> |
if (SDreportError(SDloadFile(&myBSDF, pname), stderr)) |
108 |
|
return(0); |
109 |
|
retOK = (myBSDF.dim[0] > FTINY) & (myBSDF.dim[1] > FTINY); |
110 |
|
if (!retOK) { |
117 |
|
retOK = (freopen(rname, "w", stdout) != NULL); |
118 |
|
} |
119 |
|
if (retOK) { |
120 |
+ |
printf("# Produced by: %s %s\n", progname, fname); |
121 |
+ |
if (myBSDF.matn[0] && myBSDF.makr[0]) |
122 |
+ |
printf("# Material '%s' by '%s'\n\n", |
123 |
+ |
myBSDF.matn, myBSDF.makr); |
124 |
|
if (myBSDF.mgf == NULL) { |
125 |
|
faceBSDF(&myBSDF, .0); |
126 |
|
} else { |
142 |
|
{ |
143 |
|
int status = 0; |
144 |
|
int i; |
145 |
+ |
|
146 |
+ |
progname = argv[0]; |
147 |
|
|
148 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
149 |
|
switch (argv[i][1]) { |