Skip to content
Snippets Groups Projects
Verified Commit c9ce75a5 authored by ja3-saxby's avatar ja3-saxby
Browse files

Implement loading of first argument using strtok_r()

parent 42fc4da9
No related branches found
No related tags found
1 merge request!4Implement parse_arguments()
#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;
}
......@@ -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. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment