home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / beav.1.40.lzh / BEAV140 / tcap.c < prev    next >
Text File  |  1995-06-14  |  4KB  |  224 lines

  1. /*    tcap:    Unix V5, V7 and BS4.2 Termcap video driver
  2.         for beav
  3. */
  4.  
  5. #include "def.h"
  6.  
  7. #ifdef UNIX
  8.  
  9. #ifdef OS2
  10. #ifndef __EMX__
  11. #define INCL_NOPM
  12. #define INCL_VIO
  13. #include <os2.h>
  14. #endif
  15. #endif
  16.  
  17. #define    MARGIN    8
  18. #define    SCRSIZ    64
  19. #define    NPAUSE    10        /* # times thru update to pause */
  20. #define BEL     0x07
  21. #define ESC     0x1B
  22.  
  23. extern char *tgoto ();
  24.  
  25. #ifdef NOPROTO
  26. extern int ttputc ();
  27. void putpad ();
  28. #endif
  29.  
  30. #ifdef    COLOR
  31. extern int tcapfcol ();
  32. extern int tcapbcol ();
  33. #endif
  34.  
  35. #define TCAPSLEN 315
  36. char tcapbuf[TCAPSLEN];
  37. char *UP, PC, *CM, *CE, *CL, *SO, *SE, *TI, *TE;    /* DR */
  38.  
  39. #ifdef BSD
  40. #include <sys/ioctl.h>
  41. struct winsize ttysize;
  42. #endif /* BSD */
  43. #ifdef ULTRIX
  44. struct winsize ttysize;
  45. #endif
  46.  
  47. #ifdef OSK
  48. char PC_, *BC;
  49. short ospeed;
  50. #endif
  51.  
  52. void
  53. putpad (str)
  54.     char *str;
  55. {
  56.     tputs (str, 1, ttputc);
  57. }
  58.  
  59. void
  60. tcapopen ()
  61. {
  62.     char *getenv ();
  63.     char *t, *p, *tgetstr ();
  64.     char tcbuf[1024];
  65.     char *tv_stype;
  66.     char err_str[NCOL];
  67. #ifdef ULTRIX
  68.     struct winsize ttysize;
  69. #endif
  70.  
  71.     nrow = NROW;
  72.  
  73.     if ((tv_stype = getenv ("TERM")) == NULL)
  74. #ifdef OS2
  75.     tv_stype = "ansi";
  76. #else
  77.     {
  78.     puts ("Environment variable TERM not defined!\r");
  79.     ttclose ();
  80.     exit (1);
  81.     }
  82. #endif
  83.  
  84.     if ((tgetent (tcbuf, tv_stype)) != 1)
  85.     {
  86.     sprintf (err_str, "Unknown terminal type %s!\r", tv_stype);
  87.     puts (err_str);
  88.     ttclose ();        /* fix in 1.13 */
  89.     exit (1);
  90.     }
  91.  
  92.  
  93. #ifdef BSD
  94. #ifdef ULTRIX
  95.     if (ioctl (0, TIOCGWINSZ, &ttysize) == 0
  96.     && ttysize.ws_row > 0)
  97.     {
  98.     nrow = ttysize.ws_row;
  99.     }
  100.     else
  101. #else
  102.     if (ioctl (0, TIOCGSIZE, &ttysize) == 0
  103.     && ttysize.ts_lines > 0)
  104.     {
  105.     nrow = ttysize.ts_lines;
  106.     }
  107.     else
  108. #endif /* ULTRIX */
  109. #endif /* BSD */
  110.  
  111. #ifndef OS2
  112.     if ((nrow = (short) tgetnum ("li") - 1) == -1)
  113.     {
  114.     puts ("termcap entry incomplete (lines)\r");
  115.     ttclose ();        /* fix in 1.13 */
  116.     exit (1);
  117.     }
  118.     printf ("nrow %d, ncol %d\n", nrow, ncol);
  119.  
  120.     if ((ncol = (short) tgetnum ("co")) == -1)
  121.     {
  122.     puts ("Termcap entry incomplete (columns)\r");
  123.     ttclose ();        /* fix in 1.13 */
  124.     exit (1);
  125.     }
  126.     /* don't allow to specify a larger number of cols than we can handle 1.13 */
  127.     if (ncol > NCOL)
  128.     ncol = NCOL;
  129. #else
  130.     {
  131. #ifdef __EMX__
  132.     int dst[2];
  133.     _scrsize (dst);
  134.     nrow = dst[1];
  135.     ncol = dst[0];
  136. #else
  137.     VIOMODEINFO viomi;
  138.     viomi.cb = sizeof (viomi);
  139.     VioGetMode (&viomi, 0);
  140.     nrow = viomi.row;
  141.     ncol = viomi.col;
  142. #endif
  143.     }
  144. #endif
  145.  
  146.     p = tcapbuf;
  147.     t = tgetstr ("pc", &p);
  148.     if (t)
  149.     PC = *t;
  150.  
  151.     TI = tgetstr ("ti", &p);    /* DR */
  152.     TE = tgetstr ("te", &p);    /* DR */
  153.     CL = tgetstr ("cl", &p);
  154.     CM = tgetstr ("cm", &p);
  155.     CE = tgetstr ("ce", &p);
  156.     UP = tgetstr ("up", &p);
  157.     SO = tgetstr ("so", &p);
  158.     SE = tgetstr ("se", &p);
  159.  
  160.     if (CL == NULL || CM == NULL || UP == NULL)
  161.     {
  162.     puts ("Incomplete termcap entry\r");
  163.     ttclose ();        /* fix in 1.13 */
  164.     exit (1);
  165.     }
  166.  
  167.     if (p >= &tcapbuf[TCAPSLEN])
  168.     {
  169.     puts ("Terminal description too big!\r");
  170.     ttclose ();        /* fix in 1.13 */
  171.     exit (1);
  172.     }
  173.     putpad (TI);        /* DR */
  174. }
  175.  
  176. void
  177. tcapclose ()            /* DR */
  178. {
  179.     putpad (TE);
  180. }
  181.  
  182. void
  183. tcapmove (row, col)
  184.     register int row, col;
  185. {
  186.     putpad (tgoto (CM, col, row));
  187. }
  188.  
  189. void
  190. tcapeeol ()
  191. {
  192.     putpad (CE);
  193. }
  194.  
  195. void
  196. tcapeeop ()
  197. {
  198.     putpad (CL);
  199. }
  200.  
  201. void
  202. tcaprev (state)            /* change reverse video status */
  203.     int state;            /* FALSE = normal video, TRUE = reverse video */
  204.  
  205. {
  206.     if (state)
  207.     {
  208.     if (SO != NULL)
  209.         putpad (SO);
  210.     }
  211.     else if (SE != NULL)
  212.     putpad (SE);
  213. }
  214.  
  215. void
  216. putnpad (str, n)
  217.     char *str;
  218.     int n;
  219. {
  220.     tputs (str, n, ttputc);
  221. }
  222.  
  223. #endif
  224.