File: simple.c

package info (click to toggle)
libr3 1.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 1,084 kB
  • ctags: 1,086
  • sloc: ansic: 13,117; cpp: 175; makefile: 112; sh: 64; ruby: 52
file content (58 lines) | stat: -rw-r--r-- 1,911 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * bench.c
 * Copyright (C) 2014 c9s <yoanlin93@gmail.com>
 *
 * Distributed under terms of the MIT license.
 */
#include <stdio.h>
#include <stdlib.h>
#include "r3.h"

int main()
{
    node * n = r3_tree_create(3);

    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("/garply/baz/grault", strlen("/garply/baz/grault") );
    m = r3_tree_match_entry(n , e);
    if (m) {
        printf("Matched! %s\n", e->path);
    }
    match_entry_free(e);
    return 0;
}