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.13 by greg, Mon May 4 20:53:21 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines