GithubHelp home page GithubHelp logo

3600sh's Introduction

NOTE: All CS3600 files have been migrated to github.com/mrodrig/cs3600 after this project.

CMSH: Chadbourn Mrodrig SHell

The CMSH shell, was designed by Michael Rodrigues and Michael Chadbourne.

Design:
The shell was designed to function around the information stored in a
proprietary data structure called the 'status_s' which is described below
in the Data_Structures section. In this way multiple states could be stored
as multiple instances of the status structure, each containing a context for
the shell.

The shell then works with the status to determine what to do. Calling for
execution, IO or the parser depending on the variables saved inside the
shell's active state.

Challenges:
Some of the main challenges that were faced during this project were encountered
during the development of the read_and_parse() and the execute_cmd(status *s)
functions.  In particular, the read_and_parse() function was initially very
difficult to reason about regarding how to retrieve input (initially using
readline), and later converting to getchar(). Using readline, the parser
started to support only specific cases and ultimately was thrown away.  Upon
converting to getchar(), the implementation of the parsing functionality became
more apparent and easier to reason about.  Utilizing mode/flag variables, we
were able to stop parsing data once we received bad input and therefore
making handling errors and escape characters signficantly easier than before.
The execute_cmd(status *s) function also posed some challenges.  In particular,
setting up IO redirection was tricky at first and we were only able to
perform this in the parent process, until it was covered conceptually in
class. Overall, we were able to overcome the challenges that we faced in this
project and were able to pass all provided tests.

Features:
CMSH works as a command line shell, printing a prompt which allows
input. CMSH is able to accept any number of arguments when accepting
input and based upon those arguments can:
	
Run a program from the file's directory, as a standard or background process. 
Handle escape characters according to UNIX standards.
Redirect input, output and errors according to UNIX standards.
And can exit with the “exit” command.


Data Structures:
Argument Array – The argument array holds an array of strings, and the size
of the array. This structure has specific functions which are called to add
data to the internal representation so that memory can be allocated as it is
needed.

struct arg_array_s{
	int len; 	//The size of the array
	char **emnts;	//The array of strings
}

Argument String – Used to qualify incoming arguments. Contains a single string
and the character length of that string. This structure also has specific
functions which are called to add data to the internal representation so that
memory can be allocated as it is needed.

struct arg_string_s {
	int len;	//The length of the string
	char *str;	//The String
}

Status – The various conditions and states a shell can be in, stored together 
represent  the variables in a single occurrence of the shell.

struct status_s {
	int parse_mode;	//Is the shell parsing?
	int escape_mode;	//Is the shell reading an escape character?
	int bg_proc;		//Is this process a background process?
	int redirect_type;	//What type of file redirect is the shell reading?
	int io_redirected;	//Is the shell redirecting IO?
	int status_code;	//If there was an error, which one?
	int eof_hit;		//Has the shell reached the End of File?
	arg_array *argv;	//The Incoming arguments to the shell
	arg_string *arg_string;	//Data struct containing the current argument
	char *fds[3];		//File descriptors for IO redirection
}

Internal Testing:
In addition to testing all changes via the provided test script, our shell
was also tested in multiple ways. One of way was through starting the
shell and just trying various commands in one terminal.  In another
terminal, we ran the same input on the reference shell so as to better
understand the specific behavior that was expected of our shell.  In
addition, there were many occassions where a bug caused unexpected
behavior.  When this occurred, some additional testing was performed via
gdb to identify what was occurring and where. Upon passing all
provided tests, additional tests were added to the test script.
To further ensure that our shell was performing correctly, the program
was checked for memory leaks using 'valgrind --leak-check=yes ./3600sh'.
This identified a few issues that were promptly addressed so that the
program now has no memory leaks that valgrind can identify.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.