home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1709 / tinytcap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  3.2 KB  |  143 lines

  1. /* tinytcap.c */
  2.  
  3. /* This file contains functions which simulate the termcap functions, but which
  4.  * can only describe the capabilities of the ANSI.SYS and NANSI.SYS drivers on
  5.  * an MS-DOS system or the VT-52 emulator of an Atari-ST.  These functions
  6.  * do *NOT* access a "termcap" database file.
  7.  */
  8.  
  9. #include "config.h"
  10. #if MSDOS || TOS
  11.  
  12. #define CAP(str) CAP2((str)[0], (str)[1])
  13. #define CAP2(a,b) (((a) << 8) + ((b) & 0xff))
  14.  
  15. #if MSDOS
  16. # define VAL2(v,a)    (a)
  17. # define VAL3(v,a,n)    (nansi ? (n) : (a))
  18. static int    nansi = 0;
  19. #endif
  20.  
  21. #if TOS
  22. # define VAL2(v,a)    (v)
  23. # define VAL3(v,a,n)    (v)
  24. #endif
  25.  
  26.  
  27. /*ARGSUSED*/
  28. int tgetent(bp, name)
  29.     char    *bp;    /* buffer for storing the entry -- ignored */
  30.     char    *name;    /* name of the entry */
  31. {
  32. #if MSDOS
  33.     if (!strcmp(name, "ansi") || !strcmp(name, "nansi"))
  34.     {
  35.         nansi = (name[0] == 'n');
  36.         return 1;
  37.     }
  38. #endif
  39. #if TOS
  40.     if (!strcmp(name, "vt52"))
  41.     {
  42.         return 1;
  43.     }
  44. #endif
  45.     return 0;
  46. }
  47.  
  48. int tgetnum(id)
  49.     char    *id;
  50. {
  51.     switch (CAP(id))
  52.     {
  53.       case CAP2('l','i'):    return 25;
  54.       case CAP2('c','o'):    return 80;
  55.       case CAP2('s','g'):    return 0;
  56.       case CAP2('u','g'):    return 0;
  57.       default:        return -1;
  58.     }
  59. }
  60.  
  61. int tgetflag(id)
  62.     char    *id;
  63. {
  64.     switch (CAP(id))
  65.     {
  66.       case CAP2('a','m'):    return 1;
  67.       case CAP2('b','s'):    return 1;
  68.       case CAP2('m','i'):    return 1;
  69.       default:        return 0;
  70.     }
  71. }
  72.  
  73. /*ARGSUSED*/
  74. char *tgetstr(id, bp)
  75.     char    *id;
  76.     char    **bp;    /* pointer to pointer to buffer - ignored */
  77. {
  78.     switch (CAP(id))
  79.     {
  80.       case CAP2('c','e'):    return VAL2("\033K", "\033[K");
  81.       case CAP2('c','l'):    return VAL2("\033E", "\033[2J");
  82.  
  83.       case CAP2('a','l'):    return VAL3("\033L", (char *)0, "\033[L");
  84.       case CAP2('d','l'):    return VAL3("\033M", (char *)0, "\033[M");
  85.  
  86.       case CAP2('c','m'):    return VAL2("\033Y%i%+ %+ ", "\033[%i%d;%dH");
  87.       case CAP2('d','o'):    return VAL2("\033B", "\033[B");
  88.       case CAP2('n','d'):    return VAL2("\033C", "\033[C");
  89.       case CAP2('u','p'):    return VAL2("\033A", "\033[A");
  90.       case CAP2('t','i'):    return VAL2("\033e", "");
  91.       case CAP2('t','e'):    return VAL2("", "");
  92.  
  93.       case CAP2('s','o'):    return VAL2("\033p", "\033[7m");
  94.       case CAP2('s','e'):    return VAL2("\033q", "\033[m");
  95.       case CAP2('u','s'):    return VAL2((char *)0, "\033[4m");
  96.       case CAP2('u','e'):    return VAL2((char *)0, "\033[m");
  97.       case CAP2('V','B'):    return VAL2((char *)0, "\033[1m");
  98.       case CAP2('V','b'):    return VAL2((char *)0, "\033[m");
  99.  
  100.       case CAP2('k','u'):    return "#H";
  101.       case CAP2('k','d'):    return "#P";
  102.       case CAP2('k','l'):    return "#K";
  103.       case CAP2('k','r'):    return "#M";
  104.       case CAP2('H','M'):    return "#G";
  105.       case CAP2('E','N'):    return "#O";
  106.       case CAP2('P','U'):    return "#I";
  107.       case CAP2('P','D'):    return "#Q";
  108.  
  109.       default:        return (char *)0;
  110.     }
  111. }
  112.  
  113. /*ARGSUSED*/
  114. char *tgoto(cm, destcol, destrow)
  115.     char    *cm;    /* cursor movement string -- ignored */
  116.     int    destcol;/* destination column, 0 - 79 */
  117.     int    destrow;/* destination row, 0 - 24 */
  118. {
  119.     static char buf[30];
  120.  
  121. #if MSDOS
  122.     sprintf(buf, "\033[%d;%dH", destrow + 1, destcol + 1);
  123. #endif
  124. #if TOS
  125.     sprintf(buf, "\033Y%c%c", ' ' + destrow, ' ' + destcol);
  126. #endif
  127.     return buf;
  128. }
  129.  
  130. /*ARGSUSED*/
  131. void tputs(cp, affcnt, outfn)
  132.     char    *cp;        /* the string to output */
  133.     int    affcnt;        /* number of affected lines -- ignored */
  134.     int    (*outfn)();    /* the output function */
  135. {
  136.     while (*cp)
  137.     {
  138.         (*outfn)(*cp);
  139.         cp++;
  140.     }
  141. }
  142. #endif
  143.