1 /* src/common/parse_file.h
3 * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
4 * or any later version. For details on its copyright, license, and warranties,
5 * see the file NOTICE in the root directory of the PlomRogue source package.
7 * Tools for parsing files.
13 #include <stdint.h> /* uint8_t */
17 /* Set err_line() options: "intro" message, char array used to store analyzed
18 * lines ("line"), and whether to "exit" on error message.
20 extern void set_err_line_options(char * intro, char * line, uint8_t exit);
22 /* Increment and reset (to zero) err_line() line counter. */
23 extern void err_line_inc();
24 extern void err_line_zero();
26 /* If "test", output "msg", faulty line, its number and exit if so defined by
27 * set_err_line_options(), else return 1 on "test" and 0 if "test" is 0.
29 extern uint8_t err_line(uint8_t test, char * msg);
31 /* Return next token from "line", or NULL if none is found. Tokens either a)
32 * start at the first non-whitespace character and end before the next
33 * whitespace character after that; or b) if the first non-whitespace character
34 * is a single quote followed by at least one other single quote some time later
35 * on the line, the token starts after that first single quote and ends before
36 * the second, with the next token_from_line() call starting its token search
37 * after that second quote. The only way to return an empty string (instead of
38 * NULL) as a token is to delimit the token by two succeeding single quotes.
40 extern char * token_from_line(char * line);
42 /* Test for "string" to represent proper int16 (type: "i"), uint8 ("8"), uint16
43 * ("u") or uint32 ("U"). Returns 0 if proper value, else >0.
45 extern uint8_t parsetest_int(char * string, char type);
47 /* Test for "string" to be of length 1 (excluding "\0"). Return 1 on failure. */
48 extern uint8_t parsetest_singlechar(char * string);
50 /* If "token0" fits "comparand", set "element" to value read from "token1" as
51 * string (type: "s"), char ("c") uint8 ("8"), uint16 ("u"), uint32 ("U") or
52 * int16 ("i"), and return 1; else 0.
54 extern uint8_t parse_val(char * token0, char * token1, char * comparand,
55 char type, char * element);