All pastes #551553 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-06-08 21:01 UTC
rendered paste body
git diff
diff --git a/builtin-stripspace.c b/builtin-stripspace.c
index 62bd4b5..85f9bb2 100644
--- a/builtin-stripspace.c
+++ b/builtin-stripspace.c
@@ -9,21 +9,22 @@
 static int cleanup(char *line)
 {
        int len = strlen(line);
+       int incomplete = 0;

        if (len && line[len-1] == '\n') {
-               if (len == 1)
-                       return 0;
-               do {
-                       unsigned char c = line[len-2];
-                       if (!isspace(c))
-                               break;
-                       line[len-2] = '\n';
-                       len--;
-                       line[len] = 0;
-               } while (len > 1);
-               return 0;
+               len--;
+               incomplete = 1;
+       }
+       while (len) {
+               unsigned char c = line[len-1];
+               if (!isspace(c))
+                       break;
+               len--;
        }
-       return 1;
+       if (!incomplete)
+               line[len++] = '\n';
+       line[len] = 0;
+       return incomplete;
 }

 static void stripspace(FILE *in, FILE *out)