home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume8 / ue310usp / optional next >
Encoding:
Text File  |  1989-09-23  |  10.6 KB  |  290 lines

  1. Article 5159 of comp.emacs:
  2. Path: rocky8!cmcl2!rutgers!tut.cis.ohio-state.edu!ucbvax!agate!bionet!ig!arizona!rupley
  3. From: rupley@arizona.edu (John Rupley)
  4. Newsgroups: comp.emacs
  5. Subject: Microemacs 3.10 - patch for tcap.c
  6. Message-ID: <11487@megaron.arizona.edu>
  7. Date: 9 Jun 89 01:17:52 GMT
  8. Organization: U of Arizona CS Dept, Tucson
  9. Lines: 276
  10. Keywords: function key timeout loop for USG; revised ttable[]
  11.  
  12.  
  13. context diff patch for tcap.c:
  14.  
  15. 1) added timeout loop in get1key(), for USG option; without it, one
  16. cannot use the function keys under sys5; it could be made more portable
  17. by #defining the processor speed, or building in a test for it;
  18. commented-out code gives an alternative solution, without a timeout
  19. loop.
  20.  
  21. 2) modified ttable[], to allow shifted function keys and some other stuff.
  22.  
  23. 3) sample terminfo, consistent with (2), included in comment.
  24.  
  25.  
  26. John Rupley
  27.     uucp: ..{uunet | ucbvax | cmcl2 | hao!ncar!noao}!arizona!rupley!local
  28.     internet: rupley!local@megaron.arizona.edu
  29.     (H) 30 Calle Belleza, Tucson AZ  85716 - (602) 325-4533
  30.     (O) Dept. Biochemistry, Univ. Arizona, Tucson AZ 85721 - (602) 621-3929
  31. ------------------------------------------------------------------------
  32. *** tcap.c    Mon May 22 16:21:08 1989
  33. --- ../tcap.c    Fri May 26 13:47:56 1989
  34. ***************
  35. *** 70,75
  36.                       
  37.   */
  38.   
  39.   #define termdef 1            /* don't define "term" external */
  40.   
  41.   #include <stdio.h>
  42.  
  43. --- 70,135 -----
  44.                       
  45.   */
  46.   
  47. + /*
  48. +  * a non-portable but generally usable USG option for get1key() is suggested;
  49. +  * it allows use of the function keys needed to handle menus, specifically
  50. +  * those of .emacsrc and the *.cmd files; 
  51. +  *
  52. +  * it assumes typeahead() is enabled;
  53. +  *
  54. +  * the ttable[] bindings include shifted function and keypad keys;
  55. +  *
  56. +  * following is a sample ansi terminfo file, which has strings for the 
  57. +  * normal and shifted keys, and which adheres more-or-less to the 
  58. +  * ansi standard;
  59. +  *
  60. +  * a user without write permission on the system terminfo files likely
  61. +  * will have to set up a local TERMINFO environment by use of .profile,
  62. +  * and perhaps reprogram the function and keypad strings of the terminal;
  63. +  *
  64. +  * j.a. rupley, tucson, az  - rupley!local@megaron.arizona.edu
  65. +  */
  66. + /*-
  67. + ansi|modified terminfo description 
  68. + # DELETE #...# COMMENTS #...# BEFORE #...# TIC'ING #
  69. + # standard stuff #
  70. +     am, xon, cols#80, lines#24, bel=^G, cr=\r, clear=\E[H\E[J, 
  71. +     el=\E[K, ed=\E[J, cup=\E[%i%p1%d;%p2%dH, cud1=\n, home=\E[H, 
  72. +     cub1=\b, cuf1=\E[C, cuu1=\E[A, dch1=\E[P, dl1=\E[M, blink=\E[5m, 
  73. +     bold=\E[1m, smir=\E[4h, invis=\E[8m, rev=\E[7m, smso=\E[7m, 
  74. +     smul=\E[4m, sgr0=\E[m, rmir=\E[4l, rmso=\E[0m, rmul=\E[0m, 
  75. +     is2=\E[=h, ich1=\E[@, il1=\E[L, 
  76. +     dl=\E[%p1%dM, cud=\E[%p1%dB, 
  77. +     ich=\E[%p1%d@, il=\E[%p1%dL, cub=\E[%p1%dD, cuf=\E[%p1%dC, 
  78. +     cuu=\E[%p1%dA, ind=\n, ht=\t, 
  79. + # function keys - kf0=kf10 #
  80. +     kf1=\EOc, kf2=\EOd, kf3=\EOe, kf4=\EOf, 
  81. +     kf5=\EOg, kf6=\EOh, kf7=\EOi, kf8=\EOj, kf9=\EOk, 
  82. +     kf0=\EOl, kf10=\EOl, 
  83. + # shifted function keys - lf0=lf10 #
  84. + # tricky - store and recover strings as labels #
  85. +     lf1=\EOC, lf2=\EOD, lf3=\EOE, lf4=\EOF, 
  86. +     lf5=\EOG, lf6=\EOH, lf7=\EOI, lf8=\EOJ, lf9=\EOK, 
  87. +     lf0=\EOL, lf10=\EOL, 
  88. + # keypad keys #
  89. +     khome=\E[H,    kcuu1=\E[A,    kpp=\E[U, 
  90. +     kcub1=\E[D,             kcuf1=\E[C, 
  91. +     kll=\E[E,     kcud1=\E[B,     knp=\E[V, 
  92. + # ins #
  93. +     kich1=\E[@, 
  94. + # shifted keypad keys #
  95. +     ka1=\E[!H,    kri=\E[S,    ka3=\E[!U, 
  96. +     kclr=\E[!@,            kel=\E[!A, 
  97. +     kc1=\E[!E,    kind=\E[T,    kc3=\E[!V,
  98. + # shifted ins and shifted del #
  99. +     kil1=\E[L,            kdch1=\E[P,
  100. + # miscellaneous #
  101. +     kdl1=\E[M, 
  102. +     cbt=\E[Z, 
  103. +     kbs=\b, 
  104. + */
  105.   #define termdef 1            /* don't define "term" external */
  106.   
  107.   #include <stdio.h>
  108. ***************
  109. *** 103,136
  110.   } TBIND;
  111.   
  112.   TBIND ttable[] = {
  113. !     "bt",    SHFT | CTRL | 'i',    "",    /* backtab */
  114. !     "k1",    SPEC | '1',        "",    /* function key 1 */
  115. !     "k2",    SPEC | '2',        "",    /* function key 2 */
  116. !     "k3",    SPEC | '3',        "",    /* function key 3 */
  117. !     "k4",    SPEC | '4',        "",    /* function key 4 */
  118. !     "k5",    SPEC | '5',        "",    /* function key 5 */
  119. !     "k6",    SPEC | '6',        "",    /* function key 6 */
  120. !     "k7",    SPEC | '7',        "",    /* function key 7 */
  121. !     "k8",    SPEC | '8',        "",    /* function key 8 */
  122. !     "k9",    SPEC | '9',        "",    /* function key 9 */
  123. !     "k0",    SPEC | '0',        "",    /* function key 10 */
  124. !     "kA",    CTRL | 'O',        "",    /* insert line */
  125. !     "kb",    CTRL | 'H',        "",    /* backspace */
  126. !     "kC",    CTRL | 'L',        "",    /* clear screen */
  127. !     "kD",    SPEC | 'D',        "",    /* delete character */
  128. !     "kd",    SPEC | 'N',        "",    /* down cursor */
  129. !     "kE",    CTRL | 'K',        "",    /* clear to end of line */
  130. !     "kF",    CTRL | 'V',        "",    /* scroll down */
  131. !     "kH",    SPEC | '>',        "",    /* home down [END?] key */
  132. !     "kh",    SPEC | '<',        "",    /* home */
  133. !     "kI",    SPEC | 'C',        "",    /* insert character */
  134. !     "kL",    CTRL | 'K',        "",    /* delete line */
  135. !     "kl",    SPEC | 'B',        "",    /* left cursor */
  136. !     "kN",    SPEC | 'V',        "",    /* next page */
  137. !     "kP",    SPEC | 'Z',        "",    /* previous page */
  138. !     "kR",    CTRL | 'Z',        "",    /* scroll down */
  139. !     "kr",    SPEC | 'F',        "",    /* right cursor */
  140. !     "ku",    SPEC | 'P',        "",    /* up cursor */
  141.   };
  142.   
  143.   #define    NTBINDS    sizeof(ttable)/sizeof(TBIND)
  144.  
  145. --- 163,232 -----
  146.   } TBIND;
  147.   
  148.   TBIND ttable[] = {
  149. !     "k1",    SPEC | '1',        "",    /* kf1 /* function key 1 */
  150. !     "k2",    SPEC | '2',        "",    /* kf2 /* function key 2 */
  151. !     "k3",    SPEC | '3',        "",    /* kf3 /* function key 3 */
  152. !     "k4",    SPEC | '4',        "",    /* kf4 /* function key 4 */
  153. !     "k5",    SPEC | '5',        "",    /* kf5 /* function key 5 */
  154. !     "k6",    SPEC | '6',        "",    /* kf6 /* function key 6 */
  155. !     "k7",    SPEC | '7',        "",    /* kf7 /* function key 7 */
  156. !     "k8",    SPEC | '8',        "",    /* kf8 /* function key 8 */
  157. !     "k9",    SPEC | '9',        "",    /* kf9 /* function key 9 */
  158. !     "k0",    SPEC | '0',        "",    /* kf0 /* function key 10 */
  159. !     "l1",    SPEC | SHFT | '1',    "",    /* kl1 /* shftd func key 1 */
  160. !     "l2",    SPEC | SHFT | '2',    "",    /* kl2 /* shftd func key 2 */
  161. !     "l3",    SPEC | SHFT | '3',    "",    /* kl3 /* shftd func key 3 */
  162. !     "l4",    SPEC | SHFT | '4',    "",    /* kl4 /* shftd func key 4 */
  163. !     "l5",    SPEC | SHFT | '5',    "",    /* kl5 /* shftd func key 5 */
  164. !     "l6",    SPEC | SHFT | '6',    "",    /* kl6 /* shftd func key 6 */
  165. !     "l7",    SPEC | SHFT | '7',    "",    /* kl7 /* shftd func key 7 */
  166. !     "l8",    SPEC | SHFT | '8',    "",    /* kl8 /* shftd func key 8 */
  167. !     "l9",    SPEC | SHFT | '9',    "",    /* kl9 /* shftd func key 9 */
  168. !     "l0",    SPEC | SHFT | '0',    "",    /* kl0 /* shftd func key 10 */
  169. ! /* the following key-pad keys and their bindings are obvious */
  170. !     "kh",    SPEC | '<',        "",    /* khome /* home */
  171. !     "ku",    SPEC | 'P',        "",    /* kcuu1 /* up cursor */
  172. !     "kP",    SPEC | 'Z',        "",    /* kpp /* previous page */
  173. !     "kl",    SPEC | 'B',        "",    /* kcub1 /* left cursor */
  174. !     "kr",    SPEC | 'F',        "",    /* kcuf1 /* right cursor */
  175. !     "kH",    SPEC | '>',        "",    /* kll /* home down [END] */
  176. !     "kd",    SPEC | 'N',        "",    /* kcud1 /* down cursor */
  177. !     "kN",    SPEC | 'V',        "",    /* knp /* next page */
  178. ! /* the following are less obvious */
  179. ! /* ins        # kI kich1  insert character */    /* bound to insspace */
  180. !     "kI",    SPEC | 'C',        "",    /* kich1 /* insert character */
  181. ! /* shift del    # kD kdch1  delete character */    /* bound to forwdel */
  182. !     "kD",    SPEC | 'D',        "",    /* kdch1 /* delete character */
  183. ! /* shift ins    # kA kil1  insert line */     /* bound to openline */
  184. !     "kA",    CTRL | 'O',        "",    /* kil1 /* insert line */
  185. ! /* shift up    # kR kri  scroll up */        /* bound to backpage */
  186. !     "kR",    CTRL | 'Z',        "",    /* kri /* scroll up */
  187. ! /* shift down    # kF kind  scroll down */    /* bound to forwpage */
  188. !     "kF",    CTRL | 'V',        "",    /* kind /* scroll down */
  189. ! /* shift left    # kC kclr  clear screen */    /* bound to backword */
  190. ! /*    "kC",    META | 'B',        "",    /* kclr /* clear screen */
  191. !     "kC",    SPEC | CTRL | 'B',    "",    /* kclr /* clear screen */
  192. ! /* shift right    # kE kel  clear to eol */    /* bound to forwword */
  193. ! /*    "kE",    META | 'F',        "",    /* kel /* clear to eol */
  194. !     "kE",    SPEC | CTRL | 'F',    "",    /* kel /* clear to eol */
  195. ! /* shift pgup    # K3 ka3  pad upper right */    /* bound to gotobop */
  196. ! /*    "K3",    META | 'P',        "",    /* ka3 /* pad upper right */
  197. !     "K3",    SPEC | CTRL | 'Z',    "",    /* ka3 /* pad upper right */
  198. ! /* shift pgdn    # K5 kc3  pad lower right */    /* bound to gotoeop */
  199. ! /*    "K5",    META | 'N',        "",    /* kc3 /* pad lower right */
  200. !     "K5",    SPEC | CTRL | 'V',    "",    /* kc3 /* pad lower right */
  201. ! /* shift home    # K1 ka1  pad upper left */    /* unbound key */
  202. !     "K1",    SPEC | CTRL | '<',    "",    /* ka1 /* pad upper left */
  203. ! /* shift end    # K4 kc1  pad lower left */    /* unbound key */
  204. !     "K4",    SPEC | CTRL | '>',    "",    /* kc1 /* pad lower left */
  205. ! /* shift tab     # bt cbt backtab        /* unbound key */
  206. !     "bt",    SHFT | CTRL | 'i',    "",    /* cbt /* backtab */
  207. ! /* and let's forget the following */
  208. ! /* alt del    # kL kdl1  delete line */
  209. ! /*    "kL",    CTRL | 'K',        "",    /* kdl1 /* delete line */
  210. ! /*    "kb",    CTRL | 'H',        "",    /* kbs /* backspace */
  211. ! /*    "kC",    CTRL | 'L',        "",    /* kclr /* clear screen */
  212. ! /*    "kE",    CTRL | 'K',        "",    /* kel /* clear to eol */
  213.   };
  214.   
  215.   #define    NTBINDS    sizeof(ttable)/sizeof(TBIND)
  216. ***************
  217. *** 450,457
  218.       /* we don't know how to do this check for a pending char within
  219.          1/30th of a second machine independantly in the general System V
  220.          case.... so we don't */
  221. !     if (kbdmode != PLAY)
  222. !         return(CTRL | '[');
  223.   #endif
  224.   
  225.       /* a key is pending within 1/30 of a sec... its an escape sequence */
  226.  
  227. --- 546,586 -----
  228.       /* we don't know how to do this check for a pending char within
  229.          1/30th of a second machine independantly in the general System V
  230.          case.... so we don't */
  231. !     /*
  232. !      * or... maybe we try it;
  233. !      * very non-portable solution;
  234. !      * hardware-dependent timing loop;
  235. !      * set upper-limit on loop by testing hardware, to get 30 ms;
  236. !      * use typahead() to check for waiting input on exit from loop;
  237. !      */
  238. !     {    int i;
  239. !         if (kbdmode != PLAY && typahead() <= 0) {
  240. !             /* loop limit set by hardware test */
  241. !             /* for 30 ms or a bit less */
  242. !             for (i = 0; i < 1500; i++)
  243. !                 ;
  244. !             if (typahead() <= 0)
  245. !                 return(CTRL | '[');
  246. !         }
  247. !     }
  248. !     /*-
  249. !      * another way -- using blocking read;
  250. !      * problem... when <esc> used as terminator, as in setup for
  251. !      * searches, need to give it twice, or whatever;
  252. !      * non-portable... assumes ansi standard for function keys and
  253. !      * keypad;
  254. !      */
  255. !     /*
  256. !     {
  257. !         extern char kbdq;
  258. !         extern int kbdqp;
  259. !         kbdq = ttgetc();
  260. !         kbdqp = 1;
  261. !         if ((kbdq & 255) != '[' && (kbdq & 255) != 'O')
  262. !             return(CTRL | '[');
  263. !     }
  264. !     */
  265.   #endif
  266.   
  267.       /* a key is pending within 1/30 of a sec... its an escape sequence */
  268. ***************
  269. *** 457,462
  270.       /* a key is pending within 1/30 of a sec... its an escape sequence */
  271.       cseq[0] = 27;
  272.       sp = &cseq[1];
  273.       while (sp < &cseq[6]) {
  274.           c = ttgetc();
  275.           *sp++ = c;
  276.  
  277. --- 586,592 -----
  278.       /* a key is pending within 1/30 of a sec... its an escape sequence */
  279.       cseq[0] = 27;
  280.       sp = &cseq[1];
  281. +     *sp = 0;
  282.       while (sp < &cseq[6]) {
  283.           c = ttgetc();
  284.           *sp++ = c;
  285.  
  286.  
  287.