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 |
> |
#define execvp _execvp |
25 |
> |
#endif |
26 |
|
|
27 |
+ |
static gethfunc tabstr; |
28 |
+ |
static void getdim(FILE *fp); |
29 |
+ |
static void copycat(void); |
30 |
|
|
31 |
< |
tabstr(s) /* put out line followed by tab */ |
32 |
< |
register char *s; |
31 |
> |
|
32 |
> |
static int |
33 |
> |
tabstr( /* put out line followed by tab */ |
34 |
> |
char *s, |
35 |
> |
void *p |
36 |
> |
) |
37 |
|
{ |
38 |
|
while (*s) { |
39 |
|
putchar(*s); |
41 |
|
} |
42 |
|
if (*--s == '\n') |
43 |
|
putchar('\t'); |
44 |
+ |
return(0); |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
< |
main(argc, argv) |
49 |
< |
int argc; |
50 |
< |
char **argv; |
48 |
> |
int |
49 |
> |
main( |
50 |
> |
int argc, |
51 |
> |
char **argv |
52 |
> |
) |
53 |
|
{ |
54 |
|
int dim = 0; |
55 |
|
FILE *fp; |
58 |
|
if (argc > 1 && !strcmp(argv[1], "-d")) { |
59 |
|
argc--; argv++; |
60 |
|
dim = 1; |
61 |
< |
#ifdef MSDOS |
62 |
< |
setmode(fileno(stdin), _fmode = O_BINARY); |
63 |
< |
#endif |
61 |
> |
SET_FILE_BINARY(stdin); |
62 |
> |
} else if (argc > 2 && !strcmp(argv[1], "-c")) { |
63 |
> |
SET_FILE_BINARY(stdin); |
64 |
> |
SET_FILE_BINARY(stdout); |
65 |
> |
getheader(stdin, (gethfunc *)fputs, stdout); |
66 |
> |
printargs(argc-2, argv+2, stdout); |
67 |
> |
fputc('\n', stdout); |
68 |
> |
fflush(stdout); |
69 |
> |
execvp(argv[2], argv+2); |
70 |
> |
perror(argv[2]); |
71 |
> |
return 1; |
72 |
|
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
73 |
< |
#ifdef MSDOS |
74 |
< |
setmode(fileno(stdin), O_BINARY); |
52 |
< |
setmode(fileno(stdout), O_BINARY); |
53 |
< |
#endif |
73 |
> |
SET_FILE_BINARY(stdin); |
74 |
> |
SET_FILE_BINARY(stdout); |
75 |
|
getheader(stdin, NULL, NULL); |
76 |
|
copycat(); |
77 |
< |
exit(0); |
77 |
> |
return 0; |
78 |
|
} |
79 |
|
for (i = 1; i < argc; i++) { |
80 |
|
fputs(argv[i], stdout); |
85 |
|
fputs(": ", stdout); |
86 |
|
getdim(fp); |
87 |
|
} else { |
88 |
< |
tabstr(":\n"); |
88 |
> |
tabstr(":\n", NULL); |
89 |
|
getheader(fp, tabstr, NULL); |
90 |
< |
putchar('\n'); |
90 |
> |
fputc('\n', stdout); |
91 |
|
} |
92 |
|
fclose(fp); |
93 |
|
} |
94 |
|
} |
95 |
< |
if (argc == 1) |
95 |
> |
if (argc == 1) { |
96 |
|
if (dim) { |
97 |
|
getdim(stdin); |
98 |
|
} else { |
99 |
< |
getheader(stdin, fputs, stdout); |
100 |
< |
putchar('\n'); |
99 |
> |
getheader(stdin, (gethfunc *)fputs, stdout); |
100 |
> |
fputc('\n', stdout); |
101 |
|
} |
102 |
< |
exit(0); |
102 |
> |
} |
103 |
> |
return 0; |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
< |
getdim(fp) /* get dimensions from file */ |
108 |
< |
register FILE *fp; |
107 |
> |
static void |
108 |
> |
getdim( /* get dimensions from file */ |
109 |
> |
FILE *fp |
110 |
> |
) |
111 |
|
{ |
112 |
|
int j; |
113 |
< |
register int c; |
113 |
> |
int c; |
114 |
|
|
115 |
|
getheader(fp, NULL, NULL); /* skip header */ |
116 |
|
|
125 |
|
getc(fp); |
126 |
|
j = 0; |
127 |
|
while ((c = getc(fp)) != EOF) |
128 |
< |
if (c == 0) |
128 |
> |
if (c == 0) { |
129 |
|
if (++j >= 4) |
130 |
|
break; |
131 |
< |
else |
132 |
< |
putchar(' '); |
109 |
< |
else |
131 |
> |
putchar(' '); |
132 |
> |
} else { |
133 |
|
putchar(c); |
134 |
+ |
} |
135 |
|
putchar('\n'); |
136 |
|
break; |
137 |
|
default: /* ??? */ |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
< |
copycat() /* copy input to output */ |
144 |
> |
static void |
145 |
> |
copycat(void) /* copy input to output */ |
146 |
|
{ |
147 |
< |
register int c; |
147 |
> |
char buf[8192]; |
148 |
> |
ssize_t n; |
149 |
|
|
150 |
< |
while ((c = getchar()) != EOF) |
151 |
< |
putchar(c); |
150 |
> |
fflush(stdout); |
151 |
> |
while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) |
152 |
> |
if (write(fileno(stdout), buf, n) != n) |
153 |
> |
break; |
154 |
|
} |