arthfs/Command-line-shell
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
Name : Marc-Arthur Saint Louis
NetID : MS4050
My approach
I created :
- a struct called operators with fields pos (where it happens in the command) and value (0 for "or", 1 is for "and")
- a struct called redirection with feilds fd (the file descriptor number used), pos (where it happends in the command),operator ("<" or ">") , filename (where to redirect the ouput)
- a struct command that has a lot fields (status, current index of redirection, max_number of redirections, an array of redirections).Similarly, I have informations
about the subcommands , and the pipes.
- a function called search that uses binary search to determine if there's "or" or "and" at a certain index
- a cleanup function to free the memory allocated by the arrays of struct (commands,operators,redirections,pipes...)
in my lib.h I created an array of commands (to hold the commands I will store). In main, I verify if if the number of arguments passed to mysh is correct.
if no arguments was passed I called read_file (NULL), I call read_file(path_name) if the user gave a path. Before executing in interactive mode I print the "welcome message".
My read_file () function reads from input / file depengin on the argument that was given, fills the commands array and call decide_execute each time it finishes processing a complete line .
The function decide_to_execute is in lib2.c . This function analyse the argv fields of the command to call the appropriate function. If the number
of pipes is >0 , it calls execute_pipes .If the number of redirections>0 , it calls execute_redirections. If it's a builtin command it executes it . Otherwise it calls
execute_simple (this function execute very simple commands).
helpful notes :
- test_files must have a blank line at the end
- "<" "|" ">" "or" "and" must be separated with spaces with other subcommands
- I don't store "<" "|" ">" "or" "and" in the commands , I put < > in the redirections's array, | in the pipes's array and/or in the operators's arrays
- test_basic uses test_valid_basic.txt and test_invalid_basic.txt
- test_pipes uses test_valid_pipes.txt and test_invalid_pipes.txt
- test_redirections uses test_valid_redirections.txt and test_invalid_redirections.txt
to run a test you can execute make test_basic and then execute ./test_basic.It's the same for the other tests
test plan
I create 3 test_files
- test_basic.c to process valid basic and invalid basic commands they rely on test_valid_basic.txt and test_invalid_basic.txt
this test passed succesfully
-test_redirections.c to process valid redirections and invalid redirections they rely on test_valid_redirections.txt and test_invalid_redirections.txt
this test passed succesfully
-test_pipes.c to process valid pipes commands and invalid pipes command they rely on test_valid_pipes.txt and test_invalid_pipes.txt
this test passed succesfully
I have a method called test_argument that verify mysh is called properly
sometimes ,I am have troubles handling commands that involves the builtin command which , i don't know if it will work everytime.