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

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