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.7 by schorsch, Mon Jul 21 22:30:19 2003 UTC vs.
Revision 2.10 by greg, Mon Jul 28 17:25:03 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 + #define execvp  _execvp
25 + #endif
26  
27 < int
28 < tabstr(s)                               /* put out line followed by tab */
29 < register char  *s;
27 > static gethfunc tabstr;
28 > static void getdim(FILE *fp);
29 > static void copycat(void);
30 >
31 >
32 > static int
33 > tabstr(                         /* put out line followed by tab */
34 >        char  *s,
35 >        void *p
36 > )
37   {
38          while (*s) {
39                  putchar(*s);
# Line 27 | Line 45 | register char  *s;
45   }
46  
47  
48 < main(argc, argv)
49 < int  argc;
50 < char  **argv;
48 > int
49 > main(
50 >        int  argc,
51 >        char  **argv
52 > )
53   {
54          int  dim = 0;
55          FILE  *fp;
# Line 38 | Line 58 | char  **argv;
58          if (argc > 1 && !strcmp(argv[1], "-d")) {
59                  argc--; argv++;
60                  dim = 1;
41                SET_DEFAULT_BINARY(); /* for output file */
61                  SET_FILE_BINARY(stdin);
62 +        } else if (argc > 2 && !strcmp(argv[1], "-c")) {
63 +                SET_FILE_BINARY(stdin);
64 +                SET_FILE_BINARY(stdout);
65 +                getheader(stdin, (gethfunc *)fputs, stdout);
66 +                printargs(argc-2, argv+2, stdout);
67 +                fputc('\n', stdout);
68 +                fflush(stdout);
69 +                execvp(argv[2], argv+2);
70 +                perror(argv[2]);
71 +                return 1;
72          } else if (argc == 2 && !strcmp(argv[1], "-")) {
73                  SET_FILE_BINARY(stdin);
74                  SET_FILE_BINARY(stdout);
75                  getheader(stdin, NULL, NULL);
76                  copycat();
77 <                exit(0);
77 >                return 0;
78          }
79          for (i = 1; i < argc; i++) {
80                  fputs(argv[i], stdout);
# Line 56 | Line 85 | char  **argv;
85                                  fputs(": ", stdout);
86                                  getdim(fp);
87                          } else {
88 <                                tabstr(":\n");
88 >                                tabstr(":\n", NULL);
89                                  getheader(fp, tabstr, NULL);
90 <                                putchar('\n');
90 >                                fputc('\n', stdout);
91                          }
92                          fclose(fp);
93                  }
# Line 67 | Line 96 | char  **argv;
96                  if (dim) {
97                          getdim(stdin);
98                  } else {
99 <                        getheader(stdin, fputs, stdout);
100 <                        putchar('\n');
99 >                        getheader(stdin, (gethfunc *)fputs, stdout);
100 >                        fputc('\n', stdout);
101                  }
102          }
103 <        exit(0);
103 >        return 0;
104   }
105  
106  
107 < getdim(fp)                              /* get dimensions from file */
108 < register FILE  *fp;
107 > static void
108 > getdim(                         /* get dimensions from file */
109 >        FILE  *fp
110 > )
111   {
112          int  j;
113 <        register int  c;
113 >        int  c;
114  
115          getheader(fp, NULL, NULL);      /* skip header */
116  
# Line 94 | Line 125 | register FILE  *fp;
125                  getc(fp);
126                  j = 0;
127                  while ((c = getc(fp)) != EOF)
128 <                        if (c == 0)
128 >                        if (c == 0) {
129                                  if (++j >= 4)
130                                          break;
131 <                                else
132 <                                        putchar(' ');
102 <                        else
131 >                                putchar(' ');
132 >                        } else {
133                                  putchar(c);
134 +                        }
135                  putchar('\n');
136                  break;
137          default:                /* ??? */
# Line 110 | Line 141 | register FILE  *fp;
141   }
142  
143  
144 < copycat()                       /* copy input to output */
144 > static void
145 > copycat(void)                   /* copy input to output */
146   {
147 <        register int    c;
147 >        char    buf[8192];
148 >        ssize_t n;
149  
150 <        while ((c = getchar()) != EOF)
151 <                putchar(c);
150 >        fflush(stdout);
151 >        while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
152 >                if (write(fileno(stdout), buf, n) != n)
153 >                        break;
154   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines