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

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