home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / pine3.07 / pico / ansi.c next >
Encoding:
C/C++ Source or Header  |  1992-01-06  |  3.9 KB  |  159 lines

  1. /*
  2.  * Program:    ANSI terminal driver routines
  3.  *
  4.  * Modifier:    Michael Seibel
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: mikes@cac.washington.edu
  11.  *
  12.  * Date:    19 Jan 1991
  13.  * Last Edited:    6 Jan 1992
  14.  *
  15.  * Copyright 1991 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35. /*
  36.  * The routines in this file provide support for ANSI style terminals
  37.  * over a serial line. The serial I/O services are provided by routines in
  38.  * "termio.c". It compiles into nothing if not an ANSI device.
  39.  */
  40.  
  41. #define    termdef    1            /* don't define "term" external */
  42.  
  43. #include        <stdio.h>
  44. #include    "estruct.h"
  45. #include        "edef.h"
  46. #include        "osdep.h"
  47.  
  48. #if     ANSI
  49.  
  50. #define    MARGIN    8            /* size of minimim margin and    */
  51. #define    SCRSIZ    64            /* scroll size for extended lines */
  52. #define BEL     0x07                    /* BEL character.               */
  53. #define ESC     0x1B                    /* ESC character.               */
  54.  
  55. extern  int     ttopen();               /* Forward references.          */
  56. extern  int     ttgetc();
  57. extern  int     ttputc();
  58. extern  int     ttflush();
  59. extern  int     ttclose();
  60. extern  int     ansimove();
  61. extern  int     ansieeol();
  62. extern  int     ansieeop();
  63. extern  int     ansibeep();
  64. extern  int     ansiopen();
  65. extern    int    ansirev();
  66. /*
  67.  * Standard terminal interface dispatch table. Most of the fields point into
  68.  * "termio" code.
  69.  */
  70. TERM    term    = {
  71.         NROW-1,
  72.         NCOL,
  73.     MARGIN,
  74.     SCRSIZ,
  75.         ansiopen,
  76.         ttclose,
  77.         ttgetc,
  78.         ttputc,
  79.         ttflush,
  80.         ansimove,
  81.         ansieeol,
  82.         ansieeop,
  83.         ansibeep,
  84.     ansirev
  85. };
  86.  
  87. ansimove(row, col)
  88. {
  89.         ttputc(ESC);
  90.         ttputc('[');
  91.         ansiparm(row+1);
  92.         ttputc(';');
  93.         ansiparm(col+1);
  94.         ttputc('H');
  95. }
  96.  
  97. ansieeol()
  98. {
  99.         ttputc(ESC);
  100.         ttputc('[');
  101.         ttputc('K');
  102. }
  103.  
  104. ansieeop()
  105. {
  106.         ttputc(ESC);
  107.         ttputc('[');
  108.         ttputc('J');
  109. }
  110.  
  111. ansirev(state)        /* change reverse video state */
  112.  
  113. int state;    /* TRUE = reverse, FALSE = normal */
  114.  
  115. {
  116.     ttputc(ESC);
  117.     ttputc('[');
  118.     ttputc(state ? '7': '0');
  119.     ttputc('m');
  120. }
  121.  
  122. ansibeep()
  123. {
  124.         ttputc(BEL);
  125.         ttflush();
  126. }
  127.  
  128. ansiparm(n)
  129. register int    n;
  130. {
  131.         register int    q;
  132.  
  133.         q = n/10;
  134.         if (q != 0)
  135.                 ansiparm(q);
  136.         ttputc((n%10) + '0');
  137. }
  138.  
  139. #endif
  140.  
  141. ansiopen()
  142. {
  143. #if     V7
  144.         register char *cp;
  145.         char *getenv();
  146.  
  147.         if ((cp = getenv("TERM")) == NULL) {
  148.                 puts("Shell variable TERM not defined!");
  149.                 exit(1);
  150.         }
  151.         if (strcmp(cp, "vt100") != 0) {
  152.                 puts("Terminal type not 'vt100'!");
  153.                 exit(1);
  154.         }
  155. #endif
  156.     revexist = TRUE;
  157.         ttopen();
  158. }
  159.