diff options
| author | Kristian Høgsberg <krh@bitplanet.net> | 2012-05-07 22:43:56 -0400 |
|---|---|---|
| committer | Kristian Høgsberg <krh@bitplanet.net> | 2012-05-07 22:43:56 -0400 |
| commit | 5b0d8f09af4945dad30ac0374bd617f687774fea (patch) | |
| tree | 19bab01045664dc518afd3723c182b8c168819c3 /src/scanner.c | |
| parent | scanner: Use indent() function in desc_dump() (diff) | |
| download | wayland-5b0d8f09af4945dad30ac0374bd617f687774fea.tar wayland-5b0d8f09af4945dad30ac0374bd617f687774fea.tar.gz wayland-5b0d8f09af4945dad30ac0374bd617f687774fea.tar.bz2 wayland-5b0d8f09af4945dad30ac0374bd617f687774fea.tar.lz wayland-5b0d8f09af4945dad30ac0374bd617f687774fea.tar.xz wayland-5b0d8f09af4945dad30ac0374bd617f687774fea.tar.zst wayland-5b0d8f09af4945dad30ac0374bd617f687774fea.zip | |
scanner: Fix desc_dump() to not extend beyond column 72
Diffstat (limited to 'src/scanner.c')
| -rw-r--r-- | src/scanner.c | 28 |
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]); } } |
