File: build

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 (48 lines) | stat: -rwxr-xr-x 1,208 bytes parent folder | download | duplicates (2)
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
#!/bin/sh
set -e

WORKDIR=`mktemp -d`
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR
cat <<EOF >buildtest.c
#include <r3.h>

int main()
{
    node *n;

    // create a router tree with 10 children capacity (this capacity can grow dynamically)
    n = r3_tree_create(10);

    int route_data = 3;

    // insert the route path into the router tree
    r3_tree_insert_path(n, "/bar", &route_data); // ignore the length of path

    r3_tree_insert_pathl(n, "/zoo", strlen("/zoo"), &route_data );
    r3_tree_insert_pathl(n, "/foo/bar", strlen("/foo/bar"), &route_data );

    r3_tree_insert_pathl(n ,"/post/{id}", strlen("/post/{id}") , &route_data );

    r3_tree_insert_pathl(n, "/user/{id:\\\\d+}", strlen("/user/{id:\\\\d+}"), &route_data );

    // let's compile the tree!
    r3_tree_compile(n, 0);

    // dump the compiled tree
    r3_tree_dump(n, 0);

    // match a route
    node *matched_node = r3_tree_match(n, "/foo/bar", NULL);
    if (matched_node) {
        matched_node->endpoint; // make sure there is a route end at here.
    }

    // release the tree
    r3_tree_free(n);
    return 0;
}
EOF

gcc -std=c99 -o buildtest buildtest.c `pkg-config --cflags --libs r3`
./buildtest