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 |
|
* |
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); |
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; |
57 |
|
if (argc > 1 && !strcmp(argv[1], "-d")) { |
58 |
|
argc--; argv++; |
59 |
|
dim = 1; |
60 |
+ |
} |
61 |
+ |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
62 |
+ |
flockfile(stdin); |
63 |
+ |
#endif |
64 |
+ |
SET_FILE_BINARY(stdin); |
65 |
+ |
if (argc > 2 && !strcmp(argv[1], "-c")) { |
66 |
+ |
SET_FILE_BINARY(stdout); |
67 |
+ |
setvbuf(stdin, NULL, _IONBF, 2); |
68 |
+ |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
69 |
+ |
return 1; |
70 |
+ |
printargs(argc-2, argv+2, stdout); |
71 |
+ |
fputc('\n', stdout); |
72 |
+ |
if (dim) { /* copy resolution string? */ |
73 |
+ |
RESOLU rs; |
74 |
+ |
if (!fgetsresolu(&rs, stdin)) { |
75 |
+ |
fputs("No resolution string\n", stderr); |
76 |
+ |
return 1; |
77 |
+ |
} |
78 |
+ |
fputsresolu(&rs, stdout); |
79 |
+ |
} |
80 |
+ |
fflush(stdout); |
81 |
+ |
execvp(argv[2], argv+2); |
82 |
+ |
perror(argv[2]); |
83 |
+ |
return 1; |
84 |
+ |
} else if (argc > 2 && !strcmp(argv[1], "-a")) { |
85 |
+ |
SET_FILE_BINARY(stdout); |
86 |
+ |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
87 |
+ |
return 1; |
88 |
+ |
for (i = 2; i < argc; i++) { |
89 |
+ |
int len = strlen(argv[i]); |
90 |
+ |
if (!len) continue; |
91 |
+ |
fputs(argv[i], stdout); |
92 |
+ |
if (argv[i][len-1] != '\n') |
93 |
+ |
fputc('\n', stdout); |
94 |
+ |
} |
95 |
+ |
fputc('\n', stdout); |
96 |
+ |
copycat(); |
97 |
+ |
return 0; |
98 |
|
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
99 |
< |
getheader(stdin, NULL); |
99 |
> |
SET_FILE_BINARY(stdout); |
100 |
> |
if (getheader(stdin, NULL, NULL) < 0) |
101 |
> |
return 1; |
102 |
> |
if (dim) { /* skip resolution string? */ |
103 |
> |
RESOLU rs; |
104 |
> |
if (!fgetsresolu(&rs, stdin)) { |
105 |
> |
fputs("No resolution string\n", stderr); |
106 |
> |
return 1; |
107 |
> |
} |
108 |
> |
} |
109 |
|
copycat(); |
110 |
< |
exit(0); |
110 |
> |
return 0; |
111 |
|
} |
112 |
|
for (i = 1; i < argc; i++) { |
113 |
|
fputs(argv[i], stdout); |
118 |
|
fputs(": ", stdout); |
119 |
|
getdim(fp); |
120 |
|
} else { |
121 |
< |
tabstr(":\n"); |
121 |
> |
tabstr(":\n", NULL); |
122 |
|
getheader(fp, tabstr, NULL); |
123 |
< |
putchar('\n'); |
123 |
> |
fputc('\n', stdout); |
124 |
|
} |
125 |
|
fclose(fp); |
126 |
|
} |
127 |
|
} |
128 |
< |
if (argc == 1) |
128 |
> |
if (argc == 1) { |
129 |
|
if (dim) { |
130 |
|
getdim(stdin); |
131 |
|
} else { |
132 |
< |
getheader(stdin, fputs, stdout); |
133 |
< |
putchar('\n'); |
132 |
> |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
133 |
> |
return 1; |
134 |
> |
fputc('\n', stdout); |
135 |
|
} |
136 |
< |
exit(0); |
136 |
> |
} |
137 |
> |
return 0; |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
< |
getdim(fp) /* get dimensions from file */ |
142 |
< |
register FILE *fp; |
141 |
> |
static void |
142 |
> |
getdim( /* get dimensions from file */ |
143 |
> |
FILE *fp |
144 |
> |
) |
145 |
|
{ |
146 |
|
int j; |
147 |
< |
register int c; |
148 |
< |
|
149 |
< |
getheader(fp, NULL); /* skip header */ |
150 |
< |
|
147 |
> |
int c; |
148 |
> |
/* skip header */ |
149 |
> |
if (getheader(fp, NULL, NULL) < 0) { |
150 |
> |
fputs("bad header\n", stdout); |
151 |
> |
return; |
152 |
> |
} |
153 |
|
switch (c = getc(fp)) { |
154 |
|
case '+': /* picture */ |
155 |
|
case '-': |
161 |
|
getc(fp); |
162 |
|
j = 0; |
163 |
|
while ((c = getc(fp)) != EOF) |
164 |
< |
if (c == 0) |
164 |
> |
if (c == 0) { |
165 |
|
if (++j >= 4) |
166 |
|
break; |
167 |
< |
else |
168 |
< |
putchar(' '); |
97 |
< |
else |
167 |
> |
putchar(' '); |
168 |
> |
} else { |
169 |
|
putchar(c); |
170 |
+ |
} |
171 |
|
putchar('\n'); |
172 |
|
break; |
173 |
|
default: /* ??? */ |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
< |
copycat() /* copy input to output */ |
180 |
> |
static void |
181 |
> |
copycat(void) /* copy input to output */ |
182 |
|
{ |
183 |
< |
register int c; |
183 |
> |
char buf[8192]; |
184 |
> |
int n; |
185 |
|
|
186 |
< |
while ((c = getchar()) != EOF) |
187 |
< |
putchar(c); |
186 |
> |
fflush(stdout); |
187 |
> |
while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) |
188 |
> |
if (writebuf(fileno(stdout), buf, n) != n) |
189 |
> |
break; |
190 |
|
} |