summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-10-04 12:56:59 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-10-04 12:56:59 -0400
commita4bf5aabe7ffd2a3702f6faf6a560686b308d807 (patch)
treedac9d04f93a0c6ee73c8bf35199c97fb725da241
parentdefdabbe82a35cf656f25c01d0768d24680f6ec8 (diff)
downloadbfs-a4bf5aabe7ffd2a3702f6faf6a560686b308d807.tar.xz
diag: Factor debug_flag string conversion into its own function
-rw-r--r--diag.c46
1 files changed, 21 insertions, 25 deletions
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;
+ }
}