Lines 78-84
Link Here
|
78 |
int c_width; /* width or -1 if multi-column char. filler */ |
78 |
int c_width; /* width or -1 if multi-column char. filler */ |
79 |
} ; |
79 |
} ; |
80 |
|
80 |
|
81 |
static struct CHAR obuf[MAXBUF]; |
81 |
static struct CHAR sobuf[MAXBUF]; // static output buffer |
|
|
82 |
static struct CHAR *obuf = sobuf; |
83 |
static int buflen = MAXBUF; |
82 |
static int col, maxcol; |
84 |
static int col, maxcol; |
83 |
static int mode; |
85 |
static int mode; |
84 |
static int halfpos; |
86 |
static int halfpos; |
Lines 151-156
Link Here
|
151 |
else |
153 |
else |
152 |
filter(f); |
154 |
filter(f); |
153 |
} |
155 |
} |
|
|
156 |
if (obuf != sobuf) { |
157 |
free(obuf); |
158 |
} |
154 |
exit(0); |
159 |
exit(0); |
155 |
} |
160 |
} |
156 |
|
161 |
|
Lines 166-174
Link Here
|
166 |
{ |
171 |
{ |
167 |
wint_t c; |
172 |
wint_t c; |
168 |
int i, w; |
173 |
int i, w; |
|
|
174 |
int copy = 0; |
169 |
|
175 |
|
170 |
while ((c = getwc(f)) != WEOF && col < MAXBUF) switch(c) { |
176 |
while ((c = getwc(f)) != WEOF) { |
171 |
|
177 |
if (col == buflen) { |
|
|
178 |
if (obuf == sobuf) { |
179 |
obuf = NULL; |
180 |
copy = 1; |
181 |
} |
182 |
obuf = realloc(obuf, sizeof(*obuf) * 2 * buflen); |
183 |
if (obuf == NULL) { |
184 |
obuf = sobuf; |
185 |
break; |
186 |
} else if (copy) { |
187 |
memcpy(obuf, sobuf, sizeof(*obuf) * buflen); |
188 |
copy = 0; |
189 |
} |
190 |
bzero((char *)(obuf + buflen), sizeof(*obuf) * buflen); |
191 |
buflen *= 2; |
192 |
} |
193 |
switch(c) { |
172 |
case '\b': |
194 |
case '\b': |
173 |
if (col > 0) |
195 |
if (col > 0) |
174 |
col--; |
196 |
col--; |
Lines 289-294
Link Here
|
289 |
maxcol = col; |
311 |
maxcol = col; |
290 |
continue; |
312 |
continue; |
291 |
} |
313 |
} |
|
|
314 |
} |
292 |
if (ferror(f)) |
315 |
if (ferror(f)) |
293 |
err(1, NULL); |
316 |
err(1, NULL); |
294 |
if (maxcol) |
317 |
if (maxcol) |
Lines 405-411
Link Here
|
405 |
initbuf(void) |
428 |
initbuf(void) |
406 |
{ |
429 |
{ |
407 |
|
430 |
|
408 |
bzero((char *)obuf, sizeof (obuf)); /* depends on NORMAL == 0 */ |
431 |
bzero((char *)obuf, buflen * sizeof(*obuf)); /* depends on NORMAL == 0 */ |
409 |
col = 0; |
432 |
col = 0; |
410 |
maxcol = 0; |
433 |
maxcol = 0; |
411 |
mode &= ALTSET; |
434 |
mode &= ALTSET; |