-/* 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 <stddef.h> /* size_t, NULL */
#include <stdio.h> /* FILE, snprintf() */
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();
- // err_line(UINT32_MAX == err_line_count, "Line reaches max lines limit.");
char * line_copy = strdup(errline_line);
token0 = token_from_line(line_copy);
if (token0)
free(line_copy);
}
token_to_entry(token0, token1);
- try_fclose(file, f_name);
+ try_fclose(file, __func__);
free(errline_line);
free(errline_intro);
}
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.");
}
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;
}