diff options
author | Jonathan Clairembault <jonathan@clairembault.fr> | 2012-11-23 09:24:53 +0100 |
---|---|---|
committer | Jonathan Clairembault <jonathan@clairembault.fr> | 2012-11-23 09:24:53 +0100 |
commit | ab52d02963fcb0aecd8089ddc5cdc4d783092a4b (patch) | |
tree | 0576322a24752d9ca028af0009ac832c09d146f4 /toys/posix/expand.c | |
parent | 939fa7408fa68af8568fd07de64a1606af0a0c06 (diff) | |
download | toybox-ab52d02963fcb0aecd8089ddc5cdc4d783092a4b.tar.gz |
expand: handle backspace.
Diffstat (limited to 'toys/posix/expand.c')
-rw-r--r-- | toys/posix/expand.c | 7 |
1 files changed, 4 insertions, 3 deletions
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,7 +1,5 @@ /* expand.c - expands tabs to space * - * FIXME: handle backspace. - * * Copyright 2012 Jonathan Clairembault <jonathan at clairembault dot fr> * * See http://http://pubs.opengroup.org/onlinepubs/9699919799/nframe.html @@ -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); |