Project R0.1 20131- OOP344
OOP344 | Weekly Schedule | Student List | Teams | Project | Student Resources
Contents
Release
- 0.1
Notes
- Pull the changes of the two files bconsole.cpp and bconsole.h to version 1.02 (Feb 1, 2013) from the console directory in notes repository of your section
- Using Linux: please use putty only and set the keyboard to
- Backspace = Ctrl-?
- Home and End = Standard
- Function keys and keypad = Linux
- And then:
- Connection > Data > Terminal-type string = linux (This step must be done when first connecting through putty!)
- Or if you have already connected, type in (export TERM="linux") without brackets
- Guide for Using Borland 5.5
- Note that to change the cmd.exe window size, right click on the top bar -> Properties -> Layout Tab
Due Dates
- Tue, Feb 5th
Help
Question | Comments |
---|---|
I'm stuck on test 4.4 where toggling insert mode changes the *insertMode between 1 and 0. I tried assigning *insertMode to 0 in the else statement in the if(*insertMode){} clause. I'm not sure if I'm making some kind of rookie mistake please HELP!!!! | How I did it was if (*insertMode) != true make it true else make it false. -kpersaud this was actually very simple: http://www.noobiedev.com/oop344/oop34-r-01-insert-mode/ Spike, left a better method in the comments Haha Thanks I managed to figured it out already but all your solutions are much better than mine :) |
Hi, the cio_test.cpp is V 0.94.1 but the cio_test.o on matrix is just V 0.94. Is this normal or did I copied the wrong test file on matrix? | The correct 0.94.1 cio_test.o should be up on matrix. Try $cp ~fardad.soleimanloo/cio_test.o - phuang19 |
Does ReadOnly if statement work like ESCAPE key ? (Store the string in another variable and replace it). ? And, how do you guys initialize the global variable for CIO_TABSIZE ? Do I need to specify the link in console.h file as well? (What I did was.. unsigned int CIO_TABSIZE=4 in console.cpp).: D | unsigned int CIO_TABSIZE = 4; in console.cpp and extern unsigned int CIO_TABSIZE; in console.h ReadOnly does not work like the ESCAPE key in non text editior mode. It should prevent the user from making any modifications on str. For example: when the user presses the DEL key in Read only mode, it should not remove the character that is currently on the cursor. Instead the function should return DEL and do nothing to str. -- yhwong6 |
If IsTextEditor is true and the value of *strOffset is changed at any time, then terminate the edit function immediately and return 0; CAN SOMEONE explain what it means.. please : ( - Solved! Thank you! | It means when you move cursor to show the hidden characters or to hide shown characters(move to left or right) if IsTextEditor==True, then terminate the edit function; *strOffset is the number of characters of the left postion of string that not be displayed within the text-field. At frist, you need store the original value of *strOffset, then everytime you press key, test if *strOffset is different from the original value, if it is then exit function and return 0;--hqiao3 |
Can someone help me uderstand these two underlined requirements. Thanks a lot for your help!! -Chun Your function does not allow the cursor to move before the start of the field or past the end of the field. If the field ends at the right edge of the screen, your function does not allow the cursor to the right of that edge. |
I think this means that: if the last position of the field is at getCols(), you cannot allow the cursor position to go beyond that. Remember xMOVER? how it console.alarm()'s when you try to go past getCols()? Its basically saying that, the cursor MUST stay within the field. -fjzhou |
END - moves the cursor to the position to the right of the last character in the string, changing the offset, if necessary. If the last character is at the edge of the screen, moves the cursor to that character. | Same thing as the previous question? *curPos = getCols() ? -fjzhou Thank you, fjzhou. I wonder why I didn't use any code from XMOVER. If you are right, then we have to keep tracking the cursor position on the screen by using getPos() function and comparing with the getCols()? However, I don't think that would be a problem since we keep adjusting the strOffset if the curPosition is at the end of the field. Then the last character of the string will not be at the edge of the screen and the cursor will be. So why would we put the cursor on the last character of the string? -Chun |
Can someone tell why "TAB" key does't work on the matrix using PUTTY. I have set the keybord already........hqiao3 | |
Im having problems with the initial corrections with the offset and curpos. test 4.1 - when i have to correct curpos 40 to 19, program crashes. I know it has to do with the creating a local variable instead of pointing to external. here is my code that crashes the program: http://www.noobiedev.com/oop344/oop344-release-0-1-bug/ |
Create two local variables to store *strOffset & *curPosition,the purpose of doing this is: 1. if IsTextEditor is true, test if *strOffset is changed, then teminate the program;(to do this, test everytime you press key that means test it in the loop); okay, a local variable for the offset that holds zero simply means creating a local variable int a = 0; to be pointed instead of an external variable. means curPosition = &a; (do this only when curPosition==0)
Thanks for the input. Turns out my problem had nothing to do with this. it was due to: delete [] variable being in the wrong place I saw your code, I think there might be not correct in line 9. 'maxStrLength' is not Length of *Str (len of "abcd" is 4, but the max size of str may be 10. when display the *str, the cursor will stay on the wrong position. --hqiao3 Thank you for the observation. The code was very ugly, I have rewrote it to be more efficient and neat. -fjzhou |
"git push origin master" command error message-- "Warning: Permanently added 'githup.com,192.168.400.2' (RSA) to the list of known hosts." I can't push anything to my remote githup repository. Any one any help? Thanks in advance! Gary | |
My HOME and END keys don't work on putty cio_test.o, but they all work well on visual studio when I run consoleTester.cpp. I have no idea about why they don't work on putty. When I hit HOME or END, there is nothing changed. Please help me :( ....Ran | Have you setup PUTTY's keybord before you logon matrxi using putty? if not, please see 'Notes' item aboved in this page.--hqiao3 Thank you. That's the problem. --Ran |
I need clarification as to what the backspace key should do given the *curPosition = 0 and the *strOffset != 0. Should the backspace key continue to delete characters by decreasing the offset, or should the backspace key simply sound the alarm()? I have posted the code on my blog in case my explanation sucks. http://csho3.wordpress.com/2013/02/04/r-01-backspace-key/ -- csho3 | If *cuPosition = 0 and *strOffset > 0 , that means there are still things that can be deleted, However, it doesn't make sense to delete stuff you cant see. So the logic is: Shifting the offset to the field and then working from there.
How much *strOffset to adjust?, I'll let you think about that. (if stroffset > field length?, stroffset < fieldlength?) - fjzhou |
Friends; on 4.28 in cio_test.cpp if i was pressing escape without following the instructions then I passed it but doing instructions it fails ...do anybody knows..(Pankaj Sama) |
Help Needed
I am getting errors when I am compiling code. Error is because of "strlen". but when I include the <cstring> library then "strlen" error is resolved but others are occuring. what should I do. Please help me...(Pankaj Sama)
Blog Posts
Title | Author | Comments |
---|---|---|
OOP344 Project - Release 0.1 - Sleep is key! | fjzhou | |
OOP344-Project R0.1--Insert a char into *str --- simple method | *insertMode==True |
Learning Outcome
Upon successful completion of this first assignment, you will have demonstrated the abilities to design and code
- functions that use the basic console input and output library
- a line editor
- use of extern
- operator overload
- use of namespaces
Console Line Editing Facility
As your first assignment, you are to upgrade the basic console input output class (BConsole) to include line-display and line-editing facilities and use of "<<" and ">>" operators for character I/O and string output.
Specifications
Your submission consists of a class called Console that is to be inherited from BConsole in a namespace called cio. Your application module is fully portable across Borland C++5.5 on windows, Linux GNU C++, Viusual C++ on Windows and Mac C++ platforms which accepts console input, and provides console output through the set of facilities available in your Console module.
The name of the library object to be created is console. The header file for the original version of this module is console.h and the implementation file for the original version is console.cpp. All of the identifiers for the library module and all upgrades to the module are defined in the cio namespace (short for console input output).
Your upgrade in this assignment consists of creating a class called Console, inherited from BConsole, implemented in two files; console.h and console.cpp:
In addition to all public methods of BConsole, Console must have the following two public methods and overload "<<" and ">>" operators.
external links
- instantiate Console, in an object called "console" in cio namespace and create an external linkage to in console.h
- create a global integer variable in console.cpp called CIO_TABSIZE and initialize it to 4
unsigned int CIO_TABSIZE = 4;
then create an external link in console.h to make it available in all cio files. Use this variable when you need the tab-size.
display() method
void display(const char* str, int row, int col, int fieldLen=0);
This method outputs the C-style, null-terminated string pointed to by str starting at row row and column col of the screen in a field of fieldLen characters. Row value 0 refers to the top row, and column value 0 refers to the left-most column.
If the string is longer than fieldLen, your function displays the first fieldLen characters. If the string is shorter than fieldLen, your function displays the entire string , followed by enough trailing spaces to fill out the field completely.
If fieldLen is 0, your function displays the entire string with no trailing spaces.
Your function positions the cursor after the last character displayed. Your function does not flush the output buffer. The results are undefined if the starting position of the string is not within the dimensions of the screen.
edit() method
int edit(char *str, int row, int col, int fieldLength, int maxStrLength, bool* insertMode, int* strOffset, int* curPosition, bool IsTextEditor = false, bool ReadOnly = false);
This method is to be written in two steps.
Step one
Ignore the last two arguments of the edit method (IsTextEditor and ReadOnly) and write the method as follows:
This method edits the C-style, null-terminated string pointed by str. The parameter row holds the row (0 is the top row) of the string on the screen. The parameter col holds the starting column (0 is the left-most column) on the screen. The parameter fieldLength holds the length of the editable field. The string may be larger than the field itself, in which case part of the string is hidden from view. The parameter maxStrLength holds the maximum length of the string, excluding the null byte. The parameter insertMode points to a bool variable that holds the current insert mode of the string. The parameter insertMode receives the address of a variable that stores the current editing mode - insert or overwrite. The parameter strOffset points to an int variable that holds the initial offset of the string within the field; that is, the index of the character in the string that initially occupies the first character position in the field. The parameter curPosition points to an int variable that holds the initial cursor position within the field; that is, the index of the character in the field at which the cursor is initially placed.
- Initial Corrections
- If the initial offset is beyond the end of the string, your function resets the offset to the length of the string; that is, to the index of the character immediately beyond the end of the string. If no offset variable is pointed to; that is, if the address of the variable is NULL, your function sets the offset to the index of the first character in the string; that is, to 0. (to do this have a local variable for the offset that holds zero to be pointed instead of an external variable)
- If the initial cursor position is beyond the end of the field, your function resets the position to the last character in the field. If the position is beyond the end of the string, your function resets the position to that immediately beyond the end of the string. If no cursor position variable is pointed to; that is, if the address of the variable is NULL, your function sets the cursor position to the first position in the field; that is, to position 0.(like the offset, to do this have a local variable for the cursor position that holds zero to be pointed instead of an external variable)
Your function does not allow the cursor to move before the start of the field or past the end of the field. If the field ends at the right edge of the screen, your function does not allow the cursor to the right of that edge.
Your function uses the symbolic names for non-ASCII and special keys defined in the keys.h header file. These names are the same symbolic names as those used in the original library module.
The user terminates editing by pressing ENTER, TAB, ESCAPE, UP, DOWN, PGUP, PGDN or any of the function keys F(1) through F(12) inclusive. If the user presses ESCAPE, your function aborts editing, replaces the contents of the string with the original contents upon entry into your function, and leaves the offset and cursor position values unaltered. In order to be able to revert to the original string, your function needs to allocate memory at run time.
At termination, your function passes back through the same int variables the current values of the offset and the cursor position, unless no variables were pointed to upon entry into your function; that is, unless the value of either address was NULL.
Your function returns an int identifying the key that the user pressed to exit the function.
Your function takes no action (other than perhaps beeping) 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).
Your function handles the non-ASCII keys as follows
- LEFT - moves the cursor left one character, if possible, changing the offset, if necessary.
- RIGHT - moves the cursor right one character, if possible, changing the offset, if necessary.
- HOME - moves the cursor to the beginning of the string, changing the offset, if necessary.
- END - moves the cursor to the position to the right of the last character in the string, changing the offset, if necessary. If the last character is at the edge of the screen, moves the cursor to that character.
- INSERT - toggles Insert/Overstrike mode. In Insert mode, your function inserts a printable character into the string at the current cursor position, moves the remainder of the string to the right to make room for the inserted character, and positions the cursor just to the right of the inserted character. The printable characters are the characters from space (' ') to tilde ('~') inclusive in the ASCII table. In Overstrike mode, your function overwrites the character (if any) at the current cursor position with a printable character and advances the cursor just to the right of the new character. If the cursor is past the end of the string, your function appends a printable character to the string as long as the string isn't full, regardless of the mode.
- DEL - discards the character at the current cursor position and moves all characters to the right of the cursor position one position to the left.
- BACKSPACE - discards the character to the left of the current cursor position, if possible, moves the characters at and to the right of the cursor position one position to the left, if possible, and positions the cursor one character to the left, if possible.
edit() always displays blanks in any part of the field that is not occupied by the string. UNDER NO CIRCUMSTANCES DOES YOUR FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE THE FIELD. For example, your function does not display status information (such as "INS" or "OVR") elsewhere on the screen, since such displays limit the programmer's ability to design their own screen layouts.
You may assume that it is the calling program's responsibility to ensure that the string array is large enough to handle maxStrLength characters and that the starting screen position provides enough room (on the screen) for the field, etc.
Edit Method | Interface |
---|---|
Step two
First run your program with cio_test.cpp and make sure it passes all the tests up to and including "4.16". If all tests are passed continue with step two:
IsTextEditor
If IsTextEditor is true and the value of *strOffset is changed at any time, then terminate the edit function immediately and return 0;
TAB key
If IsTextEditor is true and TAB key is hit, then instead of terminating the function, CIO_TABSIZE spaces are inserted into str. CIO_TABSIZE is to be global variable (unsigned integer initially set to be 4) to hold the number of spaces to be inserted when tab is hit.
ReadOnly
If ReadOnly is true, then edit function works exactly like before, except that any modification to the data (the content of the str string) will be ignored.
Overload "<<" and ">>" operators
operator>>
Console& operator>>(Console& cn, int& ch);
Get a key from keyboard using cn and store it in ch;
operator<<
Console& operator<<(Console& cn, char ch);
Print the character ch on the screen, where the cursor is located, using cn and return the cn reference;
Console& operator<<(Console& cn, const char* str);
print the string str on the screen where the cursor is using cn and return the cn reference
Submission
Common Submission mistakes
- Submitting the assignment with old version of cio_text.o
- Make sure you copy the latest version (currently 0.94.1) from my account : $cp ~fardad.soleimanloo/cio_test.o
- Using tab character
- As mentioned in class using tab character in your text editor makes the indentation of your code different in different editors, please make sure before submission you go to the settings of your development environment and make sure it uses spaces instead of tab character.
Tester Demo
To see how tester runs, you can run on Matrix (only use putty with the setting stated at Notes) run:
$ ~fardad.soleimanloo/cio_test
How to Compile
Compile and test your code with the test-main, in the following command-line environments and visual studio.
Local PC: Borland 5.5
bcc32 bconsole.cpp console.cpp cio_test.cpp
Local Mac: (use -lcurses to link curses library)
c++ bconsole.cpp console.cpp cio_test.cpp -lcurses -Wno-write-strings
matrix: GNU (use -lncurses to link ncurses library)
g++ bconsole.cpp console.cpp cio_test.cpp -lncurses -Wno-write-strings
Local PC: Visual Studio.net
How to submit
For submission purposes, your solution must compile, link, and run without errors in each environment.
First pull the changes of the two files bconsole.cpp and bconsole.h to version 1.02 (Feb 1, 2013) from the console directory in notes repository of your section.
Test your program with cio_test.cpp from the same console directory stated above. When your program passed all the tests; on matrix, create a directory and copy all the source files (console.cpp, console.h, bconsole.cpp, bconsole.h) into it. Then copy cio_test.o ''V 0.94.1 from "~fardad.soleimanloo" and then compile your code with your professors version of cio_test (i.e cio_test.o) and run it. If all the tests are passed successfully, an email will be sent to your professor automatically with your source code (console.h and console.cpp) attached to it.
to copy the cio_test.o do the following.
From the directory containing all source files:
$cp ~fardad.soleimanloo/cio_test.o .
to compile the code:
$g++ bconsole.cpp console.cpp cio_test.o -lncurses
This should not generate any warnings.
To run the test (with automatic submission)
$ a.out your_student_number Your Full Name as on Student Card <ENTER>
Example:
$ a.out 012345678 Home Jay Simpson <ENTER>