Changes

Jump to: navigation, search

Oop344 20102 - iof functions

769 bytes added, 07:57, 17 September 2010
no edit summary
{{OOP344 Index20102}}
As your first assignment this semester, you are to write a multi-platform Set of Basic Input Output Functions (IOF) for direct terminal interaction and later use the IOF to create a text editor. Assignment One, like the main project is done collaboratively and is divided in two parts:
Note: There is a non-negotiable rule of a two character tab space, and NO use of the tab character (\t). You can find how to set these settings in the link below.
</span> <br />
[http://zenit.senecac.on.ca/wiki/index.php/How_to_set_up_tab_spaces How to set up tab spaces]<br />[http://zenit.senecac.on.ca/wiki/index.php/Changing_bg_color_brace_matching How to change the background color "Brace Matching" ]
<br /><br />
** Create directories under branches named as your learn id.
** Branch trunk into your branches/learnID directory and start working.
* Complex io functions: Jun 13th 23rd @ 23:59== Tester Program and demo ==<!--<big> ** iofmain.c V0R0.8 9 is released svn://zenit.senecac.on.ca/oop344/trunk/AS1/iofmain.c** You can run the demo (compiled version) of iof functions tester on matrix by running:</big><pre>~fardad.soleimanloo/iof--</pre></big>
== File Names ==
=== void iof_display(const char* str, int row, int col, int len) ===
Outputs the null-terminated string pointed to by "str" on the screen starting at row "row" and column "col", up to "len" characters. As with iof_moveiof_movecur(), 0 is the top row and 0 is the left-most column. If the string is longer than "len", then only "len" characters are displayed, but if it is shorter than "len", then the entire string is displayed left-justified in the field. However, if "len" is 0 or less, then the field length is considered to be the actual length of the string (i.e. the entire string is displayed). Afterwards, the cursor is positioned after the last character of the field. (Note that on systems where output is buffered, this function should not flush the output buffer). The results are undefined if the specified values indicate a field that does not fit on the screen.
=== Line Editor: int iof_edit(........) ===
NOTE: The following corrections should be done to '''"*curpos"''' and '''"*offset"''' in case they hold invalid values before editing begins:
# If '''"*curpos"''' exceeds is greater than or equal to the value of fieldlen, correct the '''"*curpos"''' so that cursor stands at the last position inside the field.# If '''"*offset"''' is greater than the length of the string, set the '''"*offset"''' so the “last character of str” is hidden right before the first space in the field. (See'''“[[OOP344 BIO 20101Oop344 20102 - iof functions#IsTextEditor:|IsTextEditorSection #1]] ”''' for more)
# After the above, if cursor is past the last character of '''“str”''', set '''"*curpos"''' so the cursor stands right after the last character of "str".
 The cursor is never allowed tobe: 1- move  # before the start of the field, 2- be .# more than one position past the last character in the string, 3- be .# after the end of the field.
<u>Editing is terminated by pressing ENTER, TAB, UP, DOWN, PGUP, PGDN or any of the function keys (F1 to F12)</u>. Pressing<u>ESCAPE will terminate the iof_edit() and abort editing</u>: '''"str"'''will contain originally passed data when leaving function.
Note that the conditions of termination are changed if the '''“IsTextEditor”''' flag is true (non-zero). See '''“IsTextEditor”“[[Oop344 20102 - iof functions#IsTextEditor:|IsTextEditor]]”'''section for detail.
If '''"ReadOnly"''' has a true value (non-zero), then any attempt to change the content of '''"str"''' should end the function and return the key. Note that all other keys should work (Function and Non-ASCII keys). This makes the '''iof_edit()''' funciton "read only", but the user still can scroll the text to left or right and etc....
The function handles at least the following special keys:
* '''LEFT ''' - move cursor left one character. If cursor is at the beginning of the field and there is hidden data before the cursor, then shift string to right instead.* '''RIGHT ''' - move cursor right one character. If cursor is at the end of the field but not at the end of the string, then scroll one to left.* '''HOME ''' – move cursor to the beginning of the string. Scroll all the way to right if necessary. (i.e. if there is hidden data at the beginning)* '''END ''' - go to the end of the data in the string, i.e. just past the last character in the string. Scroll all the way to left if necessary.* '''DEL ''' – eat the current character above the cursor and move all subsequent characters one position to the left.* '''BACKSPACE ''' - move the rest of the field (including the cursor) one position to the left, eating the previous character.* '''TAB''':
** if '''IsTextEditor''' is false, TAB will simply terminate the function like a Function key
** if '''IsTextEditor''' is true, TAB will insert '''CIO_TAB_SIZE ''' number of spaces into the string.'''CIO_TAB_SIZE''' should be a defined "tab size" value in cioliof.h. If '''CIO_TAB_SIZE''' spaces cannot be inserted into the string for any reason then the inputted tab should be ignored. (See below for more about '''“[[Oop344 20102 - iof functions#IsTextEditor:|IsTextEditorSection #2]]”''' flagfor more)* '''ESCAPE ''' - Terminates iof_edit() and aborts editing: '''"str"''' will contain originally passed data when leaving function. (See'''“[[OOP344 BIO 20101Oop344 20102 - iof functions#IsTextEditor:|IsTextEditorSection #3]] ”''' for exception)* '''INSERT ''' - toggle Insert/Overstrike mode**<br /u>In Insert mode</u>, printable characters are inserted into the string, moving the remainder of the string to the right to make room. **<u>In Overstrike mode</u>, printable characters overwrite existing characters (if any). Note that if you are past the end of the string, printable characters are appended to the string (as long as the string isn't full) regardless of the mode. **Also note that, regardless of the mode, the cursor advances as printable characters are typed into the string. **Finally, if the cursor is at the end of the field, instead of moving to right, the characters are shifted to left.
==== <big>IsTextEditor: </big> ====
'''[Section #1] IsTextEditor and *offset'''<br/>
If IsTextEditor is true, then it means that the function is being used to edit text by editing one line of text at a time. In this case, shifting a line to the left or right should not only cause the editing line to be shifted, but also the rest of the lines in the text. To do this, iof_edit() should let the calling function know that a shift has happened. 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 iof_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.
''when '''IsTextEditor[Section #2]''' <br/># The iof_edit() function always shows blanks in any the part of the field that is true, and Escape is hit do not abort occupied by the editing but simply terminate data in the function returning the Escape keystring.#<u>UNDER NO CIRCUMSTANCES DOES THE FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE OF THE FIELD</u>.''
Any normal printable key '''[Section #3] IsTextEditor and ESCAPE KEY'''<br/># When '"IsTextEditor"' is true and ESCAPE KEY is hit, do not abort the editing, and simply placed into terminate the string according to function returning the rules laid out in ESCAPE KEY.# If memory allocation for aborting the discussion of the INSERT key above. edit (The keys from the space character to the tilde character in ESCAPE KEY) fails, quit the ASCII table are considered "printable"function returning -1.)
The iof_edit() function always shows blanks '''[Section #4] Others'''<br/># Any normal printable key is simply placed into the string according to the rules laid out in any the part discussion of the field that is not occupied by INSERT key above.(The keys from the space character to the data tilde character in the stringASCII table are considered "printable".<u>UNDER NO CIRCUMSTANCES DOES THE FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE OF THE FIELD</u>.)# Like most C library functions, your iof_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, etc. '''''Note:''''' If memory allocation for aborting the edit (ESCAPE KEY) fails, quit the function returning -1.
=== Selection Editor ===
B- [iof_displayMenuItem()]
[iof_MenuItemiof_menuItem()]
[iof_edit(): Right Key]
[Test VCC platfrom]
=== Teams with 4 members ===
<big><pre>
A- [displayflagiof_displayflag()] [flagiof_flag()] [editiof_edit(): Left key] [editiof_edit(): Home and End Key]
[Test BCC platform]
B- [displayMenuItemiof_displayMenuItem()] [MenuItemiof_menuItem()] [editiof_edit(): Right Key] [editiof_edit(): Insert Key] [editiof_edit(): Tab Key]
[Test VCC platfrom]
C- [editiof_edit(): Corrections before editing] [editiof_edit(): Backspace Key] [editiof_edit(): Enter and All function key] [editiof_edit(): data entry, overstrike mode]
[Test Linux platform]
D- [editiof_edit(): Escape key, including Undo (memory allocation and release in C (malloc() and free())] [editiof_edit(): Delete Key] [editiof_edit(): data entry, insert mode]
[Test Mac platform]
[Overall review before final release]

Navigation menu