Last change
on this file since 6006f35 was 6006f35, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago |
Create library for reading INI files and defining configuration values
Conflicts:
uspace/Makefile.common
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[6006f35] | 1 | #include "conf/text_parse.h"
|
---|
| 2 |
|
---|
| 3 | #include <assert.h>
|
---|
| 4 | #include <stdlib.h>
|
---|
| 5 |
|
---|
| 6 | /** Constructor of parse structure */
|
---|
| 7 | void text_parse_init(text_parse_t *parse)
|
---|
| 8 | {
|
---|
| 9 | assert(parse);
|
---|
| 10 | list_initialize(&parse->errors);
|
---|
| 11 | parse->has_error = false;
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | /** Destructor of parse structure
|
---|
| 15 | *
|
---|
| 16 | * It must be called before parse structure goes out of scope in order to avoid
|
---|
| 17 | * memory leaks.
|
---|
| 18 | */
|
---|
| 19 | void text_parse_deinit(text_parse_t *parse)
|
---|
| 20 | {
|
---|
| 21 | assert(parse);
|
---|
| 22 | list_foreach_safe(parse->errors, cur_link, next_link) {
|
---|
| 23 | list_remove(cur_link);
|
---|
| 24 | text_parse_error_t *error =
|
---|
| 25 | list_get_instance(cur_link, text_parse_error_t, link);
|
---|
| 26 | free(error);
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | /** Add an error to parse structure
|
---|
| 31 | *
|
---|
| 32 | * @param[in] parse the parse structure
|
---|
| 33 | * @param[in] lineno line number where error originated (or zero)
|
---|
| 34 | * @param[in] parse_errno user error code
|
---|
| 35 | */
|
---|
| 36 | void text_parse_raise_error(text_parse_t *parse, size_t lineno,
|
---|
| 37 | int parse_errno) {
|
---|
| 38 | assert(parse);
|
---|
| 39 |
|
---|
| 40 | parse->has_error = true;
|
---|
| 41 |
|
---|
| 42 | text_parse_error_t *error = malloc(sizeof(text_parse_error_t));
|
---|
| 43 | /* Silently ignore failed malloc, has_error flag is set anyway */
|
---|
| 44 | if (!error) {
|
---|
| 45 | return;
|
---|
| 46 | }
|
---|
| 47 | error->lineno = lineno;
|
---|
| 48 | error->parse_errno = parse_errno;
|
---|
| 49 | list_append(&error->link, &parse->errors);
|
---|
| 50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.