Crossfire Server, Trunk
check_mapsave.c
Go to the documentation of this file.
1 #include "global.h"
2 
3 extern int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag);
4 extern void allocate_map(mapstruct *m);
5 extern void load_objects(mapstruct *m, FILE *fp, int mapflags);
6 
7 int mapsave_test(const char *map) {
8  int flags = 0;
9  if (map[0] == '~') {
11  }
12 
13  // Load map file to get objects
15  if (m == NULL) {
16  return 1;
17  }
18 
19  // Save objects (without map header)
20  FILE *fp1 = fopen("check_mapsave_1.map", "w");
21  m->in_memory = MAP_SAVING;
22  save_objects(m, fp1, fp1, 0);
23  int width = m->width;
24  int height = m->height;
25  free_map(m);
26  fclose(fp1);
27 
28  // Load objects from saved map
29  fp1 = fopen("check_mapsave_1.map", "r");
30  m = get_linked_map();
31  m->width = width;
32  m->height = height;
33  allocate_map(m);
34  m->in_memory = MAP_LOADING;
35  load_objects(m, fp1, flags & MAP_STYLE);
36  fclose(fp1);
37 
38  // Save loaded objects out to different file
39  FILE *fp2 = fopen("check_mapsave_2.map", "w");
40  save_objects(m, fp2, fp2, 0);
41  fclose(fp2);
42 
43  // Check that file1 and file2 are the same
44  return system("cmp check_mapsave_1.map check_mapsave_2.map");
45 }
46 
47 int main(int argc, char *argv[]) {
48  if (argc < 2) {
49  puts("usage: check_mapsave PATH");
50  return 0;
51  }
52 
54  init_library();
55  return mapsave_test(argv[1]);
56 }
get_linked_map
mapstruct * get_linked_map(void)
Definition: map.c:788
global.h
MAP_SAVING
#define MAP_SAVING
Definition: map.h:134
main
int main(int argc, char *argv[])
Definition: check_mapsave.c:47
MAP_PLAYER_UNIQUE
#define MAP_PLAYER_UNIQUE
Definition: map.h:97
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.c:101
mapsave_test
int mapsave_test(const char *map)
Definition: check_mapsave.c:7
MAP_STYLE
#define MAP_STYLE
Definition: map.h:99
settings
struct Settings settings
Definition: init.c:39
m
static event_registration m
Definition: citylife.cpp:427
disinfect.map
map
Definition: disinfect.py:4
Settings::debug
LogLevel debug
Definition: global.h:239
free_map
void free_map(mapstruct *m)
Definition: map.c:1676
save_objects
int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag)
Definition: map.c:725
mapdef
Definition: map.h:317
load_objects
void load_objects(mapstruct *m, FILE *fp, int mapflags)
Definition: map.c:612
allocate_map
void allocate_map(mapstruct *m)
Definition: map.c:839
init_library
void init_library(void)
Definition: init.c:192
MAP_LOADING
#define MAP_LOADING
Definition: map.h:133
llevDebug
@ llevDebug
Definition: logger.h:13
mapfile_load
mapstruct * mapfile_load(const char *map, int flags)
Definition: map.c:1214