home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 198_01 / ansi.c < prev    next >
C/C++ Source or Header  |  1990-01-23  |  5KB  |  279 lines

  1. /*
  2.  * The routines in this file provide support for ANSI style terminals
  3.  * over a serial line. The serial I/O services are provided by routines in
  4.  * "termio.c". It compiles into nothing if not an ANSI device.
  5.  */
  6.  
  7. #define    termdef    1            /* don't define "term" external */
  8.  
  9. #include        <stdio.h>
  10. #include    "estruct.h"
  11. #include        "edef.h"
  12.  
  13. #if     ANSI
  14.  
  15. #define    MROW    25
  16.  
  17. #if    AMIGA
  18. #define NROW    23                      /* Screen size.                 */
  19. #define NCOL    77                      /* Edit if you want to.         */
  20. #else
  21. #if    COLOR
  22. #define NROW    25                      /* Screen size.                 */
  23. #else
  24. #define NROW    24                      /* Screen size.                 */
  25. #endif
  26. #define NCOL    80                      /* Edit if you want to.         */
  27. #endif
  28. #define    NPAUSE    100            /* # times thru update to pause */
  29. #define    MARGIN    8            /* size of minimim margin and    */
  30. #define    SCRSIZ    64            /* scroll size for extended lines */
  31. #define BEL     0x07                    /* BEL character.               */
  32. #define ESC     0x1B                    /* ESC character.               */
  33.  
  34. extern  int     ttopen();               /* Forward references.          */
  35. extern  int     ttgetc();
  36. extern  int     ttputc();
  37. extern  int     ttflush();
  38. extern  int     ttclose();
  39. extern  int     ansimove();
  40. extern  int     ansiel();
  41. extern  int     ansiep();
  42. extern  int     ansibeep();
  43. extern  int     ansiopen();
  44. extern    int    ansirev();
  45. extern    int    ansiclose();
  46. extern    int    ansikopen();
  47. extern    int    ansikclose();
  48. extern    int    ansicres();
  49.  
  50. #if    COLOR
  51. extern    int    ansifcol();
  52. extern    int    ansibcol();
  53.  
  54. int    cfcolor = -1;        /* current forground color */
  55. int    cbcolor = -1;        /* current background color */
  56.  
  57. #if    AMIGA
  58. /* apperently the AMIGA does not follow the ANSI standards as
  59.    regards to colors....maybe because of the default pallette
  60.    settings?
  61. */
  62.  
  63. int coltran[8] = {2, 3, 5, 7, 0, 4, 6, 1};    /* color translation table */
  64. #endif
  65. #endif
  66.  
  67. /*
  68.  * Standard terminal interface dispatch table. Most of the fields point into
  69.  * "termio" code.
  70.  */
  71. TERM    term    = {
  72.     MROW-1,
  73.         NROW-1,
  74.         NCOL,
  75.         NCOL,
  76.     MARGIN,
  77.     SCRSIZ,
  78.     NPAUSE,
  79.         ansiopen,
  80.         ansiclose,
  81.     ansikopen,
  82.     ansikclose,
  83.         ttgetc,
  84.         ttputc,
  85.         ttflush,
  86.         ansimove,
  87.         ansiel,
  88.         ansiep,
  89.         ansibeep,
  90.     ansirev,
  91.     ansicres
  92. #if    COLOR
  93.     , ansifcol,
  94.     ansibcol
  95. #endif
  96. };
  97.  
  98. #if    COLOR
  99. ansifcol(color)        /* set the current output color */
  100.  
  101. int color;    /* color to set */
  102.  
  103. {
  104.     if (color == cfcolor)
  105.         return;
  106.     ttputc(ESC);
  107.     ttputc('[');
  108. #if    AMIGA
  109.     ansiparm(coltran[color]+30);
  110. #else
  111.     ansiparm(color+30);
  112. #endif
  113.     ttputc('m');
  114.     cfcolor = color;
  115. }
  116.  
  117. ansibcol(color)        /* set the current background color */
  118.  
  119. int color;    /* color to set */
  120.  
  121. {
  122.     if (color == cbcolor)
  123.         return;
  124.     ttputc(ESC);
  125.     ttputc('[');
  126. #if    AMIGA
  127.     ansiparm(coltran[color]+40);
  128. #else
  129.     ansiparm(color+40);
  130. #endif
  131.     ttputc('m');
  132.         cbcolor = color;
  133. }
  134. #endif
  135.  
  136. ansimove(row, col)
  137. {
  138.         ttputc(ESC);
  139.         ttputc('[');
  140.         ansiparm(row+1);
  141.         ttputc(';');
  142.         ansiparm(col+1);
  143.         ttputc('H');
  144. }
  145.  
  146. ansiel()
  147. {
  148.         ttputc(ESC);
  149.         ttputc('[');
  150.         ttputc('K');
  151. }
  152.  
  153. ansiep()
  154. {
  155. #if    COLOR
  156.     ansifcol(gfcolor);
  157.     ansibcol(gbcolor);
  158. #endif
  159.         ttputc(ESC);
  160.         ttputc('[');
  161.         ttputc('J');
  162. }
  163.  
  164. ansirev(state)        /* change reverse video state */
  165.  
  166. int state;    /* TRUE = reverse, FALSE = normal */
  167.  
  168. {
  169. #if    COLOR
  170.     int ftmp, btmp;        /* temporaries for colors */
  171. #endif
  172.  
  173.     ttputc(ESC);
  174.     ttputc('[');
  175.     ttputc(state ? '7': '0');
  176.     ttputc('m');
  177. #if    COLOR
  178.     if (state == FALSE) {
  179.         ftmp = cfcolor;
  180.         btmp = cbcolor;
  181.         cfcolor = -1;
  182.         cbcolor = -1;
  183.         ansifcol(ftmp);
  184.         ansibcol(btmp);
  185.     }
  186. #endif
  187. }
  188.  
  189. ansicres()    /* change screen resolution */
  190.  
  191. {
  192.     return(TRUE);
  193. }
  194.  
  195. spal(dummy)        /* change pallette settings */
  196.  
  197. {
  198.     /* none for now */
  199. }
  200.  
  201. ansibeep()
  202. {
  203.         ttputc(BEL);
  204.         ttflush();
  205. }
  206.  
  207. ansiparm(n)
  208. register int    n;
  209. {
  210.         register int q,r;
  211.  
  212.         q = n/10;
  213.         if (q != 0) {
  214.         r = q/10;
  215.         if (r != 0) {
  216.             ttputc((r%10)+'0');
  217.         }
  218.         ttputc((q%10) + '0');
  219.         }
  220.         ttputc((n%10) + '0');
  221. }
  222.  
  223. ansiopen()
  224. {
  225. #if     V7 | USG | BSD
  226.         register char *cp;
  227.         char *getenv();
  228.  
  229.         if ((cp = getenv("TERM")) == NULL) {
  230.                 puts("Shell variable TERM not defined!");
  231.                 exit(1);
  232.         }
  233.         if (strcmp(cp, "vt100") != 0) {
  234.                 puts("Terminal type not 'vt100'!");
  235.                 exit(1);
  236.         }
  237. #endif
  238.     strcpy(sres, "NORMAL");
  239.     revexist = TRUE;
  240.         ttopen();
  241. }
  242.  
  243. ansiclose()
  244.  
  245. {
  246. #if    COLOR
  247.     ansifcol(7);
  248.     ansibcol(0);
  249. #endif
  250.     ttclose();
  251. }
  252.  
  253. ansikopen()    /* open the keyboard (a noop here) */
  254.  
  255. {
  256. }
  257.  
  258. ansikclose()    /* close the keyboard (a noop here) */
  259.  
  260. {
  261. }
  262.  
  263. #if    FLABEL
  264. fnclabel(f, n)        /* label a function key */
  265.  
  266. int f,n;    /* default flag, numeric argument [unused] */
  267.  
  268. {
  269.     /* on machines with no function keys...don't bother */
  270.     return(TRUE);
  271. }
  272. #endif
  273. #else
  274. ansihello()
  275. {
  276. }
  277. #endif
  278.  
  279.