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

Comparing ray/src/cal/rsplit.c (file contents):
Revision 1.6 by greg, Fri Jul 19 17:37:55 2019 UTC vs.
Revision 1.9 by greg, Tue Aug 13 16:31:35 2019 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *      7/4/19          Greg Ward
8   */
9  
10 #include <stdlib.h>
10   #include <ctype.h>
11  
12   #include "rtio.h"
13   #include "platform.h"
14 + #include "paths.h"
15   #include "resolu.h"
16  
17   #define DOHEADER        1
# Line 19 | Line 19 | static const char      RCSid[] = "$Id$";
19  
20   #define MAXFILE         512             /* maximum number of files */
21  
22 < FILE            *output[MAXFILE];
23 < int             bytsiz[MAXFILE];
24 < short           hdrflags[MAXFILE];
25 < const char      *format[MAXFILE];
26 < int             termc[MAXFILE];
27 < int             nfiles = 0;
22 > static FILE             *output[MAXFILE];
23 > static int              bytsiz[MAXFILE];
24 > static short            hdrflags[MAXFILE];
25 > static const char       *format[MAXFILE];
26 > static int              termc[MAXFILE];
27 > static int              nfiles = 0;
28  
29 < int             outheader = 0;          /* output header to each stream? */
29 > static RESOLU   ourres = {PIXSTANDARD, 0, 0};
30  
31 < RESOLU          ourres = {PIXSTANDARD, 0, 0};
31 > static char     buf[16384];             /* input buffer used in scanOK() */
32  
33 char            buf[16384];
33  
35
34   /* process header line */
35   static int
36   headline(char *s, void *p)
# Line 78 | Line 76 | scanOK(int termc)
76   int
77   main(int argc, char *argv[])
78   {
79 <        int             inpheader = 0;
80 <        int             inpres = 0;
83 <        int             outres = 0;
79 >        int             inpflags = 0;
80 >        int             needres = 0;
81          int             force = 0;
82          int             append = 0;
83          long            outcnt = 0;
# Line 101 | Line 98 | main(int argc, char *argv[])
98                          case 'i':
99                                  switch (argv[i][2]) {
100                                  case 'h':
101 <                                        inpheader = !inpheader;
101 >                                        inpflags ^= DOHEADER;
102                                          break;
103                                  case 'H':
104 <                                        inpres = !inpres;
104 >                                        inpflags ^= DORESOLU;
105                                          break;
106                                  default:
107                                          goto badopt;
108                                  }
109                                  break;
110                          case 'f':
111 <                                ++force;
115 <                                append = 0;
111 >                                force = !force;
112                                  break;
113                          case 'a':
114 <                                if (outheader | outres) {
119 <                                        fputs(argv[0], stderr);
120 <                                        fputs(": -a option incompatible with -oh and -oH\n",
121 <                                                        stderr);
122 <                                        return(1);
123 <                                }
124 <                                append = 1;
114 >                                append = !append;
115                                  break;
116                          case 'x':
117                                  ourres.xr = atoi(argv[++i]);
128                                outres = 1;
118                                  break;
119                          case 'y':
120                                  ourres.yr = atoi(argv[++i]);
132                                outres = 1;
121                                  break;
122                          case 'o':
123                                  switch (argv[i][2]) {
# Line 164 | Line 152 | main(int argc, char *argv[])
152                                          break;
153                                  case 'a':
154                                          curfmt = "ascii";
155 <                                        curbytes = argv[i][3] ? -1 : 0;
155 >                                        curbytes = -1;
156                                          break;
157                                  default:
158                                          goto badopt;
# Line 177 | Line 165 | main(int argc, char *argv[])
165                                          fputs(": output size too big\n", stderr);
166                                          return(1);
167                                  }
168 <                                if (curbytes > 0) {
181 <                                        curterm = '\0';
182 <                                        ++bininp;
183 <                                }
168 >                                bininp += (curbytes > 0);
169                                  break;
170                          case '\0':
171 <                                outres |= (curflags & DORESOLU);
171 >                                needres |= (curflags & DORESOLU);
172                                  termc[nfiles] = curterm;
173                                  hdrflags[nfiles] = curflags;
174                                  output[nfiles] = stdout;
# Line 199 | Line 184 | main(int argc, char *argv[])
184                                  return(1);
185                          }
186                  } else if (argv[i][0] == '!') {
187 <                        outres |= (curflags & DORESOLU);
187 >                        needres |= (curflags & DORESOLU);
188                          termc[nfiles] = curterm;
189                          hdrflags[nfiles] = curflags;
190                          if ((output[nfiles] = popen(argv[i]+1, "w")) == NULL) {
# Line 212 | Line 197 | main(int argc, char *argv[])
197                          format[nfiles] = curfmt;
198                          bytsiz[nfiles++] = curbytes;
199                  } else {
200 <                        outres |= (curflags & DORESOLU);
200 >                        if (append & (curflags != 0)) {
201 >                                fputs(argv[0], stderr);
202 >                                fputs(": -a option incompatible with -oh and -oH\n",
203 >                                                stderr);
204 >                                return(1);
205 >                        }
206 >                        needres |= (curflags & DORESOLU);
207                          termc[nfiles] = curterm;
208                          hdrflags[nfiles] = curflags;
209                          if (!append & !force && access(argv[i], F_OK) == 0) {
# Line 251 | Line 242 | main(int argc, char *argv[])
242                  flockfile(output[i]);
243   #endif
244                                                  /* load/copy header */
245 <        if (inpheader && getheader(stdin, headline, NULL) < 0) {
245 >        if (inpflags & DOHEADER && getheader(stdin, headline, NULL) < 0) {
246                  fputs(argv[0], stderr);
247                  fputs(": cannot get header from standard input\n",
248                                  stderr);
249                  return(1);
250          }
251                                                  /* handle resolution string */
252 <        if (inpres && !fgetsresolu(&ourres, stdin)) {
252 >        if (inpflags & DORESOLU && !fgetsresolu(&ourres, stdin)) {
253                  fputs(argv[0], stderr);
254                  fputs(": cannot get resolution string from standard input\n",
255                                  stderr);
256                  return(1);
257          }
258 <        if (outres && (ourres.xr <= 0) | (ourres.yr <= 0)) {
258 >        if (needres && (ourres.xr <= 0) | (ourres.yr <= 0)) {
259                  fputs(argv[0], stderr);
260                  fputs(": -oH option requires -iH or -x and -y options\n", stderr);
261                  return(1);
# Line 280 | Line 271 | main(int argc, char *argv[])
271          }
272          for (i = 0; i < nfiles; i++) {          /* complete headers */
273                  if (hdrflags[i] & DOHEADER) {
274 <                        if (!inpheader)
274 >                        if (!(inpflags & DOHEADER))
275                                  newheader("RADIANCE", output[i]);
276                          printargs(argc, argv, output[i]);
277                          if (format[i] != NULL)
# Line 295 | Line 286 | main(int argc, char *argv[])
286                          if (bytsiz[i] > 0) {            /* binary output */
287                                  if (getbinary(buf, bytsiz[i], 1, stdin) < 1)
288                                          break;
289 <                                if (putbinary(buf, bytsiz[i], 1, output[i]) != 1)
289 >                                if (putbinary(buf, bytsiz[i], 1, output[i]) < 1)
290                                          break;
291                          } else if (bytsiz[i] < 0) {     /* N-field output */
292                                  int     n = -bytsiz[i];
# Line 316 | Line 307 | main(int argc, char *argv[])
307                                          break;
308                                  if (termc[i] != '\n')   /* add EOL if none */
309                                          fputc('\n', output[i]);
310 +                        }
311 +                                                        /* skip input EOL? */
312 +                        if (!bininp && termc[nfiles-1] != '\n') {
313 +                                int     c = getchar();
314 +                                if ((c != '\n') & (c != EOF))
315 +                                        ungetc(c, stdin);
316                          }
317                  }
318                  if (i < nfiles)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines