[comp.os.minix] Patches to stkbd.c

poole@forty2.UUCP (Simon Poole) (01/30/89)

Here are the patches to stkbd.c I mentioned, besides fixing the
<Shift><ClrHome> bug, they add some more function keys (see the
README).
NOTE: these patches are in no way official.......

-------------------------------------------------------------------
echo x - README
gres '^X' '' > README << '/'
XChanges to stkbd.c and stvdu.c
X==============================
XS.Poole 30.1.89
X
Xstkbd.c: to work around the slightly chaotic assignment of keycodes
X         and to make the detection of function keys more robust, 
X         I've added a fourth table to stkbd.c. Keycodes that
X         have 0 as an entry in this table belong to normal keys,
X         other values are used as an index in to a table that
X         contains part of the character sequence to produce, see
X         the source code for more details.
X         If COMPAT is defined, the only difference to the ST-
X         Minix 1.1 is that <Shift><ClrHome> works and that <Insert>
X         generates ESC [I , if COMPAT is not defined, the following
X         sequences are generated:
X
X	 Function keys
X	 =============
X
X	 Key       	     + Shift     VT200 key	
X
X	 F1       ESC O1~    ESC O21~	Find	F10	
X	 F2       ESC O2~    ESC O23~	Insert	F11	
X	 F3       ESC O3~    ESC O24~	Remove	F12	
X	 F4       ESC O4~    ESC O25~	Select	F13	
X	 F5       ESC O5~    ESC O26~	Prev.	F14	
X	 F6       ESC O6~    ESC O31~	Next	F17	
X	 F7       ESC O17~   ESC O32~	F6	F18	
X	 F8       ESC O18~   ESC O33~	F7	F19	
X	 F9       ESC O19~   ESC O34~	F8	F20	
X	 F10      ESC O20~   ESC O35~	F9		
X	 Undo     ESC O36~   ESC O37~			
X	 Help     ESC O28~   ESC O29~	Help	Do	
X 
X         Arrow keys
X         ==========
X
X		  Normal	Application mode
X
X	 Left     ESC [D	ESC OD
X	 Down     ESC [B	ESC OB
X	 Right    ESC [C	ESC OC
X	 Up       ESC [A	ESC OA
X	 ClrHome  ESC [H	ESC OH
X          + Shift ESC [J	ESC OJ
X	 Insert   ESC [I	ESC OI
X 
X         Keypad
X         ====== 
X 
X         Key (numeric mode)     application mode
X     
X	 (        		ESC OP
X	 )        		ESC OQ
X	 /        		ESC OR
X	 *        		ESC OS
X	 7        		ESC Ow
X	 8        		ESC Ox
X	 9        		ESC Oy
X	 -        		ESC Om
X	 4        		ESC Ot
X	 5        		ESC Ou
X	 6        		ESC Ov
X	 +        		ESC Ol
X	 1        		ESC Oq
X	 2        		ESC Ow
X	 3        		ESC Os
X	 0        		ESC Op
X	 .        		ESC On
X	 Enter    		ESC OM
X
X
XNOTE: 
X	- the keypad is not 100% compatible with a VTXXX, since
X	  the top row of keys ('(',')','/','*') should always
X	  generate the escape sequences.
X
X	- the power-on defaults are:  
X	     arrow keys: normal mode
X	     keypad: application mode
X                     (this is a bit in conflict with the patches
X                      to stvdu.c, but it enables you to ignore the
X                      changes to stvdu.c and still have the keypad)
X
X	- without the patches to stvdu.c the modes of the arrow keys
X          and the kepad cannot be changed.
X
X
X
Xstvdu.c: additional escape sequences:
X
X		ESC [?1l     set arrow key application mode
X                ESC [?1l     reset          "
X
X                ESC >        keypad numeric mode
X                ESC =        keypad application mode
X
X
XNOTE: 
X	- after a reset (ESC c) the modes are set to:
X             arrow keys:   normal mode
X             keypad: numeric mode
X
X****************************************************************************
/
echo x - stkbd.cdiff
gres '^X' '' > stkbd.cdiff << '/'
X*** ORIG/stkbd.c	Thu Jan 21 20:15:59 1989
X--- stkbd.c	Thu Jan 30 01:17:13 1989
X***************
X*** 1,6 ****
X--- 1,15 ----
X  #ifdef ATARI_ST
X  /*
X   * The ACIA driver for the Atari ST, both MDI and KBD
X+  *
X+  * Modified the original 1.1 code to support more
X+  * function keys and provide a robust way of determing
X+  * which keys are function keys. 
X+  * Note: defining COMPAT will result in key definitions
X+  *       that are the same as for Minix 1.1 with the
X+  *       exception that <Shift><ClrHome> works and
X+  *       <Insert> generates ESC [I
X+  *                                    S.Poole 21.1.89 
X   */
X  #include "../h/const.h"
X  #include "../h/type.h"
X***************
X*** 98,103 ****
X--- 107,261 ----
X  /*78*/	   0,   0,   0,   0,   0,   0,   0,   0
X  };
X  
X+ /*
X+  * Flag for keypad mode
X+  * this can be set by code in stvdu.c
X+  */
X+ #ifdef COMPAT
X+ PUBLIC int keypad = FALSE;
X+ #else
X+ PUBLIC int keypad = TRUE;
X+ #endif
X+ /*
X+  * Flag for arrow key application mode
X+  * this can be set by code in stvdu.c
X+  */
X+ PUBLIC int app_mode = FALSE;
X+ 
X+ /* 
X+  * Map function keys to an index into the 
X+  * table of function key values 
X+  */
X+ PRIVATE unsigned char f_keys[] = {
X+ /*00*/	   0,   0,   0,   0,   0,   0,   0,   0,
X+ /*08*/	   0,   0,   0,   0,   0,   0,   0,   0,
X+ /*10*/	   0,   0,   0,   0,   0,   0,   0,   0,
X+ /*18*/	   0,   0,   0,   0,   0,   0,   0,   0,
X+ /*20*/	   0,   0,   0,   0,   0,   0,   0,   0,
X+ /*28*/	   0,   0,   0,   0,   0,   0,   0,   0,
X+ /*30*/	   0,   0,   0,   0,   0,   0,   0,   0,
X+ /*38*/	   0,   0,   0,   1,   2,   3,   4,   5,
X+ /*40*/	   6,   7,   8,   9,  10,   0,   0,  17,
X+ /*48*/	  16,   0,  26,  13,   0,  15,  30,   0,
X+ /*50*/	  14,   0,  18,   0,   1,   2,   3,   4,
X+ /*58*/	   5,   6,   7,   8,   9,  10,   0,   0,
X+ /*60*/	   0,  11,  12,  19,  20,  21,  22,  23,
X+ /*68*/	  24,  25,  27,  28,  29,  31,  32,  33,
X+ /*70*/	  34,  35,  36,   0,   0,   0,   0,   0,
X+ /*78*/	   0,   0,   0,   0,   0,   0,   0,   0
X+ };
X+ 
X+ /*
X+  * Numbering of the function keys, this scheme was chosen
X+  * so that it easy to determine which function to call to actually
X+  * generate the string.
X+  *
X+  * Note: the <Help> and <Undo> keys are considered to be function
X+  *       keys 11 and 12.
X+  *
X+  * F-keys:    -----------------------------------------
X+  *            | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10|
X+  *            -----------------------------------------
X+  *
X+  * Arrow-Keys:    -------------
X+  *                |  12 |  11 |
X+  *                -------------
X+  *                | 18| 16| 17|
X+  *                -------------
X+  *                | 13| 14| 15|
X+  *                -------------
X+  *
X+  * Keypad:    -----------------
X+  *            | 19| 20| 21| 22|
X+  *            -----------------
X+  *            | 23| 24| 25| 26|
X+  *            -----------------
X+  *            | 27| 28| 29| 30|
X+  *            -----------------
X+  *            | 31| 32| 33|   |
X+  *            ------------- 36|
X+  *            |   34  | 35|   |
X+  *            -----------------
X+  */     
X+ 
X+ /* 
X+  * There is no problem with  expanding this struct to
X+  * have a field for <Control> and <Alternate> (and combinations
X+  * of them),  but who needs > 152 function keys? 
X+  */
X+ struct fkey {
X+ 	char norm, shift;
X+ };
X+ 
X+ PRIVATE struct fkey ftbl[] = {
X+ #ifdef COMPAT
X+ 	/* 1  = F1      */ {'P',   0},
X+ 	/* 2  = F2      */ {'Q',   0},
X+ 	/* 3  = F3      */ {'R',   0},
X+ 	/* 4  = F4      */ {'S',   0},
X+ 	/* 5  = F5      */ {'T',   0},
X+ 	/* 6  = F6      */ {'U',   0},
X+ 	/* 7  = F7      */ {'V',   0},
X+ 	/* 8  = F8      */ {'W',   0},
X+ 	/* 9  = F9      */ {'X',   0},
X+ 	/* 10 = F10     */ {'Y',   0},
X+ 	/* 11 = Undo    */ {  0,   0},
X+ 	/* 12 = Help    */ {  0,   0},
X+ #else
X+ /* 
X+  * So that we can produce VT200 style function-key codes, 
X+  * the values here are integer values that are converted
X+  * to a string in kbdpf(). 
X+  *
X+  * The assignment of numbers to keys is rather chaotic,
X+  * but at least all the VT200 keys are there.
X+  */
X+ 	/* ST key       */		/* VT200 key	*/
X+ 	/* 1  = F1      */ {  1,  21},	/* Find	  F10	*/
X+ 	/* 2  = F2      */ {  2,  23},	/* Insert F11	*/
X+ 	/* 3  = F3      */ {  3,  24},	/* Remove F12	*/
X+ 	/* 4  = F4      */ {  4,  25},	/* Select F13	*/
X+ 	/* 5  = F5      */ {  5,  26},	/* Prev.  F14	*/
X+ 	/* 6  = F6      */ {  6,  31},	/* Next	  F17	*/
X+ 	/* 7  = F7      */ { 17,  32},	/* F6	  F18	*/
X+ 	/* 8  = F8      */ { 18,  33},	/* F7	  F19	*/
X+ 	/* 9  = F9      */ { 19,  34},	/* F8	  F20	*/
X+ 	/* 10 = F10     */ { 20,  35},	/* F9		*/
X+ 	/* 11 = Undo    */ { 36,  37},	/*		*/
X+ 	/* 12 = Help    */ { 28,  29},	/* Help	  Do	*/
X+ #endif
X+ /* 
X+  * The following codes are more conventional 
X+  */
X+ 	/* 13 = Left    */ {'D',   0},
X+ 	/* 14 = Down    */ {'B',   0},
X+ 	/* 15 = Right   */ {'C',   0},
X+ 	/* 16 = Up      */ {'A',   0},
X+ 	/* 17 = ClrHome */ {'H', 'J'},
X+ 	/* 18 = Insert  */ {'I',   0},
X+ /* 
X+  * Keypad starts here 
X+  */
X+ 	/* 19 = (       */ {'P',   0},
X+ 	/* 20 = )       */ {'Q',   0},
X+ 	/* 21 = /       */ {'R',   0},
X+ 	/* 22 = *       */ {'S',   0},
X+ 	/* 23 = 7       */ {'w',   0},
X+ 	/* 24 = 8       */ {'x',   0},
X+ 	/* 25 = 9       */ {'y',   0},
X+ 	/* 26 = -       */ {'m',   0},
X+ 	/* 27 = 4       */ {'t',   0},
X+ 	/* 28 = 5       */ {'u',   0},
X+ 	/* 29 = 6       */ {'v',   0},
X+ 	/* 30 = +       */ {'l',   0},
X+ 	/* 31 = 1       */ {'q',   0},
X+ 	/* 32 = 2       */ {'w',   0},
X+ 	/* 33 = 3       */ {'s',   0},
X+ 	/* 34 = 0       */ {'p',   0},
X+ 	/* 35 = .       */ {'n',   0},
X+ 	/* 36 = Enter   */ {'M',   0}
X+ };
X+ 
X  PRIVATE int	shift1, shift2, capslock, control, alt;	
X  				/* keep track of key statii */
X  PRIVATE char	kbdbuf[2*MAX_OVERRUN+2];
X***************
X*** 161,175 ****
X   *===========================================================================*/
X  PRIVATE kbdkey(code)
X  {
X!   register c;
X! 
X    if (shift1 || shift2)
X  	c = keyshft[code];
X    else if (capslock)
X  	c = keycaps[code];
X    else
X  	c = keynorm[code];
X!   if (c) {
X  	if (alt)
X  		c = national(code, c | 0x80);
X  	if (control) {
X--- 319,337 ----
X   *===========================================================================*/
X  PRIVATE kbdkey(code)
X  {
X!   register int c,f,fc;
X! 
X!   f = f_keys[code];
X    if (shift1 || shift2)
X  	c = keyshft[code];
X    else if (capslock)
X  	c = keycaps[code];
X    else
X  	c = keynorm[code];
X!   /* 
X!    * check if the key is not a function key 
X!    */
X!   if (!f) {
X  	if (alt)
X  		c = national(code, c | 0x80);
X  	if (control) {
X***************
X*** 195,236 ****
X  	kbdput(code - 0x3B + 1, OPERATOR);
X  	return;
X    }
X!   switch (code) {
X!   case 0x3B:	/* PF1 */
X! 	kbdpf('P'); return;
X!   case 0x3C:	/* PF2 */
X! 	kbdpf('Q'); return;
X!   case 0x3D:	/* PF3 */
X! 	kbdpf('R'); return;
X!   case 0x3E:	/* PF4 */
X! 	kbdpf('S'); return;
X!   case 0x3F:	/* PF5 */
X! 	kbdpf('T'); return;
X!   case 0x40:	/* PF6 */
X! 	kbdpf('U'); return;
X!   case 0x41:	/* PF7 */
X! 	kbdpf('V'); return;
X!   case 0x42:	/* PF8 */
X! 	kbdpf('W'); return;
X!   case 0x43:	/* PF9 */
X! 	kbdpf('X'); return;
X!   case 0x44:	/* PF10 */
X! 	kbdpf('Y'); return;
X!   case 0x47:	/* Home/Clr */
X! 	kbdansi('H');
X! 	if (shift1 || shift2)
X! 		kbdansi('J');
X! 	return;
X!   case 0x48:	/* Up */
X! 	kbdansi('A'); return;
X!   case 0x4B:	/* Left */
X! 	kbdansi('D'); return;
X!   case 0x4D:	/* Right */
X! 	kbdansi('C'); return;
X!   case 0x50:	/* Down */
X! 	kbdansi('B'); return;
X!   default:
X! 	return;
X    }
X  }
X  
X--- 357,393 ----
X  	kbdput(code - 0x3B + 1, OPERATOR);
X  	return;
X    }
X!   f--; /* correct for index into ftbl */
X!   if (shift1 || shift2)
X! 	fc = ftbl[f].shift;
X!   else
X! 	fc = ftbl[f].norm;
X!   /* 
X!    * f naturally has to be >= 0 for this piece 
X!    * of code to work 
X!    */
X!   if (fc) {
X! 	if (f < 12)
X! #ifdef COMPAT
X! 		kbdkeypad(fc);
X! #else
X! 		kbdpf(fc);
X! #endif
X! 	else if (f < 18) {
X! #ifndef COMPAT
X! 		if (app_mode)
X! 			kbdkeypad(fc);
X! 		else
X! #endif
X! 			kbdarrow(fc);
X! 	}
X! 	else if (keypad)
X! 		/*
X! 		 * keypad should be set by stvdu
X! 		 */
X! 		kbdkeypad(fc);
X! 	else
X! 		kbdput(c,CONSOLE);
X    }
X  }
X  
X***************
X*** 314,322 ****
X  }
X  
X  /*
X!  * Input escape sequence for function keys
X!  */
X! PRIVATE kbdpf(c)
X  {
X  	kbdput('\033', CONSOLE);
X  	kbdput('O', CONSOLE);
X--- 471,479 ----
X  }
X  
X  /*
X!  * Input escape sequence for keypad keys
X!  */
X! PRIVATE kbdkeypad(c)
X  {
X  	kbdput('\033', CONSOLE);
X  	kbdput('O', CONSOLE);
X***************
X*** 324,338 ****
X  }
X  
X  /*
X!  * Input ANSI escape sequence
X!  */
X! PRIVATE kbdansi(c)
X  {
X  	kbdput('\033', CONSOLE);
X  	kbdput('[', CONSOLE);
X  	kbdput(c, CONSOLE);
X  }
X  
X  /*===========================================================================*
X   *				kb_timer				     *
X   *===========================================================================*/
X--- 481,514 ----
X  }
X  
X  /*
X!  * Input escape sequence for arrow keys
X!  */
X! PRIVATE kbdarrow(c)
X  {
X  	kbdput('\033', CONSOLE);
X  	kbdput('[', CONSOLE);
X  	kbdput(c, CONSOLE);
X  }
X  
X+ #ifndef COMPAT
X+ /*
X+  * Input escape sequence for function keys
X+  */
X+ PRIVATE kbdpf(c)
X+ register char c;
X+ {
X+ 	register int t;
X+ 
X+ 	kbdput('\033', CONSOLE);
X+ 	kbdput('[', CONSOLE);
X+ 	/* this stuff is not robust */
X+ 	if ((t = c / 10) > 0)
X+ 	  kbdput(t + '0', CONSOLE);	
X+ 	kbdput((c % 10) + '0', CONSOLE);
X+ 	kbdput('~', CONSOLE);
X+ }
X+ #endif
X+ 
X  /*===========================================================================*
X   *				kb_timer				     *
X   *===========================================================================*/
/
echo x - stvdu.cdiff
gres '^X' '' > stvdu.cdiff << '/'
X*** ORIG/stvdu.c	Thu Jan  2 13:41:28 1989
X--- stvdu.c	Thu Jan 30 03:13:12 1989
X***************
X*** 45,50 ****
X--- 45,52 ----
X  
X  EXTERN char font16[];
X  EXTERN char font8[];
X+ EXTERN int keypad;
X+ EXTERN int app_mode;
X  
X  /*===========================================================================*
X   *				start					     *
X***************
X*** 324,331 ****
X  	return;
X    case 'l': /* RM: reset mode */
X    case 'h': /* SM: set mode */
X! 	if (v->next[0] == '?' && v->next[1] == '5' && v->mono)
X! 		VIDEO->vd_rgb[0] = c == 'l' ? RGB_BLACK : RGB_WHITE;
X  	return;
X    case '~': /* Minix-ST specific escape sequence */
X  	/*
X--- 326,337 ----
X  	return;
X    case 'l': /* RM: reset mode */
X    case 'h': /* SM: set mode */
X! 	if (v->next[0] == '?') { /* DEC private modes */
X! 		if (v->next[1] == '5' && v->mono) /* DECSCNM */
X! 			VIDEO->vd_rgb[0] = c == 'l' ? RGB_BLACK : RGB_WHITE;
X! 		else if (v->next[1] == '1')	  /* DECCKM */
X! 			app_mode = c == 'l' ? TRUE : FALSE;
X! 	}
X  	return;
X    case '~': /* Minix-ST specific escape sequence */
X  	/*
X***************
X*** 400,405 ****
X--- 406,417 ----
X  	v->savcrow = v->crow;
X  	v->savattr = v->attr;
X  	return;
X+   case '=': /* DECKPAM: keypad application mode */ 
X+ 	keypad = TRUE;
X+ 	return;
X+   case '>': /* DECKPNM: keypad numeric mode */ 
X+ 	keypad = FALSE;
X+ 	return;
X    case 'E': /* NEL: next line */
X  	vductrl(015);
X  	/* fall through */
X***************
X*** 417,422 ****
X--- 429,436 ----
X    case 'c': /* RIS: reset to initial state */
X  	vduinit(&tty_struct[CONSOLE]);
X  	vducursor(0);
X+ 	keypad = FALSE;
X+ 	app_mode = FALSE;
X  	return;
X    default:
X  	return;
/
-- 
----------------------------------------------------------------------------
UUCP:   ...mcvax!cernvax!forty2!poole			Simon Poole
BITNET: K538915@CZHRZU1A
----------------------------------------------------------------------------