diff --git a/userprog/parse_arguments.c b/userprog/parse_arguments.c index c86364fdd2408b978f019f9df3d7c09a48b0ec31..71abd85bcc806cd23e693f543bf4d8891c9a2aee 100644 --- a/userprog/parse_arguments.c +++ b/userprog/parse_arguments.c @@ -1,11 +1,19 @@ +#include <stdio.h> +#include <string.h> + #include "userprog/argument_parsing.h" int parse_arguments(const char* command_line, char**argv) { - /* - * XXX: Dummy implementation which sets argv[0] to "echo" so at least there's - * a filename to load. - */ - argv[0] = "echo"; - return 1; + printf("parse_arguments(command_line) = '%s'\n", command_line); + int argc = 0; + // the state pointer required by strtok_r() for use between calls + char* state_pointer; + // first call to strtok_r() is the only one where string to parse is passed + argv[0] = strtok_r(command_line, " ", &state_pointer); + printf("parse_arguments(): argv[0] = '%s'\n", argv[0]); + argc++; + // now, parse token-by-token for any additional arguments + // TODO: implementation! + return argc; } diff --git a/userprog/process.c b/userprog/process.c index 87fd42a738663bdcfd7c5d2e1da8f92bc950bee4..ce72cf27604a863c4c658a2f26ebc05da80f86c4 100644 --- a/userprog/process.c +++ b/userprog/process.c @@ -234,7 +234,14 @@ load (const char *command, void (**eip) (void), void **esp) // extract arguments (including file name) // NOTE: decide how many arguments we want --is 255 the standard number? char* argv[255]; - int argc = parse_arguments(command, argv); + printf("load(command) = '%s'\n", command); + // copy the command string so we have a separate copy to manipulate + // generous length limit based on 255 arguments that are 15 chars long each + char command_copy[255]; + strlcpy(command_copy, command, 255); + printf("load(): command_copy = '%s'\n", command_copy); + int argc = parse_arguments(command_copy, argv); + printf("load(): argv[0] = '%s'\n", argv[0]); char* file_name = argv[0]; // file name is always argument 0 /* Allocate and activate page directory. */