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;
29 free(world.map.cells);
30 if (cleanup_flags & CLEANUP_WORLDSTATE)
32 unlink(s[S_PATH_WORLDSTATE]);
34 if (cleanup_flags & CLEANUP_THINGS)
36 free_things(world.things);
38 if (cleanup_flags & CLEANUP_THING_TYPES)
40 free_thing_types(world.thing_types);
42 if (cleanup_flags & CLEANUP_THING_ACTIONS)
44 free_thing_actions(world.thing_actions);
46 if (cleanup_flags & CLEANUP_IN)
48 try_fclose(world.file_in, __func__);
51 if (cleanup_flags & CLEANUP_OUT)
53 try_fclose(world.file_out, __func__);
54 free(world.server_test);
55 unlink(s[S_PATH_OUT]);
60 extern void set_cleanup_flag(enum cleanup_flag flag)
62 cleanup_flags = cleanup_flags | flag;
67 extern void unset_cleanup_flag(enum cleanup_flag flag)
69 cleanup_flags = cleanup_flags ^ flag;