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 free_keybindings() */
12 #include "command_db.h" /* for free_command_db() */
13 #include "windows.h" /* for Win struct, free_win(), free_winmeta() */
14 #include "map_objects.h" /* for free_item_defs(), free_monster_defs() */
15 #include "wincontrol.h" /* for free_winconfs() */
16 #include "misc.h" /* for unload_interface_conf() */
20 /* The clean-up routine and the flag resource by which it decides what to do. */
21 static uint32_t cleanup_flags = 0x0000;
22 static void cleanup(struct World * world);
26 static void cleanup(struct World * world)
28 if (cleanup_flags & CLEANUP_NCURSES)
32 if (cleanup_flags & CLEANUP_MAP_OBJECTS)
34 free_items(world->item);
35 free_monsters(world->monster);
37 if (cleanup_flags & CLEANUP_MAP_OBJECT_DEFS)
39 free_item_defs(world->item_def);
40 free_monster_defs(world->monster_def);
42 if (cleanup_flags & CLEANUP_LOG)
46 if (cleanup_flags & CLEANUP_COMMAND_DB)
48 free_command_db(world);
50 if (cleanup_flags & CLEANUP_MAP)
52 free(world->map->cells);
54 if (cleanup_flags & CLEANUP_INTERFACE_CONF)
56 unload_interface_conf(world);
58 if (cleanup_flags & CLEANUP_WIN_META)
60 free_winmeta(world->wmeta);
63 if (cleanup_flags & CLEANUP_KEYBINDINGS)
65 free_keybindings(world->kb_global.kbs);
66 free_keybindings(world->kb_wingeom.kbs);
67 free_keybindings(world->kb_winkeys.kbs);
69 if (cleanup_flags & CLEANUP_WINCONFS)
78 extern void set_cleanup_flag(enum cleanup_flag flag)
80 cleanup_flags = cleanup_flags | flag;
85 extern void exit_game(struct World * world)
93 extern void exit_err(uint8_t err, struct World * world, char * msg)
102 msg = "Details unknown.";
104 printf("Aborted PlomRogue due to error. %s\nInternal error code: %d\n",
108 perror("errno states");