home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c025 / 1.ddi / RCANSLIB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1985-02-04  |  2.9 KB  |  112 lines

  1. /*            RUN/C SCREEN FUNCTIONS
  2.             for non-IBM screens with 
  3.             ANSI terminal drivers
  4.  
  5.     Functions:    cls()        (clear screen)
  6.             locate()    (move cursor or report its position)
  7.  
  8.  
  9.     Note:    This source code is provided by Age of Reason, Inc.
  10.         for information only.  AofR guarantees neither correctness
  11.         nor support.  Nevertheless, having disclaimed all that is 
  12.         necessary, we will be happy to provide advice and would
  13.         appreciate any bug reports.
  14.  
  15.     Note:    The locate() function uses 2 library functions from the
  16.         Lattice C runtime library that may not be standard in other
  17.         compiler runtime libraries.  Their descriptions follow:
  18.  
  19.             int kbhit()
  20.                 returns 1 if character available
  21.                     at keyboard.
  22.                 returns 0 otherwise.
  23.  
  24.             char getch()
  25.                 returns the next available char from the 
  26.                 keyboard with NO echo.
  27.  
  28.     Function Descriptions:
  29.  
  30.     -------------------------------------------------
  31.         cls()        clears screen
  32.     -------------------------------------------------
  33.         int locate(row, column, mode)
  34.         int row, column, mode;
  35.  
  36.             if mode == 0: move cursor to (row, column)
  37.                     this is an absolute move
  38.                     1 <= row <= 25
  39.                     1 <= column <= 80
  40.                     no action if target position outside
  41.                         screen area.
  42.             if mode == 1: change cursor by (row, column)
  43.                     this is a relative move
  44.                     -24 <= row <= 24
  45.                     -79 <= column <= 79
  46.                     no action if target position outside
  47.                         screen area.
  48.             if mode == 2: return current cursor row
  49.                     (input row and column args irrelevant)
  50.             if mode == 3: return current cursor column
  51.                     (input row and column args irrelevant)
  52.  
  53.             row and column numbering starts at 1
  54.                 namely, (1,1) is upper-left
  55.             size of screen is governed by MAXROW and MAXCOLUMN.
  56.     -----------------------------------------------------------
  57. */
  58.  
  59. #include <stdio.h>
  60. #define MAXROW        25
  61. #define MAXCOLUMN    80
  62.  
  63. cls()
  64. {    printf("\033[2J");    /* Clear Screen ANSI call */
  65. }
  66.  
  67. locate(row, column, mode)
  68. int row, column, mode;
  69. {
  70.     switch(mode)
  71.     {    case 0:        loc_amove(row, column);
  72.                 break;
  73.         case 1:        loc_dmove(row, column);
  74.                 break;
  75.         case 2:        loc_where(&row, &column);
  76.                 return(row);
  77.         case 3:        loc_where(&row, &column);
  78.                 return(column);
  79.     }
  80. }
  81.  
  82. loc_where(prow, pcolumn)    /* returns current cursor position */
  83. int *prow, *pcolumn;
  84. {
  85.  char work[20], *p, c;
  86.  
  87.     printf("\033[6n");    /* Report Cursor Position ANSI call */
  88.     while (getch() != '\033')
  89.         ;
  90.     for (p = work; kbhit() ; )
  91.         *p++ = getch();
  92.     *p = '\0';
  93.     sscanf(work, "[%d;%d", prow, pcolumn);
  94. }
  95.  
  96. loc_amove(row, column)        /* absolute cursor move */
  97. int row, column;
  98. {
  99.     if (row < 1  ||  row > MAXROW  ||  column < 1  ||  column > MAXCOLUMN)
  100.         return;
  101.     printf("\033[%d;%dH", row, column);
  102. }
  103.  
  104. loc_dmove(drow, dcolumn)    /* relative cursor move */
  105. int drow, dcolumn;
  106. {
  107.  int currrow, currcolumn;
  108.  
  109.     loc_where(&currrow, &currcolumn);
  110.     loc_amove(currrow+drow, currcolumn+dcolumn);
  111. }
  112.