added the "main" section to the README
This commit is contained in:
parent
414ae236bd
commit
6b9bedac3c
19
README.md
19
README.md
|
|
@ -77,9 +77,24 @@ These structs all come with some library functions for ease of use, which allow
|
||||||
|
|
||||||
|
|
||||||
## main
|
## 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
|
# bonuses
|
||||||
|
|
|
||||||
2
main.c
2
main.c
|
|
@ -108,7 +108,7 @@ int main(int argc, char *argv[]) {
|
||||||
#if EXT_PROMPT
|
#if EXT_PROMPT
|
||||||
if (! executeBuiltin(cmd, &status, &debug)) {
|
if (! executeBuiltin(cmd, &status, &debug)) {
|
||||||
#else
|
#else
|
||||||
if (!executeBuiltin(cmd, &status)) {
|
if (!executeBuiltin(cmd, &status)) {
|
||||||
#endif
|
#endif
|
||||||
do_loop = false;
|
do_loop = false;
|
||||||
cpy = NULL;
|
cpy = NULL;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue