home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / beav1402.zip / tcap.c < prev    next >
Text File  |  1993-04-16  |  4KB  |  219 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. void
  48. putpad (str)
  49.     char *str;
  50. {
  51.     tputs (str, 1, ttputc);
  52. }
  53.  
  54. void
  55. tcapopen ()
  56. {
  57.     char *getenv ();
  58.     char *t, *p, *tgetstr ();
  59.     char tcbuf[1024];
  60.     char *tv_stype;
  61.     char err_str[NCOL];
  62. #ifdef ULTRIX
  63.     struct winsize ttysize;
  64. #endif
  65.  
  66.     nrow = NROW;
  67.  
  68.     if ((tv_stype = getenv ("TERM")) == NULL)
  69. #ifdef OS2
  70.     tv_stype = "ansi";
  71. #else
  72.     {
  73.     puts ("Environment variable TERM not defined!\r");
  74.     ttclose ();
  75.     exit (1);
  76.     }
  77. #endif
  78.  
  79.     if ((tgetent (tcbuf, tv_stype)) != 1)
  80.     {
  81.     sprintf (err_str, "Unknown terminal type %s!\r", tv_stype);
  82.     puts (err_str);
  83.     ttclose ();        /* fix in 1.13 */
  84.     exit (1);
  85.     }
  86.  
  87.  
  88. #ifdef BSD
  89. #ifdef ULTRIX
  90.     if (ioctl (0, TIOCGWINSZ, &ttysize) == 0
  91.     && ttysize.ws_row > 0)
  92.     {
  93.     nrow = ttysize.ws_row;
  94.     }
  95.     else
  96. #else
  97.     if (ioctl (0, TIOCGSIZE, &ttysize) == 0
  98.     && ttysize.ts_lines > 0)
  99.     {
  100.     nrow = ttysize.ts_lines;
  101.     }
  102.     else
  103. #endif /* ULTRIX */
  104. #endif /* BSD */
  105.  
  106. #ifndef OS2
  107.     if ((nrow = (short) tgetnum ("li") - 1) == -1)
  108.     {
  109.     puts ("termcap entry incomplete (lines)\r");
  110.     ttclose ();        /* fix in 1.13 */
  111.     exit (1);
  112.     }
  113.     printf ("nrow %d, ncol %d\n", nrow, ncol);
  114.  
  115.     if ((ncol = (short) tgetnum ("co")) == -1)
  116.     {
  117.     puts ("Termcap entry incomplete (columns)\r");
  118.     ttclose ();        /* fix in 1.13 */
  119.     exit (1);
  120.     }
  121.     /* don't allow to specify a larger number of cols than we can handle 1.13 */
  122.     if (ncol > NCOL)
  123.     ncol = NCOL;
  124. #else
  125.     {
  126. #ifdef __EMX__
  127.     int dst[2];
  128.     _scrsize (dst);
  129.     nrow = dst[1];
  130.     ncol = dst[0];
  131. #else
  132.     VIOMODEINFO viomi;
  133.     viomi.cb = sizeof (viomi);
  134.     VioGetMode (&viomi, 0);
  135.     nrow = viomi.row;
  136.     ncol = viomi.col;
  137. #endif
  138.     }
  139. #endif
  140.  
  141.     p = tcapbuf;
  142.     t = tgetstr ("pc", &p);
  143.     if (t)
  144.     PC = *t;
  145.  
  146.     TI = tgetstr ("ti", &p);    /* DR */
  147.     TE = tgetstr ("te", &p);    /* DR */
  148.     CL = tgetstr ("cl", &p);
  149.     CM = tgetstr ("cm", &p);
  150.     CE = tgetstr ("ce", &p);
  151.     UP = tgetstr ("up", &p);
  152.     SO = tgetstr ("so", &p);
  153.     SE = tgetstr ("se", &p);
  154.  
  155.     if (CL == NULL || CM == NULL || UP == NULL)
  156.     {
  157.     puts ("Incomplete termcap entry\r");
  158.     ttclose ();        /* fix in 1.13 */
  159.     exit (1);
  160.     }
  161.  
  162.     if (p >= &tcapbuf[TCAPSLEN])
  163.     {
  164.     puts ("Terminal description too big!\r");
  165.     ttclose ();        /* fix in 1.13 */
  166.     exit (1);
  167.     }
  168.     putpad (TI);        /* DR */
  169. }
  170.  
  171. void
  172. tcapclose ()            /* DR */
  173. {
  174.     putpad (TE);
  175. }
  176.  
  177. void
  178. tcapmove (row, col)
  179.     register int row, col;
  180. {
  181.     putpad (tgoto (CM, col, row));
  182. }
  183.  
  184. void
  185. tcapeeol ()
  186. {
  187.     putpad (CE);
  188. }
  189.  
  190. void
  191. tcapeeop ()
  192. {
  193.     putpad (CL);
  194. }
  195.  
  196. void
  197. tcaprev (state)            /* change reverse video status */
  198.     int state;            /* FALSE = normal video, TRUE = reverse video */
  199.  
  200. {
  201.     if (state)
  202.     {
  203.     if (SO != NULL)
  204.         putpad (SO);
  205.     }
  206.     else if (SE != NULL)
  207.     putpad (SE);
  208. }
  209.  
  210. void
  211. putnpad (str, n)
  212.     char *str;
  213.     int n;
  214. {
  215.     tputs (str, n, ttputc);
  216. }
  217.  
  218. #endif
  219.