home · contact · privacy
60a2625c0f208bd379250c95ab1d69afd7e41837
[plomrogue] / src / client / cleanup.c
1 /* src/client/cleanup.c
2  *
3  * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
4  * or any later version. For details on its copyright, license, and warranties,
5  * see the file NOTICE in the root directory of the PlomRogue source package.
6  */
7
8 #include "cleanup.h"
9 #include <ncurses.h> /* for endwin() */
10 #include <stdint.h> /* uint32_t */
11 #include <stdlib.h> /* free() */
12 #include "../common/readwrite.h" /* try_fclose() */
13 #include "command_db.h" /* free_command_db() */
14 #include "interface_conf.h" /* unload_interface_conf() */
15 #include "world.h" /* world global */
16
17
18
19 /* The clean-up flags set by set_cleanup_flag(). */
20 static uint32_t cleanup_flags = 0x0000;
21
22
23
24 extern void cleanup()
25 {
26     free(world.map.cells);
27     free(world.mem_map);
28     free(world.log);
29     free(world.queue);
30     free(world.player_inventory);
31     if (cleanup_flags & CLEANUP_INTERFACE)
32     {
33         unload_interface_conf();
34     }
35     if (cleanup_flags & CLEANUP_NCURSES)
36     {
37         endwin();
38     }
39     if (cleanup_flags & CLEANUP_COMMANDS)
40     {
41         free_command_db();
42     }
43     if (cleanup_flags & CLEANUP_SERVER_IN)
44     {
45         try_fclose(world.file_server_in, __func__);
46     }
47     if (cleanup_flags & CLEANUP_SERVER_OUT)
48     {
49         try_fclose(world.file_server_out, __func__);
50     }
51 }
52
53
54 extern void set_cleanup_flag(enum cleanup_flag flag)
55 {
56     cleanup_flags = cleanup_flags | flag;
57 }