From 8e21b8f52a5c566767df9b3fe105706b6888a89b Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 31 Jan 2023 13:45:50 -0600 Subject: parse xml into memory --- yy/main.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'yy/main.c') diff --git a/yy/main.c b/yy/main.c index 0d97fba..823db5a 100644 --- a/yy/main.c +++ b/yy/main.c @@ -6,6 +6,44 @@ #include "kalmia.lex.h" +void print_attrs(struct kai_attr_t *attr) +{ + while(attr != NULL) { + printf("%s=\"%s\" ", attr->key, attr->value); + attr = attr->next; + } +} + + +void print_tag(char *indent, struct kai_tag_t *tag) +{ + printf("%s%s[ ", indent, tag->type); + print_attrs(tag->attrs); + printf("]\n"); +} + + +void print_level(int indent_level, struct kai_tag_t *tag) +{ + char indent[64]; + for (int i=0; ichildren != NULL) { + print_level(indent_level+1, tag->children); + } + if (tag->content != NULL) { + printf("%s\t%s\n", indent, tag->content); + } + tag = tag->next; + } +} + + int main(int argc, char **argv) { if (argc < 2) { @@ -25,5 +63,9 @@ int main(int argc, char **argv) kalmiaset_in(in, scanner); kalmiaparse(scanner, &result); kalmialex_destroy(scanner); + + print_tag("", result.tag); + print_level(1, result.tag->children); + return 0; } -- cgit v1.2.1