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.10 by greg, Tue Jun 3 21:31:51 2025 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  
14
15   /* Return appropriate suffix for Z offset */
16   static const char *
17   get_suffix(double zval)
# Line 52 | Line 52 | geomBSDF(const SDData *bsp)
52          char    command[SDnameLn+64];
53          int     fd;
54                                          /* write MGF to temp file */
55 <        fd = open(mktemp(strcpy(tmpfile,TEMPLATE)), O_WRONLY|O_CREAT|O_EXCL);
55 >        fd = open(mktemp(strcpy(tmpfile,TEMPLATE)), O_WRONLY|O_CREAT|O_EXCL, 0600);
56          if (fd < 0) {
57                  fprintf(stderr, "Cannot open temp file '%s'\n", tmpfile);
58                  return(0);
59          }
60 <        write(fd, bsp->mgf, strlen(bsp->mgf));
60 >        (void)write(fd, bsp->mgf, strlen(bsp->mgf));
61          close(fd);
62                                          /* set up command */
63          if (do_instance) {
64 <                sprintf(command, "mgf2rad %s | oconv -f - > %s.oct",
64 >                sprintf(command, "mgf2rad -s %s | oconv -f - > %s.oct",
65                                          tmpfile, bsp->name);
66          } else {
67                  fflush(stdout);
68 <                sprintf(command, "mgf2rad %s", tmpfile);
68 >                sprintf(command, "mgf2rad -s %s", tmpfile);
69          }
70          if (system(command)) {
71                  fprintf(stderr, "Error running: %s\n", command);
# Line 82 | Line 82 | geomBSDF(const SDData *bsp)
82  
83   /* Load a BSDF XML file and produce a corresponding Radiance object */
84   static int
85 < cvtBSDF(const char *fname)
85 > cvtBSDF(char *fname)
86   {
87          int     retOK;
88          SDData  myBSDF;
89 <                                        /* load the XML file */
89 >        char    *pname, *fnbeg;
90 >                                        /* find and load the XML file */
91          retOK = strlen(fname);
92 <        if (retOK < 5 || strcmp(fname+retOK-4, ".xml")) {
92 >        if (retOK < 5 || strcasecmp(fname+retOK-4, ".xml")) {
93                  fprintf(stderr, "%s: input does not end in '.xml'\n", fname);
94                  return(0);
95          }
96 +        pname = getpath(fname, getrlibpath(), R_OK);
97 +        if (pname == NULL) {
98 +                fprintf(stderr, "%s: cannot find BSDF file\n", fname);
99 +                return(0);
100 +        }
101 +        fnbeg = strrchr(fname, DIRSEP);
102 +        if (fnbeg != NULL)              /* eliminate directory */
103 +                fname = fnbeg+1;
104          SDclearBSDF(&myBSDF, fname);
105 <        if (SDreportEnglish(SDloadFile(&myBSDF, fname), stderr))
105 >        if (SDreportError(SDloadFile(&myBSDF, pname), stderr))
106                  return(0);
107          retOK = (myBSDF.dim[0] > FTINY) & (myBSDF.dim[1] > FTINY);
108          if (!retOK) {
# Line 106 | Line 115 | cvtBSDF(const char *fname)
115                          retOK = (freopen(rname, "w", stdout) != NULL);
116                  }
117                  if (retOK) {
118 +                        printf("# Produced by: %s %s\n", progname, fname);
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 {
# Line 127 | Line 140 | main(int argc, char *argv[])
140   {
141          int     status = 0;
142          int     i;
143 +
144 +        fixargv0(argv[0]);              /* sets global progname */
145  
146          for (i = 1; i < argc && argv[i][0] == '-'; i++)
147                  switch (argv[i][1]) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines