X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fcommon%2Fparse_file.h;h=e0e3c7a075fd44ffd6ca963e8e9ea15997ce4aef;hb=21ba1d03b1e883564d301c2781039017dd704b20;hp=b10f3f36b284e3efc156565b406daa71e9e7e08d;hpb=c53b42dfc7e4de104f9189428dd5b9a0d431c00a;p=plomrogue diff --git a/src/common/parse_file.h b/src/common/parse_file.h index b10f3f3..e0e3c7a 100644 --- a/src/common/parse_file.h +++ b/src/common/parse_file.h @@ -1,6 +1,10 @@ /* src/common/parse_file.h * - * Tools for parsing config files. + * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3 + * or any later version. For details on its copyright, license, and warranties, + * see the file NOTICE in the root directory of the PlomRogue source package. + * + * Tools for parsing files. */ #ifndef PARSE_FILE_H @@ -10,27 +14,21 @@ -enum parse_flags -{ - EDIT_STARTED = 0x01 -}; - - - -/* Parse file at "path" by passing each line's first two tokens to - * "token_to_entry". Ignore empty line. Non-empty lines must feature at least - * two tokens as delimited either be whitespace or single quotes (to allow for - * tokens featuring whitespaces). When EOF is reached, token_to_entry() is - * called a last time with a first token of NULL. +/* Set err_line() options: "intro" message, char array used to store analyzed + * lines ("line"), and whether to "exit" on error message. */ -extern void parse_file(char * path, void ( *token_to_entry) (char *, char *)); +extern void set_err_line_options(char * intro, char * line, uint8_t exit); -/* If "test" != 0, exit on output of "msg" and faulty line and line number as - * parsed by parse_file(). (Ought to be called as offspring to parse_file().) +/* Increment and reset (to zero) err_line() line counter. */ +extern void err_line_inc(); +extern void err_line_zero(); + +/* If "test", output "msg", faulty line, its number and exit if so defined by + * set_err_line_options(), else return 1 on "test" and 0 if "test" is 0. */ -extern void err_line(uint8_t test, char * msg); +extern uint8_t err_line(uint8_t test, char * msg); -/* Return next token from "line" or NULL if none is found. Tokens either a) +/* Return next token from "line", or NULL if none is found. Tokens either a) * start at the first non-whitespace character and end before the next * whitespace character after that; or b) if the first non-whitespace character * is a single quote followed by at least one other single quote some time later @@ -38,19 +36,23 @@ extern void err_line(uint8_t test, char * msg); * the second, with the next token_from_line() call starting its token search * after that second quote. The only way to return an empty string (instead of * NULL) as a token is to delimit the token by two succeeding single quotes. - * */ + */ extern char * token_from_line(char * line); -/* Test for "string" to represent proper int16 (type: "i") or uint8 ("8"). */ -extern void test_for_int(char * string, char type); +/* Test for "string" to represent proper int16 (type: "i"), uint8 ("8"), uint16 + * ("u") or uint32 ("U"). Returns 0 if proper value, else >0. + */ +extern uint8_t parsetest_int(char * string, char type); + +/* Test for "string" to be of length 1 (excluding "\0"). Return 1 on failure. */ +extern uint8_t parsetest_singlechar(char * string); /* If "token0" fits "comparand", set "element" to value read from "token1" as - * string (type: "s"), char ("c") uint8 ("8") or int16 ("i"), set that element's - * flag to "flags" and return 1; else return 0. + * string (type: "s"), char ("c") uint8 ("8"), uint16 ("u"), uint32 ("U") or + * int16 ("i"), and return 1; else 0. */ -extern uint8_t set_val(char * token0, char * token1, char * comparand, - uint8_t * flags, uint8_t set_flag, char type, - char * element); +extern uint8_t parse_val(char * token0, char * token1, char * comparand, + char type, char * element);