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 1.1 by greg, Thu Feb 2 10:49:19 1989 UTC vs.
Revision 2.11 by greg, Mon Jul 28 20:12:20 2014 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 + #include  "platform.h"
14 + #include  "resolu.h"
15  
16 < tabstr(s)                               /* put out line followed by tab */
17 < register char  *s;
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(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 22 | Line 42 | register char  *s;
42          }
43          if (*--s == '\n')
44                  putchar('\t');
45 +        return(0);
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 36 | Line 59 | char  *argv[];
59          if (argc > 1 && !strcmp(argv[1], "-d")) {
60                  argc--; argv++;
61                  dim = 1;
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 +                return 0;
79          }
80          for (i = 1; i < argc; i++) {
81                  fputs(argv[i], stdout);
# Line 46 | Line 86 | char  *argv[];
86                                  fputs(": ", stdout);
87                                  getdim(fp);
88                          } else {
89 <                                tabstr(":\n");
90 <                                getheader(fp, tabstr);
91 <                                putchar('\n');
89 >                                tabstr(":\n", NULL);
90 >                                getheader(fp, tabstr, NULL);
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 <                        copyheader(stdin, 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);    /* skip header */
116 >        getheader(fp, NULL, NULL);      /* skip header */
117  
118          switch (c = getc(fp)) {
119          case '+':               /* picture */
# Line 83 | 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(' ');
91 <                        else
132 >                                putchar(' ');
133 >                        } else {
134                                  putchar(c);
135 +                        }
136                  putchar('\n');
137                  break;
138          default:                /* ??? */
139                  fputs("unknown file type\n", stdout);
140                  break;
141          }
142 + }
143 +
144 +
145 + static void
146 + copycat(void)                   /* copy input to output */
147 + {
148 +        char    buf[8192];
149 +        int     n;
150 +
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