summarylogtreecommitdiffstats
path: root/0003-tomatoes-1.55-config-hiscore-file-saving-loading.patch
blob: a3c1f9b9173bb3848998d4dca7c45de4f7a2aeda (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
Subject: Fix code for loading / saving config and hiscore file

--- include/config.h	2016-11-06 18:39:10.034679787 +0100
+++ include/config.h	2016-11-06 18:40:15.210067898 +0100
@@ -30,6 +30,8 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
+#include <string>
+
 // Config structure
 struct CONFIG {
 	int vid_w;				// Video mode width
@@ -54,19 +56,19 @@
 	int moving_style[2];	// Moving style (1 == relative, 2 == absolute)
 };
 
-
-// Helper function which returns suitable path for the
-// config file. It first checks the user's home directory,
-// and if that fails it uses the CONFIG_DIR defined in the
-// makefile.
-const char *get_config_location(bool write = false);
+
+// Helper function which returns suitable path for the
+// config file. It first checks the user's home directory,
+// and if that fails it uses the CONFIG_DIR defined in the
+// makefile.
+std::string get_config_location(bool write = false);
 
 
 // Load config from file
-void load_config(const char *file, CONFIG *conf);
+void load_config(std::string file, CONFIG *conf);
 
 // Save config to file
-void save_config(const char *file, CONFIG *conf);
+void save_config(std::string file, CONFIG *conf);
 
 #endif
 

--- include/hiscore.h	2016-11-06 18:39:10.034679787 +0100
+++ include/hiscore.h	2016-11-06 18:43:27.992937549 +0100
@@ -40,6 +40,7 @@
 #define HISCORE_FILE		"hiscore.lst"
 #define HISCORE_FILE2		"hiscore2.lst"
 
+#include <string>
 
 // Record structure
 struct RECORD {
@@ -57,8 +58,8 @@
 	void sort();								// Sort the list
 	int add_name(const char *name, int score);		// Add a record
 	void draw(int place, float fade);			// Draw the list
-	void save(const char *file);						// Save the list
-	void load(const char *file);						// Load the list
+	void save(std::string file);						// Save the list
+	void load(std::string file);						// Load the list
 	void input_name(int place);					// Input a name
 };
 
@@ -66,7 +67,7 @@
 extern HISCORE_LIST hiscore_1;
 extern HISCORE_LIST hiscore_2;
 
-const char *get_hiscore_location(int which, bool write = false);
+std::string get_hiscore_location(int which, bool write = false);
 
 
 #endif

--- src/config.cpp	2016-11-06 18:39:18.441181712 +0100
+++ src/config.cpp	2016-11-06 18:46:08.603094300 +0100
@@ -76,7 +76,7 @@
 // config file. It first checks the user's home directory,
 // and if that fails it uses the CONFIG_DIR defined in the
 // makefile.
-const char *get_config_location(bool write) {
+string get_config_location(bool write) {
 #ifdef LINUX
 	// Get the path to the config file
 	string tmp = get_tomatoes_dir() + "config.cfg";
@@ -91,7 +91,7 @@
 		fclose(ftest);
 	}
 
-	return (const char*)tmp.c_str();
+	return tmp;
 #endif
 
 	// Return the CONFIG_DIR
@@ -100,11 +100,11 @@
 
 
 // Load config from file
-void load_config(const char *file, CONFIG *conf) {
+void load_config(string file, CONFIG *conf) {
 
-	FILE *f = fopen(file, "rt");
+	FILE *f = fopen(file.c_str(), "rt");
 	if(!f)
-		error_msg("Unable to load config file: %s!", file);
+		error_msg("Unable to load config file: %s!", file.c_str());
 
 	fscanf(f, "video_mode = %d x %d\n", &(conf->vid_w), &(conf->vid_h));
 	fscanf(f, "video_mode_color_depth = %d\n", &(conf->vid_color_depth));
@@ -127,11 +127,11 @@
 
 
 // Save config to file
-void save_config(const char *file, CONFIG *conf) {
+void save_config(string file, CONFIG *conf) {
 
-	FILE *f = fopen(file, "wt");
+	FILE *f = fopen(file.c_str(), "wt");
 	if(!f)
-		error_msg("Unable to save config file: %s!", file);
+		error_msg("Unable to save config file: %s!", file.c_str());
 
 	fprintf(f, "video_mode = %d x %d\n", (conf->vid_w), (conf->vid_h));
 	fprintf(f, "video_mode_color_depth = %d\n", (conf->vid_color_depth));

--- src/hiscore.cpp	2016-11-06 18:39:18.437848445 +0100
+++ src/hiscore.cpp	2016-11-06 18:48:27.587005089 +0100
@@ -69,7 +69,7 @@
 // hiscore file. It first checks the user's home directory,
 // and if that fails it uses the HISCORE_DIR defined in the
 // makefile.
-const char *get_hiscore_location(int which, bool write) {
+string get_hiscore_location(int which, bool write) {
 #ifdef LINUX
 	// Get the path to the hiscore file
 	string tmp;
@@ -91,7 +91,7 @@
 		fclose(ftest);
 	}
 
-	return (char*)tmp.c_str();
+	return tmp;
 #endif
 
 	// Return the HISCORE_DIR
@@ -401,11 +401,11 @@
 
 
 // Save the list to a file
-void HISCORE_LIST::save(const char *file) {
+void HISCORE_LIST::save(string file) {
 	FILE *fout;
-	fout = fopen(file, "wb");
+	fout = fopen(file.c_str(), "wb");
 	if(!fout)
-		error_msg("Unable to save the hiscore list to %s!\n", file);
+		error_msg("Unable to save the hiscore list to %s!\n", file.c_str());
 
 	// Write the scores
 	int f;
@@ -421,9 +421,9 @@
 
 
 // Load the list from a file
-void HISCORE_LIST::load(const char *file) {
+void HISCORE_LIST::load(string file) {
 	FILE *fin;
-	fin = fopen(file, "rb");
+	fin = fopen(file.c_str(), "rb");
 	if(!fin) {
 		// The list wasn't found, no problem.
 		clear();