X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fcommon%2Fparse_file.h;fp=src%2Fcommon%2Fparse_file.h;h=b10f3f36b284e3efc156565b406daa71e9e7e08d;hb=c53b42dfc7e4de104f9189428dd5b9a0d431c00a;hp=28865c4a2536188881b38440ef77a8eb703f6fd0;hpb=0ff9d0a37959c6f297d33c23fed0eb889114c4bc;p=plomrogue diff --git a/src/common/parse_file.h b/src/common/parse_file.h index 28865c4..b10f3f3 100644 --- a/src/common/parse_file.h +++ b/src/common/parse_file.h @@ -10,18 +10,6 @@ -/* Many functions working on config file lines / tokens work with these elements - * that only change on line change. Makes sense to pass them over together. - */ -struct Context { - char * line; - char * token0; - char * token1; - char * err_pre; -}; - - - enum parse_flags { EDIT_STARTED = 0x01 @@ -29,25 +17,41 @@ enum parse_flags -/* Writes "context"->token1 to "target" only if it describes a proper uint8. */ -extern void set_uint8(struct Context * context, uint8_t * target); +/* 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. + */ +extern void parse_file(char * path, void ( *token_to_entry) (char *, char *)); -/* If "context"->token0 fits "comparand", set "element" to value read from - * ->token1 as either string (type: "s"), char ("c") or uint8 ("8"), set - * that element's flag to "flags" and return 1; else return 0. +/* 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().) + */ +extern void err_line(uint8_t test, char * msg); + +/* 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 + * on the line, the token starts after that first single quote and ends before + * 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); + +/* 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. */ -extern uint8_t set_val(struct Context * context, char * comparand, +extern uint8_t set_val(char * token0, char * token1, char * comparand, uint8_t * flags, uint8_t set_flag, char type, char * element); -/* Parse file at "path" by passing each line's tokens to "token_to_entry" - * encapsulated into "Context". Empty lines are ignored. Non-empty lines have to - * feature exactly 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 an empty Context.token0. - */ -extern void parse_file(char * path, void ( *token_to_entry) (struct Context *)); - #endif