From 4b2a80112ee44703927fa5bc7b9a53ccfb876867 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 3 Jun 2014 22:09:49 +0800 Subject: [PATCH] include simple.c --- examples/simple.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 examples/simple.c diff --git a/examples/simple.c b/examples/simple.c new file mode 100644 index 0000000..e07ee64 --- /dev/null +++ b/examples/simple.c @@ -0,0 +1,63 @@ +/* + * bench.c + * Copyright (C) 2014 c9s + * + * Distributed under terms of the MIT license. + */ +#include +#include +#include +#include /* va_list, va_start, va_arg, va_end */ + +#include "r3/r3.h" + +int main() +{ + node * n = r3_tree_create(3); + + int route_data = 999; + + r3_tree_insert_path(n, "/foo/bar/baz", NULL); + r3_tree_insert_path(n, "/foo/bar/qux", NULL); + r3_tree_insert_path(n, "/foo/bar/quux", NULL); + r3_tree_insert_path(n, "/bar/foo/baz", NULL); + r3_tree_insert_path(n, "/bar/foo/quux", NULL); + r3_tree_insert_path(n, "/bar/garply/grault", NULL); + r3_tree_insert_path(n, "/baz/foo/bar", NULL); + r3_tree_insert_path(n, "/baz/foo/qux", NULL); + r3_tree_insert_path(n, "/baz/foo/quux", NULL); + r3_tree_insert_path(n, "/qux/foo/quux", NULL); + r3_tree_insert_path(n, "/qux/foo/corge", NULL); + r3_tree_insert_path(n, "/qux/foo/grault", NULL); + r3_tree_insert_path(n, "/corge/quux/foo", NULL); + r3_tree_insert_path(n, "/corge/quux/bar", NULL); + r3_tree_insert_path(n, "/corge/quux/baz", NULL); + r3_tree_insert_path(n, "/corge/quux/qux", NULL); + r3_tree_insert_path(n, "/corge/quux/grault", NULL); + r3_tree_insert_path(n, "/grault/foo/bar", NULL); + r3_tree_insert_path(n, "/grault/foo/baz", NULL); + r3_tree_insert_path(n, "/garply/baz/quux", NULL); + r3_tree_insert_path(n, "/garply/baz/corge", NULL); + r3_tree_insert_path(n, "/garply/baz/grault", NULL); + r3_tree_insert_path(n, "/garply/qux/foo", NULL); + + char *errstr = NULL; + int err = r3_tree_compile(n, &errstr); + if(err) { + printf("%s\n",errstr); + free(errstr); + return 1; + } + + node *m; + + m = r3_tree_match(n , "/qux/bar/corge", NULL); + + match_entry * e = match_entry_createl("/qux/bar/corge", strlen("/qux/bar/corge") ); + m = r3_tree_match_entry(n , e); + if (m) { + printf("Matched! %s\n", e->path); + } + match_entry_free(e); + return 0; +}