17 |
|
|
18 |
|
#define MAXFILE 512 /* maximum number of files */ |
19 |
|
|
20 |
< |
#define MAXLINE 4096 /* maximum input line */ |
20 |
> |
#define MAXLINE 65536 /* maximum input line */ |
21 |
|
|
22 |
|
FILE *input[MAXFILE]; |
23 |
|
int bytsiz[MAXFILE]; |
32 |
|
char *argv[]; |
33 |
|
{ |
34 |
|
int unbuff = 0; |
35 |
+ |
int binout = 0; |
36 |
|
int i; |
37 |
|
char *curtab; |
38 |
|
int curbytes; |
68 |
|
curbytes = 1; |
69 |
|
break; |
70 |
|
case 'a': |
71 |
< |
curbytes = argv[i][3] ? 1 : 0; |
71 |
> |
curbytes = argv[i][3] ? -1 : 0; |
72 |
|
break; |
73 |
|
default: |
74 |
|
goto badopt; |
75 |
|
} |
76 |
|
if (isdigit(argv[i][3])) |
77 |
|
curbytes *= atoi(argv[i]+3); |
78 |
< |
if (curbytes < 0 || curbytes > MAXLINE) { |
78 |
> |
if (abs(curbytes) > MAXLINE) { |
79 |
|
fputs(argv[0], stderr); |
80 |
< |
fputs(": illegal input size\n", stderr); |
80 |
> |
fputs(": input size too big\n", stderr); |
81 |
|
exit(1); |
82 |
|
} |
83 |
< |
if (curbytes) |
83 |
> |
if (curbytes) { |
84 |
|
curtab = ""; |
85 |
+ |
++binout; |
86 |
+ |
} |
87 |
|
break; |
88 |
|
case '\0': |
89 |
|
tabc[nfiles] = curtab; |
90 |
< |
bytsiz[nfiles] = curbytes; |
91 |
< |
input[nfiles++] = stdin; |
90 |
> |
input[nfiles] = stdin; |
91 |
> |
if (curbytes > 0) |
92 |
> |
SET_FILE_BINARY(input[nfiles]); |
93 |
> |
else |
94 |
> |
curbytes = -curbytes; |
95 |
> |
bytsiz[nfiles++] = curbytes; |
96 |
|
break; |
97 |
|
badopt:; |
98 |
|
default: |
102 |
|
} |
103 |
|
} else if (argv[i][0] == '!') { |
104 |
|
tabc[nfiles] = curtab; |
98 |
– |
bytsiz[nfiles] = curbytes; |
105 |
|
if ((input[nfiles] = popen(argv[i]+1, "r")) == NULL) { |
106 |
|
fputs(argv[i], stderr); |
107 |
|
fputs(": cannot start command\n", stderr); |
108 |
|
exit(1); |
109 |
|
} |
110 |
< |
if (bytsiz[nfiles]) |
110 |
> |
if (curbytes > 0) |
111 |
|
SET_FILE_BINARY(input[nfiles]); |
112 |
< |
++nfiles; |
112 |
> |
else |
113 |
> |
curbytes = -curbytes; |
114 |
> |
bytsiz[nfiles++] = curbytes; |
115 |
|
} else { |
116 |
|
tabc[nfiles] = curtab; |
109 |
– |
bytsiz[nfiles] = curbytes; |
117 |
|
if ((input[nfiles] = fopen(argv[i], "r")) == NULL) { |
118 |
|
fputs(argv[i], stderr); |
119 |
|
fputs(": cannot open file\n", stderr); |
120 |
|
exit(1); |
121 |
|
} |
122 |
< |
if (bytsiz[nfiles]) |
122 |
> |
if (curbytes > 0) |
123 |
|
SET_FILE_BINARY(input[nfiles]); |
124 |
< |
++nfiles; |
124 |
> |
else |
125 |
> |
curbytes = -curbytes; |
126 |
> |
bytsiz[nfiles++] = curbytes; |
127 |
|
} |
128 |
|
if (nfiles >= MAXFILE) { |
129 |
|
fputs(argv[0], stderr); |
131 |
|
exit(1); |
132 |
|
} |
133 |
|
} |
134 |
+ |
if (binout) /* binary output? */ |
135 |
+ |
SET_FILE_BINARY(stdout); |
136 |
+ |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
137 |
+ |
for (i = nfiles; i--; ) |
138 |
+ |
flockfile(input[i]); |
139 |
+ |
flockfile(stdout); |
140 |
+ |
#endif |
141 |
|
puteol = 0; /* check for ASCII output */ |
142 |
|
for (i = nfiles; i--; ) |
143 |
|
if (!bytsiz[i] || isprint(tabc[i][0]) || tabc[i][0] == '\t') { |