For the Shell assignment you'll first need to start by writing a command line parser. The parser's job will be to break up the individual parts of the command line from the shell's input.
Remember! Your shell doesn't have to execute anything yet! It only has to parse up the command line and print out the information.
/**
* parse.c
*/
void init_info(parseInfo *p) {
initialize parseInfo struct
}
/* parse a single command */
void parse_command(char * command, struct commandType *comm) {
}
/* parse commandline for space separated commands */
parseInfo *parse (char *cmdline) {
foreach cmd in cmdline {
if (cmd == command) {
parse_command(cmd, type)
}
}
}
/* prints out parse struct */
void print_info (parseInfo *info) {
foreach type in parseInfo {
print "type_name: type"
}
}
/* free memory used in parseInfo */
void free_info (parseInfo *info) {
foreach memory_block in parseInfo
free(memory_block)
}
----------------------------------------------------------
/**
* shell.c
*/
int main(int argc, char **argv) {
while(1) {
cmdLine = readline(printPrompt());
info = parse(cmdLine);
print_info(info);
}
free_info(info);
}
command <
file
command >
output_file
- Print if in background, this symbol: '&'. Your
print_info should also show weather or not the command
was passed in the background. A command being run in the background
would look like this:
command &
All
parsing of this information is done in the
parse function, the print_info simply prints
out what it finds in the parseInfo struct.
Getting Started
Examples
Here is a text file of an example run
of the parser shell. This should give you an idea of how the shell
and parser should look and interact.
Here is a tar file that contains a
Makefile that will get you started compiling on a UNIX/Linux
platform. Download the file and then execute the command tar -xf
exampleShell.tar
to unzip the contents. Then simply
cd exampleShell
into the exampleShell
directory and type make
. This will compile shell.c into
the executable shell. You can execute shell by typing
./shell
at the command prompt. You can remove the
executable by typing make clean
. Feel free to use this
example as a base for your shell.