From d2d1e48ba344788ccfd76adaf88b6eeece89a69c Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Mon, 4 Jul 2011 20:17:51 -0400 Subject: [PATCH] Split advance into two parts. We need to avoid printing spaces after things on occasion. This makes the code a little simpler, too. --- src/explain.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/explain.c b/src/explain.c index 002b857..e0916a8 100644 --- a/src/explain.c +++ b/src/explain.c @@ -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 -- 2.43.2