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

Comparing ray/src/rt/lookamb.c (file contents):
Revision 1.5 by greg, Fri Jun 7 14:24:34 1991 UTC vs.
Revision 2.4 by greg, Thu Oct 15 21:13:13 1992 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include  <stdio.h>
14  
15 + #ifdef MSDOS
16 + #include  <fcntl.h>
17 + #endif
18 +
19   #include  "color.h"
20  
21   #include  "ambient.h"
22  
23  
24   int  dataonly = 0;
25 <
25 > int  header = 1;
26   int  reverse = 0;
27  
28   AMBVAL  av;
# Line 39 | Line 43 | char  *argv[];
43                          case 'r':
44                                  reverse = 1;
45                                  break;
46 +                        case 'h':
47 +                                header = 0;
48 +                                break;
49                          default:
50                                  fprintf(stderr, "%s: unknown option '%s'\n",
51                                                  argv[0], argv[i]);
# Line 53 | Line 60 | char  *argv[];
60                  fprintf(stderr, "%s: file not found\n", argv[i]);
61                  return(1);
62          }
63 <        if (reverse)
63 >        if (reverse) {
64 >                if (header) {
65 >                        if (checkheader(fp, "ascii", stdout) < 0)
66 >                                goto formaterr;
67 >                } else
68 >                        printargs(argc, argv, stdout);
69 >                fputformat(AMBFMT, stdout);
70 >                putchar('\n');
71 > #ifdef MSDOS
72 >                setmode(fileno(stdout), O_BINARY);
73 > #endif
74 >                putambmagic(stdout);
75                  writamb(fp);
76 <        else
76 >        } else {
77 > #ifdef MSDOS
78 >                setmode(fileno(fp), O_BINARY);
79 > #endif
80 >                if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0)
81 >                        goto formaterr;
82 >                if (!hasambmagic(fp))
83 >                        goto formaterr;
84 >                if (header) {
85 >                        fputformat("ascii", stdout);
86 >                        putchar('\n');
87 >                }
88                  lookamb(fp);
89 +        }
90          fclose(fp);
91          return(0);
92 + formaterr:
93 +        fprintf(stderr, "%s: format error on input\n", argv[0]);
94 +        exit(1);
95   }
96  
97  
98   lookamb(fp)                     /* get ambient values from a file */
99   FILE  *fp;
100   {
101 <        while (fread((char *)&av, sizeof(AMBVAL), 1, fp) == 1) {
101 >        while (readambval(&av, fp)) {
102                  if (dataonly) {
103                          printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
104                          printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
# Line 132 | Line 165 | FILE  *fp;
165                                  &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3)
166                          return;
167                  av.next = NULL;
168 <                fwrite((char *)&av, sizeof(AMBVAL), 1, stdout);
168 >                writambval(&av, stdout);
169                  if (ferror(stdout))
170                          exit(1);
171          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines