X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fclient%2Fparse.c;h=5bf2bd71a957d95900c13076101ee5afc0eca415;hb=b366e1f88c64e11f4e6e0cc088b89dd7ffcab25b;hp=4f47aaa23951a24e268eee988f7b74a564281231;hpb=3451efffc74f1fbf2453d89e7858e71c97343c22;p=plomrogue diff --git a/src/client/parse.c b/src/client/parse.c index 4f47aaa..5bf2bd7 100644 --- a/src/client/parse.c +++ b/src/client/parse.c @@ -1,6 +1,11 @@ -/* src/client/parse.c */ - -#define _POSIX_C_SOURCE 200809L /* strdup() */ +/* src/client/parse.c + * + * 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. + */ + +#define _POSIX_C_SOURCE 200809L /* strdup(), snprintf() */ #include "parse.h" #include /* size_t, NULL */ #include /* FILE, snprintf() */ @@ -19,24 +24,23 @@ extern void parse_file(char * path, void (* token_to_entry) (char *, char *)) { - char * f_name = "read_new_config_file()"; char * prefix = "Failed reading config file: \""; char * affix = "\". "; size_t size = strlen(prefix) + strlen(path) + strlen(affix) + 1; - char * errline_intro = try_malloc(size, f_name); + char * errline_intro = try_malloc(size, __func__); int test = snprintf(errline_intro, size, "%s%s%s", prefix, path, affix); - exit_trouble(test < 0, f_name, "snprintf()"); + exit_trouble(test < 0, __func__, "snprintf"); exit_err(access(path, F_OK), errline_intro); - FILE * file = try_fopen(path, "r", f_name); + FILE * file = try_fopen(path, "r", __func__); uint32_t linemax = textfile_width(file); - char * errline_line = try_malloc(linemax + 1, f_name); + char * errline_line = try_malloc(linemax + 1, __func__); set_err_line_options(errline_intro, errline_line, 1); err_line_zero(); - err_line(0 == linemax, "File is empty."); + err_line(!linemax, "File is empty."); char * token0 = NULL; /* For final token_to_entry() if while() stagnates. */ char * token1 = NULL; char * err_val = "No value given."; - while (try_fgets(errline_line, linemax + 1, file, f_name)) + while (try_fgets(errline_line, linemax + 1, file, __func__)) { err_line_inc(); char * line_copy = strdup(errline_line); @@ -50,7 +54,7 @@ extern void parse_file(char * path, void (* token_to_entry) (char *, char *)) free(line_copy); } token_to_entry(token0, token1); - try_fclose(file, f_name); + try_fclose(file, __func__); free(errline_line); free(errline_intro); } @@ -66,7 +70,7 @@ extern void parsetest_defcontext(uint8_t flags) extern void parsetest_too_many_values() { - err_line(NULL != token_from_line(NULL), "Too many values."); + err_line(!(!token_from_line(NULL)), "Too many values."); } @@ -87,9 +91,8 @@ extern void parse_unknown_arg() extern char * parse_init_entry(uint8_t * flags, size_t size) { - char * f_name = "parse_init_entry()"; *flags = EDIT_STARTED; - char * p = try_malloc(size, f_name); + char * p = try_malloc(size, __func__); memset(p, 0, size); return p; }