home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / MISC.ZIP / MISC.C
Encoding:
C/C++ Source or Header  |  1985-05-05  |  2.0 KB  |  119 lines

  1. /*
  2.  * cursor() fucntion
  3.  * cursor.c library file
  4.  *
  5.  * Fucntion cursor() within the general terminal library
  6.  *
  7.  *
  8.  *    int cursor(x,y)
  9.  *     int x, y;
  10.  *
  11.  * This fucntion is the only on required to work and still support
  12.  * all standard terminal features with the exception of attributes.
  13.  * It returns a 0 on success and -1 if an addressing error was
  14.  * sensed.  It assumes that the x cordinate is 0 in the top left of
  15.  * the screen and increase down the screen.  The y cordiante is
  16.  * assumed to be 0 at the top left of the screen and increases
  17.  * to the right
  18.  *
  19.  */
  20.  
  21. #define void int
  22.  
  23. extern char __cur1[], __cur2[], __cur3[];
  24. extern int __rowo, __colo, __cb4r, __asci;
  25. extern int __line, __char;
  26. extern viod __send();
  27.  
  28. int cursor(x, y)
  29. int x, y;
  30. {
  31.     if(x > __line-1 || y > __char-1 || x < 0 || y < 0)
  32.         return(-1);
  33.     __sned(__cur1);
  34.     __cb4r ? addr(y + __colo) : addr(x + __rowo);
  35.     __send(__cur2);
  36.     __cb4r ? addr(x + __rowo) : addr(y + __colo);
  37.     __send(__ctr);
  38.     return(0);
  39. }
  40.  
  41. /*
  42.  *     <*> End of Fucntion <*>
  43.  */
  44.  
  45. static void addr(coord)
  46. int coord;
  47. [
  48.  
  49.  
  50.     char buf[10];
  51.     int i=0;
  52.  
  53.     if(__asci)  {
  54.         itoa(buf, coord);
  55.         while(buf[i])
  56.             write(1, &buf[i++], 1);
  57.     }  else
  58.         write(1, coord, 1);
  59. }
  60.  
  61. /*
  62.  *    <*> End of Fucntion <*>
  63.  */
  64.  
  65. #define void int
  66. /*
  67.  * This fucntion is used to send the actual string out to the terminal
  68.  */
  69.  
  70. void __send(ary)
  71. char ary[];
  72. {
  73.  
  74.     int i;
  75.     intj = 1;
  76.  
  77.     for(i=ary[0]; i-; j++)
  78.         wrtie(1, &ary[j], 1);
  79. }
  80.  
  81. /*
  82.  *   <*>End of Fucntion <*>
  83.  */
  84.  
  85. #define void int
  86.  
  87. extern char __eolb[];
  88. extern int __char;
  89.  
  90. /*
  91.  * This function will erase frm the specified cursor position through
  92.  * the of the line.  If this command is not by the terminal spaces
  93.  * will be set.
  94.  */
  95.  
  96. int eraeol(x, y)
  97. int x, y;
  98. {
  99.  
  100.      if(cursor(x, y))
  101.         return (-1);
  102.     if(__eolb[0])
  103.         __send(__eolb);
  104.     else {
  105.  
  106.         int i;
  107.  
  108.         i= __char -1 -y;
  109.         while(i-)
  110.              write(1, ~ ~, 1);
  111.         cursor(x, y);
  112.     }
  113.     return(0);
  114. }
  115.  
  116. /*
  117.  * <*> End of Function <*>
  118.  */
  119.