1 /* src/common/parse_file.h
3 * Tools for parsing config files.
9 #include <stddef.h> /* size_t */
10 #include <stdint.h> /* uint8_t */
21 /* Parse file at "path" by passing each line's first two tokens to
22 * "token_to_entry". Ignore empty line. Non-empty lines must feature at least
23 * two tokens as delimited either be whitespace or single quotes (to allow for
24 * tokens featuring whitespaces). When EOF is reached, token_to_entry() is
25 * called a last time with a first token of NULL.
27 extern void parse_file(char * path, void ( *token_to_entry) (char *, char *));
29 /* If "test" != 0, exit on output of "msg" and faulty line and line number as
30 * parsed by parse_file(). (Ought to be called as offspring to parse_file().)
32 extern void err_line(uint8_t test, char * msg);
34 /* Return next token from "line" or NULL if none is found. Tokens either a)
35 * start at the first non-whitespace character and end before the next
36 * whitespace character after that; or b) if the first non-whitespace character
37 * is a single quote followed by at least one other single quote some time later
38 * on the line, the token starts after that first single quote and ends before
39 * the second, with the next token_from_line() call starting its token search
40 * after that second quote. The only way to return an empty string (instead of
41 * NULL) as a token is to delimit the token by two succeeding single quotes.
43 extern char * token_from_line(char * line);
45 /* Test for "string" to represent proper int16 (type: "i") or uint8 ("8"). */
46 extern void parsetest_int(char * string, char type);
48 /* Test for "string" to be of length 1 (excluding "\0" terminator). */
49 extern void parsetest_singlechar(char * string);
51 /* Calls err_line() with fitting message if EDIT_STARTED not set in "flags". */
52 extern void parsetest_defcontext(uint8_t flags);
54 /* Ensure token_from_line() does not find any more tokens on the line. */
55 extern void parsetest_too_many_values();
57 /* Trigger err_line() with "Unknown argument" message. */
58 extern void parse_unknown_arg();
60 /* If "test"!=0 call err_line() with "Declaration of ID already used" message.*/
61 extern void parse_id_uniq(int test);
63 /* Set "flags"=EDIT_STARTED and return pointer to new zeroed array of "size". */
64 extern char * parse_init_entry(uint8_t * flags, size_t size);
66 /* If "token0" fits "comparand", set "element" to value read from "token1" as
67 * string (type: "s"), char ("c") uint8 ("8") or int16 ("i"), set that element's
68 * flag to "flags" and return 1; else return 0.
70 extern uint8_t parse_val(char * token0, char * token1, char * comparand,
71 uint8_t * flags, uint8_t set_flag, char type,
74 /* Check "ready_flag" is set in "flags", re-set "flags" to "ready_flag" only. */
75 extern void parse_and_reduce_to_readyflag(uint8_t * flags, uint8_t ready_flag);