Add a `fix' for another whitespace bug.

If the sentence starts with a multiple of eight spaces, the sentence
should in almost all practical cases have started with tabs instead.
Replace these spaces by tabs.
This commit is contained in:
Ed Schouten 2012-02-06 18:52:40 +00:00
parent cd864a19a5
commit e048cf369a
2 changed files with 15 additions and 0 deletions

View File

@ -41,6 +41,8 @@ and prints the result to standard output.
It removes leading and trailing empty lines from the input, as well as It removes leading and trailing empty lines from the input, as well as
trailing whitespace characters from ever line of text. trailing whitespace characters from ever line of text.
Multiple successive empty lines are merged together. Multiple successive empty lines are merged together.
If the whitespace at the beginning of a sentence is exactly a multiple
of eight spaces, the whitespace is replaced by tabs.
Also, spaces preceeding tabs will be merged into the tab character. Also, spaces preceeding tabs will be merged into the tab character.
.Sh AUTHORS .Sh AUTHORS
.An Ed Schouten Aq ed@FreeBSD.org .An Ed Schouten Aq ed@FreeBSD.org

View File

@ -110,6 +110,19 @@ savewhite(char c, bool leading)
static void static void
printwhite(void) printwhite(void)
{ {
off_t i;
/* Merge spaces at the start of a sentence to tabs if possible. */
if ((column % 8) == 0) {
for (i = 0; i < column; i++)
if (!peekbyte(i + 1, ' '))
break;
if (i == column) {
queuelen -= column;
for (i = 0; i < column; i += 8)
queue[queuelen++] = '\t';
}
}
if (fwrite(queue, 1, queuelen, stdout) != queuelen) { if (fwrite(queue, 1, queuelen, stdout) != queuelen) {
perror("write"); perror("write");