Crossfire Server, Trunk
test_mapsave.cpp
Go to the documentation of this file.
1 
19 #include "global.h"
20 
21 extern void map_path(const char *map, int flags, char *pathname, size_t bufsize);
22 extern mapstruct *mapfile_load_lowlevel(const char *map, const char *pathname, int flags);
23 
24 int main(int argc, char *argv[]) {
25  if (argc < 2) {
26  puts("usage: test_mapsave PATH");
27  return 0;
28  }
29 
31  init_library();
32  int flags = 0;
33  if (argv[1][0] == '~') {
35  }
36 
37  // We have to do this twice because saving twice reverses the order of the
38  // linked lists and so the save is "stable".
39  mapstruct *m;
40  m = mapfile_load(argv[1], flags);
41  if (m == NULL) {
42  return 1;
43  }
44  save_map(m, 0);
45 
46  // Save a copy of the original map's real path for diffing
47  char buf[MAX_BUF];
48  map_path(m->path, flags, buf, sizeof(buf));
49 
50  const char *path_firstpass = NULL;
51  if (m->tmpname != NULL) {
52  // happens if map is unique
53  strdup(m->tmpname);
54  } else {
55  path_firstpass = buf;
56  }
57  free_map(m);
58  m = mapfile_load_lowlevel(argv[1], path_firstpass, flags);
59  if (m == NULL) {
60  return 1;
61  }
62  save_map(m, 0);
63 
64  LOG(llevInfo, "Original:\t%s\n", buf);
65  if (!(flags & MAP_PLAYER_UNIQUE)) {
66  LOG(llevInfo, "Pass 1:\t%s\n", path_firstpass);
67  LOG(llevInfo, "Pass 2:\t%s\n", m->tmpname);
68  }
69  free_map(m);
70 }
global.h
settings
struct Settings settings
Definition: init.cpp:139
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:58
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.cpp:101
MAP_PLAYER_UNIQUE
#define MAP_PLAYER_UNIQUE
Definition: map.h:92
buf
StringBuffer * buf
Definition: readable.cpp:1565
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:1653
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:1166
main
int main(int argc, char *argv[])
Definition: test_mapsave.cpp:24
llevInfo
@ llevInfo
Definition: logger.h:12
init_library
void init_library(void)
Definition: init.cpp:324
mapstruct
Definition: map.h:313
mapfile_load_lowlevel
mapstruct * mapfile_load_lowlevel(const char *map, const char *pathname, int flags)
Definition: map.cpp:1176
save_map
int save_map(mapstruct *m, int flag)
Definition: map.cpp:1396
mapfile_load
mapstruct * mapfile_load(const char *map, int flags)
Definition: map.cpp:1217