home · contact · privacy
6bb07ee4036d852d0f333e0f783e77a086a6b622
[plomrogue] / src / common / err_try_fgets.h
1 /* err_try_fgets.h
2  *
3  * For superficial syntax checks of individual text file lines.
4  */
5
6 #ifndef ERR_TRY_FGETS_H
7 #define ERR_TRY_FGETS_H
8
9 #include <stdint.h> /* uint8_t, uint32_t */
10 #include <stdio.h> /* FILE */
11
12
13
14 /* Reset err_try_fgets() file line counter back to zero. */
15 extern void reset_err_try_fgets_counter();
16
17 /* Set delimiter expected by err_try_fgets()'s 'c' test. */
18 extern void set_err_try_fgets_delim(char * delim);
19
20 /* If "test", print error message of "intro" + "msg" and output offending line's
21  * number and content.
22  */
23 extern void err_line(uint8_t test, char * line, char * intro, char * msg);
24
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.
30  *
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().
34  *
35  * The available "test" conditions are as follows:
36  *
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)
46  * '8': check for "line" describing an integer smaller than or equal UINT8_MAX
47 */
48 extern void err_try_fgets(char * line, uint32_t linemax, FILE * file,
49                           char * context, char * test);
50
51
52
53 #endif