123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #include "trace.h"
-
- #if L2_ENABLE_TRACE
-
- #include <stdio.h>
- #include <stdarg.h>
-
- int l2_trace_depth = 0;
-
- void l2_trace_push(const char *name) {
- for (int i = 0; i < l2_trace_depth; ++i) {
- fprintf(stderr, " ");
- }
-
- fprintf(stderr, "%s {\n", name);
- l2_trace_depth += 1;
- }
-
- void l2_trace_pop() {
- l2_trace_depth -= 1;
- for (int i = 0; i < l2_trace_depth; ++i) {
- fprintf(stderr, " ");
- }
-
- fprintf(stderr, "}\n");
- }
-
- void l2_trace(const char *fmt, ...) {
- for (int i = 0; i < l2_trace_depth; ++i) {
- fprintf(stderr, " ");
- }
-
- va_list va;
- va_start(va, fmt);
- vfprintf(stderr, fmt, va);
- fprintf(stderr, "\n");
- }
-
- void l2_trace_cleanup(void *unused) {
- l2_trace_pop();
- }
-
- #endif
-
- // ISO C forbids an empty translation unit
- // (and GCC warns on usude variables, but __attribute__((unused)) isn't ISO C)
- #ifdef __GNUC__
- __attribute__((unused)) static int make_compiler_happy;
- #else
- static int make_compiler_happy;
- #endif
|