The purpose of this assignment is to get everyone up to speed on system programming and to gain some familiarity with the system call interface. A secondary goal is to use some of the programming tools provided in the UNIX environment. In this assignment you are to implement a UNIX shell program. A shell is simply a CLI program that conveniently allows you to run other programs. Read up on your favorite shell (such as bash, csh, tcsh, sh, ...) to see what it does..
Basic Commands: The input to guish is a sequence of commands, each provided on a separate line of input text (or typed interactively at the keyboard). The following command must be supported:
Runs the program progname with the given, possibly optional, arguments.
The exit internal command causes the shell to exit. This is the *only* way your shell can exit. Just prior to your shell exiting, you should print out the number of times each interrupt was detected.
The hist history internal shell command will display the (up to) 10 most recent commands entered from the user. See details below how this should work.
The r n internal shell command will execute a command from the history list. See details below how this should work.
I/O Redirection: Your shell must support I/O redirection. By default, guish runs programs so that input data is read from standard input and output data is written to standard output. However, this behavior can be changed using I/O redirection. I/O redirection is specified using the <, > operators. For example:
Write the standard output of progname to the file file.out.
Uses the contents of the file file.in as the standard input to program progname.
Both input and output redirection may be specified for a single command so your shell will have to check for both and operate accordingly. The redirections can be specified in any order.
Handling Erroneous Programs: Finally, when programs terminate, they return an integer exit code to your shell. If this code is non-zero, your shell should print the returned value. For example
guish: cp foo bar
cp: cannot access foo
[ Program returned exit code 1 ]
Make sure you understand the assignment before beginning any work. Now, a guish shell template, parser, and makefile are provided for you.
The name of our shell will be called New Island Shell (guish). You are provided with the files guish.l and guish.cpp which contain some source code that uses gettoks(), a function provided by guish.l to get and parse a line of input. The function gettoks() returns an array of pointers to character strings (i.e. NULL terminated C style strings). Each string is either a word containing the letters, numbers, ., and /, or a single character string containing one of the special characters: ( ) < > | & ;.
To compile guish.l, you have to use flex: "flex guish.l". This will produce a file called (by default) lex.yy.c which is compiled with gcc. The file guish.cpp will be compiled with g++. The final step is to link the object files lex.yy.o and guish.o with the flex library -lfl. If this is all confusing, here is a Makefile to simplify the entire process. (with a few modifications)
Other Shell Details
Your shell must support the following:
You are expected to do your own work and research regarding the usage of various system calls, header files, and libraries. Information is readily available in the man pages, UNIX reference books, or on the web. Otherwise, do not hesitate to ask a question if you are unclear about how some part of the assignment is supposed to work.
For 5 points extra added to this project, have your shell process a command, with or without arguments, whose output is piped to the input of another command.
Submitting Your Project
Please see the project submission guidelines for detailing how your project should be formatted for submission. In addition, please turn in a printed listing of guish.cpp on the due date.
Assessment and Grading
This is an individual assignment. Write a well structured, well documented, computer program using C++ and the supporting files provided to you. Your project must following the documentation standards defined here. Use procedures and functions. You may use the STL in your solution. This project is worth 100 points.