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.6 by schorsch, Thu Jun 5 19:29:35 2003 UTC vs.
Revision 2.11 by greg, Mon Jul 28 20:12:20 2014 UTC

# Line 8 | Line 8 | static const char      RCSid[] = "$Id$";
8   */
9  
10   #include  <stdio.h>
11 + #include  <string.h>
12  
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 < int
29 < tabstr(s)                               /* put out line followed by tab */
30 < register char  *s;
28 > static gethfunc tabstr;
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 >        char  *s,
36 >        void *p
37 > )
38   {
39          while (*s) {
40                  putchar(*s);
# Line 27 | Line 46 | register char  *s;
46   }
47  
48  
49 < main(argc, argv)
50 < int  argc;
51 < char  **argv;
49 > int
50 > main(
51 >        int  argc,
52 >        char  **argv
53 > )
54   {
55          int  dim = 0;
56          FILE  *fp;
# Line 38 | Line 59 | char  **argv;
59          if (argc > 1 && !strcmp(argv[1], "-d")) {
60                  argc--; argv++;
61                  dim = 1;
41                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 +                getheader(stdin, (gethfunc *)fputs, stdout);
67 +                printargs(argc-2, argv+2, stdout);
68 +                fputc('\n', stdout);
69 +                fflush(stdout);
70 +                execvp(argv[2], argv+2);
71 +                perror(argv[2]);
72 +                return 1;
73          } else if (argc == 2 && !strcmp(argv[1], "-")) {
74                  SET_FILE_BINARY(stdin);
75                  SET_FILE_BINARY(stdout);
76                  getheader(stdin, NULL, NULL);
77                  copycat();
78 <                exit(0);
78 >                return 0;
79          }
80          for (i = 1; i < argc; i++) {
81                  fputs(argv[i], stdout);
# Line 56 | Line 86 | char  **argv;
86                                  fputs(": ", stdout);
87                                  getdim(fp);
88                          } else {
89 <                                tabstr(":\n");
89 >                                tabstr(":\n", NULL);
90                                  getheader(fp, tabstr, NULL);
91 <                                putchar('\n');
91 >                                fputc('\n', stdout);
92                          }
93                          fclose(fp);
94                  }
95          }
96 <        if (argc == 1)
96 >        if (argc == 1) {
97                  if (dim) {
98                          getdim(stdin);
99                  } else {
100 <                        getheader(stdin, fputs, stdout);
101 <                        putchar('\n');
100 >                        getheader(stdin, (gethfunc *)fputs, stdout);
101 >                        fputc('\n', stdout);
102                  }
103 <        exit(0);
103 >        }
104 >        return 0;
105   }
106  
107  
108 < getdim(fp)                              /* get dimensions from file */
109 < register FILE  *fp;
108 > static void
109 > getdim(                         /* get dimensions from file */
110 >        FILE  *fp
111 > )
112   {
113          int  j;
114 <        register int  c;
114 >        int  c;
115  
116          getheader(fp, NULL, NULL);      /* skip header */
117  
# Line 93 | Line 126 | register FILE  *fp;
126                  getc(fp);
127                  j = 0;
128                  while ((c = getc(fp)) != EOF)
129 <                        if (c == 0)
129 >                        if (c == 0) {
130                                  if (++j >= 4)
131                                          break;
132 <                                else
133 <                                        putchar(' ');
101 <                        else
132 >                                putchar(' ');
133 >                        } else {
134                                  putchar(c);
135 +                        }
136                  putchar('\n');
137                  break;
138          default:                /* ??? */
# Line 109 | Line 142 | register FILE  *fp;
142   }
143  
144  
145 < copycat()                       /* copy input to output */
145 > static void
146 > copycat(void)                   /* copy input to output */
147   {
148 <        register int    c;
148 >        char    buf[8192];
149 >        int     n;
150  
151 <        while ((c = getchar()) != EOF)
152 <                putchar(c);
151 >        fflush(stdout);
152 >        while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
153 >                if (write(fileno(stdout), buf, n) != n)
154 >                        break;
155   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines