ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.c
(Generate patch)

Comparing ray/src/util/rmatrix.c (file contents):
Revision 2.12 by greg, Fri Jan 23 01:14:20 2015 UTC vs.
Revision 2.14 by greg, Mon May 4 23:27:04 2015 UTC

# Line 46 | Line 46 | rmx_free(RMATRIX *rm)
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);
# Line 184 | Line 186 | rmx_load_rgbe(RMATRIX *rm, FILE *fp)
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);
# Line 210 | Line 218 | rmx_load(const char *fname)
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
# Line 267 | Line 275 | rmx_load(const char *fname)
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines