Assignment 1
Version 3.0 (Winter 2014)


Line Editing Facility

A set of assignments has been developed for you to upgrade the original version of the library module provided in this course.  You are given the tasks of tackling complex programming problems and meeting demanding deadlines. In this first assignment, you and your team member are asked to upgrade the console input output library by including line-display and line-editing facilities. 


Learning Outcome

Upon successful completion of this first assignment, you will have demonstrated the abilities to design, code, test, and debug

  • functions that use the console input and output library,
  • a line editor,
  • an application that uses your line editor.
In addition, you will have put pair programming as well as the process of incremental testing and coding into practice. Thus you are expected to document weekly BUG REPORTS and testing code on the course wiki.

Specifications

Your submission consists of two software artifacts, namely your own upgrade to the library module and an application module that uses your upgraded library module. Your application module accepts console input and provides console output through the set of facilities available in your upgraded library module. It must be fully portable across different platforms.

The name of libary object in the original library module is console.  The header file for the original version of this module is console.h and the implementation file for the original version is console.cpp.  All of the identifiers for the library module and all upgrades to the module are defined in the cio namespace (short for console input output).

Your upgrade in this assignment consists of two files:

  • consoleplus.h - holds the prototypes for your line-display and line-edit global functions
  • consolelineedit.cpp - holds the definitions of your line-display and line-edit global functions

The two functions are:

  • void display(const char *str, int row, int col, int fieldLen)
    This function displays the C-style, null-terminated string pointed to by str, starting at row row and column col of the console screen in a field of fieldLen characters. 

    Row value 0 refers to the top row, and column value 0 refers to the left-most column.  If the string is longer than fieldLen, your function displays the first fieldLen characters.  If the string is shorter than fieldLen, your function displays the portion of the entire string that fits on the screen, followed by enough trailing spaces to fill out the field completely.  If fieldLen is 0 or less, your function displays the portion of the entire string that fits on the screen with no trailing spaces. 

    Your function positions the cursor after the last character displayed, but excluding any added trailing spaces, if the last character is not in the last column of the screen; otherwise, your function positions the cursor under the last character on the screen.  Your function does not flush the output buffer.  The results are undefined if the starting position of the string is not within the dimensions of the screen.

  • int edit(char *str, int row, int col, int fieldLength, int maxStrLength, bool* insertMode, int* strOffset, int* curPosition)

    This function edits the C-style, null-terminated string pointed to by str.  The parameter row holds the row
    (0 is the top row) of the string on the console screen.  The parameter col holds the starting column (0 is the left-most column) on the screen.  The parameter fieldLength holds the length of the editable field.  The string may be larger than the field itself, in which case part of the string is hidden from view.  The parameter maxStrLength holds the maximum length of the string, excluding the null byte.  The parameter insertMode points to a bool variable that holds the current insert mode of the string.  The parameter insertMode receives the address of a variable that stores the current editing mode - insert or overwrite.  The parameter strOffset points to an int variable that holds the initial offset of the string within the field; that is, the index of the character in the string that initially occupies the first character position in the field.  The parameter curPosition points to an int variable that holds the initial cursor position within the field; that is, the index of the character in the field at which the cursor is initially placed. 

    If the initial offset is beyond the end of the string, your function resets the offset to the length of the string; that is, to the index of the character immediately beyond the end of the string.  If no offset variable is pointed to; that is, if the address of the variable is NULL, your function sets the offset to the index of the first character in the string; that is, to 0.

    If the initial cursor position is beyond the end of the field, your function resets the position to the last character in the field.  If the position is beyond the end of the string, your function resets the position to that immediately beyond the end of the string.  If no cursor position variable is pointed to; that is, if the address of the variable is NULL, your function sets the cursor position to the first position in the field; that is, to position 0.

    The function does not allow the cursor to move before the start of the field or past the end of the field.  If the field ends at the right edge of the screen, your function does not allow the cursor to the right of that edge.

    The function uses the symbolic names for non-ASCII and special keys defined in the keys.h header file.  These names are the same symbolic names as those used in the original library module.

    The user terminates editing by pressing ENTER, TAB, ESCAPE, UP, DOWN, PGUP, PGDN or any of the Function keys F(1) through F(12) inclusive.  If the user presses ESCAPE, the function aborts editing, replaces the contents of the string with the original contents upon entry into your function, and leaves the offset and cursor position values unaltered.  In order to be able to revert to the original string, the function needs to allocate memory at run time. 

    At termination, the function passes back through the same int variables the current values of the offset and the cursor position, unless no variables were pointed to upon entry into the function; that is, unless the value of either address was NULL.

    The function returns an int identifying the key that the user pressed to exit the function. 

    The function takes no action (other than perhaps beeping) if the user tries to enter too many characters (if, for example, the string is full in insert mode, or the cursor is positioned after the last character of a full string in overstrike mode).

    The function handles the non-ASCII keys as follows

    • LEFT - moves the cursor left one character, if possible, changing the offset, if necessary.
    • RIGHT - moves the cursor right one character, if possible, changing the offset, if necessary.
    • HOME - moves the cursor to the beginning of the string, changing the offset, if necessary.
    • END - moves the cursor to the position to the right of the last character in the string, changing the offset, if necessary.  If the last character is at the edge of the screen, moves the cursor to that character.
    • INSERT - toggles Insert/Overstrike mode.  In Insert mode, the function inserts a printable character into the string at the current cursor position, moves the remainder of the string to the right to make room for the inserted character, and positions the cursor just to the right of the inserted character.  The printable characters are the characters from space (' ') to tilde ('~') inclusive in the ASCII table.  In Overstrike mode, the function overwrites the character (if any) at the current cursor position with a printable character and advances the cursor just to the right of the new character.  If the cursor is past the end of the string, the function appends a printable character to the string as long as the string isn't full, regardless of the mode. 
    • DEL - discards the character at the current cursor position and moves all characters to the right of the cursor position one position to the left.
    • BACKSPACE - discards the character to the left of the current cursor position, if possible, moves the characters at and to the right of the cursor position one position to the left, if possible, and positions the cursor one character to the left, if possible.

    The edit() function always displays blanks in any part of the field that is not occupied by the string.  UNDER NO CIRCUMSTANCES DOES THE FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE THE FIELD.  For example, the function does not display status information (such as "INS" or "OVR") elsewhere on the screen, since such displays limit the programmer's ability to design their own screen layouts.

    You may assume that it is the calling program's responsibility to ensure that the string array is large enough to handle maxStrLength characters and that the starting screen position provides enough room (on the screen) for the field, etc.

     

A copy of a test program that uses your functions is here (a1test.cpp).  The result of a sample run of this program using your functions should look something like:

 01234567890123456789012345678901234567890123456789012345678901234567890123456789
 1Perform the following instructions in turn
 2
 3  Press Right Arrow Twice, Down Arrow Twice
 4  Using Arrow and ASCII keys, change "jkl" to "JKL"
 5  Press Home, A, End, Left Arrow, Z, Home, Enter
 6  Press Home, a, End, Left Arrow, z, Home, Escape
 7  Press C, End, Backspace 4 times, 1, 2, Home, Enter
 8  Press End, Home, Right Arrow 7 times, 1, 2, Enter
 9  Press Delete Twice, Insert, 7, 8, 9, Enter
 0
 1
 2    abcdefghijklmnopqrstuvwxyz
 3
 4    AbcdefghiJKLmnopqrstuvwxyZ                                       AbCdefg12J
 5    abcdefghiJKLmnopqrstuvwxyZ
 6    AbCdefghiJKLmnopqrstuv12
 7    AbCdef7892JKLmnopqrstuv12
 8
 9  If no errors, prepare screen shot (include top row of numbers) ...
 0  Press Enter key to exit!
 1
 2
 3
 4

Submission

Compile and test your upgrade with test main a1test.cpp in the following two command-line environments: 

  • Local PC: Microsoft .net
  • matrix: GNU

For submission purposes, your solution must compile, link, and run without errors in each environment.  Capture a screen shot of the final display of your test run in each environment. 

Prepare a matrix typescript named a1.txt that includes

  • a listing of your consoleplus.h file
  • a listing of your consolelineedit.cpp file
  • a compilation and linking of console.cpp and consolelineedit.h with a1test.cpp
  • a listing of your application file
  • a compilation and linking of console.cpp and consolelineedit.h with your application file

eMail to your instructor the following and any other files specified by your instructor:

  • a1.txt
  • a screen shot of the result of a run of a1test.cpp on each of the platforms listed above
  • a screen shot of the result of a run of your application on one of the platforms listed above

Grading

If your code contains one major or more than one minor logic flaw, your instructor will ask you to fix and resubmit your code, which will attract a 50% penalty.  The late penalty is 10% per business day. Thus it is better to submit a working version late than to submit a flawed version on time.  The maximum late penalty is 50%. 

Regardless of how long it takes you to complete this assignment, you still need to submit a completed working version in order to pass this subject.







  Designed by Chris Szalwinski   Copying From This Site Last Modified: 09/14/2011 08:13  
Logo