FILE * file = fopen("config/commands", "r");
exit_err(NULL == file, world, err);
uint16_t lines, linemax;
- textfile_sizes(file, &linemax, &lines);
+ err = "Trouble in init_cmds() with textfile_sizes().";
+ exit_err(textfile_sizes(file, &linemax, &lines), world, err);
err = "Trouble in init_cmds() with malloc().";
char * line = malloc(linemax);
exit_err(NULL == line, world, err);
{
FILE * file = fopen("config/keybindings", "r");
uint16_t lines, linemax;
- textfile_sizes(file, &linemax, &lines);
+ char * err = "textfile_sizes() in init_keybindings() returns error.";
+ exit_err(textfile_sizes(file, &linemax, &lines), world, err);
struct KeyBinding * keybindings = malloc(lines * sizeof(struct KeyBinding));
char * command = malloc(linemax);
uint16_t commcount = 0;
raw();
init_keybindings(&world);
set_cleanup_flag(CLEANUP_KEYBINDINGS);
- char * err_winmem = "Trouble with init_win_meta() or draw_all_wins() in "
- "main().";
+ char * err_winmem = "Trouble with init_win_meta() in main ().";
exit_err(init_win_meta(screen, &world.wins.meta), &world, err_winmem);
set_cleanup_flag(CLEANUP_WIN_META);
world.wins.keys = init_win_from_file(&world, "Keys", draw_keys_win);
set_cleanup_flag(CLEANUP_WIN_LOG);
world.wins.map = init_win_from_file(&world, "Map", draw_map_win);
set_cleanup_flag(CLEANUP_WIN_MAP);
-
sorted_wintoggle(&world);
+ err_winmem = "Trouble with draw_all_wins() in main().";
/* Replay mode. */
int key;
#include "readwrite.h" /* for [read/write]_uint[8/16/23][_bigendian]() */
#include "misc.h" /* for textfile_sizes(), find_passable_pos() */
#include "main.h" /* for World struct */
+#include "rexit.h" /* for err_exit() */
/* Return pointer to newly allocated map object struct of size "size". If first
* in map object chain ("first" pointing to !0), point "start" to it.
+ *
+ * Returns NULL instead of MapObj pointer if malloc() failed.
*/
static struct MapObj * get_next_map_obj(void * start, char * first,
size_t size, struct MapObj * map_obj);
{
world->item_def = 0;
world->monster_def = 0;
+ char * err = "Trouble in init_map_object_defs() with fopen().";
FILE * file = fopen(filename, "r");
+ exit_err(NULL == file, world, err);
uint16_t linemax;
- textfile_sizes (file, &linemax, NULL);
+ err = "Trouble in init_map_object_defs() with textfile_sizes().";
+ exit_err(textfile_sizes(file, &linemax, NULL), world, err);
struct MapObjDef mod;
struct ItemDef id;
struct MonsterDef md;
struct ItemDef * * p_p_id = &world->item_def;
struct MonsterDef * * p_p_md = &world->monster_def;
+ err = "Trouble in init_map_object_defs() with malloc() or calloc().";
char * defline = malloc(linemax);
+ exit_err(NULL == defline, world, err);
char * line_p;
char * delim = " ";
while (fgets(defline, linemax, file))
line_p = strtok(NULL, delim);
}
mod.desc = calloc(strlen(line_p), sizeof(char));
+ exit_err(NULL == mod.desc, world, err);
memcpy(mod.desc, line_p, strlen(line_p) - 1);
if ('i' == mod.m_or_i)
{
id.map_obj_def = mod;
* p_p_id = malloc(sizeof(struct ItemDef));
+ exit_err(NULL == p_p_id, world, err);
* * p_p_id = id;
p_p_id = (struct ItemDef * *) * p_p_id;
}
{
md.map_obj_def = mod;
* p_p_md = malloc(sizeof(struct MonsterDef));
+ exit_err(NULL == p_p_md, world, err);
* * p_p_md = md;
p_p_md = (struct MonsterDef * *) * p_p_md;
}
}
free(defline);
- fclose(file);
+ err = "Trouble in init_map_object_defs() with fclose().";
+ exit_err(fclose(file), world, err);
}
char first = 1;
long pos;
uint16_t read_uint16 = 0;
+ char * err = "Trouble in read_map_objects() with get_next_map_obj().";
while (1)
{
pos = ftell(file);
size = sizeof(struct Item);
}
map_obj = get_next_map_obj(start, &first, size, map_obj);
+ exit_err(NULL == map_obj, world, err);
map_obj->type = type;
if ( read_uint16_bigendian(file, &map_obj->pos.y)
|| read_uint16_bigendian(file, &map_obj->pos.x))
char first = 1;
struct MapObjDef * mod = get_map_obj_def(world, def_id);
size_t size = 0;
+ char * err = "Trouble in build_map_objects() with get_next_map_obj().";
if ('i' == mod->m_or_i)
{
size = sizeof(struct Item);
for (i = 0; i < n; i++)
{
mo = get_next_map_obj(start, &first, size, mo);
+ exit_err(NULL == mo, world, err);
mo->pos = find_passable_pos(world->map);
if ('i' == mod->m_or_i)
{
#include <unistd.h> /* for unlink(), acess() */
#include <stdlib.h> /* for calloc(), free() */
#include <string.h> /* for strlen(), strcmp(), memcpy() */
-#include <stdint.h> /* for uint16_t */
+#include <stdint.h> /* for uint8_t, uint16_t */
#include "readwrite.h" /* for [read/write]_uint[8/16/32][_bigendian]() */
#include "map_objects.h" /* for struct Monster, write_map_objects(), */
#include "map_object_actions.h" /* for is_passable(), move_monster() */
-extern void textfile_sizes(FILE * file, uint16_t * linemax_p,
- uint16_t * n_lines_p)
+extern uint8_t textfile_sizes(FILE * file, uint16_t * linemax_p,
+ uint16_t * n_lines_p)
{
uint16_t n_lines = 0;
int c = 0;
}
}
}
- fseek(file, 0, SEEK_SET);
+ if (-1 == fseek(file, 0, SEEK_SET))
+ {
+ return 1;
+ }
* linemax_p = linemax;
if (n_lines_p)
{
* n_lines_p = n_lines;
}
+ return 0;
}
-#include <stdint.h> /* for uint16_t */
+#include <stdint.h> /* for uint8_t, uint16_t */
#include <stdio.h> /* for FILE typedef */
#include "yx_uint16.h" /* for yx_uint16 coordinates */
struct World;
/* Learn from "file" the largest line length (pointed to by "linemax_p") and
* (pointed to by "n_lines_p" if it is not set to NULL) the number of lines.
+ *
+ * Returns 0 on success, 1 on fseek() error.
*/
-extern void textfile_sizes(FILE * file, uint16_t * linemax_p,
- uint16_t * n_lines_p);
+extern uint8_t textfile_sizes(FILE * file, uint16_t * linemax_p,
+ uint16_t * n_lines_p);
free(path);
exit_err(NULL == file, world, err);
uint16_t linemax;
- textfile_sizes(file, &linemax, NULL);
+ err = "Trouble in init_win_from_file() with textfile_sizes().";
+ exit_err(textfile_sizes(file, &linemax, NULL), world, err);
char * line = malloc(linemax);
err = "Trouble in init_win_from_file() with fgets().";
exit_err(NULL == fgets(line, linemax, file), world, err);
exit_err(fclose(file), world, err);
struct WinMeta * wmeta = world->wins.meta;
- struct Win * wp; // = malloc(sizeof(struct Win));
- init_win(wmeta, &wp, title, height, width, world, f);
+ struct Win * wp;
+ err = "Trouble in init_win_from_file() with init_win().";
+ exit_err(init_win(wmeta, &wp, title, height, width, world, f), world, err);
free(title);
return wp;
}
extern void sorted_wintoggle(struct World * world)
{
- char * err = "Trouble in sorted_wintoggle() with fopen() on file "
- "'config/toggle_win_order'.";
+ char * err = "Trouble in sorted_wintoggle() with fopen().";
FILE * file = fopen("config/windows/toggle_order", "r");
exit_err(NULL == file, world, err);
uint16_t linemax;
- textfile_sizes(file, &linemax, NULL);
+ err = "Trouble in sorted_wintoggle() with textfile_sizes().";
+ exit_err(textfile_sizes(file, &linemax, NULL), world, err);
char win_order[linemax];
- err = "Trouble in sorted_wintoggle() with fgets() on file "
- "'config/toggle_win_order'.";
+ err = "Trouble in sorted_wintoggle() with fgets().";
exit_err(NULL == fgets(win_order, linemax, file), world, err);
- err = "Trouble in sorted_wintoggle() with fclose() on file "
- "'toggle_win_order'.";
+ err = "Trouble in sorted_wintoggle() with fclose().";
exit_err(fclose(file), world, err);
char c;