46 |
|
int |
47 |
|
rmx_newtype(int dtyp1, int dtyp2) |
48 |
|
{ |
49 |
< |
if ((dtyp1==DTxyze) | (dtyp1==DTrgbe) && dtyp1 != dtyp2) |
49 |
> |
if ((dtyp1==DTxyze) | (dtyp1==DTrgbe) | |
50 |
> |
(dtyp2==DTxyze) | (dtyp2==DTrgbe) |
51 |
> |
&& dtyp1 != dtyp2) |
52 |
|
return(0); |
53 |
|
if (dtyp1 < dtyp2) |
54 |
|
return(dtyp1); |
186 |
|
|
187 |
|
/* Load matrix from supported file type */ |
188 |
|
RMATRIX * |
189 |
< |
rmx_load(const char *fname) |
189 |
> |
rmx_load(const char *inspec) |
190 |
|
{ |
191 |
|
FILE *fp = stdin; |
192 |
|
RMATRIX dinfo; |
193 |
|
RMATRIX *dnew; |
194 |
|
|
195 |
< |
if (fname == NULL) { /* reading from stdin? */ |
196 |
< |
fname = "<stdin>"; |
195 |
> |
if (inspec == NULL) { /* reading from stdin? */ |
196 |
> |
inspec = "<stdin>"; |
197 |
|
#ifdef _WIN32 |
198 |
|
_setmode(fileno(stdin), _O_BINARY); |
199 |
|
#endif |
200 |
+ |
} else if (inspec[0] == '!') { |
201 |
+ |
if ((fp = popen(inspec+1, "r")) == NULL) |
202 |
+ |
return(NULL); |
203 |
+ |
#ifdef _WIN32 |
204 |
+ |
_setmode(fileno(fp), _O_BINARY); |
205 |
+ |
#endif |
206 |
|
} else { |
207 |
< |
const char *sp = fname; /* check suffix */ |
207 |
> |
const char *sp = inspec; /* check suffix */ |
208 |
|
while (*sp) |
209 |
|
++sp; |
210 |
< |
while (sp > fname && sp[-1] != '.') |
210 |
> |
while (sp > inspec && sp[-1] != '.') |
211 |
|
--sp; |
212 |
|
if (!strcasecmp(sp, "XML")) { /* assume it's a BSDF */ |
213 |
< |
CMATRIX *cm = cm_loadBTDF((char *)fname); |
213 |
> |
CMATRIX *cm = cm_loadBTDF((char *)inspec); |
214 |
|
if (cm == NULL) |
215 |
|
return(NULL); |
216 |
|
dnew = rmx_from_cmatrix(cm); |
218 |
|
return(dnew); |
219 |
|
} |
220 |
|
/* else open it ourselves */ |
221 |
< |
if ((fp = fopen(fname, "rb")) == NULL) |
221 |
> |
if ((fp = fopen(inspec, "rb")) == NULL) |
222 |
|
return(NULL); |
223 |
|
} |
224 |
|
#ifdef getc_unlocked |
275 |
|
default: |
276 |
|
goto loaderr; |
277 |
|
} |
278 |
< |
if (fp != stdin) |
279 |
< |
fclose(fp); |
278 |
> |
if (fp != stdin) { |
279 |
> |
if (inspec[0] == '!') |
280 |
> |
pclose(fp); |
281 |
> |
else |
282 |
> |
fclose(fp); |
283 |
> |
} |
284 |
> |
#ifdef getc_unlocked |
285 |
> |
else |
286 |
> |
funlockfile(fp); |
287 |
> |
#endif |
288 |
|
return(dnew); |
289 |
|
loaderr: /* should report error? */ |
290 |
< |
fclose(fp); |
290 |
> |
if (inspec[0] == '!') |
291 |
> |
pclose(fp); |
292 |
> |
else |
293 |
> |
fclose(fp); |
294 |
|
rmx_free(dnew); |
295 |
|
return(NULL); |
296 |
|
} |