-
Notifications
You must be signed in to change notification settings - Fork 0
How it all works...
In order to understand Thursday, you have to understand what a Shell is to begin with. So instead of trying to re-hash the definition of what a shell is here is a definition:
The shell is the outermost layer of the operating system. Shells incorporate a programming language to control processes and files, as well as to start and control other programs. The shell manages the interaction between you and the operating system by prompting you for input, interpreting that input for the operating system, and then handling any resulting output from the operating system.
For more information go to the website that I got it from: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.osdevice/shells.html
So like what the definition states, there are three main jobs for a Shell: take in user input, parse user input, and execute the parsed input. There are also sub jobs that the Shell needs to do in order to keep things tidy and neat, and they are process management, moving the shell in and out of directories, and be able to communicate errors to the user.
So, from receiving user commands to getting feedback from the Shell is how I will explain how Thursday works. This is going to be a generally overview, nothing to the T.
In the program main, Thursday is in a while loop constantly looking for user input. I display the prompt and capture the keystrokes coming from the keyboard. Every keystroke has a key number that I check against and depending on the key that was pressed I do something with. For every key that is "enter, tab, backspace, shift, arrow, insert, delete, home, end" I do something special, everything else just gets added to the string. If you want to know more about how the tab auto complete or the other special characters work, check the command parser page in Thursdays wiki.
From there, I take the string of input from the main.cpp file and give it to the Check_Input_Loop method. This method tokens the string, and makes sure that there are the correct number of single and double quotes, along with " (, ], } " characters. These are important characters because all the input between them needs to stay together, check the other wiki page for more information. Lastly, this method is also checking to make sure that there are not more than one operator next to each other, and that there is not more than one ampersand in each section of input. A section of input is everything before a semicolon, and if there is no semicolon then that whole line is considered a section of input.
Then, from there I take the vector full of tokens that came from the Check_Input_Loop method and give it to either the Operator_Command_Parse_Loop or Basic_Command_Parse_Loop method. If I found an operator in the last loop depends on which method is being called, and I think by the names of the methods you can distinguish which ones are being called. So, in the Basic_Command_Parse_Loop method I take the tokens and look for Thursday commands. If I don't find a command that belongs to the Thursday arsenal, then I just exec the command and give the system binaries the arguments that come with the command. If I find one I take it and the arguments that come after it and give it to the SearchCommands method. Within that method I have a huge chained if statements that look at the command and the first character, and see which section to look in based off that first character. If the code to full fill the request of the command is small you will find it in the SearchCommands method, else it will be in its own method in the Thursday class.
Now, this is not the same for the Operator_Command_Parse_Loop method. This method is looking for operators and making sure that the operators that are within the input follow the three rules of operator input. They are given here:
- Rule #1: You cannot have standard out before standard in.
- Rule #2: You can have standard out and standard error after a pipe but not standard in.
- Rule #3: You can only have one standard out and standard in each input section.
Now these are the rules for the input of Thursday, I tried to figure out all the different possibilities that a normal shell like Bash can take but man that is a lot of variations of command input. Some of the complex commands get very cryptic to understand, but hey I'm only human in this shell is for education purposes! So with those three rules I take the command and operators and handle them and execute them accordingly. From here that when output is being displayed to the screen.
For everything else that I did not mention, Thursday is keeping track of what directory it is in because of the "cd" command, and all the basic information is being saved in public variables that I have within the class. If I find any other useful information I will make sure to update this document, but that is how Thursday takes input, parses the input, and gives back output in a general way. I will have more information on the complex command parser that I have created in other pages, along with other pages filled with useful knowledge about the system.