summaryrefslogtreecommitdiff
path: root/src/test/testfunc_003_loadress.c
blob: 7c1ed46769eba5422b7cefbf783ed3f3318f8232 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <string.h>
#include "SDL/SDL.h"

#include "parser.h"
#include "loader.h"
#include "utils.h"

#define PATH_STYLE "../styles"
#define PATH_LEVEL "../level"

#define MAX_PATH_LEN 255
extern FILE *yyin;

void load_ini(gameIni_t *gIni, char *filepath) {
	yyin=fopen(filepath, "r");
	if (yyin == NULL ) {
		fprintf(stderr, "main(), Could not open '%s'\n", filepath);
		exit(2);
	}
//	printf("Parsing '%s'\n", filepath);
	parse(gIni);
	fclose(yyin);
}

int main(int argc, char **argv) {
	int res;
	char filepath[MAX_PATH_LEN];
	gameIni_t gIni;
	gameRess_t gRess;

	if (argc != 3) {
		fprintf(stderr, "Usage %s <levelpack_name> <ini_file>\n", argv[0]);
		return 1;
	}

	openLog(NULL);

	// Setting default values
	memset(&gIni,0,sizeof(gameIni_t));

	// Loading levelpack.ini
	snprintf(filepath, MAX_PATH_LEN, "%s/%s/levelpack.ini", PATH_LEVEL, argv[1]);
	load_ini(&gIni, filepath);

	// Loading lvl ini file
	snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s", PATH_LEVEL, argv[1], argv[2]);
	load_ini(&gIni, filepath);

	// Check if we found a "style =" line in level ini file
	if (gIni.level.style==NULL) {
		fprintf(stderr, "No valid style detected\n");
		exit(1);
	}
	gIni.style.name=gIni.level.style;

	// Loading style ini file
	snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s.ini", PATH_STYLE, gIni.level.style, gIni.level.style);
	load_ini(&gIni, filepath);

	
	res=loadRessources(&gIni, &gRess);

	closeLog(NULL);

	return res;
}