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

Comparing ray/src/util/radcompare.c (file contents):
Revision 2.3 by greg, Mon Oct 15 18:31:15 2018 UTC vs.
Revision 2.12 by greg, Fri Oct 19 22:15:30 2018 UTC

# Line 33 | Line 33 | double max_lim = 0.25;         /* difference limit if non-neg
33  
34   int     lin1cnt=0, lin2cnt=0;   /* file line position */
35  
36 + const char      nsuffix[10][3] = {              /* 1st, 2nd, 3rd, etc. */
37 +                        "th","st","nd","rd","th","th","th","th","th","th"
38 +                };
39 + #define num_sfx(n)      nsuffix[(n)%10]
40 +
41                                  /* file types */
42   const char      *file_type[] = {
43                          "Unrecognized",
# Line 40 | Line 45 | const char     *file_type[] = {
45                          "ascii",
46                          COLRFMT,
47                          CIEFMT,
48 <                        "BINARY_float",
49 <                        "BINARY_double",
48 >                        "float",
49 >                        "double",
50                          "BSDF_RBFmesh",
51                          "Radiance_octree",
52                          "Radiance_tmesh",
53                          "BINARY_unknown",
54                          NULL    /* terminator */
55                  };
56 <
56 >                                /* keep consistent with above */
57   enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_FLOAT,
58                  TYP_DOUBLE, TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, TYP_BINARY};
59                  
# Line 69 | Line 74 | LUTAB  hdr2 = LU_SINIT(free,free);
74   #define adv_linecnt(htp)        (lin1cnt += (htp == &hdr1), \
75                                          lin2cnt += (htp == &hdr2))
76  
77 + typedef struct {                /* dynamic line buffer */
78 +        char    *ptr;
79 +        int     len;
80 +        int     siz;
81 + } LINEBUF;
82 +
83 + #define init_line(bp)   ((bp)->ptr = NULL, (bp)->siz = 0)
84 +                                /* 100 MByte limit on line buffer */
85 + #define MAXBUF          (100L<<20)
86 +
87                                  /* input files */
88   char            *progname = NULL;
89   const char      stdin_name[] = "<stdin>";
# Line 77 | Line 92 | FILE           *f1in=NULL, *f2in=NULL;
92  
93                                  /* running real differences */
94   double  diff2sum = 0;
95 < int     nsum = 0;
95 > long    nsum = 0;
96  
97   /* Report usage and exit */
98   static void
# Line 85 | Line 100 | usage()
100   {
101          fputs("Usage: ", stderr);
102          fputs(progname, stderr);
103 <        fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] file1 file2\n",
103 >        fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
104                          stderr);
105 <        exit(1);
105 >        exit(2);
106   }
107  
108 + /* Read a text line, increasing buffer size as necessary */
109 + static int
110 + read_line(LINEBUF *bp, FILE *fp)
111 + {
112 +        bp->len = 0;
113 +        if (!bp->ptr) {
114 +                bp->ptr = (char *)malloc(bp->siz = 512);
115 +                if (!bp->ptr)
116 +                        goto memerr;
117 +        }
118 +        while (fgets(bp->ptr + bp->len, bp->siz - bp->len, fp)) {
119 +                bp->len += strlen(bp->ptr + bp->len);
120 +                if (bp->ptr[bp->len-1] == '\n')
121 +                        break;          /* found EOL */
122 +                if (bp->len < bp->siz - 4)
123 +                        continue;       /* at EOF? */
124 +                if (bp->siz >= MAXBUF)
125 +                        break;          /* don't go to extremes */
126 +                if ((bp->siz += bp->siz/2) > MAXBUF)
127 +                        bp->siz = MAXBUF;
128 +                bp->ptr = (char *)realloc(bp->ptr, bp->siz);
129 +                if (!bp->ptr)
130 +                        goto memerr;
131 +        }
132 +        return(bp->len);
133 + memerr:
134 +        fprintf(stderr,
135 +                "%s: out of memory in read_line() allocating %d byte buffer\n",
136 +                        progname, bp->siz);
137 +        exit(2);
138 + }
139 +
140 + /* Free line buffer */
141 + static void
142 + free_line(LINEBUF *bp)
143 + {
144 +        bp->len = 0;
145 +        if (!bp->ptr) return;
146 +        free(bp->ptr);
147 +        bp->ptr = NULL;
148 + }
149 +
150   /* Get type ID from name (or 0 if not found) */
151   static int
152   xlate_type(const char *nm)
# Line 117 | Line 174 | real_check(double r1, double r2)
174          }
175          if (max_lim >= 0 && diff2 > max_lim*max_lim) {
176                  if (report != REP_QUIET)
177 <                        fprintf(stderr,
178 <                        "%s: %sdifference between %.8g and %.8g exceeds epsilon\n",
177 >                        printf(
178 >                        "%s: %sdifference between %.8g and %.8g exceeds epsilon of %.8g\n",
179                                          progname,
180                                          (rel_min > 0) ? "relative " : "",
181 <                                        r1, r2);
181 >                                        r1, r2, max_lim);
182                  return(0);
183          }
184          diff2sum += diff2;
# Line 129 | Line 186 | real_check(double r1, double r2)
186          return(1);
187   }
188  
189 + /* Compare two color values for equivalence */
190 + static int
191 + color_check(COLOR c1, COLOR c2)
192 + {
193 +        int     p;
194 +
195 +        if (!real_check(colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU)*(1./3.),
196 +                        colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.))
197 +                return(0);
198 +
199 +        p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED;
200 +        if (colval(c1,BLU) > colval(c1,p)) p = BLU;
201 +        
202 +        return(real_check(colval(c1,p), colval(c2,p)));
203 + }
204 +
205   /* Compare two strings for equivalence */
206   static int
207   equiv_string(char *s1, char *s2)
# Line 223 | Line 296 | setheadvar(char *val, void *p)
296                  val++;
297          if (!*val)              /* nothing set? */
298                  return(0);
226        vln = strlen(val);      /* eliminate space and newline at end */
227        while (--vln > 0 && isspace(val[vln]))
228                ;
229        val[++vln] = '\0';
299                                  /* check if key to ignore */
300          for (n = 0; hdr_ignkey[n]; n++)
301                  if (!strcmp(key, hdr_ignkey[n]))
302                          return(0);
303 +        vln = strlen(val);      /* eliminate space and newline at end */
304 +        while (isspace(val[--vln]))
305 +                ;
306 +        val[++vln] = '\0';
307          if (!(tep = lu_find(htp, key)))
308 <                return(-1);
308 >                return(-1);     /* memory allocation error */
309          if (!tep->key)
310                  tep->key = strcpy(malloc(kln+1), key);
311          if (tep->data)
# Line 248 | Line 321 | match_val(const LUENT *ep1, void *p2)
321          const LUENT     *ep2 = lu_find((LUTAB *)p2, ep1->key);
322          if (!ep2 || !ep2->data) {
323                  if (report != REP_QUIET)
324 <                        fprintf(stderr, "%s: Variable '%s' missing in '%s'\n",
324 >                        printf("%s: variable '%s' missing in '%s'\n",
325                                          progname, ep1->key, f2name);
326                  return(-1);
327          }
328          if (!equiv_string((char *)ep1->data, (char *)ep2->data)) {
329 <                if (report != REP_QUIET)
330 <                        fprintf(stderr, "%s: Header variables '%s' have different values\n",
329 >                if (report != REP_QUIET) {
330 >                        printf("%s: header variable '%s' has different values\n",
331                                          progname, ep1->key);
332 +                        if (report >= REP_VERBOSE) {
333 +                                printf("%s: %s=%s\n", f1name,
334 +                                                ep1->key, (char *)ep1->data);
335 +                                printf("%s: %s=%s\n", f2name,
336 +                                                ep2->key, (char *)ep2->data);
337 +                        }
338 +                }
339                  return(-1);
340          }
341          return(1);              /* good match */
# Line 263 | Line 343 | match_val(const LUENT *ep1, void *p2)
343  
344   /* Compare two sets of header variables */
345   static int
346 < headers_match(LUTAB *hp1, LUTAB *hp2)
346 > headers_match()
347   {
348 <        int     ne = lu_doall(hp1, match_val, hp2);
348 >        int     ne = lu_doall(&hdr1, match_val, &hdr2);
349          if (ne < 0)
350                  return(0);      /* something didn't match! */
351 <        ne = lu_doall(hp2, NULL, NULL) - ne;
352 <        if (ne) {
353 <                if (report != REP_QUIET)
274 <                        fprintf(stderr, "%s: '%s' has %d extra header variable(s)\n",
351 >                                /* non-fatal if second header has extra */
352 >        if (report >= REP_WARN && (ne = lu_doall(&hdr2, NULL, NULL) - ne))
353 >                printf("%s: warning - '%s' has %d extra header setting(s)\n",
354                                          progname, f2name, ne);
276                return(0);
277        }
355          return(1);              /* good match */
356   }
357  
# Line 286 | Line 363 | input_is_binary(FILE *fin)
363          int     c = 0;
364  
365          while ((c = getc(fin)) != EOF) {
366 +                ++n;
367                  if (!c | (c > 127))
368                          break;                  /* non-ascii character */
369 <                if (++n >= 10240)
369 >                if (n >= 10240)
370                          break;                  /* enough to be confident */
371          }
372          if (!n)
# Line 320 | Line 398 | identify_type(const char *name, FILE *fin, LUTAB *htp)
398                          goto badeof;
399                  adv_linecnt(htp);               /* for #?ID string */
400                  if (report >= REP_WARN && strncmp(sbuf, "RADIANCE", 8)) {
401 <                        fputs(name, stderr);
402 <                        fputs(": warning - unexpected header ID: ", stderr);
403 <                        fputs(sbuf, stderr);
401 >                        fputs(name, stdout);
402 >                        fputs(": warning - unexpected header ID: ", stdout);
403 >                        fputs(sbuf, stdout);
404                  }
405                  if (getheader(fin, setheadvar, htp) < 0) {
406                          fputs(name, stderr);
407 <                        fputs(": Unknown error reading header\n", stderr);
407 >                        fputs(": unknown error reading header\n", stderr);
408                          return(-1);
409                  }
410                  adv_linecnt(htp);               /* for trailing emtpy line */
# Line 344 | Line 422 | identify_type(const char *name, FILE *fin, LUTAB *htp)
422          return(TYP_TEXT);
423   badeof:
424          if (report != REP_QUIET) {
425 <                fputs(name, stderr);
426 <                fputs(": Unexpected end-of-file\n", stderr);
425 >                fputs(name, stdout);
426 >                fputs(": unexpected end-of-file\n", stdout);
427          }
428          return(-1);
429   }
# Line 358 | Line 436 | good_RMS()
436                  return(1);
437          if (diff2sum/(double)nsum > rms_lim*rms_lim) {
438                  if (report != REP_QUIET)
439 <                        fprintf(stderr,
440 <        "%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit\n",
439 >                        printf(
440 >        "%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit of %.5g\n",
441                                          progname,
442                                          (rel_min > 0) ? "relative " : "",
443                                          f1name, f2name,
444 <                                        sqrt(diff2sum/(double)nsum));
444 >                                        sqrt(diff2sum/(double)nsum), rms_lim);
445                  return(0);
446          }
447          if (report >= REP_VERBOSE)
448 <                fprintf(stderr,
371 <                        "%s: %sRMS difference of reals in '%s' and '%s' is %.5g\n",
448 >                printf("%s: %sRMS difference of reals in '%s' and '%s' is %.5g\n",
449                                  progname, (rel_min > 0) ? "relative " : "",
450                                  f1name, f2name, sqrt(diff2sum/(double)nsum));
451          return(1);
# Line 378 | Line 455 | good_RMS()
455   static int
456   compare_binary()
457   {
458 +        int     c1=0, c2=0;
459 +
460          if (report >= REP_VERBOSE) {
461 <                fputs(progname, stderr);
462 <                fputs(": comparing inputs as binary\n", stderr);
461 >                fputs(progname, stdout);
462 >                fputs(": comparing inputs as binary\n", stdout);
463          }
464          for ( ; ; ) {                           /* exact byte matching */
465 <                int     c1 = getc(f1in);
466 <                int     c2 = getc(f2in);
465 >                c1 = getc(f1in);
466 >                c2 = getc(f2in);
467                  if (c1 == EOF) {
468                          if (c2 == EOF)
469                                  return(1);      /* success! */
470                          if (report != REP_QUIET) {
471 <                                fputs(f1name, stderr);
472 <                                fputs(": Unexpected end-of-file\n", stderr);
471 >                                fputs(f1name, stdout);
472 >                                fputs(": unexpected end-of-file\n", stdout);
473                          }
474                          return(0);
475                  }
476                  if (c2 == EOF) {
477                          if (report != REP_QUIET) {
478 <                                fputs(f2name, stderr);
479 <                                fputs(": Unexpected end-of-file\n", stderr);
478 >                                fputs(f2name, stdout);
479 >                                fputs(": unexpected end-of-file\n", stdout);
480                          }
481                          return(0);
482                  }
# Line 406 | Line 485 | compare_binary()
485          }
486          if (report == REP_QUIET)
487                  return(0);
488 <        fprintf(stderr, "%s: binary files '%s' and '%s' differ at offset %ld|%ld\n",
488 >        printf("%s: binary files '%s' and '%s' differ at byte offset %ld|%ld\n",
489                          progname, f1name, f2name, ftell(f1in), ftell(f2in));
490 +        if (report >= REP_VERBOSE)
491 +                printf("%s: byte in '%s' is 0x%X, byte in '%s' is 0x%X\n",
492 +                                progname, f1name, c1, f2name, c2);
493          return(0);
494   }
495  
# Line 415 | Line 497 | compare_binary()
497   static int
498   compare_text()
499   {
500 <        char    l1buf[4096], l2buf[4096];
500 >        LINEBUF l1buf, l2buf;
501  
502          if (report >= REP_VERBOSE) {
503 <                fputs(progname, stderr);
504 <                fputs(": comparing inputs as ASCII text\n", stderr);
503 >                fputs(progname, stdout);
504 >                fputs(": comparing inputs as ASCII text\n", stdout);
505          }
506 <                                                /* compare a line at a time */
507 <        while (fgets(l1buf, sizeof(l1buf), f1in)) {
506 >        init_line(&l1buf); init_line(&l2buf);   /* compare a line at a time */
507 >        while (read_line(&l1buf, f1in)) {
508                  lin1cnt++;
509 <                if (!*sskip2(l1buf,0))
509 >                if (!*sskip2(l1buf.ptr,0))
510                          continue;               /* ignore empty lines */
511 <                while (fgets(l2buf, sizeof(l2buf), f2in)) {
511 >
512 >                while (read_line(&l2buf, f2in)) {
513                          lin2cnt++;
514 <                        if (*sskip2(l2buf,0))
514 >                        if (*sskip2(l2buf.ptr,0))
515                                  break;          /* found other non-empty line */
516                  }
517                  if (feof(f2in)) {
518                          if (report != REP_QUIET) {
519 <                                fputs(f2name, stderr);
520 <                                fputs(": Unexpected end-of-file\n", stderr);
519 >                                fputs(f2name, stdout);
520 >                                fputs(": unexpected end-of-file\n", stdout);
521                          }
522 +                        free_line(&l1buf); free_line(&l2buf);
523                          return(0);
524                  }
525                                                  /* compare non-empty lines */
526 <                if (!equiv_string(l1buf, l2buf)) {
526 >                if (!equiv_string(l1buf.ptr, l2buf.ptr)) {
527                          if (report != REP_QUIET) {
528 <                                fprintf(stderr, "%s: inputs '%s' and '%s' differ at line %d|%d\n",
528 >                                printf("%s: inputs '%s' and '%s' differ at line %d|%d\n",
529                                                  progname, f1name, f2name,
530                                                  lin1cnt, lin2cnt);
531 <                                if (report >= REP_VERBOSE) {
532 <                                        fputs("------------- Mismatch -------------\n", stderr);
533 <                                        fprintf(stderr, "%s(%d):\t%s", f1name,
534 <                                                        lin1cnt, l1buf);
535 <                                        fprintf(stderr, "%s(%d):\t%s", f2name,
536 <                                                        lin2cnt, l2buf);
531 >                                if ( report >= REP_VERBOSE &&
532 >                                                (l1buf.len < 256) &
533 >                                                (l2buf.len < 256) ) {
534 >                                        fputs("------------- Mismatch -------------\n", stdout);
535 >                                        printf("%s@%d:\t%s", f1name,
536 >                                                        lin1cnt, l1buf.ptr);
537 >                                        printf("%s@%d:\t%s", f2name,
538 >                                                        lin2cnt, l2buf.ptr);
539                                  }
540                          }
541 +                        free_line(&l1buf); free_line(&l2buf);
542                          return(0);
543                  }
544          }
545                                                  /* check for EOF on input 2 */
546 <        while (fgets(l2buf, sizeof(l2buf), f2in)) {
547 <                if (!*sskip2(l2buf,0))
546 >        while (read_line(&l2buf, f2in)) {
547 >                if (!*sskip2(l2buf.ptr,0))
548                          continue;
549                  if (report != REP_QUIET) {
550 <                        fputs(f1name, stderr);
551 <                        fputs(": Unexpected end-of-file\n", stderr);
550 >                        fputs(f1name, stdout);
551 >                        fputs(": unexpected end-of-file\n", stdout);
552                  }
553 +                free_line(&l1buf); free_line(&l2buf);
554                  return(0);
555          }
556 +        free_line(&l1buf); free_line(&l2buf);
557          return(good_RMS());                     /* final check for reals */
558   }
559  
# Line 476 | Line 565 | compare_hdr()
565          COLOR   *scan1, *scan2;
566          int     x, y;
567  
568 +        if (report >= REP_VERBOSE) {
569 +                fputs(progname, stdout);
570 +                fputs(": comparing inputs as HDR images\n", stdout);
571 +        }
572          fgetsresolu(&rs1, f1in);
573          fgetsresolu(&rs2, f2in);
574          if (rs1.rt != rs2.rt) {
575                  if (report != REP_QUIET)
576 <                        fprintf(stderr,
576 >                        printf(
577                          "%s: Images '%s' and '%s' have different pixel ordering\n",
578                                          progname, f1name, f2name);
579                  return(0);
580          }
581          if ((rs1.xr != rs2.xr) | (rs1.yr != rs2.yr)) {
582                  if (report != REP_QUIET)
583 <                        fprintf(stderr,
583 >                        printf(
584                          "%s: Images '%s' and '%s' are different sizes\n",
585                                          progname, f1name, f2name);
586                  return(0);
# Line 502 | Line 595 | compare_hdr()
595                  if ((freadscan(scan1, scanlen(&rs1), f1in) < 0) |
596                                  (freadscan(scan2, scanlen(&rs2), f2in) < 0)) {
597                          if (report != REP_QUIET)
598 <                                fprintf(stderr, "%s: Unexpected end-of-file\n",
598 >                                printf("%s: unexpected end-of-file\n",
599                                                  progname);
600                          free(scan1);
601                          free(scan2);
602                          return(0);
603                  }
604 <                for (x = scanlen(&rs1); x--; ) {
605 <                        if (real_check(colval(scan1[x],RED),
513 <                                                colval(scan2[x],RED)) &
514 <                                        real_check(colval(scan1[x],GRN),
515 <                                                colval(scan2[x],GRN)) &
516 <                                        real_check(colval(scan1[x],BLU),
517 <                                                colval(scan2[x],BLU)))
604 >                for (x = 0; x < scanlen(&rs1); x++) {
605 >                        if (color_check(scan1[x], scan2[x]))
606                                  continue;
607                          if (report != REP_QUIET) {
608 <                                fprintf(stderr,
608 >                                printf(
609                                  "%s: pixels at scanline %d offset %d differ\n",
610                                          progname, y, x);
611                                  if (report >= REP_VERBOSE) {
612 <                                        fprintf(stderr, "%s: (R,G,B)=(%g,%g,%g)\n",
612 >                                        printf("%s: (R,G,B)=(%g,%g,%g)\n",
613                                                  f1name, colval(scan1[x],RED),
614                                                  colval(scan1[x],GRN),
615                                                  colval(scan1[x],BLU));
616 <                                        fprintf(stderr, "%s: (R,G,B)=(%g,%g,%g)\n",
616 >                                        printf("%s: (R,G,B)=(%g,%g,%g)\n",
617                                                  f2name, colval(scan2[x],RED),
618                                                  colval(scan2[x],GRN),
619                                                  colval(scan2[x],BLU));
# Line 541 | Line 629 | compare_hdr()
629          return(good_RMS());                     /* final check of RMS */
630   }
631  
544 const char      nsuffix[10][3] = {              /* 1st, 2nd, 3rd, etc. */
545                        "th","st","nd","rd","th","th","th","th","th","th"
546                };
547
632   /* Compare two inputs that are known to be 32-bit floating-point data */
633   static int
634   compare_float()
# Line 552 | Line 636 | compare_float()
636          long    nread = 0;
637          float   f1, f2;
638  
639 +        if (report >= REP_VERBOSE) {
640 +                fputs(progname, stdout);
641 +                fputs(": comparing inputs as 32-bit IEEE floats\n", stdout);
642 +        }
643          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
644                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
645                          goto badeof;
# Line 559 | Line 647 | compare_float()
647                  if (real_check(f1, f2))
648                          continue;
649                  if (report != REP_QUIET)
650 <                        fprintf(stderr, "%s: %ld%s float values differ\n",
651 <                                        progname, nread, nsuffix[nread%10]);
650 >                        printf("%s: %ld%s float values differ\n",
651 >                                        progname, nread, num_sfx(nread));
652                  return(0);
653          }
654          if (!getbinary(&f2, sizeof(f2), 1, f2in))
655                  return(good_RMS());             /* final check of RMS */
656   badeof:
657          if (report != REP_QUIET)
658 <                fprintf(stderr, "%s: Unexpected end-of-file\n", progname);
658 >                printf("%s: unexpected end-of-file\n", progname);
659          return(0);
660   }
661  
# Line 578 | Line 666 | compare_double()
666          long    nread = 0;
667          double  f1, f2;
668  
669 +        if (report >= REP_VERBOSE) {
670 +                fputs(progname, stdout);
671 +                fputs(": comparing inputs as 64-bit IEEE doubles\n", stdout);
672 +        }
673          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
674                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
675                          goto badeof;
# Line 585 | Line 677 | compare_double()
677                  if (real_check(f1, f2))
678                          continue;
679                  if (report != REP_QUIET)
680 <                        fprintf(stderr, "%s: %ld%s float values differ\n",
681 <                                        progname, nread, nsuffix[nread%10]);
680 >                        printf("%s: %ld%s double values differ\n",
681 >                                        progname, nread, num_sfx(nread));
682                  return(0);
683          }
684          if (!getbinary(&f2, sizeof(f2), 1, f2in))
685                  return(good_RMS());             /* final check of RMS */
686   badeof:
687          if (report != REP_QUIET)
688 <                fprintf(stderr, "%s: Unexpected end-of-file\n", progname);
688 >                printf("%s: unexpected end-of-file\n", progname);
689          return(0);
690   }
691  
# Line 640 | Line 732 | main(int argc, char *argv[])
732                  }
733                  break;
734          }
735 <        if (a != argc-2)
735 >        if (a != argc-2)                        /* make sure of two inputs */
736                  usage();
737 <        if (!f1name) f1name = argv[a];
646 <        if (!f2name) f2name = argv[a+1];
647 <
648 <        if (!strcmp(f1name, f2name)) {          /* inputs are same? */
737 >        if (!strcmp(argv[a], argv[a+1])) {      /* inputs are same? */
738                  if (report >= REP_WARN)
739 <                        fprintf(stderr, "%s: warning - identical inputs given\n",
739 >                        printf("%s: warning - identical inputs given\n",
740                                          progname);
741                  return(0);
742          }
743 +        if (!f1name) f1name = argv[a];
744 +        if (!f2name) f2name = argv[a+1];
745                                                  /* open inputs */
746          SET_FILE_BINARY(stdin);                 /* in case we're using it */
747          if (!f1in && !(f1in = fopen(f1name, "rb"))) {
748                  fprintf(stderr, "%s: cannot open for reading\n", f1name);
749 <                return(1);
749 >                return(2);
750          }
751          if (!strcmp(f2name, "-")) {
752                  f2in = stdin;
753                  f2name = stdin_name;
754          } else if (!(f2in = fopen(f2name, "rb"))) {
755                  fprintf(stderr, "%s: cannot open for reading\n", f2name);
756 <                return(1);
756 >                return(2);
757          }
758                                                  /* load headers */
759          if ((typ1 = identify_type(f1name, f1in, &hdr1)) < 0)
760 <                return(1);
760 >                return(2);
761          if ((typ2 = identify_type(f2name, f2in, &hdr2)) < 0)
762 <                return(1);
762 >                return(2);
763          if (typ1 != typ2) {
764                  if (report != REP_QUIET)
765 <                        fprintf(stderr, "%s: '%s' is %s and '%s' is %s\n",
765 >                        printf("%s: '%s' is %s and '%s' is %s\n",
766                                          progname, f1name, file_type[typ1],
767                                          f2name, file_type[typ2]);
768                  return(1);
769          }
770          ign_header |= !has_header(typ1);        /* check headers if indicated */
771 <        if (!ign_header && !headers_match(&hdr1, &hdr2))
771 >        if (!ign_header && !headers_match())
772                  return(1);
773          lu_done(&hdr1); lu_done(&hdr2);
774          if (!ign_header & (report >= REP_WARN)) {
775                  if (typ1 == TYP_UNKNOWN)
776 <                        fprintf(stderr, "%s: warning - unrecognized format, comparing as binary\n",
776 >                        printf("%s: warning - unrecognized format, comparing as binary\n",
777                                          progname);
778                  if (lin1cnt != lin2cnt)
779 <                        fprintf(stderr, "%s: warning - headers are different lengths\n",
779 >                        printf("%s: warning - headers are different lengths\n",
780                                          progname);
781          }
782          if (report >= REP_VERBOSE)
783 <                fprintf(stderr, "%s: input file type is %s\n",
783 >                printf("%s: input file type is %s\n",
784                                  progname, file_type[typ1]);
785  
786          switch (typ1) {                         /* compare based on type */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines