diff --git a/README.md b/README.md index 158f347..994678a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ libtoml Fast C parser using Ragel to generate the state machine. -Currently targetted at toml b098bd2. +Currently targetted at toml 4f23be43e4 (minus UTF-8) Usage ===== @@ -13,6 +13,7 @@ Usage struct toml_node *root; struct toml_node *node; +char *buf = "[foo]\nbar = 1\n"; toml_init(&root); toml_parse(toml_root, buf, len); @@ -23,6 +24,23 @@ toml_dump(toml_root, stdout); toml_free(root); ``` +Building it +=========== + +```sh +> autoconf +> ./configure +> make +``` + +If you want to run the tests + +```sh +> ./configure --with-cunit= +> make test +> ./test +``` + TODO ==== diff --git a/toml.c b/toml.c index dec46a2..42efa6f 100644 --- a/toml.c +++ b/toml.c @@ -11,8 +11,6 @@ #include "toml.h" -typedef void (*toml_node_walker)(struct toml_node *, void *); - int toml_init(struct toml_node **toml_root) { @@ -200,7 +198,6 @@ _toml_walk(struct toml_node *node, toml_node_walker fn, void *ctx) list_for_each_safe(&node->value.list, item, next, list) { _toml_walk(&item->node, fn, ctx); - free(item); } break; } @@ -214,6 +211,12 @@ _toml_walk(struct toml_node *node, toml_node_walker fn, void *ctx) } } +void +toml_walk(struct toml_node *root, toml_node_walker fn, void *ctx) +{ + _toml_walk(root, fn, ctx); +} + void toml_dump(struct toml_node *toml_root, FILE *output) { diff --git a/toml.h b/toml.h index b5a23be..dba13da 100644 --- a/toml.h +++ b/toml.h @@ -41,11 +41,14 @@ struct toml_list_item { struct toml_node node; }; +typedef void (*toml_node_walker)(struct toml_node *, void *); + int toml_init(struct toml_node **); int toml_parse(struct toml_node *, char *, int); struct toml_node *toml_get(struct toml_node *, char *); void toml_dump(struct toml_node *, FILE *); void toml_tojson(struct toml_node *, FILE *); void toml_free(struct toml_node *); +void toml_walk(struct toml_node *, toml_node_walker, void *); #endif