diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-03-27 13:39:21 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-03-27 13:39:21 -0400 |
commit | e53d03be299b19694d16c8cbc61dc174a7b56bbc (patch) | |
tree | bc832ca50c1b4636aedaee3850e8508d7b5a7510 | |
parent | 47e52194f339aeaca369ef31528e618b91390424 (diff) | |
download | bfs-e53d03be299b19694d16c8cbc61dc174a7b56bbc.tar.xz |
diag: Avoid printing trailing spaces
-rw-r--r-- | diag.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -139,7 +139,7 @@ static bool highlight_expr(const struct bfs_ctx *ctx, const struct bfs_expr *exp return highlight_expr_recursive(ctx, expr, args); } -/** Print a hilighted portion of the command line. */ +/** Print a highlighted portion of the command line. */ static void bfs_argv_diag(const struct bfs_ctx *ctx, const bool *args, bool warning) { if (warning) { bfs_warning_prefix(ctx); @@ -147,12 +147,14 @@ static void bfs_argv_diag(const struct bfs_ctx *ctx, const bool *args, bool warn bfs_error_prefix(ctx); } + size_t max_argc = 0; for (size_t i = 0; i < ctx->argc; ++i) { if (i > 0) { cfprintf(ctx->cerr, " "); } if (args[i]) { + max_argc = i + 1; cfprintf(ctx->cerr, "${bld}%s${rs}", ctx->argv[i]); } else { cfprintf(ctx->cerr, "%s", ctx->argv[i]); @@ -167,7 +169,7 @@ static void bfs_argv_diag(const struct bfs_ctx *ctx, const bool *args, bool warn bfs_error_prefix(ctx); } - for (size_t i = 0; i < ctx->argc; ++i) { + for (size_t i = 0; i < max_argc; ++i) { if (i > 0) { if (args[i - 1] && args[i]) { cfprintf(ctx->cerr, "~"); @@ -193,7 +195,7 @@ static void bfs_argv_diag(const struct bfs_ctx *ctx, const bool *args, bool warn } } - if (args[i] && (i + 1 >= ctx->argc || !args[i + 1])) { + if (args[i] && (i + 1 >= max_argc || !args[i + 1])) { cfprintf(ctx->cerr, "${rs}"); } } |