summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-10-12 13:09:11 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-10-12 13:09:11 -0400
commitda5c9dd34f65989c842cfb831b8592157dd8ed34 (patch)
tree06571b02c096ef6fe2e0c785253b0b151731e205 /src
parent257227326fe60fe70e80433fd34d1ebcb2f9f623 (diff)
downloadbfs-da5c9dd34f65989c842cfb831b8592157dd8ed34.tar.xz
diag: Move enum debug_flags out of ctx.h
Diffstat (limited to 'src')
-rw-r--r--src/ctx.c25
-rw-r--r--src/ctx.h28
-rw-r--r--src/diag.c25
-rw-r--r--src/diag.h29
4 files changed, 54 insertions, 53 deletions
diff --git a/src/ctx.c b/src/ctx.c
index 9a24a33..561ecae 100644
--- a/src/ctx.c
+++ b/src/ctx.c
@@ -17,31 +17,6 @@
#include <stdio.h>
#include <stdlib.h>
-const char *debug_flag_name(enum debug_flags flag) {
- switch (flag) {
- case DEBUG_COST:
- return "cost";
- case DEBUG_EXEC:
- return "exec";
- case DEBUG_OPT:
- return "opt";
- case DEBUG_RATES:
- return "rates";
- case DEBUG_SEARCH:
- return "search";
- case DEBUG_STAT:
- return "stat";
- case DEBUG_TREE:
- return "tree";
-
- case DEBUG_ALL:
- break;
- }
-
- bfs_bug("Unrecognized debug flag");
- return "???";
-}
-
struct bfs_ctx *bfs_ctx_new(void) {
struct bfs_ctx *ctx = ZALLOC(struct bfs_ctx);
if (!ctx) {
diff --git a/src/ctx.h b/src/ctx.h
index 2b8e8cb..96406bd 100644
--- a/src/ctx.h
+++ b/src/ctx.h
@@ -10,39 +10,13 @@
#include "bftw.h"
#include "config.h"
+#include "diag.h"
#include "trie.h"
#include <stddef.h>
#include <sys/resource.h>
#include <time.h>
/**
- * Various debugging flags.
- */
-enum debug_flags {
- /** Print cost estimates. */
- DEBUG_COST = 1 << 0,
- /** Print executed command details. */
- DEBUG_EXEC = 1 << 1,
- /** Print optimization details. */
- DEBUG_OPT = 1 << 2,
- /** Print rate information. */
- DEBUG_RATES = 1 << 3,
- /** Trace the filesystem traversal. */
- DEBUG_SEARCH = 1 << 4,
- /** Trace all stat() calls. */
- DEBUG_STAT = 1 << 5,
- /** Print the parse tree. */
- DEBUG_TREE = 1 << 6,
- /** All debug flags. */
- DEBUG_ALL = (1 << 7) - 1,
-};
-
-/**
- * Convert a debug flag to a string.
- */
-const char *debug_flag_name(enum debug_flags flag);
-
-/**
* The execution context for bfs.
*/
struct bfs_ctx {
diff --git a/src/diag.c b/src/diag.c
index fa66525..bf2343d 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -27,6 +27,31 @@ noreturn void bfs_abortf(const struct bfs_loc *loc, const char *format, ...) {
abort();
}
+const char *debug_flag_name(enum debug_flags flag) {
+ switch (flag) {
+ case DEBUG_COST:
+ return "cost";
+ case DEBUG_EXEC:
+ return "exec";
+ case DEBUG_OPT:
+ return "opt";
+ case DEBUG_RATES:
+ return "rates";
+ case DEBUG_SEARCH:
+ return "search";
+ case DEBUG_STAT:
+ return "stat";
+ case DEBUG_TREE:
+ return "tree";
+
+ case DEBUG_ALL:
+ break;
+ }
+
+ bfs_bug("Unrecognized debug flag");
+ return "???";
+}
+
void bfs_perror(const struct bfs_ctx *ctx, const char *str) {
bfs_error(ctx, "%s: %m.\n", str);
}
diff --git a/src/diag.h b/src/diag.h
index fea8847..838a794 100644
--- a/src/diag.h
+++ b/src/diag.h
@@ -9,7 +9,6 @@
#define BFS_DIAG_H
#include "config.h"
-#include "ctx.h"
#include <stdarg.h>
/**
@@ -84,9 +83,37 @@ noreturn void bfs_abortf(const struct bfs_loc *loc, const char *format, ...);
# define bfs_assert bfs_verify
#endif
+struct bfs_ctx;
struct bfs_expr;
/**
+ * Various debugging flags.
+ */
+enum debug_flags {
+ /** Print cost estimates. */
+ DEBUG_COST = 1 << 0,
+ /** Print executed command details. */
+ DEBUG_EXEC = 1 << 1,
+ /** Print optimization details. */
+ DEBUG_OPT = 1 << 2,
+ /** Print rate information. */
+ DEBUG_RATES = 1 << 3,
+ /** Trace the filesystem traversal. */
+ DEBUG_SEARCH = 1 << 4,
+ /** Trace all stat() calls. */
+ DEBUG_STAT = 1 << 5,
+ /** Print the parse tree. */
+ DEBUG_TREE = 1 << 6,
+ /** All debug flags. */
+ DEBUG_ALL = (1 << 7) - 1,
+};
+
+/**
+ * Convert a debug flag to a string.
+ */
+const char *debug_flag_name(enum debug_flags flag);
+
+/**
* Like perror(), but decorated like bfs_error().
*/
void bfs_perror(const struct bfs_ctx *ctx, const char *str);