diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-10-04 12:56:59 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-10-04 12:56:59 -0400 |
commit | a4bf5aabe7ffd2a3702f6faf6a560686b308d807 (patch) | |
tree | dac9d04f93a0c6ee73c8bf35199c97fb725da241 /diag.c | |
parent | defdabbe82a35cf656f25c01d0768d24680f6ec8 (diff) | |
download | bfs-a4bf5aabe7ffd2a3702f6faf6a560686b308d807.tar.xz |
diag: Factor debug_flag string conversion into its own function
Diffstat (limited to 'diag.c')
-rw-r--r-- | diag.c | 46 |
1 files changed, 21 insertions, 25 deletions
@@ -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; + } } |