1 |
– |
/* Copyright (c) 1992 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 |
< |
#ifdef MSDOS |
14 |
< |
#include <fcntl.h> |
15 |
< |
extern int _fmode; |
13 |
> |
#include "platform.h" |
14 |
> |
#include "resolu.h" |
15 |
> |
|
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 |
< |
extern int fputs(); |
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 |
< |
int |
33 |
< |
tabstr(s) /* put out line followed by tab */ |
34 |
< |
register char *s; |
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); |
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; |
59 |
|
if (argc > 1 && !strcmp(argv[1], "-d")) { |
60 |
|
argc--; argv++; |
61 |
|
dim = 1; |
62 |
< |
#ifdef MSDOS |
63 |
< |
setmode(fileno(stdin), _fmode = O_BINARY); |
64 |
< |
#endif |
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 |
< |
#ifdef MSDOS |
76 |
< |
setmode(fileno(stdin), O_BINARY); |
54 |
< |
setmode(fileno(stdout), O_BINARY); |
55 |
< |
#endif |
75 |
> |
SET_FILE_BINARY(stdin); |
76 |
> |
SET_FILE_BINARY(stdout); |
77 |
|
getheader(stdin, NULL, NULL); |
78 |
|
copycat(); |
79 |
< |
exit(0); |
79 |
> |
return 0; |
80 |
|
} |
81 |
|
for (i = 1; i < argc; i++) { |
82 |
|
fputs(argv[i], stdout); |
87 |
|
fputs(": ", stdout); |
88 |
|
getdim(fp); |
89 |
|
} else { |
90 |
< |
tabstr(":\n"); |
90 |
> |
tabstr(":\n", NULL); |
91 |
|
getheader(fp, tabstr, NULL); |
92 |
< |
putchar('\n'); |
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 |
< |
getheader(stdin, fputs, 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, NULL); /* skip header */ |
118 |
|
|
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(' '); |
111 |
< |
else |
133 |
> |
putchar(' '); |
134 |
> |
} else { |
135 |
|
putchar(c); |
136 |
+ |
} |
137 |
|
putchar('\n'); |
138 |
|
break; |
139 |
|
default: /* ??? */ |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
< |
copycat() /* copy input to output */ |
146 |
> |
static void |
147 |
> |
copycat(void) /* copy input to output */ |
148 |
|
{ |
149 |
< |
register int c; |
149 |
> |
char buf[8192]; |
150 |
> |
int n; |
151 |
|
|
152 |
< |
while ((c = getchar()) != EOF) |
153 |
< |
putchar(c); |
152 |
> |
fflush(stdout); |
153 |
> |
while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) |
154 |
> |
if (write(fileno(stdout), buf, n) != n) |
155 |
> |
break; |
156 |
|
} |