diff options
author | Ali Fardan <raiz@stellarbound.info> | 2020-10-21 16:32:56 +0300 |
---|---|---|
committer | Ali Fardan <raiz@stellarbound.info> | 2020-10-21 16:32:56 +0300 |
commit | a77f42d3c2d19dfa13e0f98935de8f9b59502a6a (patch) | |
tree | 0c95035255c1e93cd598f1ee43dbfd6452c34943 /test.c | |
download | libgemtext-a77f42d3c2d19dfa13e0f98935de8f9b59502a6a.tar.gz |
initial commit, decoder working
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/test.c b/test.c new file mode 100644 index 0000000..066453a --- /dev/null +++ b/test.c @@ -0,0 +1,121 @@ +#include <stdio.h> + +#include "gemtext.h" + +static void +_do_text(struct gemtext_text *t) +{ + printf("TEXT: %s\n", t->text); +} + +static void +_do_link(struct gemtext_link *t) +{ + printf("LINK: (name: %s) (link: %s)\n", t->name, t->link); +} + +static void +_do_pre(struct gemtext_pre *t) +{ + printf("PRE:\n%s\n", t->text); +} + +static void +_do_h1(struct gemtext_h1 *t) +{ + printf("H1: %s\n", t->text); +} + +static void +_do_h2(struct gemtext_h2 *t) +{ + printf("H2: %s\n", t->text); +} + +static void +_do_h3(struct gemtext_h3 *t) +{ + printf("H3: %s\n", t->text); +} + +static void +_do_ul(struct gemtext_ul *t) +{ + int i; + + for (i = 0; i < t->nitems; i++) + printf("UL: %d: %s\n", i+1, t->items[i]); +} + +static void +_do_qt(struct gemtext_qt *t) +{ + printf("QT: %s\n", t->text); +} + +static void +_printer(struct gemtext **list) +{ + int i; + + for (i = 0; list[i] != NULL; i++) { + switch (list[i]->type) { + case GEMTEXT_TEXT: + _do_text((struct gemtext_text *)list[i]); + break; + case GEMTEXT_LINK: + _do_link((struct gemtext_link *)list[i]); + break; + case GEMTEXT_PRE: + _do_pre((struct gemtext_pre *)list[i]); + break; + case GEMTEXT_H1: + _do_h1((struct gemtext_h1 *)list[i]); + break; + case GEMTEXT_H2: + _do_h2((struct gemtext_h2 *)list[i]); + break; + case GEMTEXT_H3: + _do_h3((struct gemtext_h3 *)list[i]); + break; + case GEMTEXT_UL: + _do_ul((struct gemtext_ul *)list[i]); + break; + case GEMTEXT_QT: + _do_qt((struct gemtext_qt *)list[i]); + break; + } + } +} + +char *_example = +"does it continue?\n" +"```\n" +"SO much text\n" +"I know right```\n" +"`\n" +"``\n" +" ```\n" +"```\n" +"*hello there\n" +"* this\n" +"*is\n" +"* an amazing list\n" +">this is a greentext\n" +"> this is a \"quote\"\n"; + + +int +main(void) +{ + struct gemtext **lst; + + lst = gemtext_decode(_example); + if (lst == NULL) + return 1; + + _printer(lst); + + gemtext_list_free(lst); + return 0; +} |