From 6b9bedac3cf334fad7c2826267de858219f0ddad Mon Sep 17 00:00:00 2001 From: Ali-Ert Date: Fri, 16 Feb 2024 17:37:44 +0100 Subject: [PATCH] added the "main" section to the README --- README.md | 19 +++++++++++++++++-- main.c | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6ac6f86..555aafe 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,24 @@ These structs all come with some library functions for ease of use, which allow ## main -The driver code behind the program lives (obviously) in `main()`. +The driver code behind the program lives (obviously) in `main()`. -//TODO you were writing here +The code is mostly found in the while loop, which runs until the value of `do_loop` is set to false, which only happens when the program reaches the EOF or the BUILTIN command exit is given. `inputLine` is the line that the user enters the shell. We declare `tokenList` to store all of the tokens that are picked up from the input. + +`readInputLine()` reads the entire input line. We modified this function so that it returns NULL on EOF. Before we start, `inputLine` is quickly checked to see whether or not its NULL. If it is not, the function `getTokenList()` is run to extract all the tokens from the input and place them into `tokenList`. + +Since the `tokenList` will be edited, we create two copies of the list, `cpy` and `og`. Before looking through any tokens, the `parseInputList()` function is utilised to check the validity of `tokenList`. It is also checked whether or not the list is NULL. If these are both valid, we can begin executing the line, else we print an invalid syntax error message. + +The execution is done within a while loop that runs until the `cpy` list is entirely consumed and is NULL. Within this while loop, we implemented a switch case which, at this level, should only accept the following enum types: +- EXECUTABLE +- COMPOSITION +- BUILTIN + +// TODO: discuss what the process is for each enum type. + +If the code encounters any other types at this level, it means that the syntax of the input is incorrect. If this happens, an error message is printed out and `cpy` is set to NULL in order to exit the loop. + +In the end, we use `free()` and `freeTokenList()` to free the memory. # bonuses diff --git a/main.c b/main.c index e0f81e4..0b50332 100644 --- a/main.c +++ b/main.c @@ -108,7 +108,7 @@ int main(int argc, char *argv[]) { #if EXT_PROMPT if (! executeBuiltin(cmd, &status, &debug)) { #else - if (!executeBuiltin(cmd, &status)) { + if (!executeBuiltin(cmd, &status)) { #endif do_loop = false; cpy = NULL;