X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=src%2Fcommand_db.c;h=37f4d69545c76fccecf60e02b8876f203fee9ac3;hb=c3d87a1dee96775443fdf73c53e1350af7ca5fc2;hp=fd7f4dc7a2f78ae431ebd0bf37ee52bfda574da1;hpb=00a7727e37e2d80ff115f03e7971a92c66edcd96;p=plomrogue diff --git a/src/command_db.c b/src/command_db.c index fd7f4dc..37f4d69 100644 --- a/src/command_db.c +++ b/src/command_db.c @@ -2,13 +2,14 @@ #include "command_db.h" #include /* for free() */ -#include /* for FILE typedef, fgets() */ +#include /* for FILE typedef */ #include /* for uint8_t */ #include /* for strlen(), strtok() */ #include "main.h" /* for world global */ -#include "readwrite.h" /* for textfile_sizes(), try_fopen(), try_fclose() */ +#include "readwrite.h" /* for textfile_sizes(), try_fopen(), try_fclose(), + * try_fgets() + */ #include "misc.h" /* for try_malloc() */ -#include "rexit.h" /* exit_trouble() */ @@ -79,17 +80,14 @@ extern char * get_command_longdsc(char * dsc_short) extern void init_command_db() { char * f_name = "init_command_db()"; - char * path = "config/commands"; FILE * file = try_fopen(path, "r", f_name); - uint16_t lines, linemax; - uint8_t test = textfile_sizes(file, &linemax, &lines); - exit_trouble(test, f_name, "textfile_sizes()"); + uint16_t lines; + uint16_t linemax = textfile_sizes(file, &lines); char line[linemax + 1]; - struct Command * cmds = try_malloc(lines * sizeof(struct Command), f_name); uint8_t i = 0; - while (fgets(line, linemax + 1, file)) + while (try_fgets(line, linemax + 1, file, f_name)) { if ('\n' == line[0] || 0 == line[0]) { @@ -101,7 +99,6 @@ extern void init_command_db() i++; } try_fclose(file, f_name); - world.cmd_db = try_malloc(sizeof(struct CommandDB), f_name); world.cmd_db->cmds = cmds; world.cmd_db->n = lines;