]> Sergey Matveev's repositories - bfs.git/commitdiff
diag: Move enum debug_flags out of ctx.h
authorTavian Barnes <tavianator@tavianator.com>
Thu, 12 Oct 2023 17:09:11 +0000 (13:09 -0400)
committerTavian Barnes <tavianator@tavianator.com>
Thu, 12 Oct 2023 17:09:11 +0000 (13:09 -0400)
src/ctx.c
src/ctx.h
src/diag.c
src/diag.h
tests/alloc.c

index 9a24a33fff2735421ad7c9d0b9381c3dbbc169a7..561ecaebe9fc7fcb52168d395b04da6bbb581869 100644 (file)
--- a/src/ctx.c
+++ b/src/ctx.c
 #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) {
index 2b8e8cb29ff408c612ab0026ab0c10faaebf2a07..96406bd2601c66a1da6604191aca8aff8868d9ff 100644 (file)
--- a/src/ctx.h
+++ b/src/ctx.h
 
 #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.
  */
index fa6652535779f9ad9768791413071c9935ca5b83..bf2343de8c5bec2d5b1ad0404d06bdf3c7d9e6c1 100644 (file)
@@ -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);
 }
index fea8847b13952d6fe61215906680707c1bc5efb7..838a7940f4754679c5a556e78fd020c9564bcd89 100644 (file)
@@ -9,7 +9,6 @@
 #define BFS_DIAG_H
 
 #include "config.h"
-#include "ctx.h"
 #include <stdarg.h>
 
 /**
@@ -84,8 +83,36 @@ 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().
  */
index 382131f5fda0e764fec0a4986a1d20b7dd41d960..23342419ce0161d8b09d4611c81bd8f34ae518e8 100644 (file)
@@ -5,6 +5,7 @@
 #include "../src/diag.h"
 #include <errno.h>
 #include <stdlib.h>
+#include <stdint.h>
 
 int main(void) {
        // Check sizeof_flex()