summaryrefslogtreecommitdiffstats
path: root/usr.bin/col/col.c
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1995-01-17 07:02:31 +0000
committerbde <bde@FreeBSD.org>1995-01-17 07:02:31 +0000
commit63bcd558542be8d075bb050836eb9999c5094ec7 (patch)
treeb1506956bc8bb6be7fc65483d7b1cbdbd5f7fae0 /usr.bin/col/col.c
parent6b907972704752e76939f9a5a34e9646bd444e89 (diff)
downloadFreeBSD-src-63bcd558542be8d075bb050836eb9999c5094ec7.zip
FreeBSD-src-63bcd558542be8d075bb050836eb9999c5094ec7.tar.gz
Obtained from: looked at the fix in 1.1.5 and rewrote it
Fix entabbing.
Diffstat (limited to 'usr.bin/col/col.c')
-rw-r--r--usr.bin/col/col.c26
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(' ');
OpenPOWER on IntegriCloud