OOP344 Assignment One

From CDOT Wiki
Revision as of 00:05, 14 September 2009 by Fardad (talk | contribs)
Jump to: navigation, search


OOP344

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.

Console Input Output Library

Due date: October 10, 2009

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)

Initializes the io routines. Your application calls this function before calling any other io function and only once before calling io_done().

void io_done(void)

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.

int io_rows(void)

Returns the number of rows on the screen.

int io_cols(void)

Returns the number of columns on the screen.

void io_clrscr(void)

Clears the screen and leaves the cursor in the upper left-hand corner of the screen.

void io_flush(void)

Ensures that any output sent to the screen is displayed on the screen (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 (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 non-ASCII keys in each platform:

  • 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,

You must use platform specific and unique non-ASCII values for the keys, and then you must use these specific symbolic names in your definitions.

void io_move(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 column. If either parameter is invalid, your function has undefined results. Your function does not flush any output buffer.

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)

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.