--- output.orig.c 2018-03-02 11:40:01.460960523 +0800 +++ output.c 2018-03-02 11:51:13.060960442 +0800 @@ -18,6 +18,7 @@ #include #include #include +#include #include "../ast.h" #include "../xalloc.h" @@ -40,6 +41,15 @@ static void node_walk_render(const struct node *n, struct render_context *ctx); +char *rtrim(char *s) { + int n = strlen(s); + while(--n>=0 && ( iscntrl(s[n]) || isspace(s[n]) || isblank(s[n]))) + ; + s[++n] = 0; + return s; +} + + static int bprintf(struct render_context *ctx, const char *fmt, ...) { @@ -486,7 +496,7 @@ rrd_pretty(&rrd); } - printf("%s:\n", p->name); + printf("%s:\n", rtrim(p->name)); { struct render_context ctx; @@ -519,7 +529,7 @@ node_walk_render(rrd, &ctx); for (i = 0; i < h; i++) { - printf(" %s\n", ctx.lines[i]); + printf(" %s\n", rtrim(ctx.lines[i])); free(ctx.lines[i]); }