home · contact · privacy
3499246c7abcb6b324844a0c52bd401eb238174c
[plomrogue] / src / client / cleanup.c
1 /* src/client/cleanup.c */
2
3 #include "cleanup.h"
4 #include <ncurses.h> /* for endwin() */
5 #include <stdint.h> /* uint32_t */
6 #include <stdlib.h> /* free() */
7 #include "../common/readwrite.h" /* try_fclose() */
8 #include "command_db.h" /* free_command_db() */
9 #include "interface_conf.h" /* unload_interface_conf() */
10 #include "world.h" /* world global */
11
12
13
14 /* The clean-up flags set by set_cleanup_flag(). */
15 static uint32_t cleanup_flags = 0x0000;
16
17
18
19 extern void cleanup()
20 {
21     free(world.map.cells);
22     free(world.log);
23     free(world.player_inventory);
24     if (cleanup_flags & CLEANUP_INTERFACE)
25     {
26         unload_interface_conf();
27     }
28     if (cleanup_flags & CLEANUP_NCURSES)
29     {
30         endwin();
31     }
32     if (cleanup_flags & CLEANUP_COMMANDS)
33     {
34         free_command_db();
35     }
36     if (cleanup_flags & CLEANUP_SERVER_IN)
37     {
38         try_fclose(world.file_server_in, __func__);
39     }
40     if (cleanup_flags & CLEANUP_SERVER_OUT)
41     {
42         try_fclose(world.file_server_out, __func__);
43     }
44 }
45
46
47 extern void set_cleanup_flag(enum cleanup_flag flag)
48 {
49     cleanup_flags = cleanup_flags | flag;
50 }