From 63bcd558542be8d075bb050836eb9999c5094ec7 Mon Sep 17 00:00:00 2001 From: bde Date: Tue, 17 Jan 1995 07:02:31 +0000 Subject: Obtained from: looked at the fix in 1.1.5 and rewrote it Fix entabbing. --- usr.bin/col/col.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'usr.bin/col') diff --git a/usr.bin/col/col.c b/usr.bin/col/col.c index 77b6dc6..719fef7 100644 --- a/usr.bin/col/col.c +++ b/usr.bin/col/col.c @@ -106,8 +106,10 @@ int nblank_lines; /* # blanks after last flushed line */ int no_backspaces; /* if not to output any backspaces */ #define PUTC(ch) \ - if (putchar(ch) == EOF) \ - wrerr(); + do { \ + if (putchar(ch) == EOF) \ + wrerr(); \ + } while (0) int main(argc, argv) @@ -432,12 +434,20 @@ flush_line(l) int nspace = this_col - last_col; if (compress_spaces && nspace > 1) { - int ntabs; - - ntabs = this_col / 8 - last_col / 8; - nspace -= ntabs * 8; - while (--ntabs >= 0) - PUTC('\t'); + while (1) { + int tab_col, tab_size;; + + tab_col = (last_col + 8) & ~7; + if (tab_col > this_col) + break; + tab_size = tab_col - last_col; + if (tab_size == 1) + PUTC(' '); + else + PUTC('\t'); + nspace -= tab_size; + last_col = tab_col; + } } while (--nspace >= 0) PUTC(' '); -- cgit v1.1