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