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.15 by greg, Tue Mar 20 17:48:16 2018 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 getchar
19 + #undef putchar
20 + #define getchar         getchar_unlocked
21 + #define putchar         putchar_unlocked
22 + #endif
23 +
24   static gethfunc tabstr;
25 < static void getdim(register FILE *fp);
25 > static void getdim(FILE *fp);
26   static void copycat(void);
27  
28  
29   static int
30   tabstr(                         /* put out line followed by tab */
31 <        register char  *s,
31 >        char  *s,
32          void *p
33   )
34   {
# Line 47 | Line 55 | main(
55          if (argc > 1 && !strcmp(argv[1], "-d")) {
56                  argc--; argv++;
57                  dim = 1;
50                SET_DEFAULT_BINARY(); /* for output file */
58                  SET_FILE_BINARY(stdin);
59 +        } else if (argc > 2 && !strcmp(argv[1], "-c")) {
60 +                SET_FILE_BINARY(stdin);
61 +                SET_FILE_BINARY(stdout);
62 +                setvbuf(stdin, NULL, _IONBF, 2);
63 +                getheader(stdin, (gethfunc *)fputs, stdout);
64 +                printargs(argc-2, argv+2, stdout);
65 +                fputc('\n', stdout);
66 +                fflush(stdout);
67 +                execvp(argv[2], argv+2);
68 +                perror(argv[2]);
69 +                return 1;
70 +        } else if (argc > 2 && !strcmp(argv[1], "-a")) {
71 +                SET_FILE_BINARY(stdin);
72 +                SET_FILE_BINARY(stdout);
73 +                getheader(stdin, (gethfunc *)fputs, stdout);
74 +                for (i = 2; i < argc; i++) {
75 +                        int     len = strlen(argv[i]);
76 +                        if (!len) continue;
77 +                        fputs(argv[i], stdout);
78 +                        if (argv[i][len-1] != '\n')
79 +                                fputc('\n', stdout);
80 +                }
81 +                fputc('\n', stdout);
82 +                copycat();
83 +                return 0;
84          } else if (argc == 2 && !strcmp(argv[1], "-")) {
85                  SET_FILE_BINARY(stdin);
86                  SET_FILE_BINARY(stdout);
# Line 67 | Line 99 | main(
99                          } else {
100                                  tabstr(":\n", NULL);
101                                  getheader(fp, tabstr, NULL);
102 <                                putchar('\n');
102 >                                fputc('\n', stdout);
103                          }
104                          fclose(fp);
105                  }
# Line 76 | Line 108 | main(
108                  if (dim) {
109                          getdim(stdin);
110                  } else {
111 <                        getheader(stdin, (gethfunc*)fputs, stdout);
112 <                        putchar('\n');
111 >                        getheader(stdin, (gethfunc *)fputs, stdout);
112 >                        fputc('\n', stdout);
113                  }
114          }
115          return 0;
# Line 86 | Line 118 | main(
118  
119   static void
120   getdim(                         /* get dimensions from file */
121 <        register FILE  *fp
121 >        FILE  *fp
122   )
123   {
124          int  j;
125 <        register int  c;
125 >        int  c;
126  
127          getheader(fp, NULL, NULL);      /* skip header */
128  
# Line 105 | Line 137 | getdim(                                /* get dimensions from file */
137                  getc(fp);
138                  j = 0;
139                  while ((c = getc(fp)) != EOF)
140 <                        if (c == 0)
140 >                        if (c == 0) {
141                                  if (++j >= 4)
142                                          break;
143 <                                else
144 <                                        putchar(' ');
113 <                        else
143 >                                putchar(' ');
144 >                        } else {
145                                  putchar(c);
146 +                        }
147                  putchar('\n');
148                  break;
149          default:                /* ??? */
# Line 124 | Line 156 | getdim(                                /* get dimensions from file */
156   static void
157   copycat(void)                   /* copy input to output */
158   {
159 <        register int    c;
159 >        char    buf[8192];
160 >        int     n;
161  
162 <        while ((c = getchar()) != EOF)
163 <                putchar(c);
162 >        fflush(stdout);
163 >        while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
164 >                if (writebuf(fileno(stdout), buf, n) != n)
165 >                        break;
166   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines