summaryrefslogtreecommitdiff
path: root/src/unexpand.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2011-07-19 09:06:37 +0100
committerPádraig Brady <P@draigBrady.com>2011-07-20 10:38:46 +0100
commit65a0483fb55bd2b4dab305af8a95cd25e292142b (patch)
treeb3659380054dbe0bc0f627a3d06cedb42f0736b4 /src/unexpand.c
parentdc7284ef722b64569b1cb48df6b6c2d3fcd8b9a8 (diff)
downloadcoreutils-65a0483fb55bd2b4dab305af8a95cd25e292142b.tar.gz
unexpand: fix misalignment when spaces span a tabstop
The following dropped the space from the first field printf "1234567 \t1\n" | unexpand -a Note POSIX says that spaces should not precede tabs. Also a single trailing space should not be converted if the next field starts with non blank characters. So we enforce those rules too, with this change. * src/unexpand.c (unexpand): Implement as per POSIX rules. * tests/misc/unexpand: Add tests, and adjust existing tests as per POSIX rules. * NEWS: Mention the fix. Reported by Hallvard B Furuseth
Diffstat (limited to 'src/unexpand.c')
-rw-r--r--src/unexpand.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/unexpand.c b/src/unexpand.c
index 001437504..e8bf3f0b7 100644
--- a/src/unexpand.c
+++ b/src/unexpand.c
@@ -379,13 +379,8 @@ unexpand (void)
{
column = next_tab_column;
- /* Discard pending blanks, unless it was a single
- blank just before the previous tab stop. */
- if (! (pending == 1 && one_blank_before_tab_stop))
- {
- pending = 0;
- one_blank_before_tab_stop = false;
- }
+ if (pending)
+ pending_blank[0] = '\t';
}
else
{
@@ -404,8 +399,11 @@ unexpand (void)
/* Replace the pending blanks by a tab or two. */
pending_blank[0] = c = '\t';
- pending = one_blank_before_tab_stop;
}
+
+ /* Discard pending blanks, unless it was a single
+ blank just before the previous tab stop. */
+ pending = one_blank_before_tab_stop;
}
}
else if (c == '\b')
@@ -425,6 +423,8 @@ unexpand (void)
if (pending)
{
+ if (pending > 1 && one_blank_before_tab_stop)
+ pending_blank[0] = '\t';
if (fwrite (pending_blank, 1, pending, stdout) != pending)
error (EXIT_FAILURE, errno, _("write error"));
pending = 0;