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.13 by schorsch, Sun Mar 6 01:13:18 2016 UTC vs.
Revision 2.18 by greg, Sat Jul 6 14:08:07 2019 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11   #include  <string.h>
12  
13   #include  "platform.h"
14 + #include  "rtprocess.h"
15   #include  "resolu.h"
16  
17   #ifdef getc_unlocked            /* avoid nasty file-locking overhead */
18 + #undef getc
19   #undef getchar
20   #undef putchar
21 + #define getc            getc_unlocked
22   #define getchar         getchar_unlocked
23   #define putchar         putchar_unlocked
24   #endif
25  
23 #if defined(_WIN32) || defined(_WIN64)
24 #include <process.h>
25 #define execvp  _execvp
26 #endif
27
26   static gethfunc tabstr;
27   static void getdim(FILE *fp);
28   static void copycat(void);
# Line 59 | Line 57 | main(
57          if (argc > 1 && !strcmp(argv[1], "-d")) {
58                  argc--; argv++;
59                  dim = 1;
60 <                SET_FILE_BINARY(stdin);
61 <        } else if (argc > 2 && !strcmp(argv[1], "-c")) {
62 <                SET_FILE_BINARY(stdin);
60 >        }
61 > #ifdef getc_unlocked                            /* avoid lock/unlock overhead */
62 >        flockfile(stdin);
63 > #endif
64 >        SET_FILE_BINARY(stdin);
65 >        if (argc > 2 && !strcmp(argv[1], "-c")) {
66                  SET_FILE_BINARY(stdout);
67                  setvbuf(stdin, NULL, _IONBF, 2);
68 <                getheader(stdin, (gethfunc *)fputs, stdout);
68 >                if (getheader(stdin, (gethfunc *)fputs, stdout) < 0)
69 >                        return 1;
70                  printargs(argc-2, argv+2, stdout);
71                  fputc('\n', stdout);
72 +                if (dim) {                      /* copy resolution string? */
73 +                        RESOLU  rs;
74 +                        if (!fgetsresolu(&rs, stdin)) {
75 +                                fputs("No resolution string\n", stderr);
76 +                                return 1;
77 +                        }
78 +                        fputsresolu(&rs, stdout);
79 +                }
80                  fflush(stdout);
81                  execvp(argv[2], argv+2);
82                  perror(argv[2]);
83                  return 1;
84 +        } else if (argc > 2 && !strcmp(argv[1], "-a")) {
85 +                SET_FILE_BINARY(stdout);
86 +                if (getheader(stdin, (gethfunc *)fputs, stdout) < 0)
87 +                        return 1;
88 +                for (i = 2; i < argc; i++) {
89 +                        int     len = strlen(argv[i]);
90 +                        if (!len) continue;
91 +                        fputs(argv[i], stdout);
92 +                        if (argv[i][len-1] != '\n')
93 +                                fputc('\n', stdout);
94 +                }
95 +                fputc('\n', stdout);
96 +                copycat();
97 +                return 0;
98          } else if (argc == 2 && !strcmp(argv[1], "-")) {
75                SET_FILE_BINARY(stdin);
99                  SET_FILE_BINARY(stdout);
100 <                getheader(stdin, NULL, NULL);
100 >                if (getheader(stdin, NULL, NULL) < 0)
101 >                        return 1;
102 >                if (dim) {                      /* skip resolution string? */
103 >                        RESOLU  rs;
104 >                        if (!fgetsresolu(&rs, stdin)) {
105 >                                fputs("No resolution string\n", stderr);
106 >                                return 1;
107 >                        }
108 >                }
109                  copycat();
110                  return 0;
111          }
# Line 98 | Line 129 | main(
129                  if (dim) {
130                          getdim(stdin);
131                  } else {
132 <                        getheader(stdin, (gethfunc *)fputs, stdout);
132 >                        if (getheader(stdin, (gethfunc *)fputs, stdout) < 0)
133 >                                return 1;
134                          fputc('\n', stdout);
135                  }
136          }
# Line 113 | Line 145 | getdim(                                /* get dimensions from file */
145   {
146          int  j;
147          int  c;
148 <
149 <        getheader(fp, NULL, NULL);      /* skip header */
150 <
148 >                                /* skip header */
149 >        if (getheader(fp, NULL, NULL) < 0) {
150 >                fputs("bad header\n", stdout);
151 >                return;
152 >        }
153          switch (c = getc(fp)) {
154          case '+':               /* picture */
155          case '-':
# Line 151 | Line 185 | copycat(void)                  /* copy input to output */
185  
186          fflush(stdout);
187          while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
188 <                if (write(fileno(stdout), buf, n) != n)
188 >                if (writebuf(fileno(stdout), buf, n) != n)
189                          break;
190   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines