CS 241

Vector

Groundwork For Text Editor and Shell

You are an intern for Macrohard and your team has decided to have you write a text editor and shell (more details for each when the time comes), which everyone on the team will use. These projects will take you several weeks and your mentor has decided on the following timetable:

  • Week A: Implement a Vector and Document/Log
  • Week B: Implement a Text Editor
  • Week C: Implement a Shell

The Text Editor will be a 1 line text editor that will accept commands from stdin. Your mentor has decided to abstract away documents for this text editor.

The Shell is a terminal. Like all good terminals; your shell will need to remember what commands its user has given it. Your mentor has decided to abstract all of this away as a log.

Now your mentor has realized that a log and document are not that different in the sense they are both just an array of strings. So to implement the log and document your mentor has decided that you will create a “vector” to store strings.

Vector

A vector is an array that grows and shrinks as a user adds and removes items from it. However your vector will need to be rich with enough features so one can easily create a log or document from it. Your implementation of a vector should go in vector.c, which is the only file that will be sent to your team lead for review. As an intern looking to become a fulltime employee, you should create testcases in vector_test.c to show that you are a responsible programmer. Your mentor has left notes in vector.h on how you should implement this vector.

Document and Log

Your document and log are really similar, so your mentor has negotiated with the team lead for you to only implement one of them. The mentor has chosen for you to implement the document. Both the document and log will use your vector to do all the heavy lifting. Still there are some functions that your document needs to have that your vector shouldn’t. Your mentor has provided all the trivial functions for you that assume a correctly implemented vector. The only file that will be reviewed by your team lead is document.c. Since Macrohard frowns on interns who rely on QAs to catch their mistakes you are encouraged to write your own testcases in document_test.c. Your mentor has left some notes in document.h.

Undefined Behavior

Undefined Behavior is simply a scenario or edge case for which there is no documentation describing how the code should react. For example try finding in the man pages what happens when you feed NULL in strcmp(). Your mentor will not answer questions like “What if my user wants an element past the end of the vector?”, because that is undefined behavior. So for the entirety of this MP you should use assert() statements to check that your user is passing your function valid input before operating on the input. For example if you were implementing strcmp(const char *s1, const char *s2) then your code should look like the following:

#include <assert.h>
strcmp(const char *s1, const char *s2) {
    assert(s1 != NULL && s2 != NULL);
    // Compare the two strings
    .
    .
    .
    return blah;
}

Compile and Run

To compile the release version of the code run:

make clean
make

To compile your code in debug mode, run make debug instead of make

To test vector:

./vector_test

or

./vector_test-debug

To test document:

./document_test

or

./document_test-debug

Grading, Submission, and Other Details

Please fully read details on Academic Honesty. These are shared between all MPs in CS 241.

We will be using Subversion as our hand-in system this semester. Our grading system will checkout your most recent (pre-deadline) commit for grading. Therefore, to hand in your code, all you have to do is commit it to your Subversion repository.

To check out the provided code for vector from the class repository, go to your cs241 directory (the one you checked out for “know your tools”) and run:

svn up

If you run ls you will now see a vector folder, where you can find this assignment! To commit your changes (send them to us) type:

svn ci -m "mp1 submission"

Your repository directory can be viewed from a web browser from the following URL: https://subversion.ews.illinois.edu/svn/sp16-cs241/NETID/vector where NETID is your University NetID. It is important to check that the files you expect to be graded are present and up to date in your svn copy.