+
+/* ========================================================================= */
+/* setup file functions */
+/* ========================================================================= */
+
+#define TOKEN_STR_PLAYER_PREFIX "player_"
+
+/* global setup */
+#define SETUP_TOKEN_PLAYER_NAME 0
+#define SETUP_TOKEN_SOUND 1
+#define SETUP_TOKEN_SOUND_LOOPS 2
+#define SETUP_TOKEN_SOUND_MUSIC 3
+#define SETUP_TOKEN_SOUND_SIMPLE 4
+#define SETUP_TOKEN_TOONS 5
+#define SETUP_TOKEN_SCROLL_DELAY 6
+#define SETUP_TOKEN_SOFT_SCROLLING 7
+#define SETUP_TOKEN_FADING 8
+#define SETUP_TOKEN_AUTORECORD 9
+#define SETUP_TOKEN_QUICK_DOORS 10
+#define SETUP_TOKEN_TEAM_MODE 11
+#define SETUP_TOKEN_HANDICAP 12
+#define SETUP_TOKEN_TIME_LIMIT 13
+#define SETUP_TOKEN_FULLSCREEN 14
+#define SETUP_TOKEN_ASK_ON_ESCAPE 15
+#define SETUP_TOKEN_GRAPHICS_SET 16
+#define SETUP_TOKEN_SOUNDS_SET 17
+#define SETUP_TOKEN_MUSIC_SET 18
+#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS 19
+#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS 20
+#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC 21
+
+#define NUM_GLOBAL_SETUP_TOKENS 22
+
+/* editor setup */
+#define SETUP_TOKEN_EDITOR_EL_BOULDERDASH 0
+#define SETUP_TOKEN_EDITOR_EL_EMERALD_MINE 1
+#define SETUP_TOKEN_EDITOR_EL_MORE 2
+#define SETUP_TOKEN_EDITOR_EL_SOKOBAN 3
+#define SETUP_TOKEN_EDITOR_EL_SUPAPLEX 4
+#define SETUP_TOKEN_EDITOR_EL_DIAMOND_CAVES 5
+#define SETUP_TOKEN_EDITOR_EL_DX_BOULDERDASH 6
+#define SETUP_TOKEN_EDITOR_EL_CHARS 7
+#define SETUP_TOKEN_EDITOR_EL_CUSTOM 8
+
+#define NUM_EDITOR_SETUP_TOKENS 9
+
+/* shortcut setup */
+#define SETUP_TOKEN_SHORTCUT_SAVE_GAME 0
+#define SETUP_TOKEN_SHORTCUT_LOAD_GAME 1
+#define SETUP_TOKEN_SHORTCUT_TOGGLE_PAUSE 2
+
+#define NUM_SHORTCUT_SETUP_TOKENS 3
+
+/* player setup */
+#define SETUP_TOKEN_PLAYER_USE_JOYSTICK 0
+#define SETUP_TOKEN_PLAYER_JOY_DEVICE_NAME 1
+#define SETUP_TOKEN_PLAYER_JOY_XLEFT 2
+#define SETUP_TOKEN_PLAYER_JOY_XMIDDLE 3
+#define SETUP_TOKEN_PLAYER_JOY_XRIGHT 4
+#define SETUP_TOKEN_PLAYER_JOY_YUPPER 5
+#define SETUP_TOKEN_PLAYER_JOY_YMIDDLE 6
+#define SETUP_TOKEN_PLAYER_JOY_YLOWER 7
+#define SETUP_TOKEN_PLAYER_JOY_SNAP 8
+#define SETUP_TOKEN_PLAYER_JOY_BOMB 9
+#define SETUP_TOKEN_PLAYER_KEY_LEFT 10
+#define SETUP_TOKEN_PLAYER_KEY_RIGHT 11
+#define SETUP_TOKEN_PLAYER_KEY_UP 12
+#define SETUP_TOKEN_PLAYER_KEY_DOWN 13
+#define SETUP_TOKEN_PLAYER_KEY_SNAP 14
+#define SETUP_TOKEN_PLAYER_KEY_BOMB 15
+
+#define NUM_PLAYER_SETUP_TOKENS 16
+
+/* system setup */
+#define SETUP_TOKEN_SYSTEM_SDL_AUDIODRIVER 0
+#define SETUP_TOKEN_SYSTEM_AUDIO_FRAGMENT_SIZE 1
+
+#define NUM_SYSTEM_SETUP_TOKENS 2
+
+/* options setup */
+#define SETUP_TOKEN_OPTIONS_VERBOSE 0
+
+#define NUM_OPTIONS_SETUP_TOKENS 1
+
+
+static struct SetupInfo si;
+static struct SetupEditorInfo sei;
+static struct SetupShortcutInfo ssi;
+static struct SetupInputInfo sii;
+static struct SetupSystemInfo syi;
+static struct OptionInfo soi;
+
+static struct TokenInfo global_setup_tokens[] =
+{
+ { TYPE_STRING, &si.player_name, "player_name" },
+ { TYPE_SWITCH, &si.sound, "sound" },
+ { TYPE_SWITCH, &si.sound_loops, "repeating_sound_loops" },
+ { TYPE_SWITCH, &si.sound_music, "background_music" },
+ { TYPE_SWITCH, &si.sound_simple, "simple_sound_effects" },
+ { TYPE_SWITCH, &si.toons, "toons" },
+ { TYPE_SWITCH, &si.scroll_delay, "scroll_delay" },
+ { TYPE_SWITCH, &si.soft_scrolling, "soft_scrolling" },
+ { TYPE_SWITCH, &si.fading, "screen_fading" },
+ { TYPE_SWITCH, &si.autorecord, "automatic_tape_recording" },
+ { TYPE_SWITCH, &si.quick_doors, "quick_doors" },
+ { TYPE_SWITCH, &si.team_mode, "team_mode" },
+ { TYPE_SWITCH, &si.handicap, "handicap" },
+ { TYPE_SWITCH, &si.time_limit, "time_limit" },
+ { TYPE_SWITCH, &si.fullscreen, "fullscreen" },
+ { TYPE_SWITCH, &si.ask_on_escape, "ask_on_escape" },
+ { TYPE_STRING, &si.graphics_set, "graphics_set" },
+ { TYPE_STRING, &si.sounds_set, "sounds_set" },
+ { TYPE_STRING, &si.music_set, "music_set" },
+ { TYPE_SWITCH, &si.override_level_graphics, "override_level_graphics" },
+ { TYPE_SWITCH, &si.override_level_sounds, "override_level_sounds" },
+ { TYPE_SWITCH, &si.override_level_music, "override_level_music" },
+};
+
+static struct TokenInfo editor_setup_tokens[] =
+{
+ { TYPE_SWITCH, &sei.el_boulderdash, "editor.el_boulderdash" },
+ { TYPE_SWITCH, &sei.el_emerald_mine, "editor.el_emerald_mine" },
+ { TYPE_SWITCH, &sei.el_more, "editor.el_more" },
+ { TYPE_SWITCH, &sei.el_sokoban, "editor.el_sokoban" },
+ { TYPE_SWITCH, &sei.el_supaplex, "editor.el_supaplex" },
+ { TYPE_SWITCH, &sei.el_diamond_caves, "editor.el_diamond_caves" },
+ { TYPE_SWITCH, &sei.el_dx_boulderdash,"editor.el_dx_boulderdash" },
+ { TYPE_SWITCH, &sei.el_chars, "editor.el_chars" },
+ { TYPE_SWITCH, &sei.el_custom, "editor.el_custom" },
+};
+
+static struct TokenInfo shortcut_setup_tokens[] =
+{
+ { TYPE_KEY_X11, &ssi.save_game, "shortcut.save_game" },
+ { TYPE_KEY_X11, &ssi.load_game, "shortcut.load_game" },
+ { TYPE_KEY_X11, &ssi.toggle_pause, "shortcut.toggle_pause" }
+};
+
+static struct TokenInfo player_setup_tokens[] =
+{
+ { TYPE_BOOLEAN, &sii.use_joystick, ".use_joystick" },
+ { TYPE_STRING, &sii.joy.device_name, ".joy.device_name" },
+ { TYPE_INTEGER, &sii.joy.xleft, ".joy.xleft" },
+ { TYPE_INTEGER, &sii.joy.xmiddle, ".joy.xmiddle" },
+ { TYPE_INTEGER, &sii.joy.xright, ".joy.xright" },
+ { TYPE_INTEGER, &sii.joy.yupper, ".joy.yupper" },
+ { TYPE_INTEGER, &sii.joy.ymiddle, ".joy.ymiddle" },
+ { TYPE_INTEGER, &sii.joy.ylower, ".joy.ylower" },
+ { TYPE_INTEGER, &sii.joy.snap, ".joy.snap_field" },
+ { TYPE_INTEGER, &sii.joy.bomb, ".joy.place_bomb" },
+ { TYPE_KEY_X11, &sii.key.left, ".key.move_left" },
+ { TYPE_KEY_X11, &sii.key.right, ".key.move_right" },
+ { TYPE_KEY_X11, &sii.key.up, ".key.move_up" },
+ { TYPE_KEY_X11, &sii.key.down, ".key.move_down" },
+ { TYPE_KEY_X11, &sii.key.snap, ".key.snap_field" },
+ { TYPE_KEY_X11, &sii.key.bomb, ".key.place_bomb" }
+};
+
+static struct TokenInfo system_setup_tokens[] =
+{
+ { TYPE_STRING, &syi.sdl_audiodriver, "system.sdl_audiodriver" },
+ { TYPE_INTEGER, &syi.audio_fragment_size,"system.audio_fragment_size" }
+};
+
+static struct TokenInfo options_setup_tokens[] =
+{
+ { TYPE_BOOLEAN, &soi.verbose, "options.verbose" }
+};
+
+static char *get_corrected_login_name(char *login_name)
+{
+ /* needed because player name must be a fixed length string */
+ char *login_name_new = checked_malloc(MAX_PLAYER_NAME_LEN + 1);
+
+ strncpy(login_name_new, login_name, MAX_PLAYER_NAME_LEN);
+ login_name_new[MAX_PLAYER_NAME_LEN] = '\0';
+
+ if (strlen(login_name) > MAX_PLAYER_NAME_LEN) /* name has been cut */
+ if (strchr(login_name_new, ' '))
+ *strchr(login_name_new, ' ') = '\0';
+
+ return login_name_new;
+}
+
+static void setSetupInfoToDefaults(struct SetupInfo *si)