home · contact · privacy
Server: Remove log_help(), this should be serverd by the client.
[plomrogue] / src / common / parse_file.h
1 /* src/common/parse_file.h
2  *
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.
6  *
7  * Tools for parsing files.
8  */
9
10 #ifndef PARSE_FILE_H
11 #define PARSE_FILE_H
12
13 #include <stdint.h> /* uint8_t */
14
15
16
17 /* Set err_line() options: "intro" message, char array used to store analyzed
18  * lines ("line"), and whether to "exit" on error message.
19  */
20 extern void set_err_line_options(char * intro, char * line, uint8_t exit);
21
22 /* Increment and reset (to zero) err_line() line counter. */
23 extern void err_line_inc();
24 extern void err_line_zero();
25
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.
28  */
29 extern uint8_t err_line(uint8_t test, char * msg);
30
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.
39  */
40 extern char * token_from_line(char * line);
41
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.
44  */
45 extern uint8_t parsetest_int(char * string, char type);
46
47 /* Test for "string" to be of length 1 (excluding "\0"). Return 1 on failure. */
48 extern uint8_t parsetest_singlechar(char * string);
49
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.
53  */
54 extern uint8_t parse_val(char * token0, char * token1, char * comparand,
55                          char type, char * element);
56
57
58
59 #endif