| 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 |
|
|
| 53 |
|
char command[SDnameLn+64]; |
| 54 |
|
int fd; |
| 55 |
|
/* write MGF to temp file */ |
| 56 |
< |
fd = open(mktemp(strcpy(tmpfile,TEMPLATE)), O_WRONLY|O_CREAT|O_EXCL); |
| 56 |
> |
fd = open(mktemp(strcpy(tmpfile,TEMPLATE)), O_WRONLY|O_CREAT|O_EXCL, 0600); |
| 57 |
|
if (fd < 0) { |
| 58 |
|
fprintf(stderr, "Cannot open temp file '%s'\n", tmpfile); |
| 59 |
|
return(0); |
| 60 |
|
} |
| 61 |
< |
write(fd, bsp->mgf, strlen(bsp->mgf)); |
| 61 |
> |
(void)write(fd, bsp->mgf, strlen(bsp->mgf)); |
| 62 |
|
close(fd); |
| 63 |
|
/* set up command */ |
| 64 |
|
if (do_instance) { |
| 83 |
|
|
| 84 |
|
/* Load a BSDF XML file and produce a corresponding Radiance object */ |
| 85 |
|
static int |
| 86 |
< |
cvtBSDF(const char *fname) |
| 86 |
> |
cvtBSDF(char *fname) |
| 87 |
|
{ |
| 88 |
|
int retOK; |
| 89 |
|
SDData myBSDF; |
| 90 |
< |
/* load the XML file */ |
| 90 |
> |
char *pname, *fnbeg; |
| 91 |
> |
/* find and load the XML file */ |
| 92 |
|
retOK = strlen(fname); |
| 93 |
< |
if (retOK < 5 || strcmp(fname+retOK-4, ".xml")) { |
| 93 |
> |
if (retOK < 5 || strcasecmp(fname+retOK-4, ".xml")) { |
| 94 |
|
fprintf(stderr, "%s: input does not end in '.xml'\n", fname); |
| 95 |
|
return(0); |
| 96 |
|
} |
| 97 |
+ |
pname = getpath(fname, getrlibpath(), R_OK); |
| 98 |
+ |
if (pname == NULL) { |
| 99 |
+ |
fprintf(stderr, "%s: cannot find BSDF file\n", fname); |
| 100 |
+ |
return(0); |
| 101 |
+ |
} |
| 102 |
+ |
fnbeg = strrchr(fname, DIRSEP); |
| 103 |
+ |
if (fnbeg != NULL) /* eliminate directory */ |
| 104 |
+ |
fname = fnbeg+1; |
| 105 |
|
SDclearBSDF(&myBSDF, fname); |
| 106 |
< |
if (SDreportEnglish(SDloadFile(&myBSDF, fname), stderr)) |
| 106 |
> |
if (SDreportError(SDloadFile(&myBSDF, pname), stderr)) |
| 107 |
|
return(0); |
| 108 |
|
retOK = (myBSDF.dim[0] > FTINY) & (myBSDF.dim[1] > FTINY); |
| 109 |
|
if (!retOK) { |
| 116 |
|
retOK = (freopen(rname, "w", stdout) != NULL); |
| 117 |
|
} |
| 118 |
|
if (retOK) { |
| 119 |
+ |
if (myBSDF.matn[0] && myBSDF.makr[0]) |
| 120 |
+ |
printf("# Material '%s' by '%s'\n\n", |
| 121 |
+ |
myBSDF.matn, myBSDF.makr); |
| 122 |
|
if (myBSDF.mgf == NULL) { |
| 123 |
|
faceBSDF(&myBSDF, .0); |
| 124 |
|
} else { |