Banner

Project Summary

The purpose of this project is to create a shell.  The shell provides a simple user interface to execute programs and commands of the operating system.  Special operators which we have included are < for input redirection, 1> for output redirection, 2> for error output redirection, & to run programs in the background, and | to implement piping.


Source Code

 

Pseudocode

Print out the prompt

printf(“bms:>pathname>”);

parse the string into separate words using the characters ‘ ‘, >, <, -, |, & as delimiters

save the delimiter found into op

if (program == quit)

exit program;

if(program==’\n’)

            prompt again;

if(program ==”cd”)

            if (newpath starts with ‘/’)

                        success = chdir(newpath)

                        if success != 0

                                    printf(“path can’t be found”);

            else if (newpath starts with ‘..’)

                        newpath = oldpath minus the text after the last ‘/’

            else if (newpath starts with ‘.’)

                        newpath = oldpath

            else if (newpath is the name of a folder)

                        newpath = oldpath concatenated with ‘/name of folder’

else if (program starts with ‘/’)

            run the whole command

else

{

            //when only the command or name of program is given

            find the possible search paths

            try to find the program using all the possible search paths

}

if the program was not found

            display an error message

if the program was found, fork a child

            child will execute the program

            depending on the operator, the child will change the file table

{

if the operand found == ‘<’

            fidin = open(tok, O_RDONLY);

            change the file table to read from the file instead of the keyboard

if op == ‘1>’

            fidout = open(tok, O_WRONLY|O_CREATE);

            change the file table to output to the file instead of the monitor

if op == ‘2>’

            fiderr = open(tok, O-WRONLY|O_CREATE);

            change the file table to put error messages in the given file instead of the monitor

if op == ‘&’

            backgnd = 0  //flag indicates whether the parent should wait for the child or not

if op == ‘ ‘ ignore and do nothing

if op == ‘|’

            backgnd = 1;   //run the last task in the foreground, previous tasks in the backgnd

            there are different states of piping

            if this is the first pipe

                        parent makes a pipe

                        child closes the input side of its pipe

                        child outputs to the pipe

            if this is the second pipe

                        parent makes a pipe

                        child gets input from the previous pipe and outputs to the newer pipe

                        child closes unused pipe ends

            if this is the nth pipe

                        close the output of the oldest pipe

                        have parent create another pipe

                        child gets input from the previous pipe and outputs to the newer pipe

            I            child closes unused pipe ends

            if there are no more pipes left in the command line

                        close all pipes except the last one made

                        child gets input from the last pipe

                        child outputs to the monitor

                        parent closes all pipes

}

if backgnd flag is 0, parent will wait for the child to finish

else parent does not wait

loop until program==quit

 

Task List

Tasks that are done

 

*Get Path

*Output Prompt

*Read in command line

Parse Command line

Locate program

Spawn children

 

Setup Arguments

CD command

Input Redirection

Output Redirection

Error Redirection

Pipe Operator

*Background Operator

 

All functions are implemented as basic code

* Denote full functionality with no major bugs.

 

Tasks to be done

Debug Pipe Operator (Maybe restructure) (Waits for piped program to finish)

Restructure Argument to enable dynamic arguments

Space handleing debugging (in arguments)

Fixup CD ./ irregularity

Pointer Free crash problems


Home | About Me | Text Depository | Future Enhancements | Guest Book | Links

Copyright © 1998-2008 Michael Chungkun Chen
All Rights Reserved.