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

Comparing ray/src/common/idmap.c (file contents):
Revision 2.1 by greg, Fri Jul 26 16:18:06 2019 UTC vs.
Revision 2.2 by greg, Fri Jul 26 18:37:21 2019 UTC

# Line 30 | Line 30 | idmap_ropen(const char *fname, int hflags)
30          idinit.finp = fopen(fname, "rb");
31  
32          if (!idinit.finp) {
33 <                fputs(fname, stderr);
34 <                fputs(": cannot open for reading\n", stderr);
33 >                if (hflags & HF_STDERR) {
34 >                        fputs(fname, stderr);
35 >                        fputs(": cannot open for reading\n", stderr);
36 >                }
37                  return NULL;
38          }
39          SET_FILE_BINARY(idinit.finp);
# Line 42 | Line 44 | idmap_ropen(const char *fname, int hflags)
44          gotfmt = checkheader(idinit.finp, infmt,
45                          (hflags & HF_HEADOUT) ? stdout : (FILE *)NULL);
46          if (gotfmt <= 0) {
47 <                fputs(fname, stderr);
48 <                fputs(": bad or missing header format\n", stderr);
47 >                if (hflags & HF_STDERR) {
48 >                        fputs(fname, stderr);
49 >                        fputs(": bad or missing header format\n", stderr);
50 >                }
51                  fclose(idinit.finp);
52                  return NULL;
53          }
# Line 62 | Line 66 | idmap_ropen(const char *fname, int hflags)
66                  idinit.bytespi = 3;
67                  break;
68          default:
69 <                fputs(fname, stderr);
70 <                fputs(": unsupported index size: ", stderr);
71 <                fputs(infmt, stderr);
72 <                fputc('\n', stderr);
69 >                if (hflags & HF_STDERR) {
70 >                        fputs(fname, stderr);
71 >                        fputs(": unsupported index size: ", stderr);
72 >                        fputs(infmt, stderr);
73 >                        fputc('\n', stderr);
74 >                }
75                  fclose(idinit.finp);
76                  return NULL;
77          }
78                                          /* get/copy resolution string */
79          if (!fgetsresolu(&idinit.res, idinit.finp)) {
80 <                fputs(fname, stderr);
81 <                fputs(": missing map resolution\n", stderr);
80 >                if (hflags & HF_STDERR) {
81 >                        fputs(fname, stderr);
82 >                        fputs(": missing map resolution\n", stderr);
83 >                }
84                  fclose(idinit.finp);
85                  return NULL;
86          }
# Line 85 | Line 93 | idmap_ropen(const char *fname, int hflags)
93          tablength = ftell(idinit.finp) - idinit.dstart -
94                          (long)idinit.res.xr*idinit.res.yr*idinit.bytespi;
95          if (tablength < 2) {
96 <                fputs(fname, stderr);
97 <                fputs(": truncated file\n", stderr);
96 >                if (hflags & HF_STDERR) {
97 >                        fputs(fname, stderr);
98 >                        fputs(": truncated file\n", stderr);
99 >                }
100                  fclose(idinit.finp);
101                  return NULL;
102          }
103                                          /* allocate and load table */
104          idmp = (IDMAP *)malloc(sizeof(IDMAP)+tablength);
105          if (idmp == NULL) {
106 <                fputs("Out of memory allocating ID table!\n", stderr);
106 >                if (hflags & HF_STDERR)
107 >                        fputs("Out of memory allocating ID table!\n", stderr);
108                  fclose(idinit.finp);
109                  return NULL;
110          }
# Line 102 | Line 113 | idmap_ropen(const char *fname, int hflags)
113          if (fseek(idmp->finp, -tablength, SEEK_END) < 0)
114                  goto seekerr;
115          if (fread(idmp->idtable, 1, tablength, idmp->finp) != tablength) {
116 <                fputs(fname, stderr);
117 <                fputs(": error reading identifier table\n", stderr);
116 >                if (hflags & HF_STDERR) {
117 >                        fputs(fname, stderr);
118 >                        fputs(": error reading identifier table\n", stderr);
119 >                }
120                  fclose(idmp->finp);
121                  free(idmp);
122                  return NULL;
# Line 114 | Line 127 | idmap_ropen(const char *fname, int hflags)
127                  idmp->nids += !idmp->idtable[--tablength];
128          idmp->idoffset = (int *)malloc(sizeof(int)*idmp->nids);
129          if (!idmp->idoffset) {
130 <                fputs("Out of memory in idmap_ropen!\n", stderr);
130 >                if (hflags & HF_STDERR)
131 >                        fputs("Out of memory in idmap_ropen!\n", stderr);
132                  fclose(idmp->finp);
133                  free(idmp);
134                  return NULL;
# Line 126 | Line 140 | idmap_ropen(const char *fname, int hflags)
140          }
141          return idmp;
142   seekerr:
143 <        fputs(fname, stderr);
144 <        fputs(": cannot seek on file\n", stderr);
143 >        if (hflags & HF_STDERR) {
144 >                fputs(fname, stderr);
145 >                fputs(": cannot seek on file\n", stderr);
146 >        }
147          fclose(idinit.finp);
148          if (idmp) free(idmp);
149          return NULL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines