8 /* Open the highscore file: */
13 # include "high_scores.h"
15 FILE * opendata(char * mode)
17 char * filename, * home;
22 /* Get home directory (from $HOME variable)... if we can't determine it,
23 use the current directory ("."): */
25 if (getenv("HOME") != NULL)
26 home = getenv("HOME");
31 /* Create the buffer for the filename: */
33 filename = (char *) malloc(sizeof(char) * (strlen(home) +
34 strlen("/.supertux") + 1));
36 strcpy(filename, home);
37 /* Open the high score file: */
39 strcat(filename, "/.supertux");
41 filename = "supertux.dat";
45 /* Try opening the file: */
47 fi = fopen(filename, mode);
51 fprintf(stderr, "Warning: I could not open the high score file ");
53 if (strcmp(mode, "r") == 0)
54 fprintf(stderr, "for read!!!\n");
55 else if (strcmp(mode, "w") == 0)
56 fprintf(stderr, "for write!!!\n");
63 /* Load data from high score file: */
71 /* Try to open file: */
78 fgets(temp, sizeof(temp), fi);
82 temp[strlen(temp) - 1] = '\0';
85 /* Parse each line: */
87 if (strstr(temp, "highscore=") == temp)
89 score = atoi(temp + 10);
103 void save_hs(int score)
108 /* Try to open file: */
113 fprintf(fi, "# Supertux data file\n\n");
115 fprintf(fi, "highscore=%d\n", score);
117 fprintf(fi, "# (File automatically created.)\n");