+ /* replace -r <file> so that the layout is restored */
+ if (restart_filename != NULL) {
+ /* create the new argv */
+ int num_args;
+ for (num_args = 0; start_argv[num_args] != NULL; num_args++);
+ char **new_argv = scalloc((num_args + 3) * sizeof(char*));
+
+ /* copy the arguments, but skip the ones we'll replace */
+ int write_index = 0;
+ bool skip_next = false;
+ for (int i = 0; i < num_args; ++i) {
+ if (skip_next)
+ skip_next = false;
+ else if (!strcmp(start_argv[i], "-r"))
+ skip_next = true;
+ else
+ new_argv[write_index++] = start_argv[i];
+ }
+
+ /* add the arguments we'll replace */
+ new_argv[write_index++] = "--restart";
+ new_argv[write_index++] = restart_filename;
+
+ /* swap the argvs */
+ start_argv = new_argv;
+ }
+