From d0cca976be6fb90f3724911c8a124bce56b3c5f9 Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Sun, 9 Jun 2019 09:07:48 +0200 Subject: Restructuring the main API and project This commit rewrites pretty much the entire library. It is now much smaller and more maintainable (split over multiple files). It will now also support more features (that aren't implemented yet). Adding two examples to show how to use the new API. Also changing the name of the library everywhere. --- examples/list.c | 23 +++++++++++++++++++++++ examples/tree.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 examples/list.c create mode 100644 examples/tree.c (limited to 'examples') diff --git a/examples/list.c b/examples/list.c new file mode 100644 index 0000000..a09588b --- /dev/null +++ b/examples/list.c @@ -0,0 +1,23 @@ +#include + +int main() +{ + + // Root node which contains a list + struct bowl *root; + bowl_malloc(&root, ARRAY); + + struct bowl *a; + data_malloc(&a, LITERAL, "Destroy capitalism"); + bowl_insert(root, a); + + struct bowl *b; + data_malloc(&b, INTEGER, 1312); + bowl_insert(root, b); + + struct bowl *c; + data_malloc(&c, LITERAL, "Alerta, Antifascista!"); + bowl_insert(root, c); + + return bowl_free(root); +} \ No newline at end of file diff --git a/examples/tree.c b/examples/tree.c new file mode 100644 index 0000000..e55acb9 --- /dev/null +++ b/examples/tree.c @@ -0,0 +1,46 @@ +#include + +int main() +{ + err_t e; + + // Initialise a root node + struct bowl *root; + e = bowl_malloc(&root, ARRAY); + if(e) return e; + + // First Node + struct bowl *a; + e = data_malloc(&a, LITERAL, "Destroy capitalism"); + if(e) return e; + + // Second Node + struct bowl *b; + e = data_malloc(&b, INTEGER, 1312); + if(e) return e; + + // Third node is another ARRAY + struct bowl *c; + e = bowl_malloc(&c, ARRAY); + if(e) return e; + + // Fourth node is another string + struct bowl *d; + e = data_malloc(&d, LITERAL, "Alerta, Antifascista!"); + if(e) return e; + + // Add the d node to c + e = bowl_insert(c, d); + if(e) e; + + // Add other nodes to root + e = bowl_insert(root, a); + if(e) return e; + e = bowl_insert(root, b); + if(e) return e; + e = bowl_insert(root, c); + if(e) return e; + + e = bowl_free(root); + return e; +} \ No newline at end of file -- cgit v1.2.3