+ *level_nr++ = '\0';
+
+ global.dumptape_leveldir = leveldir;
+ global.dumptape_level_nr = atoi(level_nr);
+
+ program.headless = TRUE;
+ }
+ else if (strPrefix(command, "autoplay ") ||
+ strPrefix(command, "autoffwd ") ||
+ strPrefix(command, "autowarp ") ||
+ strPrefix(command, "autotest ") ||
+ strPrefix(command, "autosave ") ||
+ strPrefix(command, "autoupload ") ||
+ strPrefix(command, "autofix "))
+ {
+ char *arg_ptr = strchr(command, ' ');
+ char *str_ptr = getStringCopy(arg_ptr); // read command parameters
+
+ global.autoplay_mode =
+ (strPrefix(command, "autoplay") ? AUTOPLAY_MODE_PLAY :
+ strPrefix(command, "autoffwd") ? AUTOPLAY_MODE_FFWD :
+ strPrefix(command, "autowarp") ? AUTOPLAY_MODE_WARP :
+ strPrefix(command, "autotest") ? AUTOPLAY_MODE_TEST :
+ strPrefix(command, "autosave") ? AUTOPLAY_MODE_SAVE :
+ strPrefix(command, "autoupload") ? AUTOPLAY_MODE_UPLOAD :
+ strPrefix(command, "autofix") ? AUTOPLAY_MODE_FIX :
+ AUTOPLAY_MODE_NONE);
+
+ while (*str_ptr != '\0') // continue parsing string
+ {
+ // cut leading whitespace from string, replace it by string terminator
+ while (*str_ptr == ' ' || *str_ptr == '\t')
+ *str_ptr++ = '\0';
+
+ if (*str_ptr == '\0') // end of string reached
+ break;
+
+ if (global.autoplay_leveldir == NULL) // read level set string
+ {
+ global.autoplay_leveldir = str_ptr;
+ global.autoplay_all = TRUE; // default: play all tapes
+
+ for (i = 0; i < MAX_TAPES_PER_SET; i++)
+ global.autoplay_level[i] = FALSE;
+ }
+ else // read level number string
+ {
+ int level_nr = atoi(str_ptr); // get level_nr value
+
+ if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
+ global.autoplay_level[level_nr] = TRUE;
+
+ global.autoplay_all = FALSE;
+ }
+
+ // advance string pointer to the next whitespace (or end of string)
+ while (*str_ptr != ' ' && *str_ptr != '\t' && *str_ptr != '\0')
+ str_ptr++;
+ }
+
+ if (global.autoplay_mode & AUTOPLAY_WARP_NO_DISPLAY)
+ program.headless = TRUE;
+ }
+ else if (strPrefix(command, "patch tapes "))
+ {
+ char *str_ptr = getStringCopy(&command[12]); // read command parameters
+
+ // skip leading whitespace
+ while (*str_ptr == ' ' || *str_ptr == '\t')
+ str_ptr++;
+
+ if (*str_ptr == '\0')
+ Fail("cannot find MODE in command '%s'", command);
+
+ global.patchtapes_mode = str_ptr; // store patch mode
+
+ // advance to next whitespace (or end of string)
+ while (*str_ptr != ' ' && *str_ptr != '\t' && *str_ptr != '\0')
+ str_ptr++;
+
+ while (*str_ptr != '\0') // continue parsing string
+ {
+ // cut leading whitespace from string, replace it by string terminator
+ while (*str_ptr == ' ' || *str_ptr == '\t')
+ *str_ptr++ = '\0';
+
+ if (*str_ptr == '\0') // end of string reached
+ break;
+
+ if (global.patchtapes_leveldir == NULL) // read level set string
+ {
+ global.patchtapes_leveldir = str_ptr;
+ global.patchtapes_all = TRUE; // default: patch all tapes
+
+ for (i = 0; i < MAX_TAPES_PER_SET; i++)
+ global.patchtapes_level[i] = FALSE;
+ }
+ else // read level number string
+ {
+ int level_nr = atoi(str_ptr); // get level_nr value
+
+ if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
+ global.patchtapes_level[level_nr] = TRUE;
+
+ global.patchtapes_all = FALSE;
+ }
+
+ // advance string pointer to the next whitespace (or end of string)
+ while (*str_ptr != ' ' && *str_ptr != '\t' && *str_ptr != '\0')
+ str_ptr++;
+ }
+
+ if (global.patchtapes_leveldir == NULL)
+ {
+ if (strEqual(global.patchtapes_mode, "help"))
+ global.patchtapes_leveldir = UNDEFINED_LEVELSET;
+ else
+ Fail("cannot find LEVELDIR in command '%s'", command);
+ }
+
+ program.headless = TRUE;
+ }
+ else if (strPrefix(command, "convert "))
+ {
+ char *str_copy = getStringCopy(strchr(command, ' ') + 1);
+ char *str_ptr = strchr(str_copy, ' ');
+
+ global.convert_leveldir = str_copy;
+ global.convert_level_nr = -1;
+
+ if (str_ptr != NULL) // level number follows
+ {
+ *str_ptr++ = '\0'; // terminate leveldir string
+ global.convert_level_nr = atoi(str_ptr); // get level_nr value
+ }
+
+ program.headless = TRUE;
+ }
+ else if (strPrefix(command, "create sketch images "))
+ {
+ global.create_sketch_images_dir = getStringCopy(&command[21]);
+
+ if (access(global.create_sketch_images_dir, W_OK) != 0)
+ Fail("image target directory '%s' not found or not writable",
+ global.create_sketch_images_dir);
+ }
+ else if (strPrefix(command, "create collect image "))
+ {
+ global.create_collect_images_dir = getStringCopy(&command[21]);
+
+ if (access(global.create_collect_images_dir, W_OK) != 0)
+ Fail("image target directory '%s' not found or not writable",
+ global.create_collect_images_dir);
+ }
+ else if (strPrefix(command, "create CE image "))
+ {
+ CreateCustomElementImages(&command[16]);
+
+ exit(0);
+ }
+ else
+ {
+ FailWithHelp("unrecognized command '%s'", command);
+ }
+
+ // disable networking if any valid command was recognized
+ options.network = setup.network_mode = FALSE;
+}
+
+static void InitSetup(void)
+{
+ LoadUserNames(); // global user names
+ LoadUserSetup(); // global user number
+
+ LoadSetup(); // global setup info
+
+ // set some options from setup file
+
+ if (setup.options.verbose)
+ options.verbose = TRUE;
+
+ if (setup.options.debug)
+ options.debug = TRUE;
+
+ if (!strEqual(setup.options.debug_mode, ARG_UNDEFINED_STRING))
+ options.debug_mode = getStringCopy(setup.options.debug_mode);
+
+ if (setup.debug.show_frames_per_second)
+ global.show_frames_per_second = TRUE;