4 #include <stdlib.h> /* for exit(), free(), defines EXIT_SUCESS, EXIT_FAILURE */
5 #include <stdio.h> /* for printf(), perror() */
6 #include <stdint.h> /* for uint8_t */
7 #include <ncurses.h> /* for endwin() */
8 #include <errno.h> /* for errno */
9 #include "main.h" /* for World struct */
10 #include "map.h" /* for Map struct */
11 #include "keybindings.h" /* for KeysWinData, KeyBinding structs */
12 #include "command_db.h" /* for free_command_db() */
13 #include "windows.h" /* for Win struct */
14 #include "wincontrol.h" /* for free_win() */
18 /* The clean-up routine and the flag resource by which it decides what to do. */
19 static uint32_t cleanup_flags = 0x0000;
20 static void cleanup(struct World * world);
24 static void cleanup(struct World * world)
26 if (cleanup_flags & CLEANUP_NCURSES)
30 if (cleanup_flags & CLEANUP_MAP)
32 free(world->map->cells);
34 if (cleanup_flags & CLEANUP_KEYBINDINGS)
37 for (key = 0; key <= world->keyswindata->max; key++)
39 free(world->keybindings[key].name);
41 free(world->keybindings);
42 free(world->keyswindata);
44 if (cleanup_flags & CLEANUP_LOG)
48 if (cleanup_flags & CLEANUP_COMMAND_DB)
50 free_command_db(world);
52 if (cleanup_flags & CLEANUP_WIN_INFO)
54 free_win(world->wins.info);
56 if (cleanup_flags & CLEANUP_WIN_MAP)
58 free_win(world->wins.map);
60 if (cleanup_flags & CLEANUP_WIN_LOG)
62 free_win(world->wins.log);
64 if (cleanup_flags & CLEANUP_WIN_KEYS)
66 free_win(world->wins.keys);
72 extern void set_cleanup_flag(enum cleanup_flag flag)
74 cleanup_flags = cleanup_flags | flag;
79 extern void exit_game(struct World * world)
87 extern void exit_err(uint8_t err, struct World * world, char * msg)
96 msg = "Details unknown.";
98 printf("Aborted PlomRogue due to error. %s\nInternal error code: %d\n",
102 perror("errno states");