home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 133_01 / eterm < prev    next >
Text File  |  1985-03-10  |  7KB  |  246 lines

  1. /*
  2.     e screen editor
  3.  
  4.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  5.  
  6.     August-December 1981
  7.  
  8.     FILE: etvi
  9.  
  10.     FUNCTIONS: terminit,terminal,gotoxy,deleteline,linedelete,delpage,
  11.             insertline,begdim,enddim,keytranslate,displayhelp
  12.  
  13.     PURPOSE: terminal dependent screen control functions
  14.  
  15.     NOTE this file is specific to the TeleVideo range of terminals.
  16.     It may be used as a model for others
  17. */
  18.  
  19. #include "e.h"
  20.  
  21. /* control key codes, here for convenience in defining terminal sequences*/
  22.  
  23. #define CTRLA    0x01    /*    SOH */
  24. #define CTRLB    0x02    /*    STX */
  25. #define CTRLC    0x03    /*    ETX */
  26. #define CTRLD    0x04    /*    EOT */
  27. #define CTRLE    0x05    /*    ENQ */
  28. #define CTRLF    0x06    /*    ACK */
  29. #define CTRLG    0x07    /*    BEL */
  30. #define CTRLH    0x08    /*    BS  */
  31. #define CTRLI    0x09    /*    HT  */
  32. #define CTRLJ    0x0a    /*    LF  */
  33. #define CTRLK    0x0b    /*    VT  */
  34. #define CTRLL    0x0c    /*    FF  */
  35. #define CTRLM    0x0d    /*    CR  */
  36. #define CTRLN    0x0e    /*    SO  */
  37. #define CTRLO    0x0f    /*    SI  */
  38. #define CTRLP    0x10    /*    DLE */
  39. #define CTRLQ    0x11    /*    DC1 */
  40. #define CTRLR    0x12    /*    DC2 */
  41. #define CTRLS    0x13    /*    DC3 */
  42. #define CTRLT    0x14    /*    DC4 */
  43. #define CTRLU    0x15    /*    NAK */
  44. #define CTRLV    0x16    /*    SYN */
  45. #define CTRLW    0x17    /*    ETB */
  46. #define CTRLX    0x18    /*    CAN */
  47. #define CTRLY    0x19    /*    EM  */
  48. #define CTRLZ    0x1a    /*    SUB */
  49. #define SOH    0x01
  50. #define STX    0x02
  51. #define ETX    0x03
  52. #define EOT    0x04
  53. #define ENQ    0x05
  54. #define ACK    0x06
  55. #define BEL    0x07
  56. #define BS     0x08
  57. #define HT     0x09
  58. #define LF     0x0a
  59. #define VT     0x0b
  60. #define FF     0x0c
  61. #define RETURN     0x0d
  62. #define SO     0x0e
  63. #define SI     0x0f
  64. #define DLE    0x10
  65. #define DC1    0x11
  66. #define DC2    0x12
  67. #define DC3    0x13
  68. #define DC4    0x14
  69. #define NAK    0x15
  70. #define SYN    0x16
  71. #define ETB    0x17
  72. #define CAN    0x18
  73. #define EM     0x19
  74. #define SUB    0x1a
  75. #define ESC     0x1b
  76. #define FS      0x1c
  77. #define GS      0x1d
  78. #define RS      0x1e
  79. #define US      0x1f
  80. #define DEL     0x7f
  81.  
  82. /*-------------------------OUTPUT TO SCREEN---------------------------*/
  83.  
  84.  
  85.  
  86. /* screen control characters for TVI912C, ADM31 */
  87. #define BEGINDIM ')'
  88. #define ENDDIM '('
  89. #define CRSADDR '='
  90. #define INSLINE 'E'
  91. #define DELLINE 'T'    /*delete to spaces*/
  92. #define LINDEL 'R'    /*delete and close up*/
  93. #define PAGEDEL 'Y'
  94.  
  95. terminit()    /*initialise terminal.  Called once before any output to
  96.           to terminal is performed */
  97. {
  98. }
  99.  
  100. termfini()    /*restore terminal to 'normal' state.  Called once before
  101.           program exits */
  102. {
  103. }
  104.  
  105. terminal()    /*display name of terminal*/
  106. {
  107.     puts("|for TVI-912/920");
  108. }
  109.  
  110. gotoxy(x,y)    /*move cursor to column x, line y {top left is (0,0) */
  111. int x,y;
  112. {
  113.     putch(ESC);
  114.     putch(CRSADDR);
  115.     putch(y+32);
  116.     putch(x+32);
  117. }
  118.  
  119. deleteline(x,y)    /*clear to spaces all characters on line y from column x
  120.             to the right edge of the screen, inclusive.
  121.             Leave cursor on left most blank */
  122. int x, y;
  123. {
  124.     gotoxy(x,y);
  125.     putch(ESC);
  126.     putch(DELLINE);
  127.     gotoxy(x,y);
  128.  
  129. }
  130.  
  131. linedelete(y)    /*delete the line y.  All following lines move up one.
  132.             Leave cursor at start of line y */
  133. int y;
  134. {
  135.     gotoxy(0,y);
  136.     putch(ESC);
  137.     putch(LINDEL);
  138. }
  139.  
  140. delpage(y)    /*clear to spaces line y and all following lines.  Leave
  141.             cursor at the start of line y */
  142. int y;
  143. {
  144.     gotoxy(0,y);
  145.     putch(ESC);
  146.     putch(PAGEDEL);
  147. }
  148.  
  149. insertline()    /*move all lines below line on which cursor is, down one,
  150.             losing last line.  New cursor line is blank, with
  151.             cursor at start of line */
  152. {
  153.     putch(ESC);
  154.     putch(INSLINE);
  155. }
  156.  
  157. begdim()    /*display all subsequent characters at half intensity*/
  158. {
  159.     putch(ESC);
  160.     putch(BEGINDIM);
  161. }
  162.  
  163. enddim()    /* display all subsequent characters at full intensity */
  164. {
  165.     putch(ESC);
  166.     putch(ENDDIM);
  167. }
  168.  
  169.  
  170. /*----------------------INPUT FROM KEYBOARD-----------------------------*/
  171.  
  172.  
  173. keytranslate()    /*defines the terminal key codes which perform
  174.             the editor commands */
  175. {
  176. /* each tran[xxxx]= should be set to the code emitted by the terminal
  177. key which will perform the indicated action.  The recommended (control)
  178. key assignments are shown in round brackets.
  179.     Some terminals precede their codes by a lead-in character
  180. (eg the Hazeltine uses the tilde).  This char should be assigned to
  181. tran[LEADIN].  If there is no lead-in character, set tran[LEADIN] to zero.
  182.     'e' will ignore the leadin character if tran[LEADIN] is non-zero,
  183. but will set the parity bit on the next character. All other chars from the
  184. keyboard will already have any parity bits removed as they are read in.  Thus
  185. codes with lead-ins should be entered in the table below as code+0x80, or
  186. more clearly, as code+PARBIT.
  187.     For example, suppose that one is coding the Hazeltine 1420, which
  188. generates a tilde,^L (0x0d) sequence when the cursor up key is pressd.  To
  189. recognise this sequence, set tran[LEADIN] to tilde (0x7e) and set
  190. tran[UPKEY] to 0x0d+PARBIT.
  191. */
  192.  
  193.     tran[LEADIN]=0;        /*lead-in character, 0 if not used*/
  194.     tran[DOWNKEY]= CTRLJ;    /*cursor down */
  195.     tran[UPKEY]= CTRLK;    /*cursor up*/
  196.     tran[LEFTKEY]= CTRLH;    /*cursor left*/
  197.     tran[RIGHTKEY]= CTRLL;    /*cursor right*/
  198.     tran[RIGHTWKEY]= CTRLD;    /*cursor right one word (D) */
  199.     tran[LEFTWKEY]= CTRLS;    /*cursor left one word (S) */
  200.     tran[EOLKEY]= CTRLE;    /*cursor to end of line (E) */
  201.     tran[BOLKEY]= CTRLB;    /*cursor to beginning of line (B) */
  202.     tran[UPPAGE]= CTRLW;    /*scroll up a page (W) */
  203.     tran[DOWNPAGE]= CTRLZ;    /*scroll down a page (Z) */
  204.     tran[BOFKEY]= CTRLU;    /*cursor to beginning of file (U) */
  205.     tran[HOMEKEY]= RS;    /*cursor to end of file (HOME) */
  206.     tran[DELLEFT]= DEL;    /*delete char to left of cursor (DEL) */
  207.     tran[DELRIGHT]= CTRLG;    /*delete char under cursor (G) */
  208.     tran[DELLNKEY]= CTRLY;    /*delete cursor line (Y) */
  209.     tran[DELWDKEY]= CTRLT;    /*delete word to right of cursor (T) */
  210.     tran[JUMPKEY]= CTRLX;    /*jump to (X) */
  211.     tran[CRSTILL]= CTRLN;    /*insert newline after cursor (N) */
  212.     tran[QUITKEY]= CTRLQ;    /*quit (Q) */
  213.     tran[ENVIRKEY]= CTRLC;    /*edit and file context (C) */
  214.     tran[FINDKEY]= CTRLF;    /*find (F) */
  215.     tran[ALTERKEY]= CTRLA;    /*alter (A) */
  216.     tran[BLOCKKEY]= CTRLO;    /*block operations (O) */
  217.     tran[RDFILEKEY]= CTRLP;    /*read a file (P) */
  218.     tran[REPKEY]= CTRLR;    /*repeat last find/alter (R) */
  219.     tran[HELPKEY]= CTRLV;    /*display help menu (V) */
  220.     tran[UNDOKEY]= FS;    /*restore unedited line (\) */
  221.     tran[TAB]= CTRLI;    /*tab (I) */
  222.     tran[RETRIEVE]= CTRLR;    /*retrieve (R)*/
  223.     tran[CR]= CTRLM;    /*return*/
  224.     tran[ESCKEY]=ESC;    /*escape, the magic key (ESC)*/
  225. }
  226.  
  227. /*-------------------------------HELP MENU-------------------------------*/
  228.  
  229.  
  230. displayhelp()    /*display the help menu.  There must be (helplines-1)
  231.             lines of menu here (see terminal function,above) */
  232. {
  233.     puts("CURSOR:  ^B|=beginning of line| ^E|=end of line|    ^S|=left word|  ^D|=right word\n");
  234.     puts("MOVE:    ^W|=up a screen|       ^Z|=down a screen|  ^U|=top,     |HOME|=bottom of file\n");
  235.     puts("DELETE: DEL|=char left|         ^G|=char right|     ^T|=word|       ^Y|=line|  ^\\|=undo\n");
  236.     puts("         ^F|=find|              ^A|=alter|          ^R|=repeat|     ^V|=view menu\n");
  237.     puts("   ^     ^N|=insert a new line| ^X|=jump to line|   ^P|=read file|  ^Q|=quit,save file\n");
  238.     puts(" <- ->   ^C|=edit,file context| ^O|=write,print,shift,move,copy,or delete block\n");
  239.     puts("---v------------------------------------------------------------------------");
  240. }
  241.  
  242.  
  243. /*---------------------------------END---------------------------------------*/
  244. *scroll down a page (Z) */
  245.     tran[BOFKEY]= CTRLU;    /*cursor to beginning of file (U) */
  246.     tran[H