diff options
Diffstat (limited to 'usr.bin/col/col.c')
-rw-r--r-- | usr.bin/col/col.c | 26 |
1 files changed, 18 insertions, 8 deletions
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(' '); |