Homework 7 Starting the DASH
Begin constructing a shell.
This homework is worth 20 points.
Goals
When you finish this homework you should:
- Established a framework for the next several projects.
- Used many of the information gathering techniques discussed in class.
Assignment
This project is the beginning of a series of assignments aimed at constructing DAn's SHell or dash. The purpose of this shell is to experiment with the concepts we have discussed. We will be adding to this so you need to keep your code open and flex able.
This shell will be line oriented. The basic loop will be
while not done
read a line (command)
process the line
Parsing the command line is your first challenge.
There are many ways you could accomplish this task. In some sense it depends on what you know and how much time you wish to invest in this portion of the project..
- A simple solution would include c++ style strings, getline and calls to find. This will require you to write code to mess with skipping white space. This should be a solution that anyone can use however. String streams might be really useful in this case.
- A more tools based solution would involve the library call strtok and c style strings. This solution would handle the white space problem, but requires c style strings.
- The right way to do it would involve flex and bison, but that is way beyond the scope of this class. I would be happy to help anyone attempting this solution.
We will be parsing input in the following form:
command: cmd | cmd redirectl | cmd pipe cmd | builtin
cmd: STRING args
args : STRING | STRING argl | ε
pipe: "|"
redirectl: redirect | redirect redirectl
redirect: < STRING | > STRING | ε
builtin: buitin_s | builtin_a
builtin_s: "UID" | "PID" | "PPID" | "NAME" | "WD" | "INFO" | "EXIT" | "UP" | "HOME" | "HD"
builtin_a: prompt | run | down | go | set
prompt: "PROMPT" INTEGER
run: "RUN" STRING
down: "DOWN" STRING
go: "GO" STRING
set: "SET" STRING STRING
Note: the grammar above may contain errors and is most certainly incomplete.
For now, you need to deal with the following built in commands:
- UID: print the user's uid.
- PID: print the process id.
- PPID: print the parent process id.
- NAME: print the user name from the password file.
- WD: print the current working directory
- HD: print the user's home directory
- INFO: print all of the above.
- EXIT: exit the program
- HOME: change the current working directory to the users home directory
- UP: change the current working directory up one level if possible.
- PROMPT n: Change the prompt setting to the integer n.
- RUN filename: execute the commands in the named file.
- DOWN path: change the current working directory to the sub-directory listed. (Append path to cwd)
- GO path: change the current working directory to be path. Path should start with a /.
- SET name value: set the value of the environment variable name to be value.
The integer associated with prompt determines how the prompt is displayed. Treat this integer as a set of bit flags, and display the following
Value | Value to Display |
0 | ">" |
1 | Environment variable PROMPT |
2 | Current directory basename |
4 | The first part of the host name (up to the first .) |
8 | username |
These are displayed in descending order. The delimiter between portions is :.Assume that the machine is Mirkwood, the current directory is foo and the user name is bennett, and the environment variable PROMPT is "%". The following prompts would be :
n | Prompt |
---|
0 | > |
1 | % |
2 | foo |
3 | foo:% |
5 | Mirkwood:% |
15 | bennett:Mirkwood:foo:%
|
I will not be adding any features to the prompt, so you may embellish on this if you wish.
Your program should recognize the following command line arguments when it is started.
- -s or --start starts an instance of dash which attempts to read and execute the commands in ~/.dash/rc
- -l or --log starts a log file, with a temporary file filename in ~/.dash/logs. Using an appropriate name, this log file should contain a history of commands executed, including builtins.
- -d or --debug runs the shell in a diagnostic mode, printing out which actions are about to occur to the standard output.
Discussion
Submission
Email a copy of the C code to complete the final task to your instructor by class time. If your code consists of a single file, the source code will be sufficient, if the code is in multiple files, you should submit a tar file containing the source code and a make configuration file required to build the project.