From 0ee6aa96f6ea3fe1a1eb855aed5d6c466643878a Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 3 Jan 2021 16:58:24 -0500 Subject: Add debug/print functions for rope --- structures/rope/rope.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ structures/rope/rope.h | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/structures/rope/rope.c b/structures/rope/rope.c index 50c7fef..aed104b 100644 --- a/structures/rope/rope.c +++ b/structures/rope/rope.c @@ -28,6 +28,53 @@ rope* rope_new() return tmp; } +void rope_debug_print_aux(root, s) +rope *root; +int s; +{ + int i; + + for (i = 0; i < s; i++) + printf("| "); + + if (!root) { + printf("\n"); + return; + } + +#ifdef ROPE_DEBUG_PARENT + printf("[%p]\n", root->parent); +#endif + + printf("{len:%d,str:\'%s\'}[%p]\n", root->len, root->str, root); + + if (root->str) + return; + + rope_debug_print_aux(root->left, ++s); + rope_debug_print_aux(root->right, s); + +} + +void rope_debug_print(root) +rope *root; +{ + rope_debug_print_aux(root, 0); +} + +void rope_print(root) +rope *root; +{ + if (!root) + return; + + if (root->str) + printf("%s", root->str); + + rope_print(root->left); + rope_print(root->right); +} + size_t rope_len(root) rope *root; { diff --git a/structures/rope/rope.h b/structures/rope/rope.h index f012cc1..86d9ae3 100644 --- a/structures/rope/rope.h +++ b/structures/rope/rope.h @@ -1,7 +1,7 @@ #ifndef ROPE_H #define ROPE_H -typede struct rope_s rope; +typedef struct rope_s rope; rope* rope_new(); rope* str_to_rope(char*); -- cgit v1.1