[comp.emacs] Microemacs 3.10 - patch for tcap.c

rupley@arizona.edu (John Rupley) (06/09/89)

context diff patch for tcap.c:

1) added timeout loop in get1key(), for USG option; without it, one
cannot use the function keys under sys5; it could be made more portable
by #defining the processor speed, or building in a test for it;
commented-out code gives an alternative solution, without a timeout
loop.

2) modified ttable[], to allow shifted function keys and some other stuff.

3) sample terminfo, consistent with (2), included in comment.


John Rupley
    uucp: ..{uunet | ucbvax | cmcl2 | hao!ncar!noao}!arizona!rupley!local
    internet: rupley!local@megaron.arizona.edu
    (H) 30 Calle Belleza, Tucson AZ  85716 - (602) 325-4533
    (O) Dept. Biochemistry, Univ. Arizona, Tucson AZ 85721 - (602) 621-3929
------------------------------------------------------------------------
*** tcap.c	Mon May 22 16:21:08 1989
--- ../tcap.c	Fri May 26 13:47:56 1989
***************
*** 70,75
                      
  */
  
  #define termdef 1			/* don't define "term" external */
  
  #include <stdio.h>

--- 70,135 -----
                      
  */
  
+ /*
+  * a non-portable but generally usable USG option for get1key() is suggested;
+  * it allows use of the function keys needed to handle menus, specifically
+  * those of .emacsrc and the *.cmd files; 
+  *
+  * it assumes typeahead() is enabled;
+  *
+  * the ttable[] bindings include shifted function and keypad keys;
+  *
+  * following is a sample ansi terminfo file, which has strings for the 
+  * normal and shifted keys, and which adheres more-or-less to the 
+  * ansi standard;
+  *
+  * a user without write permission on the system terminfo files likely
+  * will have to set up a local TERMINFO environment by use of .profile,
+  * and perhaps reprogram the function and keypad strings of the terminal;
+  *
+  * j.a. rupley, tucson, az  - rupley!local@megaron.arizona.edu
+  */
+ 
+ /*-
+ ansi|modified terminfo description 
+ # DELETE #...# COMMENTS #...# BEFORE #...# TIC'ING #
+ # standard stuff #
+ 	am, xon, cols#80, lines#24, bel=^G, cr=\r, clear=\E[H\E[J, 
+ 	el=\E[K, ed=\E[J, cup=\E[%i%p1%d;%p2%dH, cud1=\n, home=\E[H, 
+ 	cub1=\b, cuf1=\E[C, cuu1=\E[A, dch1=\E[P, dl1=\E[M, blink=\E[5m, 
+ 	bold=\E[1m, smir=\E[4h, invis=\E[8m, rev=\E[7m, smso=\E[7m, 
+ 	smul=\E[4m, sgr0=\E[m, rmir=\E[4l, rmso=\E[0m, rmul=\E[0m, 
+ 	is2=\E[=h, ich1=\E[@, il1=\E[L, 
+ 	dl=\E[%p1%dM, cud=\E[%p1%dB, 
+ 	ich=\E[%p1%d@, il=\E[%p1%dL, cub=\E[%p1%dD, cuf=\E[%p1%dC, 
+ 	cuu=\E[%p1%dA, ind=\n, ht=\t, 
+ # function keys - kf0=kf10 #
+ 	kf1=\EOc, kf2=\EOd, kf3=\EOe, kf4=\EOf, 
+ 	kf5=\EOg, kf6=\EOh, kf7=\EOi, kf8=\EOj, kf9=\EOk, 
+ 	kf0=\EOl, kf10=\EOl, 
+ # shifted function keys - lf0=lf10 #
+ # tricky - store and recover strings as labels #
+ 	lf1=\EOC, lf2=\EOD, lf3=\EOE, lf4=\EOF, 
+ 	lf5=\EOG, lf6=\EOH, lf7=\EOI, lf8=\EOJ, lf9=\EOK, 
+ 	lf0=\EOL, lf10=\EOL, 
+ # keypad keys #
+ 	khome=\E[H,	kcuu1=\E[A,	kpp=\E[U, 
+ 	kcub1=\E[D, 			kcuf1=\E[C, 
+ 	kll=\E[E, 	kcud1=\E[B, 	knp=\E[V, 
+ # ins #
+ 	kich1=\E[@, 
+ # shifted keypad keys #
+ 	ka1=\E[!H,	kri=\E[S,	ka3=\E[!U, 
+ 	kclr=\E[!@,			kel=\E[!A, 
+ 	kc1=\E[!E,	kind=\E[T,	kc3=\E[!V,
+ # shifted ins and shifted del #
+ 	kil1=\E[L,			kdch1=\E[P,
+ # miscellaneous #
+ 	kdl1=\E[M, 
+ 	cbt=\E[Z, 
+ 	kbs=\b, 
+ */
+ 
  #define termdef 1			/* don't define "term" external */
  
  #include <stdio.h>
***************
*** 103,136
  } TBIND;
  
  TBIND ttable[] = {
! 	"bt",	SHFT | CTRL | 'i',	"",	/* backtab */
! 	"k1",	SPEC | '1',		"",	/* function key 1 */
! 	"k2",	SPEC | '2',		"",	/* function key 2 */
! 	"k3",	SPEC | '3',		"",	/* function key 3 */
! 	"k4",	SPEC | '4',		"",	/* function key 4 */
! 	"k5",	SPEC | '5',		"",	/* function key 5 */
! 	"k6",	SPEC | '6',		"",	/* function key 6 */
! 	"k7",	SPEC | '7',		"",	/* function key 7 */
! 	"k8",	SPEC | '8',		"",	/* function key 8 */
! 	"k9",	SPEC | '9',		"",	/* function key 9 */
! 	"k0",	SPEC | '0',		"",	/* function key 10 */
! 	"kA",	CTRL | 'O',		"",	/* insert line */
! 	"kb",	CTRL | 'H',		"",	/* backspace */
! 	"kC",	CTRL | 'L',		"",	/* clear screen */
! 	"kD",	SPEC | 'D',		"",	/* delete character */
! 	"kd",	SPEC | 'N',		"",	/* down cursor */
! 	"kE",	CTRL | 'K',		"",	/* clear to end of line */
! 	"kF",	CTRL | 'V',		"",	/* scroll down */
! 	"kH",	SPEC | '>',		"",	/* home down [END?] key */
! 	"kh",	SPEC | '<',		"",	/* home */
! 	"kI",	SPEC | 'C',		"",	/* insert character */
! 	"kL",	CTRL | 'K',		"",	/* delete line */
! 	"kl",	SPEC | 'B',		"",	/* left cursor */
! 	"kN",	SPEC | 'V',		"",	/* next page */
! 	"kP",	SPEC | 'Z',		"",	/* previous page */
! 	"kR",	CTRL | 'Z',		"",	/* scroll down */
! 	"kr",	SPEC | 'F',		"",	/* right cursor */
! 	"ku",	SPEC | 'P',		"",	/* up cursor */
  };
  
  #define	NTBINDS	sizeof(ttable)/sizeof(TBIND)

--- 163,232 -----
  } TBIND;
  
  TBIND ttable[] = {
! 	"k1",	SPEC | '1',		"",	/* kf1 /* function key 1 */
! 	"k2",	SPEC | '2',		"",	/* kf2 /* function key 2 */
! 	"k3",	SPEC | '3',		"",	/* kf3 /* function key 3 */
! 	"k4",	SPEC | '4',		"",	/* kf4 /* function key 4 */
! 	"k5",	SPEC | '5',		"",	/* kf5 /* function key 5 */
! 	"k6",	SPEC | '6',		"",	/* kf6 /* function key 6 */
! 	"k7",	SPEC | '7',		"",	/* kf7 /* function key 7 */
! 	"k8",	SPEC | '8',		"",	/* kf8 /* function key 8 */
! 	"k9",	SPEC | '9',		"",	/* kf9 /* function key 9 */
! 	"k0",	SPEC | '0',		"",	/* kf0 /* function key 10 */
! 	"l1",	SPEC | SHFT | '1',	"",	/* kl1 /* shftd func key 1 */
! 	"l2",	SPEC | SHFT | '2',	"",	/* kl2 /* shftd func key 2 */
! 	"l3",	SPEC | SHFT | '3',	"",	/* kl3 /* shftd func key 3 */
! 	"l4",	SPEC | SHFT | '4',	"",	/* kl4 /* shftd func key 4 */
! 	"l5",	SPEC | SHFT | '5',	"",	/* kl5 /* shftd func key 5 */
! 	"l6",	SPEC | SHFT | '6',	"",	/* kl6 /* shftd func key 6 */
! 	"l7",	SPEC | SHFT | '7',	"",	/* kl7 /* shftd func key 7 */
! 	"l8",	SPEC | SHFT | '8',	"",	/* kl8 /* shftd func key 8 */
! 	"l9",	SPEC | SHFT | '9',	"",	/* kl9 /* shftd func key 9 */
! 	"l0",	SPEC | SHFT | '0',	"",	/* kl0 /* shftd func key 10 */
! /* the following key-pad keys and their bindings are obvious */
! 	"kh",	SPEC | '<',		"",	/* khome /* home */
! 	"ku",	SPEC | 'P',		"",	/* kcuu1 /* up cursor */
! 	"kP",	SPEC | 'Z',		"",	/* kpp /* previous page */
! 	"kl",	SPEC | 'B',		"",	/* kcub1 /* left cursor */
! 	"kr",	SPEC | 'F',		"",	/* kcuf1 /* right cursor */
! 	"kH",	SPEC | '>',		"",	/* kll /* home down [END] */
! 	"kd",	SPEC | 'N',		"",	/* kcud1 /* down cursor */
! 	"kN",	SPEC | 'V',		"",	/* knp /* next page */
! /* the following are less obvious */
! /* ins		# kI kich1  insert character */	/* bound to insspace */
! 	"kI",	SPEC | 'C',		"",	/* kich1 /* insert character */
! /* shift del	# kD kdch1  delete character */	/* bound to forwdel */
! 	"kD",	SPEC | 'D',		"",	/* kdch1 /* delete character */
! /* shift ins	# kA kil1  insert line */ 	/* bound to openline */
! 	"kA",	CTRL | 'O',		"",	/* kil1 /* insert line */
! /* shift up	# kR kri  scroll up */		/* bound to backpage */
! 	"kR",	CTRL | 'Z',		"",	/* kri /* scroll up */
! /* shift down	# kF kind  scroll down */	/* bound to forwpage */
! 	"kF",	CTRL | 'V',		"",	/* kind /* scroll down */
! /* shift left	# kC kclr  clear screen */	/* bound to backword */
! /*	"kC",	META | 'B',		"",	/* kclr /* clear screen */
! 	"kC",	SPEC | CTRL | 'B',	"",	/* kclr /* clear screen */
! /* shift right	# kE kel  clear to eol */	/* bound to forwword */
! /*	"kE",	META | 'F',		"",	/* kel /* clear to eol */
! 	"kE",	SPEC | CTRL | 'F',	"",	/* kel /* clear to eol */
! /* shift pgup	# K3 ka3  pad upper right */	/* bound to gotobop */
! /*	"K3",	META | 'P',		"",	/* ka3 /* pad upper right */
! 	"K3",	SPEC | CTRL | 'Z',	"",	/* ka3 /* pad upper right */
! /* shift pgdn	# K5 kc3  pad lower right */	/* bound to gotoeop */
! /*	"K5",	META | 'N',		"",	/* kc3 /* pad lower right */
! 	"K5",	SPEC | CTRL | 'V',	"",	/* kc3 /* pad lower right */
! /* shift home	# K1 ka1  pad upper left */	/* unbound key */
! 	"K1",	SPEC | CTRL | '<',	"",	/* ka1 /* pad upper left */
! /* shift end	# K4 kc1  pad lower left */	/* unbound key */
! 	"K4",	SPEC | CTRL | '>',	"",	/* kc1 /* pad lower left */
! /* shift tab 	# bt cbt backtab		/* unbound key */
! 	"bt",	SHFT | CTRL | 'i',	"",	/* cbt /* backtab */
! /* and let's forget the following */
! /* alt del	# kL kdl1  delete line */
! /*	"kL",	CTRL | 'K',		"",	/* kdl1 /* delete line */
! /*	"kb",	CTRL | 'H',		"",	/* kbs /* backspace */
! /*	"kC",	CTRL | 'L',		"",	/* kclr /* clear screen */
! /*	"kE",	CTRL | 'K',		"",	/* kel /* clear to eol */
  };
  
  #define	NTBINDS	sizeof(ttable)/sizeof(TBIND)
***************
*** 450,457
  	/* we don't know how to do this check for a pending char within
  	   1/30th of a second machine independantly in the general System V
  	   case.... so we don't */
! 	if (kbdmode != PLAY)
! 		return(CTRL | '[');
  #endif
  
  	/* a key is pending within 1/30 of a sec... its an escape sequence */

--- 546,586 -----
  	/* we don't know how to do this check for a pending char within
  	   1/30th of a second machine independantly in the general System V
  	   case.... so we don't */
! 	/*
! 	 * or... maybe we try it;
! 	 * very non-portable solution;
! 	 * hardware-dependent timing loop;
! 	 * set upper-limit on loop by testing hardware, to get 30 ms;
! 	 * use typahead() to check for waiting input on exit from loop;
! 	 */
! 	{	int i;
! 		if (kbdmode != PLAY && typahead() <= 0) {
! 			/* loop limit set by hardware test */
! 			/* for 30 ms or a bit less */
! 			for (i = 0; i < 1500; i++)
! 				;
! 			if (typahead() <= 0)
! 				return(CTRL | '[');
! 		}
! 	}
! 	/*-
! 	 * another way -- using blocking read;
! 	 * problem... when <esc> used as terminator, as in setup for
! 	 * searches, need to give it twice, or whatever;
! 	 * non-portable... assumes ansi standard for function keys and
! 	 * keypad;
! 	 */
! 	/*
! 	{
! 		extern char kbdq;
! 		extern int kbdqp;
! 
! 		kbdq = ttgetc();
! 		kbdqp = 1;
! 		if ((kbdq & 255) != '[' && (kbdq & 255) != 'O')
! 			return(CTRL | '[');
! 	}
! 	*/
  #endif
  
  	/* a key is pending within 1/30 of a sec... its an escape sequence */
***************
*** 457,462
  	/* a key is pending within 1/30 of a sec... its an escape sequence */
  	cseq[0] = 27;
  	sp = &cseq[1];
  	while (sp < &cseq[6]) {
  		c = ttgetc();
  		*sp++ = c;

--- 586,592 -----
  	/* a key is pending within 1/30 of a sec... its an escape sequence */
  	cseq[0] = 27;
  	sp = &cseq[1];
+ 	*sp = 0;
  	while (sp < &cseq[6]) {
  		c = ttgetc();
  		*sp++ = c;