changeset 723:2818724bb8be

Re-add backspace support to expand (oops) and fix test to expect data plus backspace characters rather than the chracters cancelling each other out before output.
author Rob Landley <rob@landley.net>
date Sat, 01 Dec 2012 00:21:37 -0600
parents 08d538115f39
children 9499e4cf830f
files scripts/test/expand.test toys/posix/expand.c
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/test/expand.test	Fri Nov 30 02:41:52 2012 -0600
+++ b/scripts/test/expand.test	Sat Dec 01 00:21:37 2012 -0600
@@ -11,7 +11,7 @@
 testing "expand default stdin" "expand"  "        foo     bar\n" "" "\tfoo\tbar\n"
 testing "expand single" "expand -t 2 input" "  foo bar\n" "\tfoo\tbar\n" ""
 testing "expand tablist" "expand -t 5,10,12 input" "     foo  bar foo\n" "\tfoo\tbar\tfoo\n" ""
-testing "expand backspace" "expand input" "foobarf bar\n" "foobarfoo\b\b\tbar\n" ""
+testing "expand backspace" "expand input" "foobarfoo\b\b bar\n" "foobarfoo\b\b\tbar\n" ""
 
 # advanced tests
 
--- a/toys/posix/expand.c	Fri Nov 30 02:41:52 2012 -0600
+++ b/toys/posix/expand.c	Sat Dec 01 00:21:37 2012 -0600
@@ -45,9 +45,13 @@
     if (!len) break;
     for (i=0; i<len; i++) {
       int len = 1;
-      if (toybuf[i] != '\t') {
-        if (EOF == putc(toybuf[i], stdout)) perror_exit(0);
-        if (toybuf[i] == '\n') {
+      char c = toybuf[i];
+
+      if (c != '\t') {
+        if (EOF == putc(c, stdout)) perror_exit(0);
+
+        if (c == '\b' && x) len = -1;
+        if (c == '\n') {
           x = stop = 0;
           continue;
         }