summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-05-24 18:00:38 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-05-28 15:34:29 +0800
commit95428c41f0ee3ac108cf1a4acfaa67157ad954dc (patch)
tree8565027758cd931f49ebe78738fb41126254b253 /main.c
parent7aea09077aad335ac32bfd9858ded60ffd4d8a5b (diff)
downloadglacier-95428c41f0ee3ac108cf1a4acfaa67157ad954dc.tar.gz
Build DOM.
Diffstat (limited to 'main.c')
-rw-r--r--main.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/main.c b/main.c
index 00a184a..faeb618 100644
--- a/main.c
+++ b/main.c
@@ -3,9 +3,41 @@
#include "mem.h"
#include "dom.h"
+#include "tags.h"
+
+static void node_print(const struct node *n, const char *prefix, int last)
+{
+ const char *connector = last ? "└── " : "├── ";
+ const char *extension = last ? " " : "│ ";
+ char new_prefix[256];
+ struct node *c;
+
+ printf("%s%s", prefix, connector);
+
+ if (n->tag == TAG_TEXT)
+ printf("%.*s\n", (int)n->textlen, n->text);
+ else
+ printf("%s\n", tag_to_str(n->tag));
+
+ snprintf(new_prefix, sizeof(new_prefix), "%s%s", prefix, extension);
+
+ for (c = n->first_child; c; c = c->next_sibling)
+ node_print(c, new_prefix, c->next_sibling == NULL);
+}
+
+void dom_print(const struct node *root)
+{
+ struct node *c;
+
+ printf("%s\n", tag_to_str(root->tag));
+ for (c = root->first_child; c; c = c->next_sibling)
+ node_print(c, "", c->next_sibling == NULL);
+}
int main(int argc, char *argv[])
{
+ struct node *root;
+
if (argc < 2)
errx(1, "usage: glacier <file>");
@@ -27,8 +59,10 @@ int main(int argc, char *argv[])
html[len] = '\0';
fclose(file);
- init_dom(html);
+ root = dom_init(html);
+ dom_print(root);
+ dom_free();
free(html);
return 0;