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.5 by greg, Tue Jul 16 15:59:49 2019 UTC vs.
Revision 1.11 by greg, Thu Nov 7 23:13:12 2019 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *      7/4/19          Greg Ward
8   */
9  
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdio.h>
10   #include <ctype.h>
11  
12 + #include "rtio.h"
13   #include "platform.h"
14 + #include "paths.h"
15   #include "resolu.h"
17 #include "rtio.h"
16  
17   #define DOHEADER        1
18   #define DORESOLU        2
19  
20   #define MAXFILE         512             /* maximum number of files */
21  
22 < FILE            *output[MAXFILE];
25 < int             bytsiz[MAXFILE];
26 < short           hdrflags[MAXFILE];
27 < const char      *format[MAXFILE];
28 < int             termc[MAXFILE];
29 < int             nfiles = 0;
22 > static int              swapped = 0;    /* input is byte-swapped */
23  
24 < int             outheader = 0;          /* output header to each stream? */
24 > static FILE             *output[MAXFILE];
25 > static int              bytsiz[MAXFILE];
26 > static short            hdrflags[MAXFILE];
27 > static const char       *format[MAXFILE];
28 > static int              termc[MAXFILE];
29 > static int              nfiles = 0;
30  
31 < RESOLU          ourres = {PIXSTANDARD, 0, 0};
31 > static RESOLU   ourres = {PIXSTANDARD, 0, 0};
32  
33 < char            buf[16384];
33 > static char     buf[16384];             /* input buffer used in scanOK() */
34  
35  
36   /* process header line */
# Line 40 | Line 38 | static int
38   headline(char *s, void *p)
39   {
40          extern const char       FMTSTR[];
41 <        int                     i = nfiles;
41 >        int                     i;
42  
43          if (strstr(s, FMTSTR) == s)
44                  return(0);              /* don't copy format */
# Line 50 | Line 48 | headline(char *s, void *p)
48                  return(0);
49          if (!strncmp(s, "NCOMP=", 6))
50                  return(0);
51 +        if ((i = isbigendian(s)) >= 0) {
52 +                swapped = (nativebigendian() != i);
53 +                return(0);
54 +        }
55 +        i = nfiles;
56          while (i--)                     /* else copy line to output streams */
57                  if (hdrflags[i] & DOHEADER)
58                          fputs(s, output[i]);
# Line 61 | Line 64 | headline(char *s, void *p)
64   static int
65   scanOK(int termc)
66   {
67 +        int     skip_white = (termc == ' ');
68          char    *cp = buf;
69          int     c;
70  
71          while ((c = getchar()) != EOF) {
72 +                if (skip_white && isspace(c))
73 +                        continue;
74 +                skip_white = 0;
75 +                if (c == '\n' && isspace(termc))
76 +                        c = termc;      /* forgiving assumption */
77                  *cp++ = c;
78                  if (cp-buf >= sizeof(buf))
79                          break;
80 <                if (c == termc) {
80 >                if ((termc == ' ') ? isspace(c) : (c == termc)) {
81                          *cp = '\0';
82                          return(cp-buf);
83                  }
# Line 80 | Line 89 | scanOK(int termc)
89   int
90   main(int argc, char *argv[])
91   {
92 <        int             inpheader = 0;
93 <        int             inpres = 0;
85 <        int             outres = 0;
92 >        int             inpflags = 0;
93 >        int             needres = 0;
94          int             force = 0;
95          int             append = 0;
96          long            outcnt = 0;
# Line 103 | Line 111 | main(int argc, char *argv[])
111                          case 'i':
112                                  switch (argv[i][2]) {
113                                  case 'h':
114 <                                        inpheader = !inpheader;
114 >                                        inpflags ^= DOHEADER;
115                                          break;
116                                  case 'H':
117 <                                        inpres = !inpres;
117 >                                        inpflags ^= DORESOLU;
118                                          break;
119                                  default:
120                                          goto badopt;
121                                  }
122                                  break;
123                          case 'f':
124 <                                ++force;
117 <                                append = 0;
124 >                                force = !force;
125                                  break;
126                          case 'a':
127 <                                if (outheader | outres) {
121 <                                        fputs(argv[0], stderr);
122 <                                        fputs(": -a option incompatible with -oh and -oH\n",
123 <                                                        stderr);
124 <                                        return(1);
125 <                                }
126 <                                append = 1;
127 >                                append = !append;
128                                  break;
129                          case 'x':
130                                  ourres.xr = atoi(argv[++i]);
130                                outres = 1;
131                                  break;
132                          case 'y':
133                                  ourres.yr = atoi(argv[++i]);
134                                outres = 1;
134                                  break;
135                          case 'o':
136                                  switch (argv[i][2]) {
# Line 166 | Line 165 | main(int argc, char *argv[])
165                                          break;
166                                  case 'a':
167                                          curfmt = "ascii";
168 <                                        curbytes = argv[i][3] ? -1 : 0;
168 >                                        curbytes = -1;
169                                          break;
170                                  default:
171                                          goto badopt;
# Line 179 | Line 178 | main(int argc, char *argv[])
178                                          fputs(": output size too big\n", stderr);
179                                          return(1);
180                                  }
181 <                                if (curbytes > 0) {
183 <                                        curterm = '\0';
184 <                                        ++bininp;
185 <                                }
181 >                                bininp += (curbytes > 0);
182                                  break;
183                          case '\0':
184 <                                outres |= (curflags & DORESOLU);
184 >                                needres |= (curflags & DORESOLU);
185                                  termc[nfiles] = curterm;
186                                  hdrflags[nfiles] = curflags;
187                                  output[nfiles] = stdout;
# Line 201 | Line 197 | main(int argc, char *argv[])
197                                  return(1);
198                          }
199                  } else if (argv[i][0] == '!') {
200 <                        outres |= (curflags & DORESOLU);
200 >                        needres |= (curflags & DORESOLU);
201                          termc[nfiles] = curterm;
202                          hdrflags[nfiles] = curflags;
203                          if ((output[nfiles] = popen(argv[i]+1, "w")) == NULL) {
# Line 214 | Line 210 | main(int argc, char *argv[])
210                          format[nfiles] = curfmt;
211                          bytsiz[nfiles++] = curbytes;
212                  } else {
213 <                        outres |= (curflags & DORESOLU);
213 >                        if (append & (curflags != 0)) {
214 >                                fputs(argv[0], stderr);
215 >                                fputs(": -a option incompatible with -oh and -oH\n",
216 >                                                stderr);
217 >                                return(1);
218 >                        }
219 >                        needres |= (curflags & DORESOLU);
220                          termc[nfiles] = curterm;
221                          hdrflags[nfiles] = curflags;
222                          if (!append & !force && access(argv[i], F_OK) == 0) {
# Line 253 | Line 255 | main(int argc, char *argv[])
255                  flockfile(output[i]);
256   #endif
257                                                  /* load/copy header */
258 <        if (inpheader && getheader(stdin, headline, NULL) < 0) {
258 >        if (inpflags & DOHEADER && getheader(stdin, headline, NULL) < 0) {
259                  fputs(argv[0], stderr);
260                  fputs(": cannot get header from standard input\n",
261                                  stderr);
262                  return(1);
263          }
264                                                  /* handle resolution string */
265 <        if (inpres && !fgetsresolu(&ourres, stdin)) {
265 >        if (inpflags & DORESOLU && !fgetsresolu(&ourres, stdin)) {
266                  fputs(argv[0], stderr);
267                  fputs(": cannot get resolution string from standard input\n",
268                                  stderr);
269                  return(1);
270          }
271 <        if (outres && (ourres.xr <= 0) | (ourres.yr <= 0)) {
271 >        if (needres && (ourres.xr <= 0) | (ourres.yr <= 0)) {
272                  fputs(argv[0], stderr);
273                  fputs(": -oH option requires -iH or -x and -y options\n", stderr);
274                  return(1);
# Line 282 | Line 284 | main(int argc, char *argv[])
284          }
285          for (i = 0; i < nfiles; i++) {          /* complete headers */
286                  if (hdrflags[i] & DOHEADER) {
287 <                        if (!inpheader)
287 >                        if (!(inpflags & DOHEADER))
288                                  newheader("RADIANCE", output[i]);
289                          printargs(argc, argv, output[i]);
290 <                        if (format[i] != NULL)
290 >                        if (format[i] != NULL) {
291 >                                extern const char  BIGEND[];
292 >                                if ((format[i][0] == 'f') |
293 >                                                (format[i][0] == 'd')) {
294 >                                        fputs(BIGEND, output[i]);
295 >                                        fputs(nativebigendian() ^ swapped ?
296 >                                                "1\n" : "0\n", output[i]);
297 >                                }
298                                  fputformat(format[i], output[i]);
299 +                        }
300                          fputc('\n', output[i]);
301                  }
302                  if (hdrflags[i] & DORESOLU)
# Line 297 | Line 307 | main(int argc, char *argv[])
307                          if (bytsiz[i] > 0) {            /* binary output */
308                                  if (getbinary(buf, bytsiz[i], 1, stdin) < 1)
309                                          break;
310 <                                if (putbinary(buf, bytsiz[i], 1, output[i]) != 1)
310 >                                if (putbinary(buf, bytsiz[i], 1, output[i]) < 1)
311                                          break;
312                          } else if (bytsiz[i] < 0) {     /* N-field output */
313                                  int     n = -bytsiz[i];
# Line 318 | Line 328 | main(int argc, char *argv[])
328                                          break;
329                                  if (termc[i] != '\n')   /* add EOL if none */
330                                          fputc('\n', output[i]);
331 +                        }
332 +                                                        /* skip input EOL? */
333 +                        if (!bininp && termc[nfiles-1] != '\n') {
334 +                                int     c = getchar();
335 +                                if ((c != '\n') & (c != EOF))
336 +                                        ungetc(c, stdin);
337                          }
338                  }
339                  if (i < nfiles)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines