File: 0005-shared_scorefile.patch

package info (click to toggle)
circuslinux 1.0.3-34.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,784 kB
  • sloc: ansic: 2,592; sh: 2,311; makefile: 87
file content (307 lines) | stat: -rw-r--r-- 8,059 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
From: "Christian T. Steigies" <cts@debian.org>
Date: Sun, 23 Oct 2011 22:32:42 +0200
Subject: shared_scorefile

---
 Makefile.am   |    1 +
 circuslinux.c |  165 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 configure.in  |    9 +++
 3 files changed, 156 insertions(+), 19 deletions(-)

Index: circuslinux-1.0.3/Makefile.am
===================================================================
--- circuslinux-1.0.3.orig/Makefile.am
+++ circuslinux-1.0.3/Makefile.am
@@ -18,6 +18,7 @@ VERSION = @VERSION@
 CC=@CC@
 DATA_PREFIX=$(pkgdatadir)/data/
 JOY=@JOY@
+SHARED_SCOREFILE=@SHARED_SCOREFILE@
 TARGET_DEF=@TARGET_DEF@
 
 
Index: circuslinux-1.0.3/circuslinux.c
===================================================================
--- circuslinux-1.0.3.orig/circuslinux.c
+++ circuslinux-1.0.3/circuslinux.c
@@ -15,6 +15,11 @@
   December 11, 1999 - April 28, 2001
 */
 
+#ifndef SHARED_SCOREFILE_YES
+#ifndef SHARED_SCOREFILE_NO
+#error something went wrong in configure, either SHARED_SCOREFILE_YES or SHARED_SCOREFILE_NO must be defined. Please tell cts@debian.org how you did this.
+#endif
+#endif
 
 /* Constraints: */
 
@@ -430,6 +435,9 @@ void drawtext(int x, int y, char * str);
 void drawfuzz(int x, int y, int w, int h);
 void seticon(void);
 void usage(int ret);
+#ifdef SHARED_SCOREFILE_YES
+FILE * open_score_file(char * mode);
+#endif
 FILE * open_option_file(char * mode);
 void addscore(int player, int inc);
 int highscorescreen(void);
@@ -579,7 +587,37 @@ int main(int argc, char * argv[])
       strcpy(highscorer[i], "TUX");
     }
   
+
+#ifdef SHARED_SCOREFILE_YES
+  fi = open_score_file("r");
   
+  if (fi != NULL) {
+    do {
+      fgets(temp, sizeof(temp), fi);
+
+      if (!feof(fi)) {
+	temp[strlen(temp) - 1] = '\0';
+
+	/* Parse each line: */
+
+	if (strstr(temp, "highscore") == temp &&
+	    temp[9] >= '0' && temp[9] <= '7' &&
+	    temp[10] == '=') {
+	  highscore[temp[9] - '0'] = atoi(temp + 11);
+	} else if (strstr(temp, "highscorer") == temp &&
+		   temp[10] >= '0' && temp[10] <= '7' &&
+		   temp[11] == '=') {
+	  highscorer[temp[10] - '0'][0] = temp[12];
+	  highscorer[temp[10] - '0'][1] = temp[13];
+	  highscorer[temp[10] - '0'][2] = temp[14];
+	}
+      }
+    } while (!feof(fi));
+
+    fclose(fi);
+  }
+#endif /* SHARED_SCOREFILE_YES */
+
   /* Load options: */
   
   fi = open_option_file("r");
@@ -597,7 +635,20 @@ int main(int argc, char * argv[])
 	      
 	      /* Parse each line: */
 	      
-	      if (strstr(temp, "highscore") == temp &&
+	      if (strstr(temp, "effects=") == temp)
+		{
+		  sfx_vol = atoi(temp + 8);
+		  if (sfx_vol > 3 || sfx_vol < 0)
+		    sfx_vol = 3;
+		}
+	      else if (strstr(temp, "music=") == temp)
+		{
+		  music_vol = atoi(temp + 6);
+		  if (music_vol > 3 || music_vol < 0)
+		    music_vol = 3;
+		}
+#ifdef SHARED_SCOREFILE_NO
+	      else if (strstr(temp, "highscore") == temp &&
 		  temp[9] >= '0' && temp[9] <= '7' &&
 		  temp[10] == '=')
 		{
@@ -611,18 +662,7 @@ int main(int argc, char * argv[])
 		  highscorer[temp[10] - '0'][1] = temp[13];
 		  highscorer[temp[10] - '0'][2] = temp[14];
 		}
-	      else if (strstr(temp, "effects=") == temp)
-		{
-		  sfx_vol = atoi(temp + 8);
-		  if (sfx_vol > 3 || sfx_vol < 0)
-		    sfx_vol = 3;
-		}
-	      else if (strstr(temp, "music=") == temp)
-		{
-		  music_vol = atoi(temp + 6);
-		  if (music_vol > 3 || music_vol < 0)
-		    music_vol = 3;
-		}
+#endif /* SHARED_SCOREFILE_NO */
 	    }
 	}
       while (!feof(fi));
@@ -667,8 +707,36 @@ int main(int argc, char * argv[])
   while (!done);
   
   
+  /* Save scores: */
+
+#ifdef SHARED_SCOREFILE_YES
+  fi = open_score_file("w");
+  if (fi != NULL) {
+    /* Comment at the top (I wish _everyone_ did this!) */
+
+    fprintf(fi, "# Circus Linux! score file\n\n");
+
+    /* High scores: */
+
+    fprintf(fi, "# Highscores:\n\n");
+
+    for (i = 0; i < 8; i++) {
+      fprintf(fi, "highscore%d=%d\n", i, highscore[i]);
+      fprintf(fi, "highscorer%d=%s\n\n", i, highscorer[i]);
+    }
+
+    fprintf(fi, "\n");
+
+    /* The end! */
+
+    fprintf(fi, "# (File automatically created.)\n");
+
+    fclose(fi);
+  }
+#endif /* SHARED_SCOREFILE_YES */
+
   /* Save options: */
-  
+
   fi = open_option_file("w");
   if (fi != NULL)
     {
@@ -677,6 +745,7 @@ int main(int argc, char * argv[])
       fprintf(fi, "# Circus Linux! options file\n\n");
       
       
+#ifdef SHARED_SCOREFILE_NO
       /* High scores: */
       
       fprintf(fi, "# Highscores:\n\n");
@@ -686,9 +755,9 @@ int main(int argc, char * argv[])
 	  fprintf(fi, "highscore%d=%d\n", i, highscore[i]);
 	  fprintf(fi, "highscorer%d=%s\n\n", i, highscorer[i]);
 	}
-      
+
       fprintf(fi, "\n");
-      
+#endif /* SHARED_SCOREFILE_NO */
       
       /* Volume settings: */
       
@@ -3424,6 +3493,33 @@ void usage(int ret)
 }
 
 
+#ifdef SHARED_SCOREFILE_YES
+FILE * open_score_file(char * mode)
+{
+  FILE * fi;
+
+  /* Try opening the file: */
+
+  fi = fopen("/var/games/circuslinux/scorefile", mode);
+
+  if (fi == NULL)
+    {
+      fprintf(stderr, "\nWarning: I could not open the score file ");
+
+      if (strcmp(mode, "r") == 0)
+        fprintf(stderr, "for read:");
+      else if (strcmp(mode, "w") == 0)
+        fprintf(stderr, "for write:");
+
+     fprintf(stderr, "\n%s\n"
+              "The error that occured was:\n"
+              "%s\n\n","/var/games/circuslinux/scorefile" , strerror(errno));
+    }
+
+  return(fi);
+}
+#endif
+
 /* Open the option file: */
 
 FILE * open_option_file(char * mode)
@@ -3444,25 +3540,53 @@ FILE * open_option_file(char * mode)
   else
     home = ".";
   
-  
   /* Create the buffer for the filename: */
   
+#ifdef SHARED_SCOREFILE_YES
+/* do not touch the old scorefile, options go in the (new) rc file instead */
+  filename = (char *) malloc(sizeof(char) * (strlen(home) +
+                                             strlen("/.circuslinuxrc") + 1));
+
+  strcpy(filename, home);
+  strcat(filename, "/.circuslinuxrc");
+#else
   filename = (char *) malloc(sizeof(char) * (strlen(home) +
                                              strlen("/.circuslinux") + 1));
-  
+
   strcpy(filename, home);
   strcat(filename, "/.circuslinux");
+#endif
 #else
   filename = "circuslinux.dat";
 #endif
   
   
   /* Try opening the file: */
-  
   fi = fopen(filename, mode);
   
   if (fi == NULL)
     {
+#ifdef SHARED_SCOREFILE_YES
+      if (strcmp(mode, "r") == 0)
+	{ /* try to read old options file when the new one is not found*/
+          strcpy(filename, home);
+          strcat(filename, "/.circuslinux\0\0");
+          fprintf(stderr, "Trying old options file instead: %s...\n", filename);
+          fi = fopen(filename, mode);
+
+          if (fi != NULL)
+            {
+              fprintf(stderr, "Found %s.\n", filename);
+              fprintf(stderr, "Your config will be stored in %src upon exit.\n", filename);
+              fprintf(stderr,
+"Once your sysadmin has merged all scorefiles on this system (or you can do\n"
+"without your old circuslinux highscores) you can safely delete you old config\n"
+"and scorefile :\n %s",  filename);
+	      return (fi);
+            }
+        }
+#endif /* SHARED_SCOREFILE_YES */
+      
       fprintf(stderr, "\nWarning: I could not open the options file "); 
       
       if (strcmp(mode, "r") == 0)
@@ -3474,7 +3598,7 @@ FILE * open_option_file(char * mode)
               "The error that occured was:\n"
               "%s\n\n", filename, strerror(errno));
     }
-  
+
   return(fi);
 }
 
Index: circuslinux-1.0.3/configure.in
===================================================================
--- circuslinux-1.0.3.orig/configure.in
+++ circuslinux-1.0.3/configure.in
@@ -69,7 +69,16 @@ AC_ARG_ENABLE(joystick,
               JOY=YES)
 
 AC_SUBST(JOY)
+
 	
+dnl shared scorefile
+SHARED_SCOREFILE=NO
+AC_ARG_ENABLE(scorefile,
+              [  --enable-scorefile      Use shared scorefile [default=no]],
+              SHARED_SCOREFILE=YES)
+
+AC_SUBST(SHARED_SCOREFILE)
+
 
 dnl Target
 case "$target_os" in