summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-05-07 22:43:56 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-05-07 22:43:56 -0400
commit5b0d8f09af4945dad30ac0374bd617f687774fea (patch)
tree19bab01045664dc518afd3723c182b8c168819c3
parente4026ff797fbfc743ef7b40ba70d565444a6d113 (diff)
scanner: Fix desc_dump() to not extend beyond column 72
-rw-r--r--src/scanner.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/scanner.c b/src/scanner.c
index 257b54b..c2aa599 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -157,29 +157,23 @@ static const char *indent(int n)
static void
desc_dump(char *src, int startcol)
{
- int i, col = startcol, line = 0;
+ int i, j, col = startcol;
- /* Strip leading space */
- for (i = 0; isspace(src[i]); i++)
- ;
-
- for (; src[i]; i++) {
- /* Collapse multiple spaces into 1 */
- if (isspace(src[i]) && isspace(src[i + 1]))
+ for (i = 0; src[i]; i++) {
+ if (isspace(src[i]))
continue;
- if (isspace(src[i]))
- src[i] = ' ';
+ j = i;
+ while (src[i] && !isspace(src[i]))
+ i++;
- if (col > 72 && isspace(src[i])) {
- if (src[i+1])
- printf("\n%s* ", indent(startcol + 1));
- line++;
+ if (col + i - j > 72) {
+ printf("\n%s * ", indent(startcol));
col = startcol;
- } else {
- putchar(src[i]);
- col++;
}
+
+ col += printf("%s%.*s",
+ col > startcol ? " " : "", i - j, &src[j]);
}
}