1 /* src/common/parse_file.h
3 * Tools for parsing config files.
9 #include <stdint.h> /* uint8_t */
20 /* Parse file at "path" by passing each line's first two tokens to
21 * "token_to_entry". Ignore empty line. Non-empty lines must feature at least
22 * two tokens as delimited either be whitespace or single quotes (to allow for
23 * tokens featuring whitespaces). When EOF is reached, token_to_entry() is
24 * called a last time with a first token of NULL.
26 extern void parse_file(char * path, void ( *token_to_entry) (char *, char *));
28 /* If "test" != 0, exit on output of "msg" and faulty line and line number as
29 * parsed by parse_file(). (Ought to be called as offspring to parse_file().)
31 extern void err_line(uint8_t test, char * msg);
33 /* Return next token from "line" or NULL if none is found. Tokens either a)
34 * start at the first non-whitespace character and end before the next
35 * whitespace character after that; or b) if the first non-whitespace character
36 * is a single quote followed by at least one other single quote some time later
37 * on the line, the token starts after that first single quote and ends before
38 * the second, with the next token_from_line() call starting its token search
39 * after that second quote. The only way to return an empty string (instead of
40 * NULL) as a token is to delimit the token by two succeeding single quotes.
42 extern char * token_from_line(char * line);
44 /* Test for "string" to represent proper int16 (type: "i") or uint8 ("8"). */
45 extern void test_for_int(char * string, char type);
47 /* If "token0" fits "comparand", set "element" to value read from "token1" as
48 * string (type: "s"), char ("c") uint8 ("8") or int16 ("i"), set that element's
49 * flag to "flags" and return 1; else return 0.
51 extern uint8_t set_val(char * token0, char * token1, char * comparand,
52 uint8_t * flags, uint8_t set_flag, char type,
55 /* Check "ready_flag" is set in "flags", re-set "flags" to "ready_flag" only. */
56 extern void finalize_by_readyflag(uint8_t * flags, uint8_t ready_flag);