3 * For superficial syntax checks of individual text file lines.
6 #ifndef ERR_TRY_FGETS_H
7 #define ERR_TRY_FGETS_H
9 #include <stdint.h> /* uint8_t, uint32_t */
10 #include <stdio.h> /* FILE */
14 /* Reset err_try_fgets() file line counter back to zero. */
15 extern void reset_err_try_fgets_counter();
17 /* Set delimiter expected by err_try_fgets()'s 'c' test. */
18 extern void set_err_try_fgets_delim(char * delim);
20 /* If "test", print error message of "intro" + "msg" and output offending line's
23 extern void err_line(uint8_t test, char * line, char * intro, char * msg);
25 /* fgets() / try_fgets() wrapper (therefore the common arguments "line",
26 * "linemax", "file") that performs various checks as defined by characters in
27 * "test". On failure, these tests exit the game with an error message that
28 * pre-pends "context" to a description of the individual test failure and
29 * output of the offending line's number and content.
31 * Note that for the file line count to be correct, it is necessary to call
32 * reset_err_try_fgets_counter() before reading the line, and each line must be
33 * read with a call of err_try_fgets().
35 * The available "test" conditions are as follows:
37 * '0': check for "line" not being empty (not even containing a \n char)
38 * 'n': check for "line" ending with an \n char
39 * 'e': check for "line" starting with an \n char
40 * 'f': check for "line" not starting with an \n char
41 * 's': check for "line" containing two chars (the second may be \n)
42 * 'd': check for "line" being equal to the world.delim delimiter
43 * 'i': check for "line" describing an integer in all its chars before end or \n
44 * (i.e. all other chars must be digits, except the first char, which may
45 * be '+' or '-'; a '+' or '-' without digits following is invalid)
47 extern void err_try_fgets(char * line, uint32_t linemax, FILE * file,
48 char * context, char * test);