+ if (strchr (argv[i], ' ') == NULL)
+ printf (" %s", argv[i]);
+ else
+ printf (" '%s'", argv[i]);
+ printf ("\n");
+
+ return argv;
+}
+
+/* Parses options in ARGV[]
+ and returns the first non-option argument. */
+static char **
+parse_options (char **argv)
+{
+ for (; *argv != NULL && **argv == '-'; argv++)
+ {
+ char *save_ptr;
+ char *name = strtok_r (*argv, "=", &save_ptr);
+ char *value = strtok_r (NULL, "", &save_ptr);
+
+ if (!strcmp (name, "-h"))
+ usage ();
+ else if (!strcmp (name, "-q"))
+ power_off_when_done = true;
+ else if (!strcmp (name, "-r"))
+ reboot_when_done = true;
+#ifdef FILESYS
+ else if (!strcmp (name, "-f"))
+ format_filesys = true;
+#endif
+ else if (!strcmp (name, "-rs"))
+ random_init (atoi (value));
+ else if (!strcmp (name, "-mlfqs"))
+ thread_mlfqs = true;
+#ifdef USERPROG
+ else if (!strcmp (name, "-ul"))
+ user_page_limit = atoi (value);
+#endif
+ else
+ PANIC ("unknown option `%s' (use -h for help)", name);
+ }
+
+ /* Initialize the random number generator based on the system
+ time. This has no effect if an "-rs" option was specified.
+
+ When running under Bochs, this is not enough by itself to
+ get a good seed value, because the pintos script sets the
+ initial time to a predictable value, not to the local time,
+ for reproducibility. To fix this, give the "-r" option to
+ the pintos script to request real-time execution. */
+ random_init (rtc_get_time ());
+
+ return argv;
+}
+
+/* Runs the task specified in ARGV[1]. */
+static void
+run_task (char **argv)
+{
+ const char *task = argv[1];
+
+ printf ("Executing '%s':\n", task);