home · contact · privacy
Server: Read in former "config" data as normal server god commands.
[plomrogue] / src / common / parse_file.h
1 /* src/common/parse_file.h
2  *
3  * Tools for parsing files.
4  */
5
6 #ifndef PARSE_FILE_H
7 #define PARSE_FILE_H
8
9 #include <stdint.h> /* uint8_t */
10
11
12
13 /* Set err_line() options: "intro" message, char array used to store analyzed
14  * lines ("line"), and whether to "exit" on error message.
15  */
16 extern void set_err_line_options(char * intro, char * line, uint8_t exit);
17
18 /* Increment and reset (to zero) err_line() line counter. */
19 extern void err_line_inc();
20 extern void err_line_zero();
21
22 /* If "test", output "msg", faulty line, its number and exit if so defined by
23  * set_err_line_options(), else return 1 on "test" and 0 if "test" is 0.
24  */
25 extern uint8_t err_line(uint8_t test, char * msg);
26
27 /* Return next token from "line" or NULL if none is found. Tokens either a)
28  * start at the first non-whitespace character and end before the next
29  * whitespace character after that; or b) if the first non-whitespace character
30  * is a single quote followed by at least one other single quote some time later
31  * on the line, the token starts after that first single quote and ends before
32  * the second, with the next token_from_line() call starting its token search
33  * after that second quote. The only way to return an empty string (instead of
34  * NULL) as a token is to delimit the token by two succeeding single quotes.
35  * */
36 extern char * token_from_line(char * line);
37
38 /* Test for "string" to represent proper int16 (type: "i"), uint8 ("8"), uint16
39  * ("u") or uint32 ("U"). Returns 0 if proper value, else >0.
40  */
41 extern uint8_t parsetest_int(char * string, char type);
42
43 /* Test for "string" to be of length 1 (excluding "\0"). Return 1 on failure. */
44 extern uint8_t parsetest_singlechar(char * string);
45
46 /* If "token0" fits "comparand", set "element" to value read from "token1" as
47  * string (type: "s"), char ("c") uint8 ("8"), uint16 ("u"), uint32 ("U") or
48  * int16 ("i"), and return 1; else 0.
49  */
50 extern uint8_t parse_val(char * token0, char * token1, char * comparand,
51                          char type, char * element);
52
53
54
55 #endif