home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / pine / pico / ansi.c next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  4.9 KB  |  201 lines

  1. #if    !defined(DOS)
  2. static char rcsid[] = "$Id: ansi.c,v 4.3 1993/04/15 00:18:07 mikes Exp $";
  3. #endif
  4. /*
  5.  * Program:    ANSI terminal driver routines
  6.  *
  7.  *
  8.  * Michael Seibel
  9.  * Networks and Distributed Computing
  10.  * Computing and Communications
  11.  * University of Washington
  12.  * Administration Builiding, AG-44
  13.  * Seattle, Washington, 98195, USA
  14.  * Internet: mikes@cac.washington.edu
  15.  *
  16.  * Please address all bugs and comments to "pine-bugs@cac.washington.edu"
  17.  *
  18.  * Copyright 1991-1993  University of Washington
  19.  *
  20.  *  Permission to use, copy, modify, and distribute this software and its
  21.  * documentation for any purpose and without fee to the University of
  22.  * Washington is hereby granted, provided that the above copyright notice
  23.  * appears in all copies and that both the above copyright notice and this
  24.  * permission notice appear in supporting documentation, and that the name
  25.  * of the University of Washington not be used in advertising or publicity
  26.  * pertaining to distribution of the software without specific, written
  27.  * prior permission.  This software is made available "as is", and
  28.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  29.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  30.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  31.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  32.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  33.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  34.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  35.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  36.  *
  37.  * Pine and Pico are trademarks of the University of Washington.
  38.  * No commercial use of these trademarks may be made without prior
  39.  * written permission of the University of Washington.
  40.  */
  41. /*
  42.  * The routines in this file provide support for ANSI style terminals
  43.  * over a serial line. The serial I/O services are provided by routines in
  44.  * "termio.c". It compiles into nothing if not an ANSI device.
  45.  */
  46.  
  47. #define    termdef    1            /* don't define "term" external */
  48.  
  49. #include        <stdio.h>
  50. #include    "estruct.h"
  51. #include        "edef.h"
  52. #include        "osdep.h"
  53.  
  54. #ifdef VMS
  55. #include "pico.h"
  56. #ifdef HEBREW
  57. #include "hebrew.h"
  58. #endif
  59. #endif    /* VMS */
  60.  
  61. #if     ANSI_DRIVER
  62.  
  63. #define    MARGIN    8            /* size of minimim margin and    */
  64. #define    SCRSIZ    64            /* scroll size for extended lines */
  65. #define BEL     0x07                    /* BEL character.               */
  66. #define ESC     0x1B                    /* ESC character.               */
  67.  
  68. extern  int     ttopen();               /* Forward references.          */
  69. extern  int     ttgetc();
  70. extern  int     ttputc();
  71. extern  int     ttflush();
  72. extern  int     ttclose();
  73. extern  int     ansimove();
  74. extern  int     ansieeol();
  75. extern  int     ansieeop();
  76. extern  int     ansibeep();
  77. extern  int     ansiopen();
  78. extern    int    ansirev();
  79. /*
  80.  * Standard terminal interface dispatch table. Most of the fields point into
  81.  * "termio" code.
  82.  */
  83. #ifdef VMS
  84. #ifdef __ALPHA
  85. TERM    term    = {
  86. #else
  87. globaldef TERM    term    = {
  88. #endif
  89. #endif
  90.         NROW-1,
  91.         NCOL,
  92.     MARGIN,
  93.     SCRSIZ,
  94.         ansiopen,
  95.         ttclose,
  96.         ttgetc,
  97.         ttputc,
  98.         ttflush,
  99.         ansimove,
  100.         ansieeol,
  101.         ansieeop,
  102.         ansibeep,
  103.     ansirev
  104. };
  105.  
  106. #ifdef VMS
  107. /* The functions here call TTmove which calls AnsiMove in Hebrew mode...
  108.    Hence, we call directly the output routine which is __ttputc.
  109.    This decleration MUST NOT be moved upper, as TTPUTC in TERM array must point
  110.    to the generic one.
  111. */
  112. #define    ttputc    __ttputc
  113. #endif
  114.  
  115. ansimove(row, col)
  116. {
  117. #ifdef VMS
  118. #ifdef HEBREW
  119.   if(compose_heb && hebmode)
  120.     col = term.t_ncol - col - 1;
  121. #endif
  122. #endif
  123.         ttputc(ESC);
  124.         ttputc('[');
  125.         ansiparm(row+1);
  126.         ttputc(';');
  127.         ansiparm(col+1);
  128.         ttputc('H');
  129. }
  130.  
  131. ansieeol()
  132. {
  133.         ttputc(ESC);
  134.         ttputc('[');
  135.         ttputc('K');
  136. }
  137.  
  138. ansieeop()
  139. {
  140.         ttputc(ESC);
  141.         ttputc('[');
  142.         ttputc('J');
  143. }
  144.  
  145. ansirev(state)        /* change reverse video state */
  146.  
  147. int state;    /* TRUE = reverse, FALSE = normal */
  148.  
  149. {
  150. #ifdef VMS
  151.     static    int    PrevState = 0;
  152.  
  153.     if(state == PrevState)
  154.         return;    /* Nothing to do */
  155.     else    PrevState = state;    /* remember it */
  156. #endif    /* VMS */
  157.     ttputc(ESC);
  158.     ttputc('[');
  159.     ttputc(state ? '7': '0');
  160.     ttputc('m');
  161. }
  162.  
  163. ansibeep()
  164. {
  165.         ttputc(BEL);
  166.         ttflush();
  167. }
  168.  
  169. ansiparm(n)
  170. register int    n;
  171. {
  172.         register int    q;
  173.  
  174.         q = n/10;
  175.         if (q != 0)
  176.                 ansiparm(q);
  177.         ttputc((n%10) + '0');
  178. }
  179.  
  180. #endif
  181.  
  182. ansiopen()
  183. {
  184. #if     V7
  185.         register char *cp;
  186.         char *getenv();
  187.  
  188.         if ((cp = getenv("TERM")) == NULL) {
  189.                 puts("Shell variable TERM not defined!");
  190.                 exit(1);
  191.         }
  192.         if (strcmp(cp, "vt100") != 0) {
  193.                 puts("Terminal type not 'vt100'!");
  194.                 exit(1);
  195.         }
  196. #endif
  197.  
  198.     revexist = TRUE;
  199.         ttopen();
  200. }
  201.