home
·
contact
·
privacy
projects
/
plomrogue
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed bug that led to endless loop in nearest_enemy_dir().
[plomrogue]
/
src
/
command_db.c
diff --git
a/src/command_db.c
b/src/command_db.c
index 7e60b1d3510386dd3101000acf3cc637025b3506..37f4d69545c76fccecf60e02b8876f203fee9ac3 100644
(file)
--- a/
src/command_db.c
+++ b/
src/command_db.c
@@
-2,12
+2,14
@@
#include "command_db.h"
#include <stdlib.h> /* for free() */
#include "command_db.h"
#include <stdlib.h> /* for free() */
-#include <stdio.h> /* for FILE typedef
, fgets()
*/
+#include <stdio.h> /* for FILE typedef */
#include <stdint.h> /* for uint8_t */
#include <string.h> /* for strlen(), strtok() */
#include "main.h" /* for world global */
#include <stdint.h> /* for uint8_t */
#include <string.h> /* for strlen(), strtok() */
#include "main.h" /* for world global */
-#include "readwrite.h" /* for textfile_sizes(), try_fopen(), try_fclose() */
-#include "misc.h" /* for try_malloc(), exit_trouble */
+#include "readwrite.h" /* for textfile_sizes(), try_fopen(), try_fclose(),
+ * try_fgets()
+ */
+#include "misc.h" /* for try_malloc() */
@@
-78,17
+80,14
@@
extern char * get_command_longdsc(char * dsc_short)
extern void init_command_db()
{
char * f_name = "init_command_db()";
extern void init_command_db()
{
char * f_name = "init_command_db()";
-
char * path = "config/commands";
FILE * file = try_fopen(path, "r", f_name);
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];
char line[linemax + 1];
-
struct Command * cmds = try_malloc(lines * sizeof(struct Command), f_name);
uint8_t i = 0;
struct Command * cmds = try_malloc(lines * sizeof(struct Command), f_name);
uint8_t i = 0;
- while (
fgets(line, linemax + 1, fil
e))
+ while (
try_fgets(line, linemax + 1, file, f_nam
e))
{
if ('\n' == line[0] || 0 == line[0])
{
{
if ('\n' == line[0] || 0 == line[0])
{
@@
-100,7
+99,6
@@
extern void init_command_db()
i++;
}
try_fclose(file, f_name);
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;
world.cmd_db = try_malloc(sizeof(struct CommandDB), f_name);
world.cmd_db->cmds = cmds;
world.cmd_db->n = lines;