home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gle / gle / vaxinkey.c < prev    next >
C/C++ Source or Header  |  1992-11-29  |  4KB  |  227 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include "edt.h"
  6. #define true (!false)
  7. #define false 0
  8. int fner(char *s);
  9. int scr_refresh(void);
  10. int scr_getch(void);
  11. char *function_bar()
  12. {
  13.     return "F11-Help  F12-Save  F13-Load  F14-Save as        F9-Graph Form  F10-Drawit";
  14. }
  15.  
  16. struct escape_struct {char *str; int val;};
  17.  
  18. struct escape_struct gold[] = {
  19.         "v",     epaste,
  20.         "R",    esearch,
  21.         "S",    eundeleol,
  22.         NULL,    };
  23.  
  24. struct escape_struct eseq[] = {
  25.         "4~",     eselect,
  26.         "1~",    esearch,
  27.         "2~",    epaste,
  28.         "3~",    ecut,
  29.         "4~",    eselect,
  30.         "5~",    epageup,
  31.         "6~",    epagedown,
  32.         "A",    eup,
  33.         "B",    edown,
  34.         "C",    eright,
  35.         "D",    eleft,
  36.         "20~",    egraphmenu,
  37.         "21~",    edrawit,
  38.         "23~",    ehelp,
  39.         "24~",    esave,
  40.         "25~",    eload,
  41.         "26~",    esaveas,
  42.         "P",    egold,
  43.         "Q",    ehelp,
  44.         "R",    efindnext,
  45.         "S",    edeleol,
  46.         "n",    eselect,
  47.         "v",    ecut,
  48.         "l",    edelright,
  49.         NULL,    };
  50.  
  51. int gold_fn[] = {
  52.     edrawit,ehelp,esave,eload,esaveas,eshowerror,0,0,0,egraphmenu,edrawit
  53. };
  54. struct keymatch {int m; int val;};
  55. /* Normal key and ^ commands  commands */
  56. struct keymatch kmatch2[] = {
  57.     13, ereturn,
  58.     3, equit,
  59.     4, eword,
  60.     5, eedt,
  61.     6, efast,
  62.     7, edrawit,
  63.     18, eshowerror,
  64.     8, ehelp,
  65.     20, etrace,
  66.     12, efindnext,
  67.     21, eundelline,
  68.     25, edelline,
  69.     26, eescape,
  70.     27, eescape,
  71.     127, edelete,
  72.     0,0
  73. };
  74. /* Control K commands */
  75. struct keymatch kmatch3[] = {
  76.     'b', eselect,
  77.     'v', emove,
  78.     'k', emark,
  79.     'c', ecopy,
  80.     'y', ecut,
  81.     'u', epaste,
  82.     'p', epaste,
  83.     'r', eblockread,
  84.     'w', eblockwrite,
  85.     'm', egraphmenu,
  86.     'l', eload,
  87.     'd', edrawit,
  88.     's', esave,
  89.     'x', equit,
  90.     0,0
  91. };
  92. /* Control Q commands */
  93. struct keymatch kmatch4[] = {
  94.     'f', esearch,
  95.     'c', eendoffile,
  96.     'r', etopoffile,
  97.     0,0
  98. };
  99.  
  100. text_inkey()
  101. {
  102.     int cc,i,c1,c2;
  103.  
  104.     scr_refresh();
  105.  
  106. loop1:    cc = tt_inkey();
  107.     c2 = (cc & 0xff);
  108.     switch(c2) {
  109.       default:
  110.         for (i=0;kmatch2[i].m!=0;i++)
  111.         if (kmatch2[i].m==c2) return kmatch2[i].val;
  112.         break;
  113.       case 27:
  114.         c2 = tt_inkey(); /* throw away next char (unless escape) */
  115.         if (c2==27) return eescape;
  116.       case -101:
  117.       case -113:
  118.         c2 = escape_seq();
  119.         if (c2==egold) {
  120.             c2 = tt_inkey();
  121.             if (c2==27) {
  122.                 tt_inkey();
  123.                 return escape_seq_gold();
  124.             } else if (isdigit(c2)) {
  125.                 return gold_fn[c2-'0'];
  126.             }
  127.         }
  128.         return c2;
  129.         break;
  130.       case 17:
  131.         fner("^Q  F=Find string,  R=Top of file");
  132.         cc = tt_inkey();
  133.         c2 = (cc & 0xff);
  134.         if (c2<32) c2 = c2 + 'a' - 1;
  135.         c2 = tolower(c2);
  136.         for (i=0;kmatch4[i].m!=0;i++)
  137.         if (kmatch4[i].m==c2) return kmatch4[i].val;
  138.         fner("Unrecognized Quick movement command");
  139.         goto loop1;
  140.       case 11:
  141.         fner("^K  B=begin block,  P=Paste,  (use KP6 for Cut),  K=End block");
  142.         cc = tt_inkey();
  143.         c2 = (cc & 0xff);
  144.         if (c2<32) c2 = c2 + 'a' - 1;
  145.         c2 = tolower(c2);
  146.         for (i=0;kmatch3[i].m!=0;i++)
  147.         if (kmatch3[i].m==c2) return kmatch3[i].val;
  148.         fner("Unrecognized block command");
  149.         goto loop1;
  150.     }
  151.     return c2;
  152. }
  153. escape_seq()
  154. {
  155.     int cc,i;
  156.     unsigned char esq[10];
  157.     char *s;
  158.  
  159.     s = &esq[0];
  160.     *s++ = cc = tt_inkey();
  161.     while (cc<65) *s++ = cc = tt_inkey();
  162.     *s++ = 0;
  163.     for (i=0;eseq[i].str!=NULL;i++)
  164.         if (strcmp(eseq[i].str,esq)==0) break;
  165.     if (eseq[i].str!=NULL)
  166.         return eseq[i].val;
  167.     else
  168.         return 0;
  169.  
  170. }
  171. escape_seq_gold()
  172. {
  173.     int cc,i;
  174.     unsigned char esq[10];
  175.     char *s;
  176.  
  177.     s = &esq[0];
  178.     *s++ = cc = tt_inkey();
  179.     while (cc<65) *s++ = cc = tt_inkey();
  180.     *s++ = 0;
  181.     for (i=0;gold[i].str!=NULL;i++)
  182.         if (strcmp(gold[i].str,esq)==0) break;
  183.     if (gold[i].str!=NULL)
  184.         return gold[i].val;
  185.     else
  186.         return 0;
  187.  
  188. }
  189.  
  190.  
  191. #include <descrip.h>
  192. #include <iodef.h>
  193. int tt_chan;
  194. short tt_iosb[4];
  195. int tt_inkey();
  196. key_open()
  197. {
  198.     int st;
  199.     static $DESCRIPTOR(tt_desc,"tt");
  200.     st = SYS$ASSIGN(&tt_desc,&tt_chan,0,0);
  201. }
  202. int tt_inkey()
  203. {
  204.     int read_mask,st;
  205.     unsigned char inbuff[9];
  206.     static int key_isopen;
  207.  
  208.     if (!key_isopen) {key_open(); key_isopen=true;}
  209.     read_mask = IO$_READLBLK | IO$M_NOFILTR | IO$M_NOECHO;
  210.     st = SYS$QIOW(0,tt_chan,read_mask,tt_iosb,0,0,inbuff,1,0,0,0,0);
  211.     if ((st & 1) != 1) LIB$SIGNAL(st);
  212.     if ((tt_iosb[0] & 1) != 1) LIB$SIGNAL(tt_iosb[0]);
  213.     return inbuff[0];
  214. }
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.