home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / VILE327.ZIP / VILE327.TAR / vile3.27 / ansi.c next >
C/C++ Source or Header  |  1992-12-14  |  6KB  |  371 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.  * $Log: ansi.c,v $
  7.  * Revision 1.9  1992/08/20  23:40:48  foxharp
  8.  * typo fixes -- thanks, eric
  9.  *
  10.  * Revision 1.8  1992/05/16  12:00:31  pgf
  11.  * prototypes/ansi/void-int stuff/microsoftC
  12.  *
  13.  * Revision 1.7  1992/04/10  18:47:25  pgf
  14.  * change abs to absol to get rid of name conflicts
  15.  *
  16.  * Revision 1.6  1991/11/16  18:28:25  pgf
  17.  * removed an old ifdef
  18.  *
  19.  * Revision 1.5  1991/09/10  01:19:35  pgf
  20.  * re-tabbed, and moved ESC and BEL to estruct.h
  21.  *
  22.  * Revision 1.4  1991/08/07  12:34:39  pgf
  23.  * added RCS log messages
  24.  *
  25.  * revision 1.3
  26.  * date: 1991/06/19 01:32:21;
  27.  * change name of howmany 'cuz of HP/UX conflict
  28.  * sheesh
  29.  * 
  30.  * revision 1.2
  31.  * date: 1991/05/31 10:26:19;
  32.  * moved PRETTIER_SCROLL #define to estruct.h
  33.  * 
  34.  * revision 1.1
  35.  * date: 1990/09/21 10:24:38;
  36.  * initial vile RCS revision
  37.  */
  38.  
  39. #define termdef 1            /* don't define "term" external */
  40.  
  41. #include    <stdio.h>
  42. #include    "estruct.h"
  43. #include    "edef.h"
  44.  
  45. #if    ANSI
  46.  
  47. #if    AMIGA
  48. #define NROW    23            /* Screen size.         */
  49. #define NCOL    77            /* Edit if you want to.     */
  50. #else
  51. #define NROW    24            /* Screen size.         */
  52. #define NCOL    80            /* Edit if you want to.     */
  53. #endif
  54. #define NPAUSE    100            /* # times thru update to pause */
  55. #define MARGIN    8            /* size of minimim margin and    */
  56. #define SCRSIZ    64            /* scroll size for extended lines */
  57.  
  58. extern    int    ttopen();        /* Forward references.        */
  59. extern    int    ttgetc();
  60. extern    int    ttputc();
  61. extern    int    ttflush();
  62. extern    int    ttclose();
  63. extern    int    ansimove();
  64. extern    int    ansieeol();
  65. extern    int    ansieeop();
  66. extern    int    ansibeep();
  67. extern    int    ansiopen();
  68. extern    int    ansirev();
  69. extern    int    ansiclose();
  70. extern    int    ansikopen();
  71. extern    int    ansikclose();
  72. extern    int    ansicres();
  73. #if SCROLLCODE
  74. extern    int    ansiscroll();
  75. #endif
  76.  
  77. #if    COLOR
  78. extern    int    ansifcol();
  79. extern    int    ansibcol();
  80.  
  81. int    cfcolor = -1;        /* current forground color */
  82. int    cbcolor = -1;        /* current background color */
  83.  
  84. #if    AMIGA
  85. /* apperently the AMIGA does not follow the ANSI standards as
  86.    regards to colors....maybe because of the default palette
  87.    settings?
  88. */
  89.  
  90. int coltran[8] = {2, 3, 5, 7, 0, 4, 6, 1};    /* color translation table */
  91. #endif
  92. #endif
  93.  
  94. /*
  95.  * Standard terminal interface dispatch table. Most of the fields point into
  96.  * "termio" code.
  97.  */
  98. TERM    term    = {
  99.     NROW-1,
  100.     NROW-1,
  101.     NCOL,
  102.     NCOL,
  103.     MARGIN,
  104.     SCRSIZ,
  105.     NPAUSE,
  106.     ansiopen,
  107.     ansiclose,
  108.     ansikopen,
  109.     ansikclose,
  110.     ttgetc,
  111.     ttputc,
  112.     ttflush,
  113.     ansimove,
  114.     ansieeol,
  115.     ansieeop,
  116.     ansibeep,
  117.     ansirev,
  118.     ansicres
  119. #if    COLOR
  120.     , ansifcol,
  121.     ansibcol
  122. #endif
  123. #if SCROLLCODE
  124.     , ansiscroll
  125. #endif
  126. };
  127.  
  128. csi()
  129. {
  130.     ttputc(ESC);
  131.     ttputc('[');
  132. }
  133.  
  134. #if    COLOR
  135. ansifcol(color)     /* set the current output color */
  136.  
  137. int color;    /* color to set */
  138.  
  139. {
  140.     if (color == cfcolor)
  141.         return;
  142.     csi();
  143. #if    AMIGA
  144.     ansiparm(coltran[color]+30);
  145. #else
  146.     ansiparm(color+30);
  147. #endif
  148.     ttputc('m');
  149.     cfcolor = color;
  150. }
  151.  
  152. ansibcol(color)     /* set the current background color */
  153.  
  154. int color;    /* color to set */
  155.  
  156. {
  157.     if (color == cbcolor)
  158.         return;
  159.     csi();
  160. #if    AMIGA
  161.     ansiparm(coltran[color]+40);
  162. #else
  163.     ansiparm(color+40);
  164. #endif
  165.     ttputc('m');
  166.     cbcolor = color;
  167. }
  168. #endif
  169.  
  170. ansimove(row, col)
  171. {
  172.     csi();
  173.     if (row) ansiparm(row+1);
  174.     ttputc(';');
  175.     if (col) ansiparm(col+1);
  176.     ttputc('H');
  177. }
  178.  
  179. ansieeol()
  180. {
  181.     csi();
  182.     ttputc('K');
  183. }
  184.  
  185. ansieeop()
  186. {
  187. #if    COLOR
  188.     ansifcol(gfcolor);
  189.     ansibcol(gbcolor);
  190. #endif
  191.     csi();
  192.     ttputc('J');
  193. }
  194.  
  195.  
  196. ansirev(state)        /* change reverse video state */
  197.  
  198. int state;    /* TRUE = reverse, FALSE = normal */
  199.  
  200. {
  201. #if    COLOR
  202.     int ftmp, btmp;     /* temporaries for colors */
  203. #else
  204.     static int revstate = -1;
  205.     if (state == revstate)
  206.         return;
  207.     revstate = state;
  208. #endif
  209.  
  210.     csi();
  211.     if (state) ttputc('7');
  212.     ttputc('m');
  213. #if    COLOR
  214.     if (state == FALSE) {
  215.         ftmp = cfcolor;
  216.         btmp = cbcolor;
  217.         cfcolor = -1;
  218.         cbcolor = -1;
  219.         ansifcol(ftmp);
  220.         ansibcol(btmp);
  221.     }
  222. #endif
  223. }
  224.  
  225. ansicres()    /* change screen resolution */
  226. {
  227.     return(TRUE);
  228. }
  229.  
  230. spal(dummy)        /* change palette settings */
  231. {
  232.     /* none for now */
  233. }
  234.  
  235. ansibeep()
  236. {
  237.     ttputc(BEL);
  238.     ttflush();
  239. }
  240.  
  241. #if SCROLLCODE
  242.  
  243. /* if your ansi terminal can scroll regions, like the vt100, then define
  244.     SCROLL_REG.  If not, you can use delete/insert line code, which
  245.     is prettier but slower if you do it a line at a time instead of
  246.     all at once.
  247. */
  248.  
  249. #define SCROLL_REG 1
  250.  
  251. /* move howmany lines starting at from to to */
  252. ansiscroll(from,to,n)
  253. {
  254.     int i;
  255.     if (to == from) return;
  256. #if SCROLL_REG
  257.     if (to < from) {
  258.         ansiscrollregion(to, from + n - 1);
  259.         ansimove(from + n - 1,0);
  260.         for (i = from - to; i > 0; i--)
  261.             ttputc('\n');
  262.     } else { /* from < to */
  263.         ansiscrollregion(from, to + n - 1);
  264.         ansimove(from);
  265.         for (i = to - from; i > 0; i--) {
  266.             ttputc(ESC);
  267.             ttputc('M');
  268.         }
  269.     }
  270.     ansiscrollregion(0, term.t_mrow);
  271.             
  272. #else /* use insert and delete line */
  273. #if PRETTIER_SCROLL
  274.     if (absol(from-to) > 1) {
  275.         ansiscroll(from, (from<to) ? to-1:to+1, n);
  276.         if (from < to)
  277.             from = to-1;
  278.         else
  279.             from = to+1;    
  280.     }
  281. #endif
  282.     if (to < from) {
  283.         ansimove(to,0);
  284.         csi();
  285.         if (from - to > 1) ansiparm(from - to);
  286.         ttputc('M'); /* delete */
  287.         ansimove(to+n,0);
  288.         csi();
  289.         if (from - to > 1) ansiparm(from - to);
  290.         ttputc('L'); /* insert */
  291.     } else {
  292.         ansimove(from+n,0);
  293.         csi();
  294.         if (to - from > 1) ansiparm(to - from);
  295.         ttputc('M'); /* delete */
  296.         ansimove(from,0);
  297.         csi();
  298.         if (to - from > 1) ansiparm(to - from);
  299.         ttputc('L'); /* insert */
  300.     }
  301. #endif
  302. }
  303.  
  304. #if SCROLL_REG
  305. ansiscrollregion(top,bot)
  306. {
  307.     csi();
  308.     if (top) ansiparm(top + 1);
  309.     ttputc(';');
  310.     if (bot != term.t_nrow) ansiparm(bot + 1);
  311.     ttputc('r');
  312. }
  313. #endif
  314.  
  315. #endif
  316.  
  317. ansiparm(n)
  318. register int    n;
  319. {
  320.     register int q,r;
  321.  
  322.     q = n/10;
  323.     if (q != 0) {
  324.         r = q/10;
  325.         if (r != 0) {
  326.             ttputc((r%10)+'0');
  327.         }
  328.         ttputc((q%10) + '0');
  329.     }
  330.     ttputc((n%10) + '0');
  331. }
  332.  
  333. ansiopen()
  334. {
  335.     strcpy(sres, "NORMAL");
  336.     revexist = TRUE;
  337.     ttopen();
  338. }
  339.  
  340. ansiclose()
  341. {
  342. #if    COLOR
  343.     ansifcol(7);
  344.     ansibcol(0);
  345. #endif
  346.     ttclose();
  347. }
  348.  
  349. ansikopen()    /* open the keyboard (a noop here) */
  350. {
  351. }
  352.  
  353. ansikclose()    /* close the keyboard (a noop here) */
  354. {
  355. }
  356.  
  357. #if    FLABEL
  358. int
  359. fnclabel(f, n)        /* label a function key */
  360. int f,n;    /* default flag, numeric argument [unused] */
  361. {
  362.     /* on machines with no function keys...don't bother */
  363.     return(TRUE);
  364. }
  365. #endif
  366. #else
  367. ansihello()
  368. {
  369. }
  370. #endif
  371.