diff options
Diffstat (limited to 'src/tag_print.c')
-rw-r--r-- | src/tag_print.c | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/src/tag_print.c b/src/tag_print.c deleted file mode 100644 index b6a8e1a..0000000 --- a/src/tag_print.c +++ /dev/null @@ -1,101 +0,0 @@ -#include "tag.h" -#include <stdarg.h> -#include <stdio.h> - -__attribute__((format(printf, 2, 3))) -static void printi(int depth, const char *format, ...) { - for (int i = 0; i < depth; i++) - printf("\t"); - va_list list; - va_start(list, format); - vprintf(format, list); -} - -static void tag_print_impl(const tag_t *tag, int depth); - -static void tag_print_data(const tag_t *tag, int depth) { - switch (tag->type) { - case TAG_BYTE: - printf("%hhd", tag->data.b); - break; - case TAG_SHORT: - printf("%hd", tag->data.s); - break; - case TAG_INT: - printf("%d", tag->data.i); - break; - case TAG_LONG: - printf("%ld", tag->data.l); - break; - case TAG_FLOAT: - printf("%f", tag->data.f); - break; - case TAG_DOUBLE: - printf("%lf", tag->data.d); - break; - case TAG_BYTE_ARRAY: - printf("["); - for (int32_t i = 0; i < tag->data.b_arr.size; i++) { - if (i != 0) printf(","); - printf("%hhd", tag->data.b_arr.data[i]); - } - printf("]"); - break; - case TAG_STRING: - if (tag->data.string.size > 1) - printf("\"%.*s\"", tag->data.string.size, tag->data.string.data); - else - printf("\"\""); - break; - case TAG_LIST: - printf("[\n"); - for (int32_t i = 0; i < tag->data.list.size; i++) { - if (i != 0) printf(",\n"); - tag_print_impl(&tag->data.list.tags[i], depth + 1); - } - printf("\n"); - printi(depth, "]"); - break; - case TAG_COMPOUND: - printf("{\n"); - for (int32_t i = 0; i < tag->data.compound.size; i++) { - if (i != 0) printf(",\n"); - tag_print_impl(&tag->data.compound.tags[i], depth + 1); - } - printf("\n"); - printi(depth, "}"); - break; - case TAG_INT_ARRAY: - printi(depth, "["); - for (int32_t i = 0; i < tag->data.i_arr.size; i++) { - if (i != 0) printf(","); - printf("%d", tag->data.i_arr.data[i]); - } - printf("]"); - break; - case TAG_LONG_ARRAY: - printf("["); - for (int32_t i = 0; i < tag->data.l_arr.size; i++) { - if (i != 0) printf(","); - printf("%ld", tag->data.l_arr.data[i]); - } - printf("]"); - break; - case TAG_END: - break; - } -} - -static void tag_print_impl(const tag_t *tag, int depth) { - if (tag->name_len > 0) { - printi(depth, "\"%.*s\":\t", tag->name_len, tag->name); - } else { - for (int i = 0; i < depth; i++) printf("\t"); - } - tag_print_data(tag, depth); -} - -void tag_print(const tag_t *tag) { - tag_print_impl(tag, 0); - printf("\n"); -} |