Crossfire Server, Trunk
test_mapsave.cpp
Go to the documentation of this file.
1 #include "global.h"
2 
3 extern void map_path(const char *map, int flags, char *pathname, size_t bufsize);
4 extern mapstruct *mapfile_load_lowlevel(const char *map, const char *pathname, int flags);
5 
6 int main(int argc, char *argv[]) {
7  if (argc < 2) {
8  puts("usage: test_mapsave PATH");
9  return 0;
10  }
11 
13  init_library();
14  int flags = 0;
15  if (argv[1][0] == '~') {
17  }
18 
19  // We have to do this twice because saving twice reverses the order of the
20  // linked lists and so the save is "stable".
21  mapstruct *m;
22  m = mapfile_load(argv[1], flags);
23  if (m == NULL) {
24  return 1;
25  }
26  save_map(m, 0);
27 
28  // Save a copy of the original map's real path for diffing
29  char buf[MAX_BUF];
30  map_path(m->path, flags, buf, sizeof(buf));
31 
32  const char *path_firstpass = strdup(m->tmpname);
33  free_map(m);
34  m = mapfile_load_lowlevel(argv[1], path_firstpass, flags);
35  if (m == NULL) {
36  return 1;
37  }
38  save_map(m, 0);
39 
40  LOG(llevInfo, "Original:\t%s\n", buf);
41  LOG(llevInfo, "Pass 1:\t%s\n", path_firstpass);
42  LOG(llevInfo, "Pass 2:\t%s\n", m->tmpname);
43  free_map(m);
44 }
global.h
settings
struct Settings settings
Definition: init.cpp:138
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:51
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.cpp:101
MAP_PLAYER_UNIQUE
#define MAP_PLAYER_UNIQUE
Definition: map.h:97
buf
StringBuffer * buf
Definition: readable.cpp:1551
m
static event_registration m
Definition: citylife.cpp:425
disinfect.map
map
Definition: disinfect.py:4
Settings::debug
LogLevel debug
Definition: global.h:243
free_map
void free_map(mapstruct *m)
Definition: map.cpp:1684
MAX_BUF
#define MAX_BUF
Definition: define.h:35
map_path
void map_path(const char *map, int flags, char *pathname, size_t bufsize)
Definition: map.cpp:1199
main
int main(int argc, char *argv[])
Definition: test_mapsave.cpp:6
llevInfo
@ llevInfo
Definition: logger.h:12
init_library
void init_library(void)
Definition: init.cpp:322
mapstruct
Definition: map.h:316
mapfile_load_lowlevel
mapstruct * mapfile_load_lowlevel(const char *map, const char *pathname, int flags)
Definition: map.cpp:1209
save_map
int save_map(mapstruct *m, int flag)
Definition: map.cpp:1428
mapfile_load
mapstruct * mapfile_load(const char *map, int flags)
Definition: map.cpp:1250