home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume26 / mytinfo / part01 / termcap.c < prev    next >
C/C++ Source or Header  |  1992-12-26  |  2KB  |  155 lines

  1. /*
  2.  * termcap.c
  3.  *
  4.  * By Ross Ridge
  5.  * Public Domain
  6.  * 92/06/01 07:43:08
  7.  *
  8.  * termcap compatibility functions
  9.  *
  10.  */
  11.  
  12. #include "defs.h"
  13. #include "term.h"
  14.  
  15. static const char SCCSid[] = "@(#) mytinfo termcap.c 3.3 92/06/01 public domain, By Ross Ridge";
  16.  
  17. extern char _mytinfo_version[];
  18. static char *force = _mytinfo_version;
  19.  
  20. int
  21. tgetent(buf, term)
  22. char *term, *buf; {
  23.     char *s;
  24.     struct term_path *path;
  25.     int r = -1;
  26.     int fd;
  27.  
  28.     if (term == NULL) 
  29.         term = getenv("TERM");
  30.     if (term == NULL)
  31.         return 0;
  32.  
  33.     path = _buildpath("$MYTERMINFO", 2,
  34.               "$TERMINFO", 2,
  35.               "$TERMCAP", 1,
  36. #ifdef TERMINFODIR
  37.               TERMINFODIR, 0,
  38. #endif
  39. #ifdef TERMCAPFILE
  40.               TERMCAPFILE, 0,
  41. #endif
  42. #ifdef TERMINFOSRC
  43.               TERMINFOSRC, 0,
  44. #endif
  45.               NULL, -1);
  46.  
  47.     if (path == NULL)
  48.         return -1;
  49.  
  50. #if 1
  51.     {
  52.         char buf1[MAX_BUF];
  53.         r = _fillterm(term, path, buf1);
  54.     }
  55. #else
  56.     r = _fillterm(term, path, buf);
  57. #endif
  58.  
  59.     _delpath(path);
  60.  
  61.     switch(r) {
  62.     case -3:
  63.     case -2:
  64.     case -1:
  65.         return -1;
  66.     case 0:
  67.         return 0;
  68.     case 1:
  69.     case 2:
  70.     case 3:
  71.         if (isatty(1))
  72.             fd = 1;
  73.         else if (isatty(2))
  74.             fd = 2;
  75.         else if (isatty(3))    /* V10 /dev/tty ?? */
  76.             fd = 3;
  77.         else if (isatty(0))
  78.             fd = 0;
  79.         else
  80.             fd = 1;
  81.  
  82.         cur_term->fd = fd;
  83.         _term_buf.fd = fd;
  84.  
  85.         if (_init_tty() == ERR)
  86.             return 0;
  87.         if ((s = getenv("LINES")) != NULL && atoi(s) > 0) 
  88.             lines = atoi(s);
  89.         if ((s = getenv("COLUMNS")) != NULL && atoi(s) > 0)
  90.             columns = atoi(s);
  91.         cur_term->termcap = 1;
  92.         return 1;
  93.     default:
  94.         return -1;
  95.     }
  96. }
  97.  
  98. static char cap2[3];
  99.  
  100. int
  101. tgetnum(cap)
  102. char *cap; {
  103.     int ind;
  104.  
  105.     cap2[0] = cap[0]; 
  106.     cap2[1] = cap[1];
  107.     cap2[2] = '\0';
  108.  
  109.     ind = _findnumcode(cap2);
  110.     if (ind == -1)
  111.         return -1;
  112.     return cur_term->nums[ind];
  113. }
  114.  
  115. int
  116. tgetflag(cap)
  117. char *cap; {
  118.     int ind;
  119.  
  120.     cap2[0] = cap[0]; 
  121.     cap2[1] = cap[1];
  122.     cap2[2] = '\0';
  123.  
  124.     ind = _findboolcode(cap2);
  125.     if (ind == -1)
  126.         return 0;
  127.     return cur_term->bools[ind];
  128. }
  129.  
  130. char *
  131. tgetstr(cap, area)
  132. char *cap;
  133. char **area; {
  134.     register char *sp, *dp;
  135.     int ind;
  136.  
  137.     cap2[0] = cap[0]; 
  138.     cap2[1] = cap[1];
  139.     cap2[2] = '\0';
  140.  
  141.     ind = _findstrcode(cap2);
  142.     if (ind == -1)
  143.         return NULL;
  144.     sp = cur_term->strs[ind];
  145.     if (area == NULL || sp == NULL)
  146.         return sp;
  147.     dp = *area;
  148.     while (*sp != '\0')
  149.         *dp++ = *sp++;
  150.     *dp++ = '\0';
  151.     sp = *area;
  152.     *area = dp;
  153.     return sp;
  154. }
  155.