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

Comparing ray/src/cv/pkgBSDF.c (file contents):
Revision 2.1 by greg, Thu Jun 23 18:05:18 2011 UTC vs.
Revision 2.8 by greg, Sat Dec 1 19:45:43 2018 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
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 *
# Line 52 | Line 54 | geomBSDF(const SDData *bsp)
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) {
# Line 82 | Line 84 | geomBSDF(const SDData *bsp)
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) {
# Line 106 | Line 117 | cvtBSDF(const char *fname)
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 {
# Line 127 | Line 142 | main(int argc, char *argv[])
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]) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines