21
edits
Changes
no edit summary
[[OOP344]] - [[OOP344 Student List]] - [[OOP344 Teams]] - [[OOP344 Assignment One]] - [[OOP344 Assignment Two]] - [[OOP344 IRC Schedules 20093 |OOP344 IRC Schedules]]<br />- [[OOP344 Student Resources]]<br />
As your first assignment this semester, you are to write a multi-platform direct terminal library and later use that library to create a text editor. Assignment One is done individually! Each student must complete and hand her/his own work, no collaboration permitted for this part.
==Console Input Output Library ==
===Due date===
Due date: Thursday October 15, 2009, 23:59
===File Names===
Save your work in ciol.h for the header file and ciol.c for the source of the library.<br/>
===int io_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 io_move(int '''r''', int '''c''')===
===void io_putch(int c)===
Displays the character '''c ''' at the current cursor position and advances the cursor by one position to the right. If the cursor is already at the rightmost column of the screen, the advance is system dependent. This function does not flush any output buffer.
===void io_putstr(const char *s)===
===Line Editor: int io_edit(........)===
<big>int io_edit(char* '''str''', int '''row''', int '''col''', <br /> int '''fieldlen''', int '''maxdatalen''', int '''*insertmode''', int'''* offset''', <br /> int'''* curpos''', int '''IsTextEditor''')</big>
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 will be are: 1('''insertmode'''), 0('''curpos'''), and 0 respectively.('''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 corrections should be done to '''"*curpos" ''' and '''"*offset" ''' in case they hold invalid values before editing begins:
# Set the '''"*curpos" ''' so that cursor stands at the last position of the field if it exceeds fieldlen.# 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 Assignment One#IsTextEditor:|IsTextEditor |]] for more)# After the above, if cursor is past last character of '''“str” ''' set '''"*curpos" ''' so the cursor stands right after the last character of "str".
The cursor is never allowed to move before the start of the field, more than one position past the last character in the string, or 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 io_edit(). If ESCAPE is used, Then and abort editing is aborted - the string is left containing the </u>; '''"str"''' will contain orinally passed data originally passed to io_edit()when leaving function.
Note that the conditions of termination are changed if '''“IsTextEditor” ''' flag is true (non-zero). See '''“IsTextEditor” ''' section for detail.
The function returns an int identifying the key that was pressed to exit. (This function uses the same key codes as io_getch())
The function takes no action 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). However if curser cursor reaches the end of the field and the string is not full then after inserting the character string will be scrolled to left, positioning the curser cursor right after the last character in the string.
The function handles at least the following special keys:
* 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 ciol.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 '''IsTextEditor''' flag)
====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, io_edit should let the calling function take care of shifting instead of doing it by itself. 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 instead. With termination, the function should return the terminating key.
The only exception is when upon the beginning of the execution of io_edit, when validating '''*offset''', make sure to correct the offset before returning the default value of key.
''when '''IsTextEditor ''' is true, and Escape is hit do not abort the editing but simply terminate the function returning the Escape key.''
Any normal printable key is simply placed into the string according to the rules laid out 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".)
The io_edit() function always shows blanks in any the part of the field that is not occupied by the data in the string. <u>UNDER NO CIRCUMSTANCES DOES THE FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE OF THE FIELD</u>.
Like most C library functions, your io_edit() may assume that it is the calling program's responsibility 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.
====void io_displayflag(..........)====
<big>void io_displayflag(const char '''*format''', int '''row''', int '''col''', int '''status''');</big>
Allows the user to display a <u>checkbox </u> at '''row ''' and '''col ''' on the screen. Depending on the value of '''status'''; being zero or non-zero, the checkbox will be checked or unchecked respectively.
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 surrounding characters and format[1] is the check-mark. The '''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 place under the check-mark (in centre).
====int io_flag(..........)====
<big>int io_flag(const char '''*format''', int '''row''', int '''col''', int'''* status''', int '''radio''');</big>
io_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, io_flag() corrects value to one. '''"format" ''' holds the shape of the checkbox as io_displayflag() function.
io_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.
*If the user input is SPACE:
**If '''“radio” ''' is true, then the '''"*status "''' is set to one, checkbox is displayed and function is terminated returning space.**If '''“radio” ''' is false, then the value of '''"*status "''' is toggled between 0 and 1, the checkbox is displayed and function is exited returning space.
====void io_displayMenuItem(..........)====
<big>void io_displayMenuItem(const char '''*format''', const char '''*menuItem''', int '''row''', int '''col''', int '''len''', int '''status''');</big>
Allows the user to display a menu-item at '''row ''' and '''col ''' on the screenwith width of '''len'''. Depending on the value of '''status'''; being zero or non-zero, the menu-item will be surrounded by '''format '''characters or space respectively.
The '''menuItem ''' argument will be always shown surrounded by two characters.* <u>If status is zero</u>, then at '''row ''' and '''col ''' a <u>space </u> will be shown, then the '''menuItem and finally ''' followed by another <u>space</u>.If the length of '''menuItem''' is less than (len-2), then enough spaces will be printed up to make the length (len-2).<pre>"Hello"</pre> with 10 as len will be printed as : <pre>" Hello "</pre>
* If status is non-zero, then at row and col format[0] will be shown then the menuItem and finally format[1].If the length of menuItem is less than (len-2), then enough spaces will be printed up to make the length (len-2).<pre>"Hello"</pre> with 10 as len and <code>"[]"</code> as format chars, will be printed as : <pre>"[Hello ]"</pre>
After the Menu item is displayed, the cursor is always placed under the first character of mentItem. (position row and col+1)
====int io_menuItem(..........)====
<big>int io_menuItem(const char '''*format''', const char '''*menuItem''', int '''row''', int '''col''', int'''len''', int '''* status''');</big>
io_menuItem() allows the user to make a single item 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, io_menuItem() corrects value to one. '''"*format" ''' holds the shape of the selection indicator as io_displayMenuItem() function.
io_menuItem() begins the selection by displaying the menu item according to its '''“*status”''' using [[#void_io_displayMenuItem.28...........29|io_displayMenuItem()]]. (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.
*If the user input is SPACE, then the *status is set to one, menu item is displayed and function is terminated returning space.
==Platforms==
===Windows Visual C++===
Say the installation is done in '''X:\Borland\BCC55''' <br />
Create a file called '''bcc32.cfg''' in '''X:\BorlnadBorland\BCC55\Bin''' and add the following two lines to it:
<pre>-I"X:\Borland\Bcc55\include"
-L"X:\Borland\Bcc55\lib"</pre>
Create another file called '''ilink32.cfg''' in '''X:\BorlnadBorland\BCC55\Bin''' and add the following line to it:
<pre>-L"X:\Borland\Bcc55\lib"</pre>
Then add '''X:\BorlnadBorland\BCC55\Bin''' to the system path:<br />
Vista:
* Right-click on '''Computer''' and select properties.
* Select '''path''' and click on '''edit''' button
* Add ''';X:\Borland\Bcc55\bin''' to the end of the '''path''' value, click '''OK''' on all windows to close and you are done.
Compile your code as:
<pre>
> bcc32 as1tester.c ciol.c
</pre>
'''Happy Compiling!'''
To compile using gcc issue the following command:<br />
<pre>
gcc as1tester.c ciol.c -lncurses
</pre>
or
<pre>
cc as1tester.c ciol.c -lncurses
</pre>
'''Also make sure you use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Putty] for your telnet client and set the Temminal/keyboard / function keys to Xterm R6'''
Here are [http://pastebin.ca/1603333 the key codes] for linux if you use putty with above settings
===Mac OS C++===
==How to submit your assignment==
Close to the due date of the assignment, I will release [https://cs.senecac.on.ca/~fardad.soleimanloo/oop344/notes/AS1/as1tester.c a tester] program called '''"a1tester.c"'''. This program uses your functions and does series of tests. Each test will use your functions to produce an output or perform and an action. If all the output is produced or the action is performed as stated in the tester program, you can submit through email to be evaluated.
To submit your program after you tested it and made sure it can be submitted, you have to do the following:
* Compile your program with as1tester.c on matrix and call the executable "as1"
* Copy as1 into root of your matrix account.(home directory)* Give your root account execute access to public($chmod 711 .)* Give your assignment one executable "as1", read and execute access to public($chmod 755 as1)
* Move the code to windows and test it on borland and VCC and make sure it works correctly
* Set the platform to BCC (windows + Borland C compiler)
** In '''Send to''' menu select '''Compressed (zipped) folder'''
** This will create '''ciol.zip''' in the same directory
* Attach '''ciol.zip''' to an email to me to: [mailto:fardad.soleimanloo@senecac.on.ca?subject=OOP344AS1 fardadsfardad.soleimanloo@senecac.on.ca] '''only from your Seneca email'''
* Make sure the subject is set to '''OOP344AS1'''
=== [https://cs.senecac.on.ca/~fardad.soleimanloo/oop344/notes/AS1/as1tester.c as1tester.cV1.2] ===[https://cs.senecac.on.ca/~fardad.soleimanloo/oop344/notes/AS1/as1tester.c as1tester.cV1.2] is released Version 1.1 (removed warnings) Version 1.2 (corrected typo message in 9.3 from curpos supposed to be 6, to curpos supposed to be 5) The program tests the functions written for assignment one and makes sure they are as bug free as possible. The program may (very possibly) have bugs. If you find any, I'll appreciate if you [http://zenit.senecac.on.ca/~chris.tyler/planet/ blog] about it and also send an email to [mailto:fardad.soleimanloo@senecac.on.ca?subject=OOP344_AS1_BUG me]. (But if you find a bug, make sure it is a bug and not a problem with your assignment) To make sure you can get help if you face unsolvable problems in your assignment, I am extending the assignment [http://zenit.senecac.on.ca/wiki/index.php/OOP344_Assignment_One#Due_date due date] to Wed. Oct 14 23:59. As usual I will be in the office on Tuesday, check my [https://cs.senecac.on.ca/~fardad.soleimanloo/timetable/FardadTimeTable.html Schedule] on my [https://cs.senecac.on.ca/~fardad.soleimanloo/ Seneca Website] for office hours.