diff --git a/include/r3.h b/include/r3.h index 58d1160..26a5352 100644 --- a/include/r3.h +++ b/include/r3.h @@ -12,14 +12,10 @@ #include #include #include -#include "config.h" #include "r3_define.h" #include "str_array.h" #include "match_entry.h" -#ifdef ENABLE_JSON -#include -#endif #ifdef __cplusplus @@ -108,7 +104,7 @@ edge * r3_node_find_edge(const node * n, const char * pat, int pat_len); void r3_node_append_edge(node *n, edge *child); -edge * r3_node_find_common_prefix(node *n, char *path, int path_len, int *prefix_len, char **errstr); +edge * r3_node_find_common_prefix(node *n, const char *path, int path_len, int *prefix_len, char **errstr); node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * data); @@ -181,34 +177,6 @@ enum { NODE_COMPARE_STR, NODE_COMPARE_PCRE, NODE_COMPARE_OPCODE }; enum { OP_EXPECT_MORE_DIGITS = 1, OP_EXPECT_MORE_WORDS, OP_EXPECT_NOSLASH, OP_EXPECT_NODASH, OP_EXPECT_MORE_ALPHA }; -#ifdef ENABLE_JSON -json_object * r3_edge_to_json_object(const edge * e); -json_object * r3_node_to_json_object(const node * n); -json_object * r3_route_to_json_object(const route * r); - -const char * r3_node_to_json_string_ext(const node * n, int options); -const char * r3_node_to_json_pretty_string(const node * n); -const char * r3_node_to_json_string(const node * n); -#endif - - -#ifdef ENABLE_GRAPHVIZ -#include -#include - -void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node * n, int node_cnt); - -int r3_tree_render(const node * tree, const char *layout, const char * format, FILE *fp); - -int r3_tree_render_dot(const node * tree, const char *layout, FILE *fp); - -int r3_tree_render_file(const node * tree, const char * format, const char * filename); -#endif - - - - - #ifdef __cplusplus } #endif diff --git a/include/r3_gvc.h b/include/r3_gvc.h new file mode 100644 index 0000000..334fab9 --- /dev/null +++ b/include/r3_gvc.h @@ -0,0 +1,23 @@ +/* + * r3_gvc.h + * Copyright (C) 2014 c9s + * + * Distributed under terms of the MIT license. + */ +#ifndef R3_GVC_H +#define R3_GVC_H + +#include +#include +#include "r3.h" + +void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node * n, int node_cnt); + +int r3_tree_render(const node * tree, const char *layout, const char * format, FILE *fp); + +int r3_tree_render_dot(const node * tree, const char *layout, FILE *fp); + +int r3_tree_render_file(const node * tree, const char * format, const char * filename); + + +#endif /* !R3_GVC_H */ diff --git a/include/r3_json.h b/include/r3_json.h new file mode 100644 index 0000000..8925e1d --- /dev/null +++ b/include/r3_json.h @@ -0,0 +1,24 @@ +/* + * r3_json.h + * Copyright (C) 2014 c9s + * + * Distributed under terms of the MIT license. + */ + +#ifndef R3_JSON_H +#define R3_JSON_H + +#include +#include "r3.h" + +json_object * r3_edge_to_json_object(const edge * e); +json_object * r3_node_to_json_object(const node * n); +json_object * r3_route_to_json_object(const route * r); + +const char * r3_node_to_json_string_ext(const node * n, int options); +const char * r3_node_to_json_pretty_string(const node * n); +const char * r3_node_to_json_string(const node * n); + + + +#endif /* !R3_JSON_H */ diff --git a/src/edge.c b/src/edge.c index ad6eb7f..ea4371e 100644 --- a/src/edge.c +++ b/src/edge.c @@ -4,6 +4,7 @@ * * Distributed under terms of the MIT license. */ +#include "config.h" #include #include #include @@ -17,8 +18,6 @@ // Judy array // #include -#include - #include "r3.h" #include "r3_str.h" #include "slug.h" diff --git a/src/gvc.c b/src/gvc.c index 963df28..5475409 100644 --- a/src/gvc.c +++ b/src/gvc.c @@ -4,11 +4,12 @@ * * Distributed under terms of the MIT license. */ - +#include "config.h" #include #include #include #include "r3.h" +#include "r3_gvc.h" #include "zmalloc.h" void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node * n, int node_cnt) { diff --git a/src/json.c b/src/json.c index a8a1194..61af5cb 100644 --- a/src/json.c +++ b/src/json.c @@ -4,10 +4,10 @@ * * Distributed under terms of the MIT license. */ -#include #include "config.h" +#include #include "r3.h" - +#include "r3_json.h" json_object * r3_route_to_json_object(const route * r) { json_object *obj; diff --git a/src/node.c b/src/node.c index 93d1f82..cafa643 100644 --- a/src/node.c +++ b/src/node.c @@ -494,7 +494,7 @@ node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * d * 4. "aaa{slug:xxx}/hate" vs "aab{slug:yyy}/bar" => common prefix = "aa" * 5. "/foo/{slug}/hate" vs "/fo{slug}/bar" => common prefix = "/fo" */ -edge * r3_node_find_common_prefix(node *n, char *path, int path_len, int *prefix_len, char **errstr) { +edge * r3_node_find_common_prefix(node *n, const char *path, int path_len, int *prefix_len, char **errstr) { int i = 0; int prefix = 0; *prefix_len = 0; diff --git a/src/slug.c b/src/slug.c index a55c2fe..4edbead 100644 --- a/src/slug.c +++ b/src/slug.c @@ -15,11 +15,11 @@ -r3_slug_t * r3_slug_new(char * path, int path_len) { +r3_slug_t * r3_slug_new(const char * path, int path_len) { r3_slug_t * s = zmalloc(sizeof(r3_slug_t)); if (!s) return NULL; - s->path = path; + s->path = (char*) path; s->path_len = path_len; s->begin = NULL; @@ -76,8 +76,8 @@ Return 1 => Slug found Return -1 => Slug parsing error */ -int r3_slug_parse(r3_slug_t *s, char *needle, int needle_len, char *offset, char **errstr) { - s->path = needle; +int r3_slug_parse(r3_slug_t *s, const char *needle, int needle_len, char *offset, char **errstr) { + s->path = (char*) needle; s->path_len = needle_len; if (offset == NULL) { diff --git a/src/slug.h b/src/slug.h index b42f6dd..cd51700 100644 --- a/src/slug.h +++ b/src/slug.h @@ -39,11 +39,11 @@ typedef struct { } r3_slug_t; -r3_slug_t * r3_slug_new(char * path, int path_len); +r3_slug_t * r3_slug_new(const char * path, int path_len); int r3_slug_check(r3_slug_t *s); -int r3_slug_parse(r3_slug_t *s, char *needle, int needle_len, char *offset, char **errstr); +int r3_slug_parse(r3_slug_t *s, const char *needle, int needle_len, char *offset, char **errstr); char * r3_slug_to_str(const r3_slug_t *s); diff --git a/tests/check_gvc.c b/tests/check_gvc.c index 6442d0a..b337f1d 100644 --- a/tests/check_gvc.c +++ b/tests/check_gvc.c @@ -9,6 +9,7 @@ #include #include #include "r3.h" +#include "r3_gvc.h" #include "r3_str.h" #include "bench.h" diff --git a/tests/check_json.c b/tests/check_json.c index f15109e..fa8ec12 100644 --- a/tests/check_json.c +++ b/tests/check_json.c @@ -11,6 +11,7 @@ #include #include "r3.h" #include "r3_str.h" +#include "r3_json.h" #include "zmalloc.h" START_TEST (test_json_encode)