Changes

Jump to: navigation, search

IOL Functions oop344 20112

12,351 bytes added, 11:19, 19 July 2011
no edit summary
{{OOP344 Index | 20112}}
 
For the assignments in OOP344 this semester, you will work collaboratively
in groups of 4 or 5 and submit your completed assignments as a group.
Finally, if the cursor is at the end of the field, instead of the cursor moving
to the right, instead, the characters are shifted to left.
 
The following table describes what each of the special
keys is required to do:
<table border="2" width="600">
<tr>
<td width="100">
<center><font color="#ff0000"><b>INS</b></font><b></b></center>
</td>
 
<td>Toggles the <b>insert</b>/<b>overstrike</b> mode. If the
mode is <b>insert</b>, the characters typed are inserted into the
string at the current cursor position. If the mode is <b>overstrike</b>,
the character typed overwrites the character at the current cursor position.
The cursor in both cases should be placed one position past the character that was
added. Examples:
 
 
<p>Suppose that the field is as follows (underlined char indicates the
cursor location):&nbsp;
</p><table border="1" cols="1" width="200">
<tr>
<td><tt><font color="#000000">This i<u>s</u> the string</font></tt></td>
</tr>
</table>
<font color="#000000">Suppose the key X is pressed.&nbsp; The following
shows what the different modes would change the field to</font>
<p><font color="#000000">&nbsp;<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Insert Mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
Overstrike Mode</tt></font>
</p><table border="1" cols="2" width="400">
<tr>
<td><tt><font color="#000000">This iX<u>s</u> the string</font></tt></td>
 
<td><tt><font color="#000000">This iX<u> </u>the string</font></tt></td>
</tr>
</table>
 
</td>
 
</tr>
 
<tr>
<td>
<center><font color="#ff0000"><b>LEFT</b></font><b></b></center>
</td>
 
<td>Moves the cursor to the left by one character if possible.</td>
</tr>
 
<tr>
<td>
<center><font color="#ff0000"><b>RIGHT</b></font><b></b></center>
 
</td>
 
<td>Moves the cursor to the right by one character if possible. Note that
the cursor cannot move more than one character past the last character
in the string. The following describes the right most possible location
for the cursor in the following field.
<table border="1" cols="1" width="200">
<tr>
<td><tt><font color="#000000">string ends here_</font></tt></td>
</tr>
</table>
</td>
</tr>
 
<tr>
<td>
<center><font color="#ff0000"><b>HOME</b></font><b></b></center>
</td>
 
<td><font color="#000000">Moves the cursor to the very beginning of the
string, scrolling the string if necessary.</font></td>
</tr>
 
<tr>
<td>
<center><font color="#ff0000"><b>END</b></font><b></b></center>
</td>
 
<td>Moves the cursor to one character past the last character in the string,
scrolling if necessary.&nbsp;
<table border="1" cols="1" width="200">
<tr>
<td><tt><font color="#000000">move it past here_</font></tt></td>
 
</tr>
 
</table>
</td>
</tr>
 
<tr>
<td>
<center><font color="#ff0000"><b>BS</b></font><b></b></center>
</td>
 
<td>Moves the entire field starting at current cursor location one character
to the left if possible. The character just to the left of the cursor is
deleted. Note the positioning of the cursor after the operation. See below for
an example.
<p><font color="#000000">Before</font>
</p><table border="1" cols="1" width="200">
<tr>
 
<td><tt><font color="#000000">The fiel<u>d</u> of text</font></tt></td>
 
</tr>
</table>
 
<p><font color="#000000">After</font>
</p><table border="1" cols="1" width="200">
<tr>
<td><tt><font color="#000000">The fie<u>d</u> of text</font></tt></td>
 
</tr>
</table>
</td>
</tr>
 
<tr>
<td>
<center><font color="#ff0000"><b>DEL</b></font><b></b></center>
</td>
 
<td>Deletes the character at the current cursor location and moves all characters
right of it one character to the left if possible. Note the positioning
of the cursor after the operation. See below for an example.
<p><font color="#000000">Before</font>
</p><table border="1" cols="1" width="200">
<tr>
<td><tt><font color="#000000">The fiel<u>d</u> of text</font></tt></td>
 
</tr>
 
</table>
 
<p><font color="#000000">After</font>
</p><table border="1" cols="1" width="200">
<tr>
<td><tt><font color="#000000">The fiel<u> </u>of text</font></tt></td>
</tr>
</table>
</td>
</tr>
</table>
 
<font color="#ff0000"><b>UNDER NO CIRCUMSTANCES DOES THE FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE OF THE FIELD</b></font><b></b>.
 
*IsTextEditor:
:* [Section #1] IsTextEditor and *offset
:*: If IsTextEditor is true, then the function is being used to edit textone line at a time. In this case, shifting a line to the left or right should not only cause the line being edited to be shifted, but also the rest of the lines in the text. To do this, iol_edit( ) should let the calling function know that a shift has occured. Since shifting essentially means modifying "*offset" when "IsTextEditor" is true, and that there are times when you find that "*offset" needs to be modified, you should terminate the function afterwards. With termination, the function should return the terminating key. Note that at the beginning of the execution of iol_edit( ), validating *offset may require the value of *offset to change. If so, make sure to correct the offset and then terminate the function before any editing happens returning the
default value of key.
* [Section #2]
:# The iol_edit( ) function always displays blanks in any the part of the field that is not occupied by the data in the string.
:# UNDER NO CIRCUMSTANCES DOES THE FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE OF THE FIELD.
*[Section #3] IsTextEditor and ESCAPE
:# When "IsTextEditor" is true and the ESCAPE KEY is pressed, the function simply terminates (returning the ESCAPE key), but the editing is NOT to be undone.
:# If the dynamic memory allocation fails, quit the function returning -1.
*[Section #4] Others
:# Any normal printable key is simply placed into the string according to the rules outlined in the discussion of the INSERT key above (The keys from the space character to the tilde character in the ASCII table are considered "printable").
:# Like most C library functions, your iol_edit( ) may assume that it is the
calling program's responsibility is to ensure that the array is large enough
to handle the specified number of characters, and that the starting screen
position provides enough room (on the screen) for the field.
 
 
Selection Editor:
===void iol_displayflag(-----)===
<big><pre>
void iol_displayflag(const char* format, int row, int col, int status)
</pre></big>
This function allows the user to display a checkbox at row and col on the screen. the checkbox will be checked or unchecked based on the value of the "status" parameter (non-zero for checked 0 for unchecked).
 
The checkbox will be always shown using 3 characters (two surrounding characters and one character in the middle as the checkmark). If the status argument is zero, then instead of the check-mark a space will be printed on the screen.
 
The 3 characters held in the "format" array: format[0] and format[2] are the surrounding characters and format[1] is the check-mark. const char* format is used to specify the character used for the checkbox, so for example if the format argument is "[X]", then an unchecked checkbox will be
<big><pre>
[ ]
</pre></big>
and a checked checkbox will be
<big><pre>
[X]
</pre></big>
 
After the checkbox is displayed, the cursor is always placed under the check-mark (in centre).
 
===int iol_flag(-----)===
<big><pre>
int iol_flag(const char* format, int row, int col, int* status, int radio)
</pre></big>
 
iol_flag( ) allows the user to make a single true/false selection. "status" points to the status of the selection and can be zero or non-zero. If "*status" is initially set to anything other than zero, iol_flag( ) corrects
the value to hold 1. "format" holds the shape of the checkbox as in the iol_displayflag() function.
 
iol_flag( ) begins the selection by displaying the checkbox according to its
"*status" (Remember that the value of "*status" is corrected before the editing
begins). Then the function waits for the user input.
 
* If the user enters any of the printable keys (' ' < key <= '~') excluding the space key, it should be ignored (no action taken). If the user enters any of the function keys, the function is terminated returning that key.
* If the user input is a SPACE:
#If the "radio" parameter is true, then the "*status" is set to one, the checkbox is displayed, and the function is terminated returning the keycode for the space character.
#If the "radio" parameter is false, then the value of "*status" is toggled (changing from 0 to 1 or 1 to 0), the checkbox is displayed, and the function terminated returning the space key.
 
===void iol_displayMenuItem(----)===
<big><pre>
void iol_displayMenuItem(const char* format, const char* menuItem, int row,
int col, int len, int status)
</pre></big>
Allows the user to display a menu-item at row and col on the screen with a width of len. The menu-item will be surrounded by either format characters (when "status" is zero) or by spaces (when "status" is non-zero).
 
The menuItem argument will be always shown surrounded by two characters.
 
* If "status" is zero, then a space, followed by the menuItem, followed by another space will be shown at row and col on the screen. If the length of the menuItem is less than (len - 2), then enough spaces will be printed to make up the difference; making the entire field (len - 2) characters.
 
For example:
<big><pre>
"Hello"
</pre></big>
with 10 as len will be displayed as:
<big><pre>
" Hello "
</pre></big>
 
* If "status" is non-zero, then format[0], followed by the menuItem, followed by format[1] will be shown at row and col on the screen.
If the length of the menuItem is less than (len - 2), then enough spaces will be printed to make up the difference; making the entire field (len - 2) characters.
 
For example:
 
<big><pre>
"[Hello]"
</pre></big>
with 10 as len and "[]" as format chars, will be printed as :
<big><pre>
"[Hello ]"
</pre></big>
After the Menu item is displayed, the cursor is always placed under the first
character of menutItem. (position row and col + 1)
 
 
===int iol_menuItem(----)===
<big><pre>
int iol_menuItem(const char* format, const char* menuItem, int row,
int col, int len, int* status)
</pre></big>
 
iol_menuItem( ) allows the user to make a single item selection. "*status" points to the status of the selection (zero or non-zero). If "*status" is initially set to anything but zero, iol_menuItem( ) corrects the value
so that it is set to one.
 
"*format" holds the shape of the selection indicator as outlined in the
iol_displayMenuItem( ) function.
 
iol_menuItem( ) begins the selection by displaying the menu item according to its
"*status" using iol_displayMenuItem( )
(Remember that the value of "*status" is corrected before the editing begins).
The function waits for the user input.
 
* If the user presses any of the printable keys (' ' < key <= '~') excluding the space key,
then no action is taken and the function waits for the user to press another key.
* If the user presses any of the non-ASCII keys, the function is terminated
returning that key.
* If the user presses the SPACE key, then the *status is set to one, the menu item
is displayed, and the function is terminated returning the ASCII value of space character.
 
Submission Instructions:
These functions are to be declared in a file named iol.h
along with the symbolic key codes mentioned above. The
functions are to be defined in a file named iol.c.
They must compile and work properly in both the MS-DOS
environment (using the Visual Studio 2010 C/C++ compiler) and the UNIX (on Matrix)
environment (using GNU C/C++ compiler). At most only
one or two lines of iol.h should need to be modified when
changing from one environment to the other.
 
Whichever terminal program (ssh only) you are using must
be capable of handling all of the keypresses properly
(note that many do not!!).
It is highly recommended that you use putty as your ssh client.
See the "PuTTY" link on my webpage, under the "resources" folder.
 
Submission Instructions:
A main( ) program will be released shortly before the due
date to test that you have written your functions correctly.
You are encouraged to write your own test code in the
meantime however. If you wait for the assignment main( ) to
be released before you start testing your code in detail,
you will likely not have enough time to finish this assignment.
 
 
Late Submission Penalty:
1 letter grade per week.
 
Due Date: Thursday June 16, 2011 @ 11:59:59 p.m.
This assignment is worth 5% of your final grade in OOP344 this semester.
GOOD LUCK!

Navigation menu