X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;ds=sidebyside;f=src%2Frexit.c;h=f79eac7582f25f0d5c7284a47198740b35015344;hb=10680a2398daf76e6a0cd261c2b247e6902f2ad0;hp=84664a8491cd03c3915a7261e28d6453f528b82d;hpb=d701e79e9297470b56315eefd431c62c9aba28b2;p=plomrogue diff --git a/src/rexit.c b/src/rexit.c index 84664a8..f79eac7 100644 --- a/src/rexit.c +++ b/src/rexit.c @@ -2,17 +2,17 @@ #include "rexit.h" #include /* for exit(), free(), defines EXIT_SUCESS, EXIT_FAILURE */ -#include /* for printf(), perror() */ +#include /* for printf(), perror(), sprintf() */ #include /* for uint8_t */ -#include /* for endwin() */ +#include /* for strlen() */ #include /* for errno */ #include "main.h" /* for world global */ -#include "map.h" /* for Map struct */ -#include "keybindings.h" /* for free_keybindings() */ +#include "map.h" /* for Map struct ("free(world.map->cells)") */ #include "command_db.h" /* for free_command_db() */ -#include "windows.h" /* for Win struct, free_win(), free_winmeta() */ +#include "windows.h" /* for free_winmeta_and_endwin() */ #include "map_objects.h" /* for free_map_objects, free_map_object_defs() */ #include "misc.h" /* for unload_interface_conf() */ +#include "map_object_actions.h" /* for free_map_object_actions() */ @@ -24,18 +24,6 @@ static void cleanup(); static void cleanup() { - if (cleanup_flags & CLEANUP_NCURSES) - { - endwin(); - } - if (cleanup_flags & CLEANUP_MAP_OBJECTS) - { - free_map_objects(world.map_objs); - } - if (cleanup_flags & CLEANUP_MAP_OBJECT_DEFS) - { - free_map_object_defs(world.map_obj_defs); - } if (cleanup_flags & CLEANUP_LOG) { free(world.log); @@ -48,13 +36,25 @@ static void cleanup() { free(world.map->cells); } - if (cleanup_flags & CLEANUP_INTERFACE_CONF) + if (cleanup_flags & CLEANUP_MAP_OBJECTS) + { + free_map_objects(world.map_objs); + } + if (cleanup_flags & CLEANUP_MAP_OBJECT_DEFS) { - unload_interface_conf(/*&world*/); + free_map_object_defs(world.map_obj_defs); } - if (cleanup_flags & CLEANUP_WIN_META) + if (cleanup_flags & CLEANUP_MAP_OBJECT_ACTS) { - free_winmeta(); + free_map_object_actions(world.map_obj_acts); + } + if (cleanup_flags & CLEANUP_INTERFACE) /* Only cleaning-up order */ + { /* dependency known so far: */ + unload_interface_conf(); /* unload_interface_conf() must */ + } /* come before */ + if (cleanup_flags & CLEANUP_NCURSES) /* free_winmeta_and_endwin() */ + { /* since it depends on world.wmeta */ + free_winmeta_and_endwin(); /* for closing all windows. */ } } @@ -94,3 +94,17 @@ extern void exit_err(uint8_t err, char * msg) } exit(EXIT_FAILURE); } + + + +extern void exit_trouble(uint8_t err, char * parent, char * child) +{ + char * p1 = "Trouble in "; + char * p2 = " with "; + char * p3 = "."; + uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child) + + strlen(p3) + 1; + char msg[size]; + sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3); + exit_err(err, msg); +}