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