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.1 by greg, Tue Nov 12 16:05:05 1991 UTC vs.
Revision 2.16 by greg, Tue Mar 20 18:18:39 2018 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  getinfo.c - program to read info. header from file.
6   *
# Line 11 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   */
9  
10   #include  <stdio.h>
11 + #include  <string.h>
12  
13 < extern int  fputs();
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  
26 < tabstr(s)                               /* put out line followed by tab */
27 < register char  *s;
26 > static gethfunc tabstr;
27 > static void getdim(FILE *fp);
28 > static void copycat(void);
29 >
30 >
31 > static int
32 > tabstr(                         /* put out line followed by tab */
33 >        char  *s,
34 >        void *p
35 > )
36   {
37          while (*s) {
38                  putchar(*s);
# Line 24 | Line 40 | register char  *s;
40          }
41          if (*--s == '\n')
42                  putchar('\t');
43 +        return(0);
44   }
45  
46  
47 < main(argc, argv)
48 < int  argc;
49 < char  *argv[];
47 > int
48 > main(
49 >        int  argc,
50 >        char  **argv
51 > )
52   {
53          int  dim = 0;
54          FILE  *fp;
# Line 38 | Line 57 | char  *argv[];
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);
63 +                SET_FILE_BINARY(stdout);
64 +                setvbuf(stdin, NULL, _IONBF, 2);
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], "-a")) {
73 +                SET_FILE_BINARY(stdin);
74 +                SET_FILE_BINARY(stdout);
75 +                getheader(stdin, (gethfunc *)fputs, stdout);
76 +                for (i = 2; i < argc; i++) {
77 +                        int     len = strlen(argv[i]);
78 +                        if (!len) continue;
79 +                        fputs(argv[i], stdout);
80 +                        if (argv[i][len-1] != '\n')
81 +                                fputc('\n', stdout);
82 +                }
83 +                fputc('\n', stdout);
84 +                copycat();
85 +                return 0;
86          } else if (argc == 2 && !strcmp(argv[1], "-")) {
87 <                getheader(stdin, NULL);
87 >                SET_FILE_BINARY(stdin);
88 >                SET_FILE_BINARY(stdout);
89 >                getheader(stdin, NULL, NULL);
90                  copycat();
91 <                exit(0);
91 >                return 0;
92          }
93          for (i = 1; i < argc; i++) {
94                  fputs(argv[i], stdout);
# Line 52 | Line 99 | char  *argv[];
99                                  fputs(": ", stdout);
100                                  getdim(fp);
101                          } else {
102 <                                tabstr(":\n");
102 >                                tabstr(":\n", NULL);
103                                  getheader(fp, tabstr, NULL);
104 <                                putchar('\n');
104 >                                fputc('\n', stdout);
105                          }
106                          fclose(fp);
107                  }
108          }
109 <        if (argc == 1)
109 >        if (argc == 1) {
110                  if (dim) {
111                          getdim(stdin);
112                  } else {
113 <                        getheader(stdin, fputs, stdout);
114 <                        putchar('\n');
113 >                        getheader(stdin, (gethfunc *)fputs, stdout);
114 >                        fputc('\n', stdout);
115                  }
116 <        exit(0);
116 >        }
117 >        return 0;
118   }
119  
120  
121 < getdim(fp)                              /* get dimensions from file */
122 < register FILE  *fp;
121 > static void
122 > getdim(                         /* get dimensions from file */
123 >        FILE  *fp
124 > )
125   {
126          int  j;
127 <        register int  c;
127 >        int  c;
128  
129 <        getheader(fp, NULL);    /* skip header */
129 >        getheader(fp, NULL, NULL);      /* skip header */
130  
131          switch (c = getc(fp)) {
132          case '+':               /* picture */
# Line 89 | Line 139 | register FILE  *fp;
139                  getc(fp);
140                  j = 0;
141                  while ((c = getc(fp)) != EOF)
142 <                        if (c == 0)
142 >                        if (c == 0) {
143                                  if (++j >= 4)
144                                          break;
145 <                                else
146 <                                        putchar(' ');
97 <                        else
145 >                                putchar(' ');
146 >                        } else {
147                                  putchar(c);
148 +                        }
149                  putchar('\n');
150                  break;
151          default:                /* ??? */
# Line 105 | Line 155 | register FILE  *fp;
155   }
156  
157  
158 < copycat()                       /* copy input to output */
158 > static void
159 > copycat(void)                   /* copy input to output */
160   {
161 <        register int    c;
161 >        char    buf[8192];
162 >        int     n;
163  
164 <        while ((c = getchar()) != EOF)
165 <                putchar(c);
164 >        fflush(stdout);
165 >        while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
166 >                if (writebuf(fileno(stdout), buf, n) != n)
167 >                        break;
168   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines