21
edits
Changes
m
===Due date===* Simple FunctionsDue date: Thursday October 15, 2009, 23:59* Complex Functions
===File Names===Save your work Each student must complete at least ?? of Simple Functions and take part in ciol.h for the header file and ciol.c for the source completion of the libraryat least ?? Complex Functions.<br/>
==Basic Console Input Output ==You are to write a program that places characters at various positions on a screen using a direct terminal library module. Your library module is named '''''io''''' and contains the following functions:==Specifications=====void io_init(void)==Function Set =
Initializes the '''io''' routines. Your application calls this function before calling any other '''io''' function and only once before calling '''io_end()'''.===void io_end(void)=Due date ==
Shuts down the '''io''' routines and ensures that the cursor is not left in the middle of the screen, which may be partly filled with characters. Any application that has called'''io_init()''' should call this function before terminating.Due date: ???
Returns Save your work in biof.h for the header file and biof.c for the number source of rows on the screenlibrary.<br/>The test main will be released as bioftest.c<br />===The functions in BIOF all share the same prefix '''int io_cols(void)''bio'=== ''''.
Returns the number of columns on the screen.===void io_clrscr(void)=Simple Functions ==
Clears the screen and leaves the cursor in the upper left-hand corner of the screen.===void io_flushbio_init(void)===
Ensures that Initializes the '''bio''' routines. Your application calls this function before calling any output sent to the screen other '''bio''' function and this function is displayed on the screen called only once before calling '''bio_end(that is, this function flushes the output buffer)'''.===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 === void bio_end(if any is pending to be displayedvoid), 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:===
*Shuts down the '''UP_KEYio''' - routines and ensures that the up arrow key valuecursor is not left in the middle of the screen,which may be partly filled with characters. Any application that has called'''bio_init()''' should call this function before terminating.
*'''DOWN_KEY''' - the down arrow key value,=== int bio_rows(void) ===
*'''LEFT_KEY''' - Returns the left arrow key value,number of rows on the screen.
*'''RIGHT_KEY''' - the right arrow key value,=== int bio_cols(void) ===
*'''PGUP_KEY''' - Returns the Page Up key value,number of columns on the screen.
*'''PGDN_KEY''' - the Page Down key value,=== void bio_clrscr(void) ===
*'''HOME_KEY''' Clears the screen and leaves the cursor in the upper left- hand corner of the Home key value,screen.
*'''END_KEY''' - the End key value,=== void bio_flush(void) ===
*'''ENTER_KEY''' - Ensures that any output sent to the Enter key valuescreen is displayed on the screen (that is,this function flushes the output buffer).
*'''TAB_KEY''' - the Tab key value,=== int bio_getch(void) ===
*'''BACKSPACE_KEY''' Returns the virtual key code identifying the key pressed by the user. - This function first displays all output that has been sent to the Backspace screen (if any is pending to be displayed), waits for a key to be pressed and returns an int valuethat uniquely identifies the key pressed. To accommodate platform dependency,define the following symbolic names for the <u>non-ASCII</u> keys in each platform:
*'''DEL_KEY''' You must use platform specific and <u>unique non- ASCII</u> values for the Delete key valuekeys,and then you must use these specific symbolic names in your definitions.
*'''INSERT_KEY''' - the Insert key value=== void bio_move(int r,int c) ===
*Positions the cursor at row '''F1_KEYr''' to and column '''F12_KEYc''' , where row 0 is the top row and column 0 is the leftmost column. - the If either parameter is invalid, this function has undefined results. This function key value, does not flush any output buffer.
You must use platform specific === void bio_putch(int c) === Displays the character '''c''' at the current cursor position and <u>unique non-ASCII</u> values for advances the cursor by one position to the right. If the cursor is already at the rightmost column of the keysscreen, and then you must use these specific symbolic names in your definitionsthe advance is system dependent. This function does not flush any output buffer.
Positions Displays the null-terminated string pointed to by s starting at the current cursor at row '''r''' and column '''c''', where row 0 is position. This function leaves the top row and column 0 is cursor just after the leftmost columnlast character displayed. If either parameter is invalidthe string exceeds in length the available space on the current line of output, your this function has undefined results. Your This function does not flush any output buffer.
Displays Outputs the null-terminated string pointed to by "str", on the character '''c''' screen starting at row "row" and column "col" on the current cursor position screen, upto "len" characters. As with bio_move(), 0 is the top row, and advances 0 is the cursor by one position to the rightleftmost column. If the cursor 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 already at 0 or less, then the rightmost field length is considered to be column the actual length of the screenstring (i.e. the entire string is displayed). Afterwards, the advance cursor is system dependentpositioned after the last character of the field. This (Note that on systems where output is buffered, this function does should not flush any the output buffer). The results are undefined if the specified values indicate a field that does not fit on the screen.
Displays the null-terminated string pointed to by s starting at the current cursor position. Your function leaves the cursor just after the last character displayed. If the string exceeds in length the available space on the current line of output, your function has undefined results. Your function does not flush any output buffer. ===void io_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" on the screen, upto "len" characters. As with io_move(), 0 is the top row, and 0 is the leftmost 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 and Selection Editor=====Line Editor: int io_editbio_edit(........)===
====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. : ====
→Saving Frist changes
(just a copy from last semester, Under Construction)
As your first assignment this semester, you are to write a multi-platform Set of Basic Input Output Functions (BIOF) for direct terminal library interaction and later use that library the BIOF to create a text editor. Assignment One , like the main project is done individually! Each student must complete collaboratively and hand her/his own work, no collaboration permitted for this part.==Console Input Output Library ==is divided in two parts;
==='''int io_rows(void)'''=File Names ==
* '''UP_KEY''' - the up arrow key value,* '''DOWN_KEY''' - the down arrow key value,* '''LEFT_KEY''' - the left arrow key value,* '''RIGHT_KEY''' - the right arrow key value,* '''PGUP_KEY''' - the Page Up key value,* '''PGDN_KEY''' - the Page Down key value,* '''HOME_KEY''' - the Home key value,* '''END_KEY''' - the End key value,* '''ENTER_KEY''' - the Enter key value,* '''TAB_KEY''' - the Tab key value,* '''BACKSPACE_KEY''' - the Backspace key value,*'''ESCAPE_KEY''' - the Escape key value,* '''DEL_KEY''' - the Delete key value,* '''INSERT_KEY''' - the Insert key value,* '''F1_KEY''' to '''F12_KEY''' - the function key value,
===void io_movebio_putstr(int '''r''', int '''c'''const char *s)===
===void io_putchbio_display(const char *str, int crow, int col, int len)===
==Line and Selection Editor =void io_putstr(const char *s)===
<big>int io_editbio_edit(char* '''str''', int '''row''', int '''col''', <br />
int '''fieldlen''', int '''maxdatalen''', int '''*insertmode''', int '''*offset''',<br />
int '''*curpos''', int '''IsTextEditor''')</big>
# 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_editbio_edit(), and abort editing</u>; '''"str"'''will contain orinally passed data 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_getchbio_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 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 cursor right after the last character in the string.
** 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)
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, bio_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_editbio_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_editbio_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_editbio_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.
'''''Note:'''''
If memory allocation for aborting the edit (ESCAPE KEY) fails, quit the function returning -1.
===Selection Editor===
====void io_displayflagbio_displayflag(..........)====
<big>void io_displayflagbio_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 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_flagbio_flag(..........)====
<big>int io_flagbio_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_flagbio_flag() corrects value to one. '''"format"''' holds the shape of the checkbox as io_displayflagbio_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_displayMenuItembio_displayMenuItem(..........)====
<big>void io_displayMenuItembio_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 screen with 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''' 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_menuItembio_menuItem(..........)====
<big>int io_menuItembio_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_menuItembio_menuItem() corrects value to one. '''"*format"''' holds the shape of the selection indicator as io_displayMenuItembio_displayMenuItem() function.
io_menuItem() begins the selection by displaying the menu item according to its '''“*status”'''using [[#void_io_displayMenuItemvoid 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++===
To Download Visual studio from [https://acs.senecac.on.ca/pages/download.php Seneca/ACS download page] Seneca students should first login using their Seneca account, click on MSDN and scroll down to the DVD Downloads subheading. Download the file "(Dual Layer) Visual Studio 2008 Professional Edition, MSDN Library for Visual Studio 2008 ".
<br/>
If you have other MS Visual Studio products (eg. Visual Basic) installed you may be asked to first uninstall them before installing the Visual C++ Express Edition.
====Creating a Project for console application in Visual C++ 2008====
* Press '''Ctrl+Shift+N''' or click on '''File/New/Project'''
* In Project types select '''Visual C++/Win32''' and then in Templates select '''Win32 Console Application''' (Text Mode)
** Click on '''Application Setting'''
** Check '''Empty Project''' and then click on '''Finish'''
You can now either add new files to the solution or add existing ones.
===Windows Borland C++===
Borland C++ Compiler 5.5 is a free version. You can download it from[https://acs.senecac.on.ca/pages/download.php ACS].
Then add '''X:\Borland\BCC55\Bin''' to the system path:<br />
Vista:
* Right-click on '''Computer''' and select properties.
* Click on '''Advanced System Settings''' on the left panel and the '''System properties''' will open with '''Advanced''' tag already selected
XP:
* Right-click on '''My Computer''' and select properties and the '''System properties''' will open
* Click on '''Advanced''' tag
Common:
* Click on '''Environment Variables''' Button
* In '''System Variables''' scroll down to '''path'''
* Select '''path''' and click on '''edit''' button
'''Happy Compiling!'''
===Linux Gnu C===
Many distro come with compiler pre-installed. If not, you can use the package manager tool (yum, apt-get, merger...) in your system to search for GCC, and install that package. Also, there are some useful tools that you may need, such as autoconf, make, ctag and etc.
gcc as1tester.c ciol.c -lncurses
</pre>
or
<pre>
cc as1tester.c ciol.c -lncurses
Here are [http://pastebin.ca/1603333 the key codes] for linux if you use putty with above settings
===Mac OS C++===
Mac OS, being a Unix base operating system, supports curses library. So if you follow the case study in the book (the one written for AIX)it should work on Mac too.<br />
I will leave this platform as an option. If you like to get some bonus marks, you can implement it. But not doing it will not cost you anything.
==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 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)
* 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)
* Compress '''ciol.h''' and '''ciol.c''' into ciol.zip (no other compression utilities accepted)
** Select the two files by holding the control key and and clicking on them
** Right click on '''ciol.c''' form the opened menu select '''Send to'''
* Attach '''ciol.zip''' to an email to me to: [mailto:fardad.soleimanloo@senecac.on.ca?subject=OOP344AS1 fardad.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.c V1.2] ===
[https://cs.senecac.on.ca/~fardad.soleimanloo/oop344/notes/AS1/as1tester.c as1tester.c V1.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.
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.
===Late Submission Penalty===
10% Per day (Saturday and Sunday) counted as one