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

Comparing ray/src/util/getinfo.c (file contents):
Revision 2.18 by greg, Sat Jul 6 14:08:07 2019 UTC vs.
Revision 2.21 by greg, Wed Jul 24 17:27:54 2019 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *     1/3/86
8   */
9  
10 < #include  <stdio.h>
11 < #include  <string.h>
12 <
10 > #include  "rtio.h"
11   #include  "platform.h"
12   #include  "rtprocess.h"
13   #include  "resolu.h"
# Line 54 | Line 52 | main(
52          FILE  *fp;
53          int  i;
54  
55 <        if (argc > 1 && !strcmp(argv[1], "-d")) {
55 >        if (argc > 1 && (argv[1][0] == '-') | (argv[1][0] == '+') &&
56 >                        argv[1][1] == 'd') {
57 >                dim = 1 - 2*(argv[1][0] == '-');
58                  argc--; argv++;
59                dim = 1;
59          }
60   #ifdef getc_unlocked                            /* avoid lock/unlock overhead */
61          flockfile(stdin);
# Line 65 | Line 64 | main(
64          if (argc > 2 && !strcmp(argv[1], "-c")) {
65                  SET_FILE_BINARY(stdout);
66                  setvbuf(stdin, NULL, _IONBF, 2);
67 <                if (getheader(stdin, (gethfunc *)fputs, stdout) < 0)
67 >                if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) {
68 >                        fputs("Bad header!\n", stderr);
69                          return 1;
70 +                }
71                  printargs(argc-2, argv+2, stdout);
72                  fputc('\n', stdout);
73                  if (dim) {                      /* copy resolution string? */
74                          RESOLU  rs;
75                          if (!fgetsresolu(&rs, stdin)) {
76 <                                fputs("No resolution string\n", stderr);
76 >                                fputs("No resolution string!\n", stderr);
77                                  return 1;
78                          }
79 <                        fputsresolu(&rs, stdout);
79 >                        if (dim > 0)
80 >                                fputsresolu(&rs, stdout);
81                  }
82                  fflush(stdout);
83                  execvp(argv[2], argv+2);
# Line 83 | Line 85 | main(
85                  return 1;
86          } else if (argc > 2 && !strcmp(argv[1], "-a")) {
87                  SET_FILE_BINARY(stdout);
88 <                if (getheader(stdin, (gethfunc *)fputs, stdout) < 0)
88 >                if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) {
89 >                        fputs("Bad header!\n", stderr);
90                          return 1;
91 +                }
92                  for (i = 2; i < argc; i++) {
93                          int     len = strlen(argv[i]);
94                          if (!len) continue;
# Line 97 | Line 101 | main(
101                  return 0;
102          } else if (argc == 2 && !strcmp(argv[1], "-")) {
103                  SET_FILE_BINARY(stdout);
104 <                if (getheader(stdin, NULL, NULL) < 0)
104 >                if (getheader(stdin, NULL, NULL) < 0) {
105 >                        fputs("Bad header!\n", stderr);
106                          return 1;
107 <                if (dim) {                      /* skip resolution string? */
107 >                }
108 >                if (dim < 0) {                  /* skip resolution string? */
109                          RESOLU  rs;
110                          if (!fgetsresolu(&rs, stdin)) {
111 <                                fputs("No resolution string\n", stderr);
111 >                                fputs("No resolution string!\n", stderr);
112                                  return 1;
113                          }
114                  }
# Line 114 | Line 120 | main(
120                  if ((fp = fopen(argv[i], "r")) == NULL)
121                          fputs(": cannot open\n", stdout);
122                  else {
123 <                        if (dim) {
123 >                        if (dim < 0) {                  /* dimensions only */
124 >                                if (getheader(fp, NULL, NULL) < 0) {
125 >                                        fputs("bad header!\n", stdout);
126 >                                        continue;      
127 >                                }
128                                  fputs(": ", stdout);
129                                  getdim(fp);
130                          } else {
131                                  tabstr(":\n", NULL);
132 <                                getheader(fp, tabstr, NULL);
132 >                                if (getheader(fp, tabstr, NULL) < 0) {
133 >                                        fputs(argv[i], stderr);
134 >                                        fputs(": bad header!\n", stderr);
135 >                                        return 1;
136 >                                }
137                                  fputc('\n', stdout);
138 +                                if (dim > 0) {
139 +                                        fputc('\t', stdout);
140 +                                        getdim(fp);
141 +                                }
142                          }
143                          fclose(fp);
144                  }
145          }
146          if (argc == 1) {
147 <                if (dim) {
147 >                if (dim < 0) {
148 >                        if (getheader(stdin, NULL, NULL) < 0) {
149 >                                fputs("Bad header!\n", stderr);
150 >                                return 1;      
151 >                        }
152                          getdim(stdin);
153                  } else {
154 <                        if (getheader(stdin, (gethfunc *)fputs, stdout) < 0)
154 >                        if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) {
155 >                                fputs("Bad header!\n", stderr);
156                                  return 1;
157 +                        }
158                          fputc('\n', stdout);
159 +                        if (dim > 0)
160 +                                getdim(stdin);
161                  }
162          }
163          return 0;
# Line 145 | Line 171 | getdim(                                /* get dimensions from file */
171   {
172          int  j;
173          int  c;
174 <                                /* skip header */
149 <        if (getheader(fp, NULL, NULL) < 0) {
150 <                fputs("bad header\n", stdout);
151 <                return;
152 <        }
174 >
175          switch (c = getc(fp)) {
176          case '+':               /* picture */
177          case '-':

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines