From ff7e7e3f2fb514b7c9fcbb451c804a8288ec1db4 Mon Sep 17 00:00:00 2001
From: Joshua Saxby <joshua.a.saxby@gmail.com>
Date: Fri, 29 Nov 2019 16:39:44 +0000
Subject: [PATCH] Add skeleton code unit for argument parsing

---
 Makefile.build              | 1 +
 userprog/argument_parsing.h | 9 +++++++++
 userprog/parse_arguments.c  | 6 ++++++
 3 files changed, 16 insertions(+)
 create mode 100644 userprog/parse_arguments.c

diff --git a/Makefile.build b/Makefile.build
index 2989dec..823d5af 100644
--- a/Makefile.build
+++ b/Makefile.build
@@ -55,6 +55,7 @@ lib/kernel_SRC += lib/kernel/console.c	# printf(), putchar().
 
 # User process code.
 userprog_SRC  = userprog/process.c	# Process loading.
+userprog_SRC += userprog/parse_arguments.c  # Parses arguments from command line string.
 userprog_SRC += userprog/populate_stack.c  # Populates stack with program arguments.
 userprog_SRC += userprog/pagedir.c	# Page directories.
 userprog_SRC += userprog/exception.c	# User exception handler.
diff --git a/userprog/argument_parsing.h b/userprog/argument_parsing.h
index 78be27f..78f4e0e 100644
--- a/userprog/argument_parsing.h
+++ b/userprog/argument_parsing.h
@@ -1,6 +1,15 @@
 #ifndef USERPROG_ARGUMENT_PARSING_H
 #define USERPROG_ARGUMENT_PARSING_H
 
+/*
+ * Given a string containing the command invoking the program `command_line`
+ * and a pointer to an array of C strings (pointer to `char* argv[]`), parse
+ * `command_line` into individual arguments, populate `argv` with these and
+ * return the number of arguments that were parsed (this is the value that can
+ * be used for `argc`).
+ */
+int parse_arguments(const char* command_line, char***argv);
+
 /*
  * Given stack pointer `esp`, argument count `argc` and arguments array `argv`,
  * Populates the stack pointed to by the stack pointer with the given arguments.
diff --git a/userprog/parse_arguments.c b/userprog/parse_arguments.c
new file mode 100644
index 0000000..aeaefd0
--- /dev/null
+++ b/userprog/parse_arguments.c
@@ -0,0 +1,6 @@
+#include "userprog/argument_parsing.h"
+
+
+int parse_arguments(const char* command_line, char***argv) {
+    #warning "Implement me"
+}
-- 
GitLab