File: maptest.cpp

package info (click to toggle)
warzone2100 4.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 660,320 kB
  • sloc: cpp: 676,209; ansic: 391,201; javascript: 78,238; python: 16,632; php: 4,294; sh: 4,094; makefile: 2,629; lisp: 1,492; cs: 489; xml: 404; perl: 224; ruby: 156; java: 89
file content (54 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "map/mapload.h"

int main(int argc, char **argv)
{
	char datapath[PATH_MAX];
	FILE *fp = fopen("maplist.txt", "r");

	if (!fp)
	{
		fprintf(stderr, "%s: Failed to open list file\n", argv[0]);
		return -1;
	}
	PHYSFS_init(argv[0]);
	strcpy(datapath, getenv("srcdir"));
	strcat(datapath, "/../data");
	PHYSFS_mount(datapath, NULL, 1);

	while (!feof(fp))
	{
		GAMEMAP *map;
		char filename[PATH_MAX], *delim;

		if (fscanf(fp, "%254s\n", filename) != 1)
		{
			fprintf(stderr, "maptest: Couldn't fscanf maplist.txt.\n");
			return -1;
		}

		// Strip "/game.map"
		delim = strrchr(filename, '/');
		if (!delim)
		{
			fprintf(stderr, "maptest: Failed to find map directory for \"%s\"\n", filename);
			return -1;
		}
		*delim = '\0';

		printf("Testing map: %s\n", filename);
		map = mapLoad(filename);
		if (!map)
		{
			fprintf(stderr, "maptest: Failed to load \"%s\"\n", filename);
			return -1;
		}
		mapFree(map);
	}
	fclose(fp);

	return 0;
}