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 <errno.h> /* for errno */
8 #include "main.h" /* for world global */
9 #include "map.h" /* for Map struct */
10 #include "keybindings.h" /* for free_keybindings() */
11 #include "command_db.h" /* for free_command_db() */
12 #include "windows.h" /* for Win struct, free_winmeta_and_endwin() */
13 #include "map_objects.h" /* for free_map_objects, free_map_object_defs() */
14 #include "misc.h" /* for unload_interface_conf() */
15 #include "map_object_actions.h" /* for free_map_object_actions() */
19 /* The clean-up routine and the flag resource by which it decides what to do. */
20 static uint32_t cleanup_flags = 0x0000;
21 static void cleanup();
27 if (cleanup_flags & CLEANUP_MAP_OBJECTS)
29 free_map_objects(world.map_objs);
31 if (cleanup_flags & CLEANUP_MAP_OBJECT_DEFS)
33 free_map_object_defs(world.map_obj_defs);
35 if (cleanup_flags & CLEANUP_LOG)
39 if (cleanup_flags & CLEANUP_COMMAND_DB)
43 if (cleanup_flags & CLEANUP_MAPOBJACTS)
45 free_map_object_actions(world.map_obj_acts);
47 if (cleanup_flags & CLEANUP_MAP)
49 free(world.map->cells);
51 if (cleanup_flags & CLEANUP_INTERFACE)
53 unload_interface_conf();
55 if (cleanup_flags & CLEANUP_NCURSES)
57 free_winmeta_and_endwin();
63 extern void set_cleanup_flag(enum cleanup_flag flag)
65 cleanup_flags = cleanup_flags | flag;
70 extern void exit_game()
78 extern void exit_err(uint8_t err, char * msg)
87 msg = "Details unknown.";
89 printf("Aborted PlomRogue due to error. %s\nInternal error code: %d\n",
93 perror("errno states");