home *** CD-ROM | disk | FTP | other *** search
- /* RUN/C SCREEN FUNCTIONS
- for non-IBM screens with
- ANSI terminal drivers
-
- Functions: cls() (clear screen)
- locate() (move cursor or report its position)
-
-
- Note: This source code is provided by Age of Reason, Inc.
- for information only. AofR guarantees neither correctness
- nor support. Nevertheless, having disclaimed all that is
- necessary, we will be happy to provide advice and would
- appreciate any bug reports.
-
- Note: The locate() function uses 2 library functions from the
- Lattice C runtime library that may not be standard in other
- compiler runtime libraries. Their descriptions follow:
-
- int kbhit()
- returns 1 if character available
- at keyboard.
- returns 0 otherwise.
-
- char getch()
- returns the next available char from the
- keyboard with NO echo.
-
- Function Descriptions:
-
- -------------------------------------------------
- cls() clears screen
- -------------------------------------------------
- int locate(row, column, mode)
- int row, column, mode;
-
- if mode == 0: move cursor to (row, column)
- this is an absolute move
- 1 <= row <= 25
- 1 <= column <= 80
- no action if target position outside
- screen area.
- if mode == 1: change cursor by (row, column)
- this is a relative move
- -24 <= row <= 24
- -79 <= column <= 79
- no action if target position outside
- screen area.
- if mode == 2: return current cursor row
- (input row and column args irrelevant)
- if mode == 3: return current cursor column
- (input row and column args irrelevant)
-
- row and column numbering starts at 1
- namely, (1,1) is upper-left
- size of screen is governed by MAXROW and MAXCOLUMN.
- -----------------------------------------------------------
- */
-
- #include <stdio.h>
- #define MAXROW 25
- #define MAXCOLUMN 80
-
- cls()
- { printf("\033[2J"); /* Clear Screen ANSI call */
- }
-
- locate(row, column, mode)
- int row, column, mode;
- {
- switch(mode)
- { case 0: loc_amove(row, column);
- break;
- case 1: loc_dmove(row, column);
- break;
- case 2: loc_where(&row, &column);
- return(row);
- case 3: loc_where(&row, &column);
- return(column);
- }
- }
-
- loc_where(prow, pcolumn) /* returns current cursor position */
- int *prow, *pcolumn;
- {
- char work[20], *p, c;
-
- printf("\033[6n"); /* Report Cursor Position ANSI call */
- while (getch() != '\033')
- ;
- for (p = work; kbhit() ; )
- *p++ = getch();
- *p = '\0';
- sscanf(work, "[%d;%d", prow, pcolumn);
- }
-
- loc_amove(row, column) /* absolute cursor move */
- int row, column;
- {
- if (row < 1 || row > MAXROW || column < 1 || column > MAXCOLUMN)
- return;
- printf("\033[%d;%dH", row, column);
- }
-
- loc_dmove(drow, dcolumn) /* relative cursor move */
- int drow, dcolumn;
- {
- int currrow, currcolumn;
-
- loc_where(&currrow, &currcolumn);
- loc_amove(currrow+drow, currcolumn+dcolumn);
- }