r3/examples/simple.c

59 lines
1.9 KiB
C
Raw Normal View History

2014-06-03 10:09:49 -04:00
/*
* bench.c
2014-06-27 01:24:40 -04:00
* Copyright (C) 2014 c9s <yoanlin93@gmail.com>
2014-06-03 10:09:49 -04:00
*
* Distributed under terms of the MIT license.
*/
#include <stdio.h>
#include <stdlib.h>
2014-06-03 10:41:39 -04:00
#include "r3.h"
2014-06-03 10:09:49 -04:00
int main()
{
R3Node * n = r3_tree_create(3);
2014-06-03 10:09:49 -04:00
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;
}
R3Node *m;
2014-06-03 10:09:49 -04:00
m = r3_tree_match(n , "/qux/bar/corge", NULL);
2014-06-03 10:31:30 -04:00
match_entry * e = match_entry_createl("/garply/baz/grault", strlen("/garply/baz/grault") );
2014-06-03 10:09:49 -04:00
m = r3_tree_match_entry(n , e);
if (m) {
printf("Matched! %s\n", e->path);
}
match_entry_free(e);
return 0;
}