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.12 by greg, Mon Sep 8 18:21:39 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 +                setvbuf(stdin, NULL, _IONBF, 2);
67 +                getheader(stdin, (gethfunc *)fputs, stdout);
68 +                printargs(argc-2, argv+2, stdout);
69 +                fputc('\n', stdout);
70 +                fflush(stdout);
71 +                execvp(argv[2], argv+2);
72 +                perror(argv[2]);
73 +                return 1;
74 +        } else if (argc == 2 && !strcmp(argv[1], "-")) {
75 +                SET_FILE_BINARY(stdin);
76 +                SET_FILE_BINARY(stdout);
77 +                getheader(stdin, NULL, NULL);
78 +                copycat();
79 +                return 0;
80          }
81          for (i = 1; i < argc; i++) {
82                  fputs(argv[i], stdout);
# Line 46 | Line 87 | char  *argv[];
87                                  fputs(": ", stdout);
88                                  getdim(fp);
89                          } else {
90 <                                tabstr(":\n");
91 <                                getheader(fp, tabstr);
92 <                                putchar('\n');
90 >                                tabstr(":\n", NULL);
91 >                                getheader(fp, tabstr, NULL);
92 >                                fputc('\n', stdout);
93                          }
94                          fclose(fp);
95                  }
96          }
97 <        if (argc == 1)
97 >        if (argc == 1) {
98                  if (dim) {
99                          getdim(stdin);
100                  } else {
101 <                        copyheader(stdin, stdout);
102 <                        putchar('\n');
101 >                        getheader(stdin, (gethfunc *)fputs, stdout);
102 >                        fputc('\n', stdout);
103                  }
104 <        exit(0);
104 >        }
105 >        return 0;
106   }
107  
108  
109 < getdim(fp)                              /* get dimensions from file */
110 < register FILE  *fp;
109 > static void
110 > getdim(                         /* get dimensions from file */
111 >        FILE  *fp
112 > )
113   {
114          int  j;
115 <        register int  c;
115 >        int  c;
116  
117 <        getheader(fp, NULL);    /* skip header */
117 >        getheader(fp, NULL, NULL);      /* skip header */
118  
119          switch (c = getc(fp)) {
120          case '+':               /* picture */
# Line 83 | Line 127 | register FILE  *fp;
127                  getc(fp);
128                  j = 0;
129                  while ((c = getc(fp)) != EOF)
130 <                        if (c == 0)
130 >                        if (c == 0) {
131                                  if (++j >= 4)
132                                          break;
133 <                                else
134 <                                        putchar(' ');
91 <                        else
133 >                                putchar(' ');
134 >                        } else {
135                                  putchar(c);
136 +                        }
137                  putchar('\n');
138                  break;
139          default:                /* ??? */
140                  fputs("unknown file type\n", stdout);
141                  break;
142          }
143 + }
144 +
145 +
146 + static void
147 + copycat(void)                   /* copy input to output */
148 + {
149 +        char    buf[8192];
150 +        int     n;
151 +
152 +        fflush(stdout);
153 +        while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0)
154 +                if (write(fileno(stdout), buf, n) != n)
155 +                        break;
156   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines