Skip to content

Commit

Permalink
add example to README, lightly update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andy5995 committed Feb 22, 2024
1 parent 7701304 commit d7d35bb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_multiple_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ main(void)
}

int i = 0;
do
while (list)
{
printf("\n\
Key: %s\n\
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/test_parse_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ main(void)
}

int i = 0;
do
while (list)
{
fprintf(stderr, "\n\
Key: %s | Expected: %s\n\
Expand All @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions tests/test_parse_file_colons.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ main(void)
}

int i = 0;
do
while (list != NULL)
{
printf("\n\
Key: %s\n\
Expand All @@ -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]);

Expand Down
4 changes: 2 additions & 2 deletions tests/test_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ main(void)
}

int i = 0;
do
while (list)
{
printf("\n\
Key: %s\n\
Expand All @@ -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;
}

0 comments on commit d7d35bb

Please sign in to comment.