Add function to print to file.
This commit is contained in:
parent
2823b0b66b
commit
08513a2315
|
@ -2,7 +2,9 @@
|
||||||
#define LIBABACUS_DEBUG_H
|
#define LIBABACUS_DEBUG_H
|
||||||
|
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void libab_debug_fprint_tree(libab_tree* print, FILE* file);
|
||||||
void libab_debug_print_tree(libab_tree* print);
|
void libab_debug_print_tree(libab_tree* print);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
26
src/debug.c
26
src/debug.c
|
@ -1,5 +1,4 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int _debug_foreach_print_tree(void* data, va_list args);
|
int _debug_foreach_print_tree(void* data, va_list args);
|
||||||
|
|
||||||
|
@ -19,30 +18,35 @@ const char* _debug_node_name(libab_tree_variant var) {
|
||||||
return names[var];
|
return names[var];
|
||||||
}
|
}
|
||||||
|
|
||||||
void _debug_print_tree_node(libab_tree* tree) {
|
void _debug_print_tree_node(libab_tree* tree, FILE* file) {
|
||||||
printf("%s", _debug_node_name(tree->variant));
|
fprintf(file, "%s", _debug_node_name(tree->variant));
|
||||||
if(libab_tree_has_string(tree->variant)) {
|
if(libab_tree_has_string(tree->variant)) {
|
||||||
printf(": %s", tree->string_value);
|
fprintf(file, ": %s", tree->string_value);
|
||||||
}
|
}
|
||||||
printf("\n");
|
fprintf(file, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void _debug_print_tree(libab_tree* tree, int depth) {
|
void _debug_print_tree(libab_tree* tree, FILE* file, int depth) {
|
||||||
int i = depth;
|
int i = depth;
|
||||||
while(i--) printf(" ");
|
while(i--) printf(" ");
|
||||||
_debug_print_tree_node(tree);
|
_debug_print_tree_node(tree, file);
|
||||||
if(libab_tree_has_vector(tree->variant)) {
|
if(libab_tree_has_vector(tree->variant)) {
|
||||||
vec_foreach(&tree->children, NULL, compare_always,
|
vec_foreach(&tree->children, NULL, compare_always,
|
||||||
_debug_foreach_print_tree, depth + 1);
|
_debug_foreach_print_tree, file, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int _debug_foreach_print_tree(void* data, va_list args) {
|
int _debug_foreach_print_tree(void* data, va_list args) {
|
||||||
|
FILE* file = va_arg(args, FILE*);
|
||||||
int depth = va_arg(args, int);
|
int depth = va_arg(args, int);
|
||||||
_debug_print_tree(data, depth);
|
_debug_print_tree(data, file, depth);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void libab_debug_print_tree(libab_tree* print) {
|
void libab_debug_fprint_tree(libab_tree* print, FILE* file) {
|
||||||
_debug_print_tree(print, 0);
|
_debug_print_tree(print, file, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void libab_debug_print_tree(libab_tree* print) {
|
||||||
|
_debug_print_tree(print, stdout, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user