diff --git a/README.md b/README.md index 49c79c5..b718a2d 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,23 @@ See the annotated declarations in [/canfigger.h](https://github.com/andy5995/can ## Examples +```c +st_canfigger_list *config = canfigger_parse_file("path/to/config.conf", ','); +while (config != NULL) { + printf("Key: %s, Value: %s\n", config->key, config->value); + + // Process attributes if necessary + st_canfigger_attr_node *attr = config->attr_node; + while (attr) { + printf("Attribute: %s\n", attr->str); + attr = canfigger_get_next_attr_list_node(attr); + } + + // Move to the next node and automatically free the current node + config = canfigger_get_next_node(config); +} +``` + * [tests/test_parse_file.c](https://github.com/andy5995/canfigger/blob/trunk/tests/test_parse_file.c) * [tests/test_multiple_attributes.c](https://github.com/andy5995/canfigger/blob/trunk/tests/test_multiple_attributes.c) diff --git a/tests/test_multiple_attributes.c b/tests/test_multiple_attributes.c index 1500a9a..89402f6 100644 --- a/tests/test_multiple_attributes.c +++ b/tests/test_multiple_attributes.c @@ -31,7 +31,7 @@ main(void) } int i = 0; - do + while (list) { printf("\n\ Key: %s\n\ @@ -42,7 +42,7 @@ Attribute: %s\n", list->key, list->value, list->attr_node->str); // assert (strcmp (data[i].value, list->value) == 0); int j = 0; - do + while (list->attr_node != NULL) { fprintf(stderr, "attr: %s\n", list->attr_node->str); switch (i) @@ -60,7 +60,7 @@ Attribute: %s\n", list->key, list->value, list->attr_node->str); j++; list->attr_node = canfigger_get_next_attr_list_node(list->attr_node); - } while (list->attr_node != NULL); + } fprintf(stderr, "j: %d\n", j); if (j > 0) @@ -82,7 +82,7 @@ Attribute: %s\n", list->key, list->value, list->attr_node->str); i++; list = canfigger_get_next_node(list); - } while (list != NULL); + } assert(i == 3); diff --git a/tests/test_parse_file.c b/tests/test_parse_file.c index fc619e8..eb72161 100644 --- a/tests/test_parse_file.c +++ b/tests/test_parse_file.c @@ -33,7 +33,7 @@ main(void) } int i = 0; - do + while (list) { fprintf(stderr, "\n\ Key: %s | Expected: %s\n\ @@ -47,7 +47,7 @@ Attribute: %s | Expected: %s\n", list->key, data[i].key, list->value, data[i].va i++; list = canfigger_get_next_node(list); - } while (list != NULL); + } assert(i == ARRAY_SIZE(data)); diff --git a/tests/test_parse_file_colons.c b/tests/test_parse_file_colons.c index bfdffca..912daa1 100644 --- a/tests/test_parse_file_colons.c +++ b/tests/test_parse_file_colons.c @@ -25,7 +25,7 @@ main(void) } int i = 0; - do + while (list != NULL) { printf("\n\ Key: %s\n\ @@ -40,7 +40,7 @@ Attribute: %s\n", list->key, list->value, list->attr_node->str); i++; list = canfigger_get_next_node(list); - } while (list != NULL); + } assert(i == sizeof data / sizeof data[0]); diff --git a/tests/test_unicode.c b/tests/test_unicode.c index ed8a4d0..6f518f7 100644 --- a/tests/test_unicode.c +++ b/tests/test_unicode.c @@ -31,7 +31,7 @@ main(void) } int i = 0; - do + while (list) { printf("\n\ Key: %s\n\ @@ -45,7 +45,7 @@ Attribute: %s\n", list->key, list->value, list->attr_node->str); i++; list = canfigger_get_next_node(list); - } while (list != NULL); + } return 0; }