From a4bf5aabe7ffd2a3702f6faf6a560686b308d807 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 4 Oct 2020 12:56:59 -0400 Subject: diag: Factor debug_flag string conversion into its own function --- diag.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'diag.c') diff --git a/diag.c b/diag.c index 7ed132e..308b05d 100644 --- a/diag.c +++ b/diag.c @@ -93,41 +93,37 @@ bool bfs_warning_prefix(const struct bfs_ctx *ctx) { } } -bool bfs_debug_prefix(const struct bfs_ctx *ctx, enum debug_flags flag) { - if (!(ctx->debug & flag)) { - return false; - } - - const char *str; - +static const char *debug_flag_str(enum debug_flags flag) { switch (flag) { case DEBUG_COST: - str = "cost"; - break; + return "cost"; case DEBUG_EXEC: - str = "exec"; - break; + return "exec"; case DEBUG_OPT: - str = "opt"; - break; + return "opt"; case DEBUG_RATES: - str = "rates"; - break; + return "rates"; case DEBUG_SEARCH: - str = "search"; - break; + return "search"; case DEBUG_STAT: - str = "stat"; - break; + return "stat"; case DEBUG_TREE: - str = "tree"; - break; - default: + return "tree"; + + case DEBUG_ALL: assert(false); - str = "???"; break; } - cfprintf(ctx->cerr, "${bld}%s:${rs} ${cyn}-D %s${rs}: ", xbasename(ctx->argv[0]), str); - return true; + assert(false); + return "???"; +} + +bool bfs_debug_prefix(const struct bfs_ctx *ctx, enum debug_flags flag) { + if (ctx->debug & flag) { + cfprintf(ctx->cerr, "${bld}%s:${rs} ${cyn}-D %s${rs}: ", xbasename(ctx->argv[0]), debug_flag_str(flag)); + return true; + } else { + return false; + } } -- cgit v1.2.3