Changes

Jump to: navigation, search

Oop344 20102 - iof functions

854 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;:
* Simple Functions
* Complex Functions
Each student must complete at least one of the Simple Functions individually and commit it to the repository and take part in the completion of at least ?? Complex Functions.
<br />
<span style="color: #FF0000; font-weight: bolder">
Note there : 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 />
* Simple io functions Jun 6th @ 23:59
** create Create directories under branches named as your learn id.** branch 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 ==
<!--
The test main is released as iofmain.c;:
<big>
svn://zenit.senecac.on.ca/oop344/trunk/iofmain.c<br />
</big>
-->
the The iofmain.c should run.
== Simple Functions ==
=== int iof_getch(void) ===
Returns the virtual key code identifying the key pressed by the user. This function first displays all output that has been sent to the screen (if any is pending to be displayed), waits for a key to be pressed and returns an int value that uniquely identifies the key pressed. To accommodate platform dependency, define the following symbolic names for the <u>non-ASCII</u>keys in each platform:
* '''UP_KEY''' - the up arrow key value,
* '''F1_KEY''' to '''F12_KEY''' - the function key value,
You must use platform -specific and <u>unique non-ASCII</u> values for the keys, and then you must use these specific symbolic names in your definitions.
=== void iof_movecur(int r, int c) ===
Positions the cursor at row '''r''' and column '''c''', where row 0 is the top row and column 0 is the leftmost left-most column. If either parameter is invalid, this function has undefined results. This function does not flush any output buffer.
=== void iof_putch(int c) ===
=== void iof_prnstr(const char* s) ===
Displays the null-terminated string pointed to by s starting at the current cursor position. This function leaves the cursor just after the last character displayed. If the string length exceeds in length the available space on the current line of output, this function has undefined results. This function does not flush any output buffer.
== Complex Functions ==
=== 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", upto up to "len" characters. As with iof_moveiof_movecur(), 0 is the top row, and 0 is the leftmost 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(........) ===
<br />
Allows the user to perform full screen editing of the null-terminated string pointed to by '''"str"'''. The parameter '''"row"''' identifies the row of the screen for the field (0 is the top row), while '''"col"''' indicates the starting column of the field (0 is the left-most column). The parameter '''"maxdatalen"''' specifies the maximum length of the string'''"str"'''. The parameter '''"fieldlen"''' specifies the length of the field in which editing is to be performed (visible area of '''“str”'''). The pointer '''"offset"''' points to an integer, holding the index of the first character of'''"str"''', shown in the field. The pointer'''"curpos"''' points to an integer holding the position of the cursor in the field (0 is the first position). '''"insertmode"''' is a pointer pointing to an integer flag, that is true (1) for insert mode being on, or false (0) for insert mode being off.<br />
''If any of '''insertmode''', '''curpos''' or '''offset''' is <u>NULL</u> then a local integer variable will be used instead. If local variables are used for any of insertmode, curpos, or offset, the default values are: 1 ('''insertmode'''), 0 ('''curpos'''), and 0 ('''offset''')''
Editing begins with the display of '''"str"''' from where '''"*offset"''' is referring to, and the cursor will be standing at the position which '''"*curpos"''' is indicating.
NOTE: Following The following corrections should be done to '''"*curpos"''' and '''"*offset"''' in case they hold invalid values before editing begins: # If '''"*curpos"''' 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 20102 - iof functions#IsTextEditor:|IsTextEditor Section #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".
# If '''"*curpos"''' exceeds 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 20101#IsTextEditor:|IsTextEditor]] 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- more than one position past the last character in the string, 3- after the end of the field.
<u>Editing is terminated by pressing ENTER, TAB, UP, DOWN, PGUP, PGDN or any # before the start of the function keys (F1 to F12)</u>field.# more than one position past the last character in the string. Pressing<u>ESCAPE will terminate # after the end of the iof_edit(), and abort editing</u>; '''"str"'''will contain orinally passed data when leaving functionfield.
Note that <u>Editing is terminated by pressing ENTER, TAB, UP, DOWN, PGUP, PGDN or any of the conditions of termination are changed if '''“IsTextEditor”''' flag is true function keys (non-zeroF1 to F12)</u>. See Pressing<u>ESCAPE will terminate the iof_edit() and abort editing</u>: '''“IsTextEditor”"str"'''section for detailwill contain originally passed data when leaving function.
Note that the conditions of termination are changed if the '''“IsTextEditor”''' flag is true (non-zero). See '''“[[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 make makes the '''iof_edit()'''funciton "read only", but the user still user can scroll the text to left or right and etc....
The function returns an int identifying the key that was pressed to exit. (This function uses the same key codes as iof_getch())
The function takes no action if the user tries to enter too many characters (if, for example, the string is in full in insert mode, or the cursor is positioned after the last character of a full string in overstrike mode). However , if the cursor reaches the end of the field and the string is not full , then after inserting , the character string will be scrolled to the left, positioning the cursor right after the last character in the string.
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 the iof_edit(), and abort 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. ==== IsTextEditor: ==== If IsTextEditor is true, then it means that the function is being used to edit a text by editing one line of the 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 '''==== <big>IsTextEditor''' is true, and Escape is hit do not abort the editing but simply terminate the function returning the Escape key.'':</big> ====
Any normal printable key '''[Section #1] IsTextEditor and *offset'''<br/>If IsTextEditor is simply placed into true, then it means that the string according function is being used to edit text by editing one line of text at a time. In this case, shifting a line to the rules laid out in left or right should not only cause the editing line to be shifted, but also the discussion rest of the INSERT key abovelines in the text. To do this, iof_edit(The keys from ) should let the space character 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 tilde character in function should return the ASCII table are considered "printable"terminating key.)
The Note that at the beginning of the execution of iof_edit() function always shows blanks in any , validating '''*offset''' may require the part value of '''*offset''' to change. If so, make sure to correct the field that is not occupied by offset and then terminate the data in function before any editing happens returning the string.<u>UNDER NO CIRCUMSTANCES DOES THE FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE OF THE FIELD</u>default value of key.
Like most C library functions, your '''[Section #2]'''<br/># The iof_edit() may assume that it is function always shows blanks in any the part of the calling program's responsibility to ensure field that the array is large enough to handle the specified number of characters, and that not occupied by the starting screen position provides enough room (on data in the screen) for the field, etcstring.#<u>UNDER NO CIRCUMSTANCES DOES THE FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE OF THE FIELD</u>.
'''''Note:[Section #3] IsTextEditor and ESCAPE KEY'''<br/># When '"IsTextEditor"'is true and ESCAPE KEY is hit, do not abort the editing, and simply terminate the function returning the ESCAPE KEY.# If memory allocation for aborting the edit (ESCAPE KEY) fails, quit the function returning -1.
If memory allocation for aborting '''[Section #4] Others'''<br/># Any normal printable key is simply placed into the string according to the rules laid out in the discussion of the edit INSERT key above.(ESCAPE KEYThe keys from the space character to the tilde character in the ASCII table are considered "printable".) fails# Like most C library functions, quit your iof_edit() may assume that it is the function returning -1calling 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.
=== Selection Editor ===
<big>int iof_flag(const char* '''format''', int '''row''', int '''col''', int* '''status''', int '''radio''');</big>
io_flagiof_flag() allows the user to make a single true/false selection. '''"status"''' points to the status of the selection, that can be zero or non-zero. If '''"*status"''' is initially set to anything but zero, iof_flag() corrects value to one.'''"format"''' holds the shape of the checkbox as iof_displayflag() function.
io_flagiof_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 input is any of the printable keys (' ' < key <= '~') excluding space, it should be ignored (no action taken). If the user input is any of the function keys, the function is terminated returning the key.
=== Teams with 5 members ===
<big><pre>
A- [displayflagiof_displayflag()], [flagiof_flag()] [editiof_edit(): LeftkeyLeft key]
[Test BCC platform]
B- [displayMenuItemiof_displayMenuItem()], [MenuItemiof_menuItem()] [editiof_edit(): RightKeyRight Key]
[Test VCC platfrom]
C- [editiof_edit(): Corrections before editing] [editiof_edit(): BackspaceKeyBackspace Key] [editiof_edit(): Enter and All function keys]
[Test Linux platform]
D- [editiof_edit(): Escape key, including Undo (memory allocation and release)] [editiof_edit(): DeleteKeyDelete Key] [editiof_edit(): data entry, insert mode]
[Test Mac platform]
E- [editiof_edit(): Home and End Key] [InsertKeyInsert Key] [TabKeyTab Key]
[data entry, overstrike mode]
[Overall review beofre before final release]
</pre></big>
=== Teams with 4 members ===
<big><pre>
A- [displayflagiof_displayflag()], [flagiof_flag()] [editiof_edit(): LeftkeyLeft key] [editiof_edit(): Home and End Key]
[Test BCC platform]
B- [displayMenuItemiof_displayMenuItem()], [MenuItemiof_menuItem()] [editiof_edit(): RightKeyRight Key] [editiof_edit(): InsertKeyInsert Key] [editiof_edit(): TabKeyTab Key]
[Test VCC platfrom]
C- [editiof_edit(): Corretions Corrections before editing] [editiof_edit(): BackspaceKeyBackspace 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(): DeleteKeyDelete Key] [editiof_edit(): data entry, insert mode]
[Test Mac platform]
[Overall review beofre before final release]
</pre></big>

Navigation menu