home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2872 / tcap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-28  |  2.3 KB  |  130 lines

  1. /*    tcap:    Unix V5, V7 and BS4.2 Termcap video driver
  2.         for beav
  3. */
  4.  
  5. #include "def.h"
  6.  
  7. #if UNIX
  8.  
  9. #define    MARGIN    8
  10. #define    SCRSIZ    64
  11. #define    NPAUSE    10            /* # times thru update to pause */
  12. #define BEL     0x07
  13. #define ESC     0x1B
  14.  
  15. extern int      ttgetc();
  16. extern int      ttputc();
  17. extern int        tgetnum();
  18. extern int      ttflush();
  19. extern int      ttclose();
  20. extern int      tput();
  21. extern char     *tgoto();
  22. #if    COLOR
  23. extern int        tcapfcol();
  24. extern int        tcapbcol();
  25. #endif
  26.  
  27. #define TCAPSLEN 315
  28. char tcapbuf[TCAPSLEN];
  29. char *UP, PC, *CM, *CE, *CL, *SO, *SE;
  30.  
  31. tcapopen()
  32. {
  33.         char *getenv();
  34.         char *t, *p, *tgetstr();
  35.         char tcbuf[1024];
  36.         char *tv_stype;
  37.         char err_str[72];
  38.  
  39.         if ((tv_stype = getenv("TERM")) == NULL)
  40.         {
  41.                 puts("Environment variable TERM not defined!");
  42.                 exit(1);
  43.         }
  44.  
  45.         if ((tgetent(tcbuf, tv_stype)) != 1)
  46.         {
  47.                 sprintf(err_str, "Unknown terminal type %s!", tv_stype);
  48.                 puts(err_str);
  49.                 exit(1);
  50.         }
  51.  
  52.  
  53.        if ((nrow=(short)tgetnum("li")-1) == -1){
  54.                puts("termcap entry incomplete (lines)");
  55.                exit(1);
  56.        }
  57.  
  58.        if ((ncol=(short)tgetnum("co")) == -1){
  59.                puts("Termcap entry incomplete (columns)");
  60.                exit(1);
  61.        }
  62.  
  63.     p = tcapbuf;
  64.     t = tgetstr("pc", &p);
  65.     if(t)
  66.         PC = *t;
  67.  
  68.     CL = tgetstr("cl", &p);
  69.     CM = tgetstr("cm", &p);
  70.     CE = tgetstr("ce", &p);
  71.     UP = tgetstr("up", &p);
  72.     SE = tgetstr("se", &p);
  73.     SO = tgetstr("so", &p);
  74.  
  75.     if(CL == NULL || CM == NULL || UP == NULL)
  76.         {
  77.         puts("Incomplete termcap entry\n");
  78.         exit(1);
  79.         }
  80.  
  81.     if (p >= &tcapbuf[TCAPSLEN])
  82.         {
  83.         puts("Terminal description too big!\n");
  84.         exit(1);
  85.         }
  86. }
  87.  
  88. tcapmove(row, col)
  89. register int row, col;
  90. {
  91.         putpad(tgoto(CM, col, row));
  92. }
  93.  
  94. tcapeeol()
  95. {
  96.         putpad(CE);
  97. }
  98.  
  99. tcapeeop()
  100. {
  101.         putpad(CL);
  102. }
  103.  
  104. tcaprev(state)        /* change reverse video status */
  105. int state;        /* FALSE = normal video, TRUE = reverse video */
  106.  
  107. {
  108.     static int revstate = FALSE;
  109.     if (state) {
  110.         if (SO != NULL)
  111.             putpad(SO);
  112.     } else
  113.         if (SE != NULL)
  114.             putpad(SE);
  115. }
  116.  
  117. putpad(str)
  118. char    *str;
  119. {
  120.     tputs(str, 1, ttputc);
  121. }
  122.  
  123. putnpad(str, n)
  124. char    *str;
  125. {
  126.     tputs(str, n, ttputc);
  127. }
  128.  
  129. #endif
  130.