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.8 by schorsch, Fri Jan 2 11:44:24 2004 UTC vs.
Revision 2.12 by greg, Mon Sep 8 18:21:39 2014 UTC

# Line 13 | Line 13 | static const char      RCSid[] = "$Id$";
13   #include  "platform.h"
14   #include  "resolu.h"
15  
16 + #ifdef getc_unlocked            /* avoid nasty file-locking overhead */
17 + #undef getchar
18 + #undef putchar
19 + #define getchar         getchar_unlocked
20 + #define putchar         putchar_unlocked
21 + #endif
22 +
23 + #ifdef _WIN32
24 + #include <process.h>
25 + #define execvp  _execvp
26 + #endif
27 +
28   static gethfunc tabstr;
29 < static void getdim(register FILE *fp);
29 > static void getdim(FILE *fp);
30   static void copycat(void);
31  
32  
33   static int
34   tabstr(                         /* put out line followed by tab */
35 <        register char  *s,
35 >        char  *s,
36          void *p
37   )
38   {
# Line 47 | Line 59 | main(
59          if (argc > 1 && !strcmp(argv[1], "-d")) {
60                  argc--; argv++;
61                  dim = 1;
50                SET_DEFAULT_BINARY(); /* for output file */
62                  SET_FILE_BINARY(stdin);
63 +        } else if (argc > 2 && !strcmp(argv[1], "-c")) {
64 +                SET_FILE_BINARY(stdin);
65 +                SET_FILE_BINARY(stdout);
66 +                setvbuf(stdin, NULL, _IONBF, 2);
67 +                getheader(stdin, (gethfunc *)fputs, stdout);
68 +                printargs(argc-2, argv+2, stdout);
69 +                fputc('\n', stdout);
70 +                fflush(stdout);
71 +                execvp(argv[2], argv+2);
72 +                perror(argv[2]);
73 +                return 1;
74          } else if (argc == 2 && !strcmp(argv[1], "-")) {
75                  SET_FILE_BINARY(stdin);
76                  SET_FILE_BINARY(stdout);
# Line 67 | Line 89 | main(
89                          } else {
90                                  tabstr(":\n", NULL);
91                                  getheader(fp, tabstr, NULL);
92 <                                putchar('\n');
92 >                                fputc('\n', stdout);
93                          }
94                          fclose(fp);
95                  }
# Line 76 | Line 98 | main(
98                  if (dim) {
99                          getdim(stdin);
100                  } else {
101 <                        getheader(stdin, (gethfunc*)fputs, stdout);
102 <                        putchar('\n');
101 >                        getheader(stdin, (gethfunc *)fputs, stdout);
102 >                        fputc('\n', stdout);
103                  }
104          }
105          return 0;
# Line 86 | Line 108 | main(
108  
109   static void
110   getdim(                         /* get dimensions from file */
111 <        register FILE  *fp
111 >        FILE  *fp
112   )
113   {
114          int  j;
115 <        register int  c;
115 >        int  c;
116  
117          getheader(fp, NULL, NULL);      /* skip header */
118  
# Line 105 | Line 127 | getdim(                                /* get dimensions from file */
127                  getc(fp);
128                  j = 0;
129                  while ((c = getc(fp)) != EOF)
130 <                        if (c == 0)
130 >                        if (c == 0) {
131                                  if (++j >= 4)
132                                          break;
133 <                                else
134 <                                        putchar(' ');
113 <                        else
133 >                                putchar(' ');
134 >                        } else {
135                                  putchar(c);
136 +                        }
137                  putchar('\n');
138                  break;
139          default:                /* ??? */
# Line 124 | Line 146 | getdim(                                /* get dimensions from file */
146   static void
147   copycat(void)                   /* copy input to output */
148   {
149 <        register int    c;
149 >        char    buf[8192];
150 >        int     n;
151  
152 <        while ((c = getchar()) != EOF)
153 <                putchar(c);
152 >        fflush(stdout);
153 >        while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
154 >                if (write(fileno(stdout), buf, n) != n)
155 >                        break;
156   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines