]> git.draconx.ca Git - cdecl99.git/commitdiff
Split advance into two parts.
authorNick Bowler <nbowler@draconx.ca>
Tue, 5 Jul 2011 00:17:51 +0000 (20:17 -0400)
committerNick Bowler <nbowler@draconx.ca>
Tue, 5 Jul 2011 12:55:39 +0000 (08:55 -0400)
We need to avoid printing spaces after things on occasion.  This makes
the code a little simpler, too.

src/explain.c

index 002b85702104b7068fb63d5e558f54955ef0fc09..e0916a8a4e9a5e5c181c300cc7aec7e734476326 100644 (file)
@@ -28,26 +28,29 @@ static size_t output(char *buf, size_t n, size_t off, const char *fmt, ...)
        return ret;
 }
 
-static size_t advance(char **buf, size_t *n, size_t amount)
+static size_t advance_(char **buf, size_t *n, size_t amount)
 {
-       if (!amount)
-               return 0;
-
        if (amount >= *n) {
                *n   = 0;
                *buf = 0;
        } else {
-               (*buf)[amount] = ' ';
-               if (amount + 1 >= *n) {
-                       *buf = 0;
-                       *n = 0;
-               } else {
-                       *buf += amount + 1;
-                       *n   -= amount + 1;
-               }
+               *buf += amount;
+               *n   -= amount;
        }
 
-       return amount + 1;
+       return amount;
+}
+
+static size_t advance(char **buf, size_t *n, size_t amount)
+{
+       size_t ret, rc;
+
+       if (!amount)
+               return 0;
+
+       ret = advance_(buf, n, amount);
+       rc = snprintf(*buf, *n, " ");
+       return ret + advance_(buf, n, rc);
 }
 
 static size_t