1 /* src/server/cleanup.c
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.
9 #include <stdint.h> /* uint32_t */
10 #include <stdlib.h> /* free() */
11 #include <unistd.h> /* unlink() */
12 #include "../common/readwrite.h" /* try_fclose() */
13 #include "hardcoded_strings.h" /* s */
14 #include "thing_actions.h" /* free_thing_actions() */
15 #include "things.h" /* free_things(), free_thing_types() */
16 #include "world.h" /* global world */
21 /* The clean-up flags set by set_cleanup_flag(). */
22 static uint32_t cleanup_flags = 0x0000;
30 free(world.map.cells);
31 if (cleanup_flags & CLEANUP_WORLDSTATE)
33 unlink(s[S_PATH_WORLDSTATE]);
35 if (cleanup_flags & CLEANUP_THINGS)
37 free_things(world.things);
39 if (cleanup_flags & CLEANUP_THING_TYPES)
41 free_thing_types(world.thing_types);
43 if (cleanup_flags & CLEANUP_THING_ACTIONS)
45 free_thing_actions(world.thing_actions);
47 if (cleanup_flags & CLEANUP_IN)
49 try_fclose(world.file_in, __func__);
52 if (cleanup_flags & CLEANUP_OUT)
54 try_fclose(world.file_out, __func__);
55 free(world.server_test);
56 unlink(s[S_PATH_OUT]);
61 extern void set_cleanup_flag(enum cleanup_flag flag)
63 cleanup_flags = cleanup_flags | flag;
68 extern void unset_cleanup_flag(enum cleanup_flag flag)
70 cleanup_flags = cleanup_flags ^ flag;