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 getchar |
19 |
+ |
#undef putchar |
20 |
+ |
#define getchar getchar_unlocked |
21 |
+ |
#define putchar putchar_unlocked |
22 |
+ |
#endif |
23 |
|
|
24 |
< |
tabstr(s) /* put out line followed by tab */ |
25 |
< |
register char *s; |
24 |
> |
static gethfunc tabstr; |
25 |
> |
static void getdim(FILE *fp); |
26 |
> |
static void copycat(void); |
27 |
> |
|
28 |
> |
|
29 |
> |
static int |
30 |
> |
tabstr( /* put out line followed by tab */ |
31 |
> |
char *s, |
32 |
> |
void *p |
33 |
> |
) |
34 |
|
{ |
35 |
|
while (*s) { |
36 |
|
putchar(*s); |
38 |
|
} |
39 |
|
if (*--s == '\n') |
40 |
|
putchar('\t'); |
41 |
+ |
return(0); |
42 |
|
} |
43 |
|
|
44 |
|
|
45 |
< |
main(argc, argv) |
46 |
< |
int argc; |
47 |
< |
char *argv[]; |
45 |
> |
int |
46 |
> |
main( |
47 |
> |
int argc, |
48 |
> |
char **argv |
49 |
> |
) |
50 |
|
{ |
51 |
|
int dim = 0; |
52 |
|
FILE *fp; |
55 |
|
if (argc > 1 && !strcmp(argv[1], "-d")) { |
56 |
|
argc--; argv++; |
57 |
|
dim = 1; |
58 |
+ |
SET_FILE_BINARY(stdin); |
59 |
+ |
} else if (argc > 2 && !strcmp(argv[1], "-c")) { |
60 |
+ |
SET_FILE_BINARY(stdin); |
61 |
+ |
SET_FILE_BINARY(stdout); |
62 |
+ |
setvbuf(stdin, NULL, _IONBF, 2); |
63 |
+ |
getheader(stdin, (gethfunc *)fputs, stdout); |
64 |
+ |
printargs(argc-2, argv+2, stdout); |
65 |
+ |
fputc('\n', stdout); |
66 |
+ |
fflush(stdout); |
67 |
+ |
execvp(argv[2], argv+2); |
68 |
+ |
perror(argv[2]); |
69 |
+ |
return 1; |
70 |
+ |
} else if (argc > 2 && !strcmp(argv[1], "-a")) { |
71 |
+ |
SET_FILE_BINARY(stdin); |
72 |
+ |
SET_FILE_BINARY(stdout); |
73 |
+ |
getheader(stdin, (gethfunc *)fputs, stdout); |
74 |
+ |
for (i = 2; i < argc; i++) { |
75 |
+ |
int len = strlen(argv[i]); |
76 |
+ |
if (!len) continue; |
77 |
+ |
fputs(argv[i], stdout); |
78 |
+ |
if (argv[i][len-1] != '\n') |
79 |
+ |
fputc('\n', stdout); |
80 |
+ |
} |
81 |
+ |
fputc('\n', stdout); |
82 |
+ |
copycat(); |
83 |
+ |
return 0; |
84 |
|
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
85 |
< |
getheader(stdin, NULL); |
85 |
> |
SET_FILE_BINARY(stdin); |
86 |
> |
SET_FILE_BINARY(stdout); |
87 |
> |
getheader(stdin, NULL, NULL); |
88 |
|
copycat(); |
89 |
< |
exit(0); |
89 |
> |
return 0; |
90 |
|
} |
91 |
|
for (i = 1; i < argc; i++) { |
92 |
|
fputs(argv[i], stdout); |
97 |
|
fputs(": ", stdout); |
98 |
|
getdim(fp); |
99 |
|
} else { |
100 |
< |
tabstr(":\n"); |
100 |
> |
tabstr(":\n", NULL); |
101 |
|
getheader(fp, tabstr, NULL); |
102 |
< |
putchar('\n'); |
102 |
> |
fputc('\n', stdout); |
103 |
|
} |
104 |
|
fclose(fp); |
105 |
|
} |
106 |
|
} |
107 |
< |
if (argc == 1) |
107 |
> |
if (argc == 1) { |
108 |
|
if (dim) { |
109 |
|
getdim(stdin); |
110 |
|
} else { |
111 |
< |
getheader(stdin, fputs, stdout); |
112 |
< |
putchar('\n'); |
111 |
> |
getheader(stdin, (gethfunc *)fputs, stdout); |
112 |
> |
fputc('\n', stdout); |
113 |
|
} |
114 |
< |
exit(0); |
114 |
> |
} |
115 |
> |
return 0; |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
< |
getdim(fp) /* get dimensions from file */ |
120 |
< |
register FILE *fp; |
119 |
> |
static void |
120 |
> |
getdim( /* get dimensions from file */ |
121 |
> |
FILE *fp |
122 |
> |
) |
123 |
|
{ |
124 |
|
int j; |
125 |
< |
register int c; |
125 |
> |
int c; |
126 |
|
|
127 |
< |
getheader(fp, NULL); /* skip header */ |
127 |
> |
getheader(fp, NULL, NULL); /* skip header */ |
128 |
|
|
129 |
|
switch (c = getc(fp)) { |
130 |
|
case '+': /* picture */ |
137 |
|
getc(fp); |
138 |
|
j = 0; |
139 |
|
while ((c = getc(fp)) != EOF) |
140 |
< |
if (c == 0) |
140 |
> |
if (c == 0) { |
141 |
|
if (++j >= 4) |
142 |
|
break; |
143 |
< |
else |
144 |
< |
putchar(' '); |
97 |
< |
else |
143 |
> |
putchar(' '); |
144 |
> |
} else { |
145 |
|
putchar(c); |
146 |
+ |
} |
147 |
|
putchar('\n'); |
148 |
|
break; |
149 |
|
default: /* ??? */ |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
< |
copycat() /* copy input to output */ |
156 |
> |
static void |
157 |
> |
copycat(void) /* copy input to output */ |
158 |
|
{ |
159 |
< |
register int c; |
159 |
> |
char buf[8192]; |
160 |
> |
int n; |
161 |
|
|
162 |
< |
while ((c = getchar()) != EOF) |
163 |
< |
putchar(c); |
162 |
> |
fflush(stdout); |
163 |
> |
while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) |
164 |
> |
if (writebuf(fileno(stdout), buf, n) != n) |
165 |
> |
break; |
166 |
|
} |