=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/col/col.c,v retrieving revision 1.12 retrieving revision 1.13 diff -c -r1.12 -r1.13 *** src/usr.bin/col/col.c 2014/10/08 19:59:58 1.12 --- src/usr.bin/col/col.c 2014/10/16 13:45:12 1.13 *************** *** 1,4 **** ! /* $OpenBSD: col.c,v 1.12 2014/10/08 19:59:58 deraadt Exp $ */ /* $NetBSD: col.c,v 1.7 1995/09/02 05:48:50 jtc Exp $ */ /*- --- 1,4 ---- ! /* $OpenBSD: col.c,v 1.13 2014/10/16 13:45:12 schwarze Exp $ */ /* $NetBSD: col.c,v 1.7 1995/09/02 05:48:50 jtc Exp $ */ /*- *************** *** 62,68 **** typedef struct char_str { #define CS_NORMAL 1 #define CS_ALTERNATE 2 ! short c_column; /* column character is in */ CSET c_set; /* character set (currently only 2) */ char c_char; /* character in question */ } CHAR; --- 62,68 ---- typedef struct char_str { #define CS_NORMAL 1 #define CS_ALTERNATE 2 ! size_t c_column; /* column character is in */ CSET c_set; /* character set (currently only 2) */ char c_char; /* character in question */ } CHAR; *************** *** 72,81 **** CHAR *l_line; /* characters on the line */ LINE *l_prev; /* previous line */ LINE *l_next; /* next line */ ! int l_lsize; /* allocated sizeof l_line */ ! int l_line_len; /* strlen(l_line) */ int l_needs_sort; /* set if chars went in out of order */ - int l_max_col; /* max column in the line */ }; LINE *alloc_line(void); --- 72,81 ---- CHAR *l_line; /* characters on the line */ LINE *l_prev; /* previous line */ LINE *l_next; /* next line */ ! size_t l_lsize; /* allocated sizeof l_line */ ! size_t l_line_len; /* strlen(l_line) */ ! size_t l_max_col; /* max column in the line */ int l_needs_sort; /* set if chars went in out of order */ }; LINE *alloc_line(void); *************** *** 107,113 **** CSET cur_set; /* current character set */ LINE *l; /* current line */ int extra_lines; /* # of lines above first line */ ! int cur_col; /* current column */ int cur_line; /* line number of current position */ int max_line; /* max value of cur_line */ int this_line; /* line l points to */ --- 107,113 ---- CSET cur_set; /* current character set */ LINE *l; /* current line */ int extra_lines; /* # of lines above first line */ ! size_t cur_col; /* current column */ int cur_line; /* line number of current position */ int max_line; /* max value of cur_line */ int this_line; /* line l points to */ *************** *** 148,154 **** /* this value is in half lines */ max_bufd_lines *= 2; ! adjust = cur_col = extra_lines = warned = 0; cur_line = max_line = nflushd_lines = this_line = 0; cur_set = last_set = CS_NORMAL; lines = l = alloc_line(); --- 148,155 ---- /* this value is in half lines */ max_bufd_lines *= 2; ! adjust = extra_lines = warned = 0; ! cur_col = 0; cur_line = max_line = nflushd_lines = this_line = 0; cur_set = last_set = CS_NORMAL; lines = l = alloc_line(); *************** *** 261,267 **** } /* grow line's buffer? */ if (l->l_line_len + 1 >= l->l_lsize) { ! int need; need = l->l_lsize ? l->l_lsize : 45; l->l_line = xreallocarray(l->l_line, --- 262,268 ---- } /* grow line's buffer? */ if (l->l_line_len + 1 >= l->l_lsize) { ! size_t need; need = l->l_lsize ? l->l_lsize : 45; l->l_line = xreallocarray(l->l_line, *************** *** 364,377 **** flush_line(LINE *l) { CHAR *c, *endc; ! int nchars, last_col, this_col; last_col = 0; nchars = l->l_line_len; if (l->l_needs_sort) { static CHAR *sorted; ! static int count_size, *count, i, save, sorted_size, tot; /* * Do an O(n) sort on l->l_line by column being careful to --- 365,379 ---- flush_line(LINE *l) { CHAR *c, *endc; ! size_t nchars, last_col, this_col; last_col = 0; nchars = l->l_line_len; if (l->l_needs_sort) { static CHAR *sorted; ! static size_t count_size, i, sorted_size; ! static int *count, save, tot; /* * Do an O(n) sort on l->l_line by column being careful to *************** *** 387,394 **** count = xreallocarray(count, count_size, sizeof(int)); } ! memset((char *)count, 0, sizeof(int) * l->l_max_col + 1); ! for (i = nchars, c = l->l_line; --i >= 0; c++) count[c->c_column]++; /* --- 389,396 ---- count = xreallocarray(count, count_size, sizeof(int)); } ! memset(count, 0, sizeof(*count) * (l->l_max_col + 1)); ! for (i = nchars, c = l->l_line; i-- > 0; c++) count[c->c_column]++; /* *************** *** 401,407 **** tot += save; } ! for (i = nchars, c = l->l_line; --i >= 0; c++) sorted[count[c->c_column]++] = *c; c = sorted; } else --- 403,409 ---- tot += save; } ! for (i = nchars, c = l->l_line; i-- > 0; c++) sorted[count[c->c_column]++] = *c; c = sorted; } else *************** *** 418,436 **** c = endc - 1; if (this_col > last_col) { ! int nspace = this_col - last_col; if (compress_spaces && nspace > 1) { ! int ntabs; ntabs = ((last_col % 8) + nspace) / 8; if (ntabs) { nspace -= (ntabs * 8) - (last_col % 8); ! while (--ntabs >= 0) PUTC('\t'); } } ! while (--nspace >= 0) PUTC(' '); last_col = this_col; } --- 420,438 ---- c = endc - 1; if (this_col > last_col) { ! size_t nspace = this_col - last_col; if (compress_spaces && nspace > 1) { ! size_t ntabs; ntabs = ((last_col % 8) + nspace) / 8; if (ntabs) { nspace -= (ntabs * 8) - (last_col % 8); ! while (ntabs-- > 0) PUTC('\t'); } } ! while (nspace-- > 0) PUTC(' '); last_col = this_col; }