14 |
|
|
15 |
|
#include "platform.h" |
16 |
|
#include "rtprocess.h" |
17 |
+ |
#include "rtio.h" |
18 |
|
|
19 |
|
#define MAXFILE 512 /* maximum number of files */ |
20 |
|
|
21 |
< |
#define MAXLINE 4096 /* maximum input line */ |
21 |
> |
#define MAXLINE 65536 /* maximum input line */ |
22 |
|
|
23 |
+ |
long incnt = 0; /* limit number of records? */ |
24 |
+ |
|
25 |
|
FILE *input[MAXFILE]; |
26 |
|
int bytsiz[MAXFILE]; |
27 |
|
char *tabc[MAXFILE]; |
35 |
|
char *argv[]; |
36 |
|
{ |
37 |
|
int unbuff = 0; |
38 |
+ |
int binout = 0; |
39 |
|
int i; |
40 |
|
char *curtab; |
41 |
|
int curbytes; |
55 |
|
break; |
56 |
|
case 'i': |
57 |
|
switch (argv[i][2]) { |
58 |
+ |
case 'n': |
59 |
+ |
incnt = atol(argv[++i]); |
60 |
+ |
break; |
61 |
|
case 'f': |
62 |
|
curbytes = sizeof(float); |
63 |
|
break; |
86 |
|
fputs(": input size too big\n", stderr); |
87 |
|
exit(1); |
88 |
|
} |
89 |
< |
if (curbytes) |
89 |
> |
if (curbytes) { |
90 |
|
curtab = ""; |
91 |
+ |
++binout; |
92 |
+ |
} |
93 |
|
break; |
94 |
|
case '\0': |
95 |
|
tabc[nfiles] = curtab; |
137 |
|
exit(1); |
138 |
|
} |
139 |
|
} |
140 |
< |
puteol = 0; /* check for ASCII output */ |
140 |
> |
if (binout) /* binary output? */ |
141 |
> |
SET_FILE_BINARY(stdout); |
142 |
> |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
143 |
|
for (i = nfiles; i--; ) |
144 |
+ |
flockfile(input[i]); |
145 |
+ |
flockfile(stdout); |
146 |
+ |
#endif |
147 |
+ |
puteol = 0; /* any ASCII output at all? */ |
148 |
+ |
for (i = nfiles; i--; ) |
149 |
|
if (!bytsiz[i] || isprint(tabc[i][0]) || tabc[i][0] == '\t') { |
150 |
|
puteol++; |
151 |
|
break; |
152 |
|
} |
153 |
< |
for ( ; ; ) { /* main loop */ |
153 |
> |
do { /* main loop */ |
154 |
|
for (i = 0; i < nfiles; i++) { |
155 |
|
if (bytsiz[i]) { /* binary file */ |
156 |
< |
if (fread(buf, bytsiz[i], 1, input[i]) < 1) |
156 |
> |
if (getbinary(buf, bytsiz[i], 1, input[i]) < 1) |
157 |
|
break; |
158 |
|
if (i) |
159 |
|
fputs(tabc[i], stdout); |
160 |
< |
fwrite(buf, bytsiz[i], 1, stdout); |
160 |
> |
putbinary(buf, bytsiz[i], 1, stdout); |
161 |
|
} else { |
162 |
|
if (fgets(buf, MAXLINE, input[i]) == NULL) |
163 |
|
break; |
173 |
|
putchar('\n'); |
174 |
|
if (unbuff) |
175 |
|
fflush(stdout); |
176 |
< |
} |
176 |
> |
} while (--incnt); |
177 |
|
return(0); |
178 |
|
} |