From ab52d02963fcb0aecd8089ddc5cdc4d783092a4b Mon Sep 17 00:00:00 2001 From: Jonathan Clairembault Date: Fri, 23 Nov 2012 09:24:53 +0100 Subject: expand: handle backspace. --- toys/posix/expand.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'toys/posix/expand.c') diff --git a/toys/posix/expand.c b/toys/posix/expand.c index 739c326d..bbe6fdf1 100644 --- a/toys/posix/expand.c +++ b/toys/posix/expand.c @@ -1,6 +1,4 @@ /* expand.c - expands tabs to space - * - * FIXME: handle backspace. * * Copyright 2012 Jonathan Clairembault * @@ -116,7 +114,10 @@ static void expand_file(int fd, char *name) wrlinei += count; } else { /* copy input to output */ wrbuf[wrbufi++] = rdbuf[rdbufi]; - wrlinei += 1; + if (rdbuf[rdbufi] == '\b') /* go back one column on backspace */ + wrlinei -= !!wrlinei; /* do not go below zero */ + else + wrlinei += 1; /* flush expand buffer and reset tablist at newline */ if (rdbuf[rdbufi] == '\n') { writeall(STDOUT_FILENO, wrbuf, wrbufi); -- cgit v1.2.3