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 |
+ |
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 |
+ |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
66 |
+ |
return 1; |
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], "-a")) { |
74 |
+ |
SET_FILE_BINARY(stdin); |
75 |
+ |
SET_FILE_BINARY(stdout); |
76 |
+ |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
77 |
+ |
return 1; |
78 |
+ |
for (i = 2; i < argc; i++) { |
79 |
+ |
int len = strlen(argv[i]); |
80 |
+ |
if (!len) continue; |
81 |
+ |
fputs(argv[i], stdout); |
82 |
+ |
if (argv[i][len-1] != '\n') |
83 |
+ |
fputc('\n', stdout); |
84 |
+ |
} |
85 |
+ |
fputc('\n', stdout); |
86 |
+ |
copycat(); |
87 |
+ |
return 0; |
88 |
|
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
89 |
< |
getheader(stdin, NULL); |
89 |
> |
SET_FILE_BINARY(stdin); |
90 |
> |
SET_FILE_BINARY(stdout); |
91 |
> |
if (getheader(stdin, NULL, NULL) < 0) |
92 |
> |
return 1; |
93 |
|
copycat(); |
94 |
< |
exit(0); |
94 |
> |
return 0; |
95 |
|
} |
96 |
|
for (i = 1; i < argc; i++) { |
97 |
|
fputs(argv[i], stdout); |
102 |
|
fputs(": ", stdout); |
103 |
|
getdim(fp); |
104 |
|
} else { |
105 |
< |
tabstr(":\n"); |
105 |
> |
tabstr(":\n", NULL); |
106 |
|
getheader(fp, tabstr, NULL); |
107 |
< |
putchar('\n'); |
107 |
> |
fputc('\n', stdout); |
108 |
|
} |
109 |
|
fclose(fp); |
110 |
|
} |
111 |
|
} |
112 |
< |
if (argc == 1) |
112 |
> |
if (argc == 1) { |
113 |
|
if (dim) { |
114 |
|
getdim(stdin); |
115 |
|
} else { |
116 |
< |
getheader(stdin, fputs, stdout); |
117 |
< |
putchar('\n'); |
116 |
> |
if (getheader(stdin, (gethfunc *)fputs, stdout) < 0) |
117 |
> |
return 1; |
118 |
> |
fputc('\n', stdout); |
119 |
|
} |
120 |
< |
exit(0); |
120 |
> |
} |
121 |
> |
return 0; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
< |
getdim(fp) /* get dimensions from file */ |
126 |
< |
register FILE *fp; |
125 |
> |
static void |
126 |
> |
getdim( /* get dimensions from file */ |
127 |
> |
FILE *fp |
128 |
> |
) |
129 |
|
{ |
130 |
|
int j; |
131 |
< |
register int c; |
132 |
< |
|
133 |
< |
getheader(fp, NULL); /* skip header */ |
134 |
< |
|
131 |
> |
int c; |
132 |
> |
/* skip header */ |
133 |
> |
if (getheader(fp, NULL, NULL) < 0) { |
134 |
> |
fputs("bad header\n", stdout); |
135 |
> |
return; |
136 |
> |
} |
137 |
|
switch (c = getc(fp)) { |
138 |
|
case '+': /* picture */ |
139 |
|
case '-': |
145 |
|
getc(fp); |
146 |
|
j = 0; |
147 |
|
while ((c = getc(fp)) != EOF) |
148 |
< |
if (c == 0) |
148 |
> |
if (c == 0) { |
149 |
|
if (++j >= 4) |
150 |
|
break; |
151 |
< |
else |
152 |
< |
putchar(' '); |
97 |
< |
else |
151 |
> |
putchar(' '); |
152 |
> |
} else { |
153 |
|
putchar(c); |
154 |
+ |
} |
155 |
|
putchar('\n'); |
156 |
|
break; |
157 |
|
default: /* ??? */ |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
< |
copycat() /* copy input to output */ |
164 |
> |
static void |
165 |
> |
copycat(void) /* copy input to output */ |
166 |
|
{ |
167 |
< |
register int c; |
167 |
> |
char buf[8192]; |
168 |
> |
int n; |
169 |
|
|
170 |
< |
while ((c = getchar()) != EOF) |
171 |
< |
putchar(c); |
170 |
> |
fflush(stdout); |
171 |
> |
while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) |
172 |
> |
if (writebuf(fileno(stdout), buf, n) != n) |
173 |
> |
break; |
174 |
|
} |