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.7 by greg, Sat Jul 20 23:12:53 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>
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 + static int              swapped = 0;    /* input is byte-swapped */
23 +
24   static FILE             *output[MAXFILE];
25   static int              bytsiz[MAXFILE];
26   static short            hdrflags[MAXFILE];
# Line 26 | Line 28 | static const char      *format[MAXFILE];
28   static int              termc[MAXFILE];
29   static int              nfiles = 0;
30  
29 static int      outheader = 0;          /* output header to each stream? */
30
31   static RESOLU   ourres = {PIXSTANDARD, 0, 0};
32  
33   static char     buf[16384];             /* input buffer used in scanOK() */
# Line 38 | 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 48 | 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 59 | 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 78 | Line 89 | scanOK(int termc)
89   int
90   main(int argc, char *argv[])
91   {
92 <        int             inpheader = 0;
93 <        int             inpres = 0;
83 <        int             outres = 0;
92 >        int             inpflags = 0;
93 >        int             needres = 0;
94          int             force = 0;
95          int             append = 0;
96          long            outcnt = 0;
# Line 101 | 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;
115 <                                append = 0;
124 >                                force = !force;
125                                  break;
126                          case 'a':
127 <                                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;
127 >                                append = !append;
128                                  break;
129                          case 'x':
130                                  ourres.xr = atoi(argv[++i]);
128                                outres = 1;
131                                  break;
132                          case 'y':
133                                  ourres.yr = atoi(argv[++i]);
132                                outres = 1;
134                                  break;
135                          case 'o':
136                                  switch (argv[i][2]) {
# Line 180 | Line 181 | main(int argc, char *argv[])
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 196 | 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 209 | 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 248 | 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 277 | 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)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines