}
if (!done_esc && (a & ~0xFF) == 0) { if (a == b && !found_CSI(c,b) && c == CH_ESC) { current_modifier = LKC_MOD2; c = a; done_esc = TRUE; } else { done_esc = TRUE; } } } #ifdef USE_KEYMAPS  if (c >= 0 && (c&LKC_ISLECLAC)) { if (!(code == FOR_INPUT || code == FOR_PROMPT)) c = LKC2_TO_LKC(c); } else if (c >= 0 && (c&LKC_ISLKC)) { c &= ~LKC_ISLKC; done_esc = TRUE;  } if (c >= 0 && LKC_HAS_ESC_MOD(c)) { current_modifier = LKC_MOD2; c &= LKC_MASK; } if (c >= 0 && (c&(LKC_ISLECLAC|LKC_ISLAC))) { done_esc = TRUE;  } #endif if (done_esc) {  } else {
PUBLIC int LYgetch_for ARGS1(	int, 	code){    int a, b, c, d = -1;    have_levent = 0;#if defined(IGNORE_CTRL_C) || defined(USE_GETCHAR) || !defined(NCURSES)re_read:#endif /* IGNORE_CTRL_C || USE_GETCHAR */#ifndef USE_SLANG    clearerr(stdin); /* needed here for ultrix and SOCKETSHR, but why? - FM */#endif /* !USE_SLANG */#if !defined(USE_SLANG) || defined(VMS) || defined(DJGPP_KEYHANDLER)    c = GetChar();#else    if (LYCursesON) {	c = GetChar();    } else {	c = getchar();	if (c == EOF && errno == EINTR) /* Ctrl-Z causes EINTR in getchar() */	    clearerr(stdin);	if (feof(stdin) || ferror(stdin) || c == EOF) {#ifdef IGNORE_CTRL_C	    if (sigint)		sigint = FALSE;#endif /* IGNORE_CTRL_C */	    return(7); /* use ^G to cancel whatever called us. */	}    }#endif /* !USE_SLANG || VMS */#ifdef USE_GETCHAR    if (c == EOF && errno == EINTR)	/* Ctrl-Z causes EINTR in getchar() */	goto re_read;#endif /* USE_GETCHAR */#ifdef USE_SLANG    if (c == 0xFFFF && LYCursesON) {#ifdef IGNORE_CTRL_C	if (sigint) {	    sigint = FALSE;	    goto re_read;	}#endif /* IGNORE_CTRL_C */	return(7); /* use ^G to cancel whatever called us. */    }#else    if (feof(stdin) || ferror(stdin) || c == EOF) {	if (recent_sizechange)	    return(7); /* use ^G to cancel whatever called us. */#ifdef IGNORE_CTRL_C	if (sigint) {	    sigint = FALSE;	    /* clearerr(stdin);  don't need here if stays above - FM */	    goto re_read;	}#endif /* IGNORE_CTRL_C */#if !defined(USE_GETCHAR) && !defined(VMS) && !defined(NCURSES)	if (c == ERR && errno == EINTR) /* may have been handled signal - kw */	    goto re_read;#endif /* USE_GETCHAR */	cleanup();	exit_immediately(0);    }#endif /* USE_SLANG */    if (c == CH_ESC || (csi_is_csi && c == (unsigned char)CH_ESC_PAR)) { /* handle escape sequence  S/390 -- gil -- 2024 */	b = GetChar();	if (b == '[' || b == 'O') {	    a = GetChar();	} else {	    a = b;	}	switch (a) {	case 'A': c = UPARROW; break;	case 'x': c = UPARROW; break;  /* keypad up on pc ncsa telnet */	case 'B': c = DNARROW; break;	case 'r': c = DNARROW; break; /* keypad down on pc ncsa telnet */	case 'C': c = RTARROW; break;	case 'v': c = RTARROW; break; /* keypad right on pc ncsa telnet */	case 'D': c = LTARROW; break;	case 't': c = LTARROW; break;  /* keypad left on pc ncsa telnet */	case 'y': c = PGUP;    break;  /* keypad on pc ncsa telnet */	case 's': c = PGDOWN;  break;  /* keypad on pc ncsa telnet */	case 'w': c = HOME;    break;  /* keypad on pc ncsa telnet */	case 'q': c = END_KEY; break;  /* keypad on pc ncsa telnet */	case 'M':#ifdef USE_SLANG_MOUSE	   if (found_CSI(c,b))	     {		c = sl_read_mouse_event ();	     }	   else#endif	     c = '\n'; /* keypad enter on pc ncsa telnet */	   break;	case 'm':#ifdef VMS	    if (b != 'O')#endif /* VMS */		c = '-';  /* keypad on pc ncsa telnet */	    break;	case 'k':	    if (b == 'O')		c = '+';  /* keypad + on my xterminal :) */	    break;	case 'l':#ifdef VMS	    if (b != 'O')#endif /* VMS */		c = '+';  /* keypad on pc ncsa telnet */	    break;	case 'P':#ifdef VMS	    if (b != 'O')#endif /* VMS */		c = F1;	    break;	case 'u':#ifdef VMS	    if (b != 'O')#endif /* VMS */		c = F1;  /* macintosh help button */	    break;	case 'p':#ifdef VMS	    if (b == 'O')#endif /* VMS */		c = '0';  /* keypad 0 */	    break;	case '1':			    /** VTxxx  Find  **/	    if (found_CSI(c,b) && (d=GetChar()) == '~')		c = FIND_KEY;	    break;	case '2':	    if (found_CSI(c,b)) {		if ((d=GetChar())=='~')     /** VTxxx Insert **/		    c = INSERT_KEY;		else if ((d == '8' ||			  d == '9') &&			 GetChar() == '~')		 {		    if (d == '8')	     /** VTxxx	Help **/			c = F1;		    else if (d == '9')	     /** VTxxx	 Do  **/			c = DO_KEY;		    d = -1;		 }	    }	    break;	case '3':			     /** VTxxx Delete **/	    if (found_CSI(c,b) && (d=GetChar()) == '~')		c = REMOVE_KEY;	    break;	case '4':			     /** VTxxx Select **/	    if (found_CSI(c,b) && (d=GetChar()) == '~')		c = SELECT_KEY;	    break;	case '5':			     /** VTxxx PrevScreen **/	    if (found_CSI(c,b) && (d=GetChar()) == '~')		c = PGUP;	    break;	case '6':			     /** VTxxx NextScreen **/	    if (found_CSI(c,b) && (d=GetChar()) == '~')		c = PGDOWN;	    break;	case '[':			     /** Linux F1-F5: ^[[[A etc. **/	    if (found_CSI(c,b)) {		if ((d=GetChar()) == 'A')		    c = F1;		break;	    }	default:	    CTRACE(tfp,"Unknown key sequence: %d:%d:%d\n",c,b,a);	    CTRACE_SLEEP(MessageSecs);	    break;	}	if (isdigit(a) && found_CSI(c,b) && d != -1 && d != '~')	    d = GetChar();    }#if HAVE_KEYPAD    else {	/*	 *  Convert keypad() mode keys into Lynx defined keys.	 */	switch(c) {	case KEY_DOWN:		   /* The four arrow keys ... */	   c = DNARROW;	   break;	case KEY_UP:	   c = UPARROW;	   break;	case KEY_LEFT:	   c = LTARROW;	   break;	case KEY_RIGHT: 	   /* ... */	   c = RTARROW;	   break;	case KEY_HOME:		   /* Home key (upward+left arrow) */	   c = HOME;	   break;	case KEY_CLEAR: 	   /* Clear screen */	   c = 18; /* CTRL-R */	   break;	case KEY_NPAGE: 	   /* Next page */	   c = PGDOWN;	   break;	case KEY_PPAGE: 	   /* Previous page */	   c = PGUP;	   break;	case KEY_LL:		   /* home down or bottom (lower left) */	   c = END_KEY;	   break;					/* The keypad is arranged like this:*/					/*    a1    up	  a3   */					/*   left   b2	right  */					/*    c1   down   c3   */	case KEY_A1:		   /* upper left of keypad */	   c = HOME;	   break;	case KEY_A3:		   /* upper right of keypad */	   c = PGUP;	   break;	case KEY_B2:		   /* center of keypad */	   c = DO_NOTHING;	   break;	case KEY_C1:		   /* lower left of keypad */	   c = END_KEY;	   break;	case KEY_C3:		   /* lower right of keypad */	   c = PGDOWN;	   break;#ifdef KEY_ENTER	case KEY_ENTER:		   /* enter/return	*/	   c = '\n';	   break;#endif /* KEY_ENTER */#ifdef PADENTER			   /* PDCURSES */	case PADENTER:	   c = '\n';	   break;#endif /* PADENTER */#ifdef KEY_END	case KEY_END:		   /* end key		001 */	   c = END_KEY;	   break;#endif /* KEY_END */#ifdef KEY_HELP	case KEY_HELP:		   /* help key		001 */	   c = F1;	   break;#endif /* KEY_HELP */#ifdef KEY_BACKSPACE	case KEY_BACKSPACE:	   c = CH_DEL;		   /* backspace key (delete, not Ctrl-H)  S/390 -- gil -- 2041 */	   break;#endif /* KEY_BACKSPACE */	case KEY_F(1):	   c = F1;		   /* VTxxx Help */	   break;#if defined(KEY_F) && !defined(__DJGPP__) && !defined(_WINDOWS)	case KEY_F(16):	   c = DO_KEY;		   /* VTxxx Do */	   break;#endif /* KEY_F */#ifdef KEY_REDO	case KEY_REDO:		   /* VTxxx Do */	   c = DO_KEY;	   break;#endif /* KEY_REDO */#ifdef KEY_FIND	case KEY_FIND:	   c = FIND_KEY;	   /* VTxxx Find */	   break;#endif /* KEY_FIND */#ifdef KEY_SELECT	case KEY_SELECT:	   c = SELECT_KEY;	   /* VTxxx Select */	   break;#endif /* KEY_SELECT */#ifdef KEY_IC	case KEY_IC:	   c = INSERT_KEY;	   /* VTxxx Insert */	   break;#endif /* KEY_IC */#ifdef KEY_DC	case KEY_DC:	   c = REMOVE_KEY;	   /* VTxxx Remove */	   break;#endif /* KEY_DC */#ifdef KEY_BTAB	case KEY_BTAB:	   c = BACKTAB_KEY;	   /* Back tab, often Shift-Tab */	   break;#endif /* KEY_BTAB *//* The following maps PDCurses keys away from lynx reserved values */#if (defined(_WINDOWS) || defined(__DJGPP__)) && !defined(USE_SLANG)	case KEY_F(2):	   c = 0x213;	   break;	case KEY_F(3):	   c = 0x214;	   break;	case KEY_F(4):	   c = 0x215;	   break;	case KEY_F(5):	   c = 0x216;	   break;	case KEY_F(6):	   c = 0x217;	   break;	case KEY_F(7):	   c = 0x218;	   break;#endif /* PDCurses */#ifdef NCURSES_MOUSE_VERSION	case KEY_MOUSE:	    if (code == FOR_CHOICE) {		c = MOUSE_KEY;		/* Will be processed by the caller */	    } else {#ifndef DOSPATH		MEVENT event;		int err;		c = -1;		mouse_link = -1;		err = getmouse(&event);		levent = event;		/* Allow setting pos in entry fields */		if (event.bstate & BUTTON1_CLICKED) {		    c = set_clicked_link(event.x, event.y, code);		} else if (event.bstate & BUTTON1_DOUBLE_CLICKED) {		    c = set_clicked_link(event.x, event.y, code);		    if (c == PGDOWN)			c = END_KEY;		    else if (c == PGUP)			c = HOME;		    else if (c == LTARROW)			c = LYReverseKeymap(LYK_MAIN_MENU);		} else if (event.bstate & BUTTON3_CLICKED) {		    c = LYReverseKeymap (LYK_PREV_DOC);		} else if (event.bstate & BUTTON2_CLICKED) {		    int atlink;		    c = set_clicked_link(event.x, event.y, code);		    atlink = c == LYReverseKeymap (LYK_ACTIVATE);		    if (!atlink)			mouse_link = -1; /* Forget about approx stuff. */		    c = LYmouse_menu(event.x, event.y, atlink);		    if (c == LYK_ACTIVATE && mouse_link == -1) {			HTAlert("No link chosen");			c = LYK_DO_NOTHING;			c = LYK_REFRESH; /* refresh() below does not work... */		    }		    c = LYReverseKeymap(c);		    lynx_force_repaint();		    refresh();		}		if (code == FOR_INPUT && mouse_link == -1) {		    ungetmouse(&event);	/* Caller will process this. */		    getch();		/* ungetmouse puts KEY_MOUSE back */		    c = MOUSE_KEY;		}#else /* pdcurses version */		c = -1;		mouse_link = -1;		request_mouse_pos();		if (BUTTON_STATUS(1) & BUTTON_CLICKED) {		    c = set_clicked_link(MOUSE_X_POS, MOUSE_Y_POS, FOR_PANEL);		} else if (BUTTON_STATUS(3) & BUTTON_CLICKED) {		    c = LYReverseKeymap (LYK_PREV_DOC);		}#endif /* DOSPATH */	    }	    break;#endif /* NCURSES_MOUSE_VERSION */	}    }#endif /* HAVE_KEYPAD */#ifdef DJGPP_KEYHANDLER    else {	switch(c) {	case K_Down:		   /* The four arrow keys ... */	case K_EDown:	   c = DNARROW;	   break;	case K_Up:	case K_EUp:	   c = UPARROW;	   break;	case K_Left:	case K_ELeft:	   c = LTARROW;	   break;	case K_Right: 		   /* ... */	case K_ERight:	   c = RTARROW;	   break;	case K_Home:		   /* Home key (upward+left arrow) */	case K_EHome:	   c = HOME;	   break;	case K_PageDown: 	   /* Next page */	case K_EPageDown:	   c = PGDOWN;	   break;	case K_PageUp:	 	   /* Previous page */	case K_EPageUp:	   c = PGUP;	   break;	case K_End:		   /* home down or bottom (lower left) */	case K_EEnd:	   c = END_KEY;	   break;	case K_F1:		   /* F1 key */	   c = F1;	   break;	case K_Insert:		   /* Insert key */	case K_EInsert:	   c = INSERT_KEY;	   break;	case K_Delete:		   /* Delete key */	case K_EDelete:	   c = REMOVE_KEY;	   break;	case K_Alt_Escape:	   /* Alt-Escape */	   c = 0x1a7;	   break;	case K_Control_At:	   /* CTRL-@ */	   c = 0x1a8;	   break;	case K_Alt_Backspace:	   /* Alt-Backspace */	   c = 0x1a9;	   break;	case K_BackTab:		   /* BackTab */	   c = BACKTAB_KEY;	   break;	}    }#endif /* DGJPP_KEYHANDLER */#if defined(USE_SLANG) && defined(__DJGPP__) && !defined(DJGPP_KEYHANDLER)  && !defined(USE_KEYMAPS)    else {	switch(c) {	case SL_KEY_DOWN:	   /* The four arrow keys ... */	   c = DNARROW;	   break;	case SL_KEY_UP:	   c = UPARROW;	   break;	case SL_KEY_LEFT:	   c = LTARROW;	   break;	case SL_KEY_RIGHT: 	   /* ... */	   c = RTARROW;	   break;	case SL_KEY_HOME:	   /* Home key (upward+left arrow) */	case SL_KEY_A1:		   /* upper left of keypad */	   c = HOME;	   break;	case SL_KEY_NPAGE: 	   /* Next page */	case SL_KEY_C3:		   /* lower right of keypad */	   c = PGDOWN;	   break;	case SL_KEY_PPAGE: 	   /* Previous page */	case SL_KEY_A3:		   /* upper right of keypad */	   c = PGUP;	   break;	case SL_KEY_END:	   /* home down or bottom (lower left) */	case SL_KEY_C1:		   /* lower left of keypad */	   c = END_KEY;	   break;	case SL_KEY_F(1):	   /* F1 key */	   c = F1;	   break;	case SL_KEY_IC:		   /* Insert key */	   c = INSERT_KEY;	   break;	case SL_KEY_DELETE:	   /* Delete key */	   c = REMOVE_KEY;	   break;	}    }#endif /* USE_SLANG && __DJGPP__ && !DJGPP_KEYHANDLER && !USE_KEYMAPS */    if ((c+1) >= KEYMAP_SIZE) {	/*	 *  Don't return raw values for KEYPAD symbols which we may have	 *  missed in the switch above if they are obviously invalid when	 *  used as an index into (e.g.) keypad[]. - KW	 */	return (0);    } else {	return(c);    }}