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

Comparing ray/src/util/rcollate.c (file contents):
Revision 2.9 by greg, Fri May 30 00:00:54 2014 UTC vs.
Revision 2.12 by greg, Fri May 30 18:10:20 2014 UTC

# Line 276 | Line 276 | int            no_columns = 0;                 /* number of output columns */
276   int             no_rows = 0;                    /* number of output rows */
277  
278   /* check settings and assign defaults */
279 < static void
279 > static int
280   check_sizes()
281   {
282          if (fmtid == NULL) {
# Line 288 | Line 288 | check_sizes()
288                          comp_size = sizeof(double);
289                  else if (!strcmp(fmtid, "byte"))
290                          comp_size = 1;
291 +                else {
292 +                        fprintf(stderr, "Unsupported format: %s\n", fmtid);
293 +                        return(0);
294 +                }
295          }
296          if (n_comp <= 0)
297                  n_comp = 3;
298 +        return(1);
299   }
300  
301   /* output transposed ASCII or binary data from memory */
# Line 367 | Line 372 | do_resize(FILE *fp)
372          int     columns2go = no_columns;
373          char    word[256];
374                                                  /* sanity checks */
375 <        if (comp_size) {
376 <                fputs("Bad call to do_resize (binary input)\n", stderr);
372 <                return(0);
373 <        }
375 >        if (comp_size)
376 >                return(output_stream(fp));      /* binary data -- just copy */
377          if (no_columns <= 0) {
378                  fprintf(stderr, "Missing -oc specification\n");
379                  return(0);
# Line 471 | Line 474 | headline(char *s, void *p)
474   int
475   main(int argc, char *argv[])
476   {
477 <        int     do_header = 1;                  /* header i/o? */
477 >        int     i_header = 1;                   /* input header? */
478 >        int     o_header = 1;                   /* output header? */
479          int     transpose = 0;                  /* transpose rows & cols? */
480          int     i;
481  
# Line 493 | Line 497 | main(int argc, char *argv[])
497                          else
498                                  goto userr;
499                          break;
500 <                case 'h':                       /* header on/off */
501 <                        do_header = !do_header;
500 >                case 'h':                       /* turn off header */
501 >                        switch (argv[i][2]) {
502 >                        case 'i':
503 >                                i_header = 0;
504 >                                break;
505 >                        case 'o':
506 >                                o_header = 0;
507 >                                break;
508 >                        case '\0':
509 >                                i_header = o_header = 0;
510 >                                break;
511 >                        default:
512 >                                goto userr;
513 >                        }
514                          break;
515                  case 't':                       /* transpose on/off */
516                          transpose = !transpose;
# Line 548 | Line 564 | main(int argc, char *argv[])
564                  SET_FILE_BINARY(stdout);
565          }
566                                                  /* check for no-op */
567 <        if (!transpose && (comp_size ||
567 >        if (!transpose & (i_header == o_header) && (comp_size ||
568                          (no_columns == ni_columns) & (no_rows == ni_rows))) {
569                  if (warnings)
570                          fprintf(stderr, "%s: no-op -- copying input verbatim\n",
# Line 557 | Line 573 | main(int argc, char *argv[])
573                          return(1);
574                  return(0);
575          }
576 <        if (do_header) {                        /* read/write header */
576 >        if (i_header) {                         /* read header */
577                  if (getheader(stdin, &headline, NULL) < 0)
578                          return(1);
579 <                check_sizes();
579 >                if (!check_sizes())
580 >                        return(1);
581                  if (comp_size) {                /* a little late... */
582                          SET_FILE_BINARY(stdin);
583                          SET_FILE_BINARY(stdout);
584                  }
585 +        } else if (!check_sizes())
586 +                return(1);
587 +        if (o_header) {                         /* write header */
588                  printargs(argc, argv, stdout);
589                  if (transpose && (no_rows <= 0) & (no_columns <= 0)) {
590                          if (ni_rows > 0) no_columns = ni_rows;
# Line 577 | Line 597 | main(int argc, char *argv[])
597                  printf("NCOMP=%d\n", n_comp);
598                  fputformat(fmtid, stdout);
599                  fputc('\n', stdout);            /* finish new header */
600 <        } else
581 <                check_sizes();
600 >        }
601          if (transpose) {                        /* transposing rows & columns? */
602                  MEMLOAD myMem;                  /* need to load into memory */
603                  if (i == argc-1) {
# Line 600 | Line 619 | main(int argc, char *argv[])
619          return(0);
620   userr:
621          fprintf(stderr,
622 < "Usage: %s [-h][-w][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n",
622 > "Usage: %s [-h[io]][-w][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n",
623                          argv[0]);
624          return(1);
625   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines