aboutsummaryrefslogtreecommitdiff
path: root/engines/griffon/config.cpp
blob: d430380bea4629b35fb7e4ed7efa40058bc320cb (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <sys/stat.h>

#include <SDL/SDL.h>

#include "config.h"

CONFIG config = {
	320, 240, 16, 0, 0, 0, 1, 127, 1, 127
};

char config_ini[64] = "config.ini";

#define PRINT(A,B)          \
	do {                    \
		char line[256];         \
		sprintf(line, A "\n", B);   \
		fputs(line, fp);        \
	} while(0)

#define INPUT(A, B)         \
	do {                    \
		char line[256];         \
		fgets(line, sizeof(line), fp);  \
		sscanf(line, A, B);     \
	} while(0)

void config_load(CONFIG *config) {
	char line[128];
	char arg[128];
	FILE *fp;

	fp = fopen(config_ini, "r");
	if (fp) {
		while (fgets(line, sizeof(line), fp) != NULL) {
			sscanf(line, "%s", arg); // eliminate eol and eof by this

			if (strcmp(arg, "SCR_WIDTH:") == 0) {
				fgets(line, sizeof(line), fp);
				sscanf(line, "%i", &config->scr_width);
			} else if (strcmp(arg, "SCR_HEIGHT:") == 0) {
				fgets(line, sizeof(line), fp);
				sscanf(line, "%i", &config->scr_height);
			} else if (strcmp(arg, "SCR_BITS:") == 0) {
				fgets(line, sizeof(line), fp);
				sscanf(line, "%i", &config->scr_bpp);
			} else if (strcmp(arg, "HWACCEL:YES") == 0) {
				config->hwaccel = SDL_HWACCEL;
			} else if (strcmp(arg, "HWACCEL:NO") == 0) {
				config->hwaccel = 0;
			} else if (strcmp(arg, "HWSURFACE:YES") == 0) {
				config->hwsurface = SDL_HWSURFACE;
			} else if (strcmp(arg, "HWSURFACE:NO") == 0) {
				config->hwsurface = 0;
			} else if (strcmp(arg, "FULLSCREEN:YES") == 0) {
				config->fullscreen = SDL_FULLSCREEN;
			} else if (strcmp(arg, "FULLSCREEN:NO") == 0) {
				config->fullscreen = 0;
			} else if (strcmp(arg, "MUSIC:YES") == 0) {
				config->music = 1;
			} else if (strcmp(arg, "MUSIC:NO") == 0) {
				config->music = 0;
			} else if (strcmp(arg, "SNDEFFECTS:YES") == 0) {
				config->effects = 1;
			} else if (strcmp(arg, "SNDEFFECTS:NO") == 0) {
				config->effects = 0;
			} else if (strcmp(arg, "opmusicvol:") == 0) {
				fgets(line, sizeof(line), fp);
				sscanf(line, "%i", &config->musicvol);
			} else if (strcmp(arg, "opeffectsvol:") == 0) {
				fgets(line, sizeof(line), fp);
				sscanf(line, "%i", &config->effectsvol);
			}
		}

		fclose(fp);
	}
}

void config_save(CONFIG *config) {
	FILE *fp = fopen(config_ini, "w");

	if (fp) {
		PRINT("%s", "SCR_WIDTH:");
		PRINT("%i", config->scr_width);
		PRINT("%s", "SCR_HEIGHT:");
		PRINT("%i", config->scr_height);
		PRINT("%s", "SCR_BITS:");
		PRINT("%i", config->scr_bpp);
		PRINT("%s", config->hwaccel ? "HWACCEL:YES" : "HWACCEL:NO");
		PRINT("%s", config->hwsurface ? "HWSURFACE:YES" : "HWSURFACE:NO");
		PRINT("%s", config->fullscreen ? "FULLSCREEN:YES" : "FULLSCREEN:NO");
		PRINT("%s", config->music ? "MUSIC:YES" : "MUSIC:NO");
		PRINT("%s", config->effects ? "SNDEFFECTS:YES" : "SNDEFFECTS:NO");
		PRINT("%s", "opmusicvol:");
		PRINT("%i", config->musicvol);
		PRINT("%s", "opeffectsvol:");
		PRINT("%i", config->effectsvol);
		fclose(fp);
	}
}