#include <string.h>
#include <stdio.h>
#include <unistd.h>
-#include "nls.h"
+#include "nls.h"
+#include "xalloc.h"
#include "widechar.h"
#define BS '\b' /* backspace */
void usage(void);
void wrerr(void);
-void warn(int);
void free_line(LINE *l);
void flush_line(LINE *l);
void flush_lines(int);
void flush_blanks(void);
-void *xmalloc(void *p, size_t size);
LINE *alloc_line(void);
CSET last_set; /* char_set of last char printed */
}
} else {
if (!warned++)
- warn(cur_line);
+ fprintf(stderr,
+ _("col: warning: can't back up %s.\n"), cur_line < 0 ?
+ _("past first line") : _("-- line already flushed"));
cur_line -= nmove;
}
}
int need;
need = l->l_lsize ? l->l_lsize * 2 : 90;
- l->l_line = (CHAR *)xmalloc((void *) l->l_line,
- (unsigned) need * sizeof(CHAR));
+ l->l_line = (CHAR *)xrealloc((void *) l->l_line,
+ (unsigned) need * sizeof(CHAR));
l->l_lsize = need;
}
c = &l->l_line[l->l_line_len++];
*/
if (l->l_lsize > sorted_size) {
sorted_size = l->l_lsize;
- sorted = (CHAR *)xmalloc((void *)sorted,
- (unsigned)sizeof(CHAR) * sorted_size);
+ sorted = (CHAR *)xrealloc((void *)sorted,
+ (unsigned)sizeof(CHAR) * sorted_size);
}
if (l->l_max_col >= count_size) {
count_size = l->l_max_col + 1;
- count = (int *)xmalloc((void *)count,
+ count = (int *)xrealloc((void *)count,
(unsigned)sizeof(int) * count_size);
}
memset(count, 0, sizeof(int) * l->l_max_col + 1);
int i;
if (!line_freelist) {
- l = (LINE *)xmalloc((void *)NULL, sizeof(LINE) * NALLOC);
+ l = xmalloc(sizeof(LINE) * NALLOC);
line_freelist = l;
for (i = 1; i < NALLOC; i++, l++)
l->l_next = l + 1;
line_freelist = l;
}
-void *
-xmalloc(void *p, size_t size)
-{
- if (!(p = (void *)realloc(p, size))) {
- (void)fprintf(stderr, "col: %s.\n", strerror(ENOMEM));
- exit(1);
- }
- return(p);
-}
-
void usage()
{
(void)fprintf(stderr, _("usage: col [-bfpx] [-l nline]\n"));
(void)fprintf(stderr, _("col: write error.\n"));
exit(1);
}
-
-void warn(int line)
-{
- (void)fprintf(stderr,
- _("col: warning: can't back up %s.\n"), line < 0 ?
- _("past first line") : _("-- line already flushed"));
-}