1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
25 #define MAX_FILENAME_LEN 256 /* maximal filename length */
26 #define MAX_LINE_LEN 1000 /* maximal input line length */
27 #define CHUNK_ID_LEN 4 /* IFF style chunk id length */
28 #define LEVEL_HEADER_SIZE 80 /* size of level file header */
29 #define LEVEL_HEADER_UNUSED 18 /* unused level header bytes */
30 #define TAPE_HEADER_SIZE 20 /* size of tape file header */
31 #define TAPE_HEADER_UNUSED 7 /* unused tape header bytes */
32 #define FILE_VERSION_1_0 10 /* old 1.0 file version */
33 #define FILE_VERSION_1_2 12 /* actual file version */
35 /* file identifier strings */
36 #define LEVEL_COOKIE "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.2"
37 #define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.2"
38 #define TAPE_COOKIE "ROCKSNDIAMONDS_TAPE_FILE_VERSION_1.2"
39 #define SETUP_COOKIE "ROCKSNDIAMONDS_SETUP_FILE_VERSION_1.2"
40 #define LEVELSETUP_COOKIE "ROCKSNDIAMONDS_LEVELSETUP_FILE_VERSION_1.2"
41 #define LEVELINFO_COOKIE "ROCKSNDIAMONDS_LEVELINFO_FILE_VERSION_1.2"
42 /* old file identifiers for backward compatibility */
43 #define LEVEL_COOKIE_10 "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.0"
44 #define TAPE_COOKIE_10 "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.0"
46 /* file names and filename extensions */
48 #define USERDATA_DIRECTORY ".rocksndiamonds"
49 #define SETUP_FILENAME "setup.conf"
50 #define LEVELSETUP_FILENAME "levelsetup.conf"
51 #define LEVELINFO_FILENAME "levelinfo.conf"
52 #define LEVELFILE_EXTENSION "level"
53 #define TAPEFILE_EXTENSION "tape"
54 #define SCOREFILE_EXTENSION "score"
56 #define USERDATA_DIRECTORY "userdata"
57 #define SETUP_FILENAME "setup.cnf"
58 #define LEVELSETUP_FILENAME "lvlsetup.cnf"
59 #define LEVELINFO_FILENAME "lvlinfo.cnf"
60 #define LEVELFILE_EXTENSION "lvl"
61 #define TAPEFILE_EXTENSION "rec"
62 #define SCOREFILE_EXTENSION "sco"
65 /* file permissions for newly written files */
66 #define MODE_R_ALL (S_IRUSR | S_IRGRP | S_IROTH)
67 #define MODE_W_ALL (S_IWUSR | S_IWGRP | S_IWOTH)
68 #define MODE_X_ALL (S_IXUSR | S_IXGRP | S_IXOTH)
69 #define USERDATA_DIR_MODE (MODE_R_ALL | MODE_X_ALL | S_IWUSR)
70 #define LEVEL_PERMS (MODE_R_ALL | MODE_W_ALL)
71 #define SCORE_PERMS LEVEL_PERMS
72 #define TAPE_PERMS LEVEL_PERMS
73 #define SETUP_PERMS LEVEL_PERMS
75 static void SaveUserLevelInfo(); /* for 'InitUserLevelDir()' */
76 static char *getSetupLine(char *, int); /* for 'SaveUserLevelInfo()' */
78 static char *getGlobalDataDir()
83 static char *getUserDataDir()
85 static char *userdata_dir = NULL;
89 char *home_dir = getHomeDir();
90 char *data_dir = USERDATA_DIRECTORY;
92 userdata_dir = getPath2(home_dir, data_dir);
98 static char *getSetupDir()
100 return getUserDataDir();
103 static char *getUserLevelDir(char *level_subdir)
105 static char *userlevel_dir = NULL;
106 char *data_dir = getUserDataDir();
107 char *userlevel_subdir = LEVELS_DIRECTORY;
112 if (strlen(level_subdir) > 0)
113 userlevel_dir = getPath3(data_dir, userlevel_subdir, level_subdir);
115 userlevel_dir = getPath2(data_dir, userlevel_subdir);
117 return userlevel_dir;
120 static char *getTapeDir(char *level_subdir)
122 static char *tape_dir = NULL;
123 char *data_dir = getUserDataDir();
124 char *tape_subdir = TAPES_DIRECTORY;
129 if (strlen(level_subdir) > 0)
130 tape_dir = getPath3(data_dir, tape_subdir, level_subdir);
132 tape_dir = getPath2(data_dir, tape_subdir);
137 static char *getScoreDir(char *level_subdir)
139 static char *score_dir = NULL;
140 char *data_dir = getGlobalDataDir();
141 char *score_subdir = SCORES_DIRECTORY;
146 if (strlen(level_subdir) > 0)
147 score_dir = getPath3(data_dir, score_subdir, level_subdir);
149 score_dir = getPath2(data_dir, score_subdir);
154 static char *getLevelFilename(int nr)
156 static char *filename = NULL;
157 char basename[20 + strlen(LEVELFILE_EXTENSION)];
159 if (filename != NULL)
162 sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION);
163 filename = getPath3((leveldir[leveldir_nr].user_defined ?
164 getUserLevelDir("") :
165 options.level_directory),
166 leveldir[leveldir_nr].filename,
172 static char *getTapeFilename(int nr)
174 static char *filename = NULL;
175 char basename[20 + strlen(LEVELFILE_EXTENSION)];
177 if (filename != NULL)
180 sprintf(basename, "%03d.%s", nr, TAPEFILE_EXTENSION);
181 filename = getPath2(getTapeDir(leveldir[leveldir_nr].filename), basename);
186 static char *getScoreFilename(int nr)
188 static char *filename = NULL;
189 char basename[20 + strlen(LEVELFILE_EXTENSION)];
191 if (filename != NULL)
194 sprintf(basename, "%03d.%s", nr, SCOREFILE_EXTENSION);
195 filename = getPath2(getScoreDir(leveldir[leveldir_nr].filename), basename);
200 static void createDirectory(char *dir, char *text)
202 if (access(dir, F_OK) != 0)
203 if (mkdir(dir, USERDATA_DIR_MODE) != 0)
204 Error(ERR_WARN, "cannot create %s directory '%s'", text, dir);
207 static void InitUserDataDirectory()
209 createDirectory(getUserDataDir(), "user data");
212 static void InitTapeDirectory(char *level_subdir)
214 createDirectory(getUserDataDir(), "user data");
215 createDirectory(getTapeDir(""), "main tape");
216 createDirectory(getTapeDir(level_subdir), "level tape");
219 static void InitScoreDirectory(char *level_subdir)
221 createDirectory(getScoreDir(""), "main score");
222 createDirectory(getScoreDir(level_subdir), "level score");
225 static void InitUserLevelDirectory(char *level_subdir)
227 if (access(getUserLevelDir(level_subdir), F_OK) != 0)
229 createDirectory(getUserDataDir(), "user data");
230 createDirectory(getUserLevelDir(""), "main user level");
231 createDirectory(getUserLevelDir(level_subdir), "user level");
237 static void setLevelInfoToDefaults()
241 lev_fieldx = level.fieldx = STD_LEV_FIELDX;
242 lev_fieldy = level.fieldy = STD_LEV_FIELDY;
244 for(x=0; x<MAX_LEV_FIELDX; x++)
245 for(y=0; y<MAX_LEV_FIELDY; y++)
246 Feld[x][y] = Ur[x][y] = EL_ERDREICH;
249 level.edelsteine = 0;
250 level.tempo_amoebe = 10;
251 level.dauer_sieb = 10;
252 level.dauer_ablenk = 10;
253 level.amoebe_inhalt = EL_DIAMANT;
255 strcpy(level.name, "Nameless Level");
257 for(i=0; i<LEVEL_SCORE_ELEMENTS; i++)
263 level.mampfer_inhalt[i][x][y] = EL_FELSBROCKEN;
265 Feld[0][0] = Ur[0][0] = EL_SPIELFIGUR;
266 Feld[STD_LEV_FIELDX-1][STD_LEV_FIELDY-1] =
267 Ur[STD_LEV_FIELDX-1][STD_LEV_FIELDY-1] = EL_AUSGANG_ZU;
270 void LoadLevel(int level_nr)
273 char *filename = getLevelFilename(level_nr);
274 char cookie[MAX_LINE_LEN];
275 char chunk[CHUNK_ID_LEN + 1];
276 int file_version = FILE_VERSION_1_2; /* last version of level files */
280 /* always start with reliable default values */
281 setLevelInfoToDefaults();
283 if (!(file = fopen(filename, "r")))
285 Error(ERR_WARN, "cannot read level '%s' - creating new level", filename);
289 /* check file identifier */
290 fgets(cookie, MAX_LINE_LEN, file);
291 if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
292 cookie[strlen(cookie) - 1] = '\0';
294 if (strcmp(cookie, LEVEL_COOKIE_10) == 0) /* old 1.0 level format */
295 file_version = FILE_VERSION_1_0;
296 else if (strcmp(cookie, LEVEL_COOKIE) != 0) /* unknown level format */
298 Error(ERR_WARN, "wrong file identifier of level file '%s'", filename);
303 /* read chunk "HEAD" */
304 if (file_version >= FILE_VERSION_1_2)
306 /* first check header chunk identifier and chunk length */
307 fgets(chunk, CHUNK_ID_LEN + 1, file);
309 (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
310 if (strcmp(chunk, "HEAD") || chunk_length != LEVEL_HEADER_SIZE)
312 Error(ERR_WARN, "wrong 'HEAD' chunk of level file '%s'", filename);
318 lev_fieldx = level.fieldx = fgetc(file);
319 lev_fieldy = level.fieldy = fgetc(file);
321 level.time = (fgetc(file)<<8) | fgetc(file);
322 level.edelsteine = (fgetc(file)<<8) | fgetc(file);
324 for(i=0; i<MAX_LEVNAMLEN; i++)
325 level.name[i] = fgetc(file);
326 level.name[MAX_LEVNAMLEN - 1] = 0;
328 for(i=0; i<LEVEL_SCORE_ELEMENTS; i++)
329 level.score[i] = fgetc(file);
334 level.mampfer_inhalt[i][x][y] = fgetc(file);
336 level.tempo_amoebe = fgetc(file);
337 level.dauer_sieb = fgetc(file);
338 level.dauer_ablenk = fgetc(file);
339 level.amoebe_inhalt = fgetc(file);
341 for(i=0; i<LEVEL_HEADER_UNUSED; i++) /* skip unused header bytes */
344 /* read chunk "BODY" */
345 if (file_version >= FILE_VERSION_1_2)
347 /* next check body chunk identifier and chunk length */
348 fgets(chunk, CHUNK_ID_LEN + 1, file);
350 (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
351 if (strcmp(chunk, "BODY") || chunk_length != lev_fieldx * lev_fieldy)
353 Error(ERR_WARN, "wrong 'BODY' chunk of level file '%s'", filename);
359 for(y=0; y<lev_fieldy; y++)
360 for(x=0; x<lev_fieldx; x++)
361 Feld[x][y] = Ur[x][y] = fgetc(file);
365 if (level.time <= 10) /* minimum playing time of each level */
369 void SaveLevel(int level_nr)
372 char *filename = getLevelFilename(level_nr);
376 if (!(file = fopen(filename, "w")))
378 Error(ERR_WARN, "cannot save level file '%s'", filename);
382 fputs(LEVEL_COOKIE, file); /* file identifier */
385 fputs("HEAD", file); /* chunk identifier for file header */
387 chunk_length = LEVEL_HEADER_SIZE;
389 fputc((chunk_length >> 24) & 0xff, file);
390 fputc((chunk_length >> 16) & 0xff, file);
391 fputc((chunk_length >> 8) & 0xff, file);
392 fputc((chunk_length >> 0) & 0xff, file);
394 fputc(level.fieldx, file);
395 fputc(level.fieldy, file);
396 fputc(level.time / 256, file);
397 fputc(level.time % 256, file);
398 fputc(level.edelsteine / 256, file);
399 fputc(level.edelsteine % 256, file);
401 for(i=0; i<MAX_LEVNAMLEN; i++)
402 fputc(level.name[i], file);
403 for(i=0; i<LEVEL_SCORE_ELEMENTS; i++)
404 fputc(level.score[i], file);
408 fputc(level.mampfer_inhalt[i][x][y], file);
409 fputc(level.tempo_amoebe, file);
410 fputc(level.dauer_sieb, file);
411 fputc(level.dauer_ablenk, file);
412 fputc(level.amoebe_inhalt, file);
414 for(i=0; i<LEVEL_HEADER_UNUSED; i++) /* set unused header bytes to zero */
417 fputs("BODY", file); /* chunk identifier for file body */
418 chunk_length = lev_fieldx * lev_fieldy;
420 fputc((chunk_length >> 24) & 0xff, file);
421 fputc((chunk_length >> 16) & 0xff, file);
422 fputc((chunk_length >> 8) & 0xff, file);
423 fputc((chunk_length >> 0) & 0xff, file);
425 for(y=0; y<lev_fieldy; y++)
426 for(x=0; x<lev_fieldx; x++)
427 fputc(Ur[x][y], file);
431 chmod(filename, LEVEL_PERMS);
434 void LoadTape(int level_nr)
437 char *filename = getTapeFilename(level_nr);
438 char cookie[MAX_LINE_LEN];
439 char chunk[CHUNK_ID_LEN + 1];
441 int num_participating_players;
442 int file_version = FILE_VERSION_1_2; /* last version of tape files */
445 if (!(file = fopen(filename, "r")))
448 /* check file identifier */
449 fgets(cookie, MAX_LINE_LEN, file);
450 if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
451 cookie[strlen(cookie) - 1] = '\0';
453 if (strcmp(cookie, TAPE_COOKIE_10) == 0) /* old 1.0 tape format */
454 file_version = FILE_VERSION_1_0;
455 else if (strcmp(cookie, TAPE_COOKIE) != 0) /* unknown tape format */
457 Error(ERR_WARN, "wrong file identifier of tape file '%s'", filename);
462 /* read chunk "HEAD" */
463 if (file_version >= FILE_VERSION_1_2)
465 /* first check header chunk identifier and chunk length */
466 fgets(chunk, CHUNK_ID_LEN + 1, file);
468 (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
470 if (strcmp(chunk, "HEAD") || chunk_length != TAPE_HEADER_SIZE)
472 Error(ERR_WARN, "wrong 'HEAD' chunk of tape file '%s'", filename);
479 (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
481 (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
483 (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
485 /* read header fields that are new since version 1.2 */
486 if (file_version >= FILE_VERSION_1_2)
488 byte store_participating_players = fgetc(file);
490 for(i=0; i<TAPE_HEADER_UNUSED; i++) /* skip unused header bytes */
493 /* check which players participate in this tape recording */
494 num_participating_players = 0;
495 for(i=0; i<MAX_PLAYERS; i++)
497 tape.player_participates[i] = FALSE;
499 if (store_participating_players & (1 << i))
501 tape.player_participates[i] = TRUE;
502 num_participating_players++;
507 tape.level_nr = level_nr;
509 tape.changed = FALSE;
511 tape.recording = FALSE;
512 tape.playing = FALSE;
513 tape.pausing = FALSE;
515 /* read chunk "BODY" */
516 if (file_version >= FILE_VERSION_1_2)
518 /* next check body chunk identifier and chunk length */
519 fgets(chunk, CHUNK_ID_LEN + 1, file);
521 (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
522 if (strcmp(chunk, "BODY") ||
523 chunk_length != (num_participating_players + 1) * tape.length)
525 Error(ERR_WARN, "wrong 'BODY' chunk of tape file '%s'", filename);
531 for(i=0; i<tape.length; i++)
533 if (i >= MAX_TAPELEN)
536 for(j=0; j<MAX_PLAYERS; j++)
538 tape.pos[i].action[j] = MV_NO_MOVING;
540 /* pre-1.2 tapes store data for only one player */
541 if (file_version == FILE_VERSION_1_0 && j > 0)
544 if (tape.player_participates[j])
545 tape.pos[i].action[j] = fgetc(file);
548 tape.pos[i].delay = fgetc(file);
550 if (file_version == FILE_VERSION_1_0)
552 /* eliminate possible diagonal moves in old tapes */
553 /* this is only for backward compatibility */
555 byte joy_dir[4] = { JOY_LEFT, JOY_RIGHT, JOY_UP, JOY_DOWN };
556 byte action = tape.pos[i].action[0];
557 int k, num_moves = 0;
561 if (action & joy_dir[k])
563 tape.pos[i + num_moves].action[0] = joy_dir[k];
565 tape.pos[i + num_moves].delay = 0;
574 tape.length += num_moves;
584 if (i != tape.length)
585 Error(ERR_WARN, "level recording file '%s' corrupted", filename);
587 tape.length_seconds = GetTapeLength();
590 void SaveTape(int level_nr)
593 char *filename = getTapeFilename(level_nr);
595 boolean new_tape = TRUE;
596 byte store_participating_players;
597 int num_participating_players;
600 InitTapeDirectory(leveldir[leveldir_nr].filename);
602 /* if a tape still exists, ask to overwrite it */
603 if (access(filename, F_OK) == 0)
606 if (!Request("Replace old tape ?", REQ_ASK))
610 /* count number of players and set corresponding bits for compact storage */
611 store_participating_players = 0;
612 num_participating_players = 0;
613 for(i=0; i<MAX_PLAYERS; i++)
615 if (tape.player_participates[i])
617 num_participating_players++;
618 store_participating_players |= (1 << i);
622 if (!(file = fopen(filename, "w")))
624 Error(ERR_WARN, "cannot save level recording file '%s'", filename);
628 fputs(TAPE_COOKIE, file); /* file identifier */
631 fputs("HEAD", file); /* chunk identifier for file header */
633 chunk_length = TAPE_HEADER_SIZE;
635 fputc((chunk_length >> 24) & 0xff, file);
636 fputc((chunk_length >> 16) & 0xff, file);
637 fputc((chunk_length >> 8) & 0xff, file);
638 fputc((chunk_length >> 0) & 0xff, file);
640 fputc((tape.random_seed >> 24) & 0xff, file);
641 fputc((tape.random_seed >> 16) & 0xff, file);
642 fputc((tape.random_seed >> 8) & 0xff, file);
643 fputc((tape.random_seed >> 0) & 0xff, file);
645 fputc((tape.date >> 24) & 0xff, file);
646 fputc((tape.date >> 16) & 0xff, file);
647 fputc((tape.date >> 8) & 0xff, file);
648 fputc((tape.date >> 0) & 0xff, file);
650 fputc((tape.length >> 24) & 0xff, file);
651 fputc((tape.length >> 16) & 0xff, file);
652 fputc((tape.length >> 8) & 0xff, file);
653 fputc((tape.length >> 0) & 0xff, file);
655 fputc(store_participating_players, file);
657 for(i=0; i<TAPE_HEADER_UNUSED; i++) /* set unused header bytes to zero */
660 fputs("BODY", file); /* chunk identifier for file body */
661 chunk_length = (num_participating_players + 1) * tape.length;
663 fputc((chunk_length >> 24) & 0xff, file);
664 fputc((chunk_length >> 16) & 0xff, file);
665 fputc((chunk_length >> 8) & 0xff, file);
666 fputc((chunk_length >> 0) & 0xff, file);
668 for(i=0; i<tape.length; i++)
672 for(j=0; j<MAX_PLAYERS; j++)
673 if (tape.player_participates[j])
674 fputc(tape.pos[i].action[j], file);
676 fputc(tape.pos[i].delay, file);
681 chmod(filename, TAPE_PERMS);
683 tape.changed = FALSE;
686 Request("tape saved !", REQ_CONFIRM);
689 void LoadScore(int level_nr)
692 char *filename = getScoreFilename(level_nr);
693 char cookie[MAX_LINE_LEN];
694 char line[MAX_LINE_LEN];
698 /* always start with reliable default values */
699 for(i=0; i<MAX_SCORE_ENTRIES; i++)
701 strcpy(highscore[i].Name, EMPTY_PLAYER_NAME);
702 highscore[i].Score = 0;
705 if (!(file = fopen(filename, "r")))
708 /* check file identifier */
709 fgets(cookie, MAX_LINE_LEN, file);
710 if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
711 cookie[strlen(cookie) - 1] = '\0';
713 if (strcmp(cookie, SCORE_COOKIE) != 0)
715 Error(ERR_WARN, "wrong file identifier of score file '%s'", filename);
720 for(i=0; i<MAX_SCORE_ENTRIES; i++)
722 fscanf(file, "%d", &highscore[i].Score);
723 fgets(line, MAX_LINE_LEN, file);
725 if (line[strlen(line)-1] == '\n')
726 line[strlen(line)-1] = '\0';
728 for (line_ptr = line; *line_ptr; line_ptr++)
730 if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0')
732 strncpy(highscore[i].Name, line_ptr, MAX_NAMELEN - 1);
733 highscore[i].Name[MAX_NAMELEN - 1] = '\0';
742 void SaveScore(int level_nr)
745 char *filename = getScoreFilename(level_nr);
748 InitScoreDirectory(leveldir[leveldir_nr].filename);
750 if (!(file = fopen(filename, "w")))
752 Error(ERR_WARN, "cannot save score for level %d", level_nr);
756 fprintf(file, "%s\n\n", SCORE_COOKIE);
758 for(i=0; i<MAX_SCORE_ENTRIES; i++)
759 fprintf(file, "%d %s\n", highscore[i].Score, highscore[i].Name);
763 chmod(filename, SCORE_PERMS);
766 #define TOKEN_STR_FILE_IDENTIFIER "file_identifier"
767 #define TOKEN_STR_LAST_LEVEL_SERIES "last_level_series"
768 #define TOKEN_STR_PLAYER_PREFIX "player_"
770 #define TOKEN_VALUE_POSITION 30
773 #define SETUP_TOKEN_PLAYER_NAME 0
774 #define SETUP_TOKEN_SOUND 1
775 #define SETUP_TOKEN_SOUND_LOOPS 2
776 #define SETUP_TOKEN_SOUND_MUSIC 3
777 #define SETUP_TOKEN_SOUND_SIMPLE 4
778 #define SETUP_TOKEN_TOONS 5
779 #define SETUP_TOKEN_DOUBLE_BUFFERING 6
780 #define SETUP_TOKEN_SCROLL_DELAY 7
781 #define SETUP_TOKEN_SOFT_SCROLLING 8
782 #define SETUP_TOKEN_FADING 9
783 #define SETUP_TOKEN_AUTORECORD 10
784 #define SETUP_TOKEN_QUICK_DOORS 11
785 #define SETUP_TOKEN_TEAM_MODE 12
788 #define SETUP_TOKEN_USE_JOYSTICK 13
789 #define SETUP_TOKEN_JOY_DEVICE_NAME 14
790 #define SETUP_TOKEN_JOY_XLEFT 15
791 #define SETUP_TOKEN_JOY_XMIDDLE 16
792 #define SETUP_TOKEN_JOY_XRIGHT 17
793 #define SETUP_TOKEN_JOY_YUPPER 18
794 #define SETUP_TOKEN_JOY_YMIDDLE 19
795 #define SETUP_TOKEN_JOY_YLOWER 20
796 #define SETUP_TOKEN_JOY_SNAP 21
797 #define SETUP_TOKEN_JOY_BOMB 22
798 #define SETUP_TOKEN_KEY_LEFT 23
799 #define SETUP_TOKEN_KEY_RIGHT 24
800 #define SETUP_TOKEN_KEY_UP 25
801 #define SETUP_TOKEN_KEY_DOWN 26
802 #define SETUP_TOKEN_KEY_SNAP 27
803 #define SETUP_TOKEN_KEY_BOMB 28
805 /* level directory info */
806 #define LEVELINFO_TOKEN_NAME 29
807 #define LEVELINFO_TOKEN_LEVELS 30
808 #define LEVELINFO_TOKEN_SORT_PRIORITY 31
809 #define LEVELINFO_TOKEN_READONLY 32
811 #define FIRST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_PLAYER_NAME
812 #define LAST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_TEAM_MODE
814 #define FIRST_PLAYER_SETUP_TOKEN SETUP_TOKEN_USE_JOYSTICK
815 #define LAST_PLAYER_SETUP_TOKEN SETUP_TOKEN_KEY_BOMB
817 #define FIRST_LEVELINFO_TOKEN LEVELINFO_TOKEN_NAME
818 #define LAST_LEVELINFO_TOKEN LEVELINFO_TOKEN_READONLY
820 #define TYPE_BOOLEAN 1
821 #define TYPE_SWITCH 2
822 #define TYPE_KEYSYM 3
823 #define TYPE_INTEGER 4
824 #define TYPE_STRING 5
826 static struct SetupInfo si;
827 static struct SetupInputInfo sii;
828 static struct LevelDirInfo ldi;
837 { TYPE_STRING, &si.player_name, "player_name" },
838 { TYPE_SWITCH, &si.sound, "sound" },
839 { TYPE_SWITCH, &si.sound_loops, "repeating_sound_loops" },
840 { TYPE_SWITCH, &si.sound_music, "background_music" },
841 { TYPE_SWITCH, &si.sound_simple, "simple_sound_effects" },
842 { TYPE_SWITCH, &si.toons, "toons" },
843 { TYPE_SWITCH, &si.double_buffering, "double_buffering" },
844 { TYPE_SWITCH, &si.scroll_delay, "scroll_delay" },
845 { TYPE_SWITCH, &si.soft_scrolling, "soft_scrolling" },
846 { TYPE_SWITCH, &si.fading, "screen_fading" },
847 { TYPE_SWITCH, &si.autorecord, "automatic_tape_recording" },
848 { TYPE_SWITCH, &si.quick_doors, "quick_doors" },
849 { TYPE_SWITCH, &si.team_mode, "team_mode" },
852 { TYPE_BOOLEAN, &sii.use_joystick, ".use_joystick" },
853 { TYPE_STRING, &sii.joy.device_name, ".joy.device_name" },
854 { TYPE_INTEGER, &sii.joy.xleft, ".joy.xleft" },
855 { TYPE_INTEGER, &sii.joy.xmiddle, ".joy.xmiddle" },
856 { TYPE_INTEGER, &sii.joy.xright, ".joy.xright" },
857 { TYPE_INTEGER, &sii.joy.yupper, ".joy.yupper" },
858 { TYPE_INTEGER, &sii.joy.ymiddle, ".joy.ymiddle" },
859 { TYPE_INTEGER, &sii.joy.ylower, ".joy.ylower" },
860 { TYPE_INTEGER, &sii.joy.snap, ".joy.snap_field" },
861 { TYPE_INTEGER, &sii.joy.bomb, ".joy.place_bomb" },
862 { TYPE_KEYSYM, &sii.key.left, ".key.move_left" },
863 { TYPE_KEYSYM, &sii.key.right, ".key.move_right" },
864 { TYPE_KEYSYM, &sii.key.up, ".key.move_up" },
865 { TYPE_KEYSYM, &sii.key.down, ".key.move_down" },
866 { TYPE_KEYSYM, &sii.key.snap, ".key.snap_field" },
867 { TYPE_KEYSYM, &sii.key.bomb, ".key.place_bomb" },
869 /* level directory info */
870 { TYPE_STRING, &ldi.name, "name" },
871 { TYPE_INTEGER, &ldi.levels, "levels" },
872 { TYPE_INTEGER, &ldi.sort_priority, "sort_priority" },
873 { TYPE_BOOLEAN, &ldi.readonly, "readonly" }
876 static char *string_tolower(char *s)
878 static char s_lower[100];
881 if (strlen(s) >= 100)
886 for (i=0; i<strlen(s_lower); i++)
887 s_lower[i] = tolower(s_lower[i]);
892 static int get_string_integer_value(char *s)
894 static char *number_text[][3] =
896 { "0", "zero", "null", },
897 { "1", "one", "first" },
898 { "2", "two", "second" },
899 { "3", "three", "third" },
900 { "4", "four", "fourth" },
901 { "5", "five", "fifth" },
902 { "6", "six", "sixth" },
903 { "7", "seven", "seventh" },
904 { "8", "eight", "eighth" },
905 { "9", "nine", "ninth" },
906 { "10", "ten", "tenth" },
907 { "11", "eleven", "eleventh" },
908 { "12", "twelve", "twelfth" },
915 if (strcmp(string_tolower(s), number_text[i][j]) == 0)
921 static boolean get_string_boolean_value(char *s)
923 if (strcmp(string_tolower(s), "true") == 0 ||
924 strcmp(string_tolower(s), "yes") == 0 ||
925 strcmp(string_tolower(s), "on") == 0 ||
926 get_string_integer_value(s) == 1)
932 static char *getFormattedSetupEntry(char *token, char *value)
935 static char entry[MAX_LINE_LEN];
937 sprintf(entry, "%s:", token);
938 for (i=strlen(entry); i<TOKEN_VALUE_POSITION; i++)
942 strcat(entry, value);
947 static void freeSetupFileList(struct SetupFileList *setup_file_list)
949 if (!setup_file_list)
952 if (setup_file_list->token)
953 free(setup_file_list->token);
954 if (setup_file_list->value)
955 free(setup_file_list->value);
956 if (setup_file_list->next)
957 freeSetupFileList(setup_file_list->next);
958 free(setup_file_list);
961 static struct SetupFileList *newSetupFileList(char *token, char *value)
963 struct SetupFileList *new = checked_malloc(sizeof(struct SetupFileList));
965 new->token = checked_malloc(strlen(token) + 1);
966 strcpy(new->token, token);
968 new->value = checked_malloc(strlen(value) + 1);
969 strcpy(new->value, value);
976 static char *getTokenValue(struct SetupFileList *setup_file_list,
979 if (!setup_file_list)
982 if (strcmp(setup_file_list->token, token) == 0)
983 return setup_file_list->value;
985 return getTokenValue(setup_file_list->next, token);
988 static void setTokenValue(struct SetupFileList *setup_file_list,
989 char *token, char *value)
991 if (!setup_file_list)
994 if (strcmp(setup_file_list->token, token) == 0)
996 free(setup_file_list->value);
997 setup_file_list->value = checked_malloc(strlen(value) + 1);
998 strcpy(setup_file_list->value, value);
1000 else if (setup_file_list->next == NULL)
1001 setup_file_list->next = newSetupFileList(token, value);
1003 setTokenValue(setup_file_list->next, token, value);
1007 static void printSetupFileList(struct SetupFileList *setup_file_list)
1009 if (!setup_file_list)
1012 printf("token: '%s'\n", setup_file_list->token);
1013 printf("value: '%s'\n", setup_file_list->value);
1015 printSetupFileList(setup_file_list->next);
1019 static struct SetupFileList *loadSetupFileList(char *filename)
1022 char line[MAX_LINE_LEN];
1023 char *token, *value, *line_ptr;
1024 struct SetupFileList *setup_file_list = newSetupFileList("", "");
1025 struct SetupFileList *first_valid_list_entry;
1029 if (!(file = fopen(filename, "r")))
1031 Error(ERR_WARN, "cannot open configuration file '%s'", filename);
1037 /* read next line of input file */
1038 if (!fgets(line, MAX_LINE_LEN, file))
1041 /* cut trailing comment or whitespace from input line */
1042 for (line_ptr = line; *line_ptr; line_ptr++)
1044 if (*line_ptr == '#' || *line_ptr == '\n')
1051 /* cut trailing whitespaces from input line */
1052 for (line_ptr = &line[strlen(line)]; line_ptr > line; line_ptr--)
1053 if ((*line_ptr == ' ' || *line_ptr == '\t') && line_ptr[1] == '\0')
1056 /* ignore empty lines */
1060 line_len = strlen(line);
1062 /* cut leading whitespaces from token */
1063 for (token = line; *token; token++)
1064 if (*token != ' ' && *token != '\t')
1067 /* find end of token */
1068 for (line_ptr = token; *line_ptr; line_ptr++)
1070 if (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == ':')
1077 if (line_ptr < line + line_len)
1078 value = line_ptr + 1;
1082 /* cut leading whitespaces from value */
1083 for (; *value; value++)
1084 if (*value != ' ' && *value != '\t')
1087 if (*token && *value)
1088 setTokenValue(setup_file_list, token, value);
1093 first_valid_list_entry = setup_file_list->next;
1095 /* free empty list header */
1096 setup_file_list->next = NULL;
1097 freeSetupFileList(setup_file_list);
1099 if (first_valid_list_entry == NULL)
1100 Error(ERR_WARN, "configuration file '%s' is empty", filename);
1102 return first_valid_list_entry;
1105 static void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list,
1108 if (!setup_file_list)
1111 if (strcmp(setup_file_list->token, TOKEN_STR_FILE_IDENTIFIER) == 0)
1113 if (strcmp(setup_file_list->value, identifier) != 0)
1115 Error(ERR_WARN, "configuration file has wrong version");
1122 if (setup_file_list->next)
1123 checkSetupFileListIdentifier(setup_file_list->next, identifier);
1126 Error(ERR_WARN, "configuration file has no version information");
1131 static void setLevelDirInfoToDefaults(struct LevelDirInfo *ldi)
1133 ldi->name = getStringCopy("non-existing");
1135 ldi->sort_priority = 999; /* default: least priority */
1136 ldi->readonly = TRUE;
1139 static void setSetupInfoToDefaults(struct SetupInfo *si)
1143 si->player_name = getStringCopy(getLoginName());
1146 si->sound_loops = FALSE;
1147 si->sound_music = FALSE;
1148 si->sound_simple = FALSE;
1150 si->double_buffering = TRUE;
1151 si->direct_draw = !si->double_buffering;
1152 si->scroll_delay = FALSE;
1153 si->soft_scrolling = TRUE;
1155 si->autorecord = FALSE;
1156 si->quick_doors = FALSE;
1158 for (i=0; i<MAX_PLAYERS; i++)
1160 si->input[i].use_joystick = FALSE;
1161 si->input[i].joy.device_name = getStringCopy(joystick_device_name[i]);
1162 si->input[i].joy.xleft = JOYSTICK_XLEFT;
1163 si->input[i].joy.xmiddle = JOYSTICK_XMIDDLE;
1164 si->input[i].joy.xright = JOYSTICK_XRIGHT;
1165 si->input[i].joy.yupper = JOYSTICK_YUPPER;
1166 si->input[i].joy.ymiddle = JOYSTICK_YMIDDLE;
1167 si->input[i].joy.ylower = JOYSTICK_YLOWER;
1168 si->input[i].joy.snap = (i == 0 ? JOY_BUTTON_1 : 0);
1169 si->input[i].joy.bomb = (i == 0 ? JOY_BUTTON_2 : 0);
1170 si->input[i].key.left = (i == 0 ? DEFAULT_KEY_LEFT : KEY_UNDEFINDED);
1171 si->input[i].key.right = (i == 0 ? DEFAULT_KEY_RIGHT : KEY_UNDEFINDED);
1172 si->input[i].key.up = (i == 0 ? DEFAULT_KEY_UP : KEY_UNDEFINDED);
1173 si->input[i].key.down = (i == 0 ? DEFAULT_KEY_DOWN : KEY_UNDEFINDED);
1174 si->input[i].key.snap = (i == 0 ? DEFAULT_KEY_SNAP : KEY_UNDEFINDED);
1175 si->input[i].key.bomb = (i == 0 ? DEFAULT_KEY_BOMB : KEY_UNDEFINDED);
1179 static void setSetupInfo(int token_nr, char *token_value)
1181 int token_type = token_info[token_nr].type;
1182 void *setup_value = token_info[token_nr].value;
1184 if (token_value == NULL)
1187 /* set setup field to corresponding token value */
1192 *(boolean *)setup_value = get_string_boolean_value(token_value);
1196 *(KeySym *)setup_value = getKeySymFromX11KeyName(token_value);
1200 *(int *)setup_value = get_string_integer_value(token_value);
1204 if (*(char **)setup_value != NULL)
1205 free(*(char **)setup_value);
1206 *(char **)setup_value = getStringCopy(token_value);
1214 static void decodeSetupFileList(struct SetupFileList *setup_file_list)
1218 if (!setup_file_list)
1221 /* handle global setup values */
1223 for (i=FIRST_GLOBAL_SETUP_TOKEN; i<=LAST_GLOBAL_SETUP_TOKEN; i++)
1224 setSetupInfo(i, getTokenValue(setup_file_list, token_info[i].text));
1227 /* handle player specific setup values */
1228 for (pnr=0; pnr<MAX_PLAYERS; pnr++)
1232 sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, pnr + 1);
1234 sii = setup.input[pnr];
1235 for (i=FIRST_PLAYER_SETUP_TOKEN; i<=LAST_PLAYER_SETUP_TOKEN; i++)
1237 char full_token[100];
1239 sprintf(full_token, "%s%s", prefix, token_info[i].text);
1240 setSetupInfo(i, getTokenValue(setup_file_list, full_token));
1242 setup.input[pnr] = sii;
1246 int getLevelSeriesNrFromLevelSeriesName(char *level_series_name)
1250 if (!level_series_name)
1253 for (i=0; i<num_leveldirs; i++)
1254 if (strcmp(level_series_name, leveldir[i].filename) == 0)
1260 int getLastPlayedLevelOfLevelSeries(char *level_series_name)
1263 int level_series_nr = getLevelSeriesNrFromLevelSeriesName(level_series_name);
1264 int last_level_nr = 0;
1266 if (!level_series_name)
1269 token_value = getTokenValue(level_setup_list, level_series_name);
1273 int highest_level_nr = leveldir[level_series_nr].levels - 1;
1275 last_level_nr = atoi(token_value);
1277 if (last_level_nr < 0)
1279 if (last_level_nr > highest_level_nr)
1280 last_level_nr = highest_level_nr;
1283 return last_level_nr;
1286 static int compareLevelDirInfoEntries(const void *object1, const void *object2)
1288 const struct LevelDirInfo *entry1 = object1;
1289 const struct LevelDirInfo *entry2 = object2;
1292 if (entry1->sort_priority != entry2->sort_priority)
1293 compare_result = entry1->sort_priority - entry2->sort_priority;
1296 char *name1 = getStringToLower(entry1->name);
1297 char *name2 = getStringToLower(entry2->name);
1299 compare_result = strcmp(name1, name2);
1305 return compare_result;
1308 static int LoadLevelInfoFromLevelDir(char *level_directory, int start_entry)
1311 struct stat file_status;
1312 char *directory = NULL;
1313 char *filename = NULL;
1314 struct SetupFileList *setup_file_list = NULL;
1315 struct dirent *dir_entry;
1316 int i, current_entry = start_entry;
1318 if ((dir = opendir(level_directory)) == NULL)
1320 Error(ERR_WARN, "cannot read level directory '%s'", level_directory);
1321 return current_entry;
1324 while (current_entry < MAX_LEVDIR_ENTRIES)
1326 if ((dir_entry = readdir(dir)) == NULL) /* last directory entry */
1329 /* skip entries for current and parent directory */
1330 if (strcmp(dir_entry->d_name, ".") == 0 ||
1331 strcmp(dir_entry->d_name, "..") == 0)
1334 /* find out if directory entry is itself a directory */
1335 directory = getPath2(level_directory, dir_entry->d_name);
1336 if (stat(directory, &file_status) != 0 || /* cannot stat file */
1337 (file_status.st_mode & S_IFMT) != S_IFDIR) /* not a directory */
1343 filename = getPath2(directory, LEVELINFO_FILENAME);
1344 setup_file_list = loadSetupFileList(filename);
1346 if (setup_file_list)
1348 checkSetupFileListIdentifier(setup_file_list, LEVELINFO_COOKIE);
1349 setLevelDirInfoToDefaults(&leveldir[current_entry]);
1351 ldi = leveldir[current_entry];
1352 for (i=FIRST_LEVELINFO_TOKEN; i<=LAST_LEVELINFO_TOKEN; i++)
1353 setSetupInfo(i, getTokenValue(setup_file_list, token_info[i].text));
1354 leveldir[current_entry] = ldi;
1356 leveldir[current_entry].filename = getStringCopy(dir_entry->d_name);
1357 leveldir[current_entry].user_defined =
1358 (level_directory == options.level_directory ? FALSE : TRUE);
1360 freeSetupFileList(setup_file_list);
1364 Error(ERR_WARN, "ignoring level directory '%s'", directory);
1370 if (current_entry == MAX_LEVDIR_ENTRIES)
1371 Error(ERR_WARN, "using %d level directories -- ignoring the rest",
1376 if (current_entry == start_entry)
1377 Error(ERR_WARN, "cannot find any valid level series in directory '%s'",
1380 return current_entry;
1383 void LoadLevelInfo()
1385 InitUserLevelDirectory(getLoginName());
1390 num_leveldirs = LoadLevelInfoFromLevelDir(options.level_directory,
1392 num_leveldirs = LoadLevelInfoFromLevelDir(getUserLevelDir(""),
1395 if (num_leveldirs == 0)
1396 Error(ERR_EXIT, "cannot find any valid level series in any directory");
1398 if (num_leveldirs > 1)
1399 qsort(leveldir, num_leveldirs, sizeof(struct LevelDirInfo),
1400 compareLevelDirInfoEntries);
1403 static void SaveUserLevelInfo()
1409 filename = getPath2(getUserLevelDir(getLoginName()), LEVELINFO_FILENAME);
1411 if (!(file = fopen(filename, "w")))
1413 Error(ERR_WARN, "cannot write level info file '%s'", filename);
1418 ldi.name = getLoginName();
1420 ldi.sort_priority = 300;
1421 ldi.readonly = FALSE;
1423 fprintf(file, "%s\n\n",
1424 getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, LEVELINFO_COOKIE));
1426 for (i=FIRST_LEVELINFO_TOKEN; i<=LAST_LEVELINFO_TOKEN; i++)
1427 fprintf(file, "%s\n", getSetupLine("", i));
1432 chmod(filename, SETUP_PERMS);
1438 struct SetupFileList *setup_file_list = NULL;
1440 /* always start with reliable default values */
1441 setSetupInfoToDefaults(&setup);
1443 filename = getPath2(getSetupDir(), SETUP_FILENAME);
1445 setup_file_list = loadSetupFileList(filename);
1447 if (setup_file_list)
1449 checkSetupFileListIdentifier(setup_file_list, SETUP_COOKIE);
1450 decodeSetupFileList(setup_file_list);
1452 setup.direct_draw = !setup.double_buffering;
1454 freeSetupFileList(setup_file_list);
1456 /* needed to work around problems with fixed length strings */
1457 if (strlen(setup.player_name) >= MAX_NAMELEN)
1458 setup.player_name[MAX_NAMELEN - 1] = '\0';
1459 else if (strlen(setup.player_name) < MAX_NAMELEN - 1)
1461 char *new_name = checked_malloc(MAX_NAMELEN);
1463 strcpy(new_name, setup.player_name);
1464 free(setup.player_name);
1465 setup.player_name = new_name;
1469 Error(ERR_WARN, "using default setup values");
1474 static char *getSetupLine(char *prefix, int token_nr)
1477 static char entry[MAX_LINE_LEN];
1478 int token_type = token_info[token_nr].type;
1479 void *setup_value = token_info[token_nr].value;
1480 char *token_text = token_info[token_nr].text;
1482 /* start with the prefix, token and some spaces to format output line */
1483 sprintf(entry, "%s%s:", prefix, token_text);
1484 for (i=strlen(entry); i<TOKEN_VALUE_POSITION; i++)
1487 /* continue with the token's value (which can have different types) */
1491 strcat(entry, (*(boolean *)setup_value ? "true" : "false"));
1495 strcat(entry, (*(boolean *)setup_value ? "on" : "off"));
1500 KeySym keysym = *(KeySym *)setup_value;
1501 char *keyname = getKeyNameFromKeySym(keysym);
1503 strcat(entry, getX11KeyNameFromKeySym(keysym));
1504 for (i=strlen(entry); i<50; i++)
1507 /* add comment, if useful */
1508 if (strcmp(keyname, "(undefined)") != 0 &&
1509 strcmp(keyname, "(unknown)") != 0)
1511 strcat(entry, "# ");
1512 strcat(entry, keyname);
1519 char buffer[MAX_LINE_LEN];
1521 sprintf(buffer, "%d", *(int *)setup_value);
1522 strcat(entry, buffer);
1527 strcat(entry, *(char **)setup_value);
1543 InitUserDataDirectory();
1545 filename = getPath2(getSetupDir(), SETUP_FILENAME);
1547 if (!(file = fopen(filename, "w")))
1549 Error(ERR_WARN, "cannot write setup file '%s'", filename);
1554 fprintf(file, "%s\n",
1555 getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, SETUP_COOKIE));
1556 fprintf(file, "\n");
1558 /* handle global setup values */
1560 for (i=FIRST_GLOBAL_SETUP_TOKEN; i<=LAST_GLOBAL_SETUP_TOKEN; i++)
1562 fprintf(file, "%s\n", getSetupLine("", i));
1564 /* just to make things nicer :) */
1565 if (i == SETUP_TOKEN_PLAYER_NAME)
1566 fprintf(file, "\n");
1569 /* handle player specific setup values */
1570 for (pnr=0; pnr<MAX_PLAYERS; pnr++)
1574 sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, pnr + 1);
1575 fprintf(file, "\n");
1577 sii = setup.input[pnr];
1578 for (i=FIRST_PLAYER_SETUP_TOKEN; i<=LAST_PLAYER_SETUP_TOKEN; i++)
1579 fprintf(file, "%s\n", getSetupLine(prefix, i));
1585 chmod(filename, SETUP_PERMS);
1588 void LoadLevelSetup()
1592 /* always start with reliable default values */
1596 filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME);
1598 if (level_setup_list)
1599 freeSetupFileList(level_setup_list);
1601 level_setup_list = loadSetupFileList(filename);
1603 if (level_setup_list)
1605 char *last_level_series =
1606 getTokenValue(level_setup_list, TOKEN_STR_LAST_LEVEL_SERIES);
1608 leveldir_nr = getLevelSeriesNrFromLevelSeriesName(last_level_series);
1609 level_nr = getLastPlayedLevelOfLevelSeries(last_level_series);
1611 checkSetupFileListIdentifier(level_setup_list, LEVELSETUP_COOKIE);
1615 level_setup_list = newSetupFileList(TOKEN_STR_FILE_IDENTIFIER,
1617 Error(ERR_WARN, "using default setup values");
1623 void SaveLevelSetup()
1626 struct SetupFileList *list_entry = level_setup_list;
1629 InitUserDataDirectory();
1631 setTokenValue(level_setup_list,
1632 TOKEN_STR_LAST_LEVEL_SERIES, leveldir[leveldir_nr].filename);
1634 setTokenValue(level_setup_list,
1635 leveldir[leveldir_nr].filename, int2str(level_nr, 0));
1637 filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME);
1639 if (!(file = fopen(filename, "w")))
1641 Error(ERR_WARN, "cannot write setup file '%s'", filename);
1646 fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
1647 LEVELSETUP_COOKIE));
1650 if (strcmp(list_entry->token, TOKEN_STR_FILE_IDENTIFIER) != 0)
1651 fprintf(file, "%s\n",
1652 getFormattedSetupEntry(list_entry->token, list_entry->value));
1654 /* just to make things nicer :) */
1655 if (strcmp(list_entry->token, TOKEN_STR_LAST_LEVEL_SERIES) == 0)
1656 fprintf(file, "\n");
1658 list_entry = list_entry->next;
1664 chmod(filename, SETUP_PERMS);