From 81431d2d76106fabcdd901554b7d2c031378fa18 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Fri, 9 Aug 2019 20:47:05 +0800 Subject: [PATCH] Map DEL (0x7F) consistently to CTL-? so that it can be bound with bind-to-key command. Revise Y/N prompt and function name keying. --- ebind.c | 7 ++----- input.c | 48 +++++++++++++++++++----------------------------- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/ebind.c b/ebind.c index 4f10901..04df09d 100644 --- a/ebind.c +++ b/ebind.c @@ -35,6 +35,7 @@ * control-X commands. */ struct key_tab keytab[NBINDS] = { + {CONTROL | '?', backdel}, {CONTROL | 'A', (fn_t) gotobol} , {CONTROL | 'B', (fn_t) backchar} @@ -206,6 +207,7 @@ struct key_tab keytab[NBINDS] = { , {CTLX | 'Z', enlargewind} , + {META | CONTROL | '?', delbword}, #if WORDPRO {META | CONTROL | 'C', wordcount} , @@ -315,8 +317,6 @@ struct key_tab keytab[NBINDS] = { , {META | 'Z', quickexit} , - {META | 0x7F, delbword} - , #if VT220 {SPEC | '1', (fn_t) gotobob /* fisearch */} @@ -353,9 +353,6 @@ struct key_tab keytab[NBINDS] = { , #endif - {0x7F, backdel} - , - /* special internal bindings */ { SPEC | META | 'W', wrapword }, /* called on word wrap */ { SPEC | META | 'C', nullproc }, /* every command input */ diff --git a/input.c b/input.c index e9fa69e..d252c1d 100644 --- a/input.c +++ b/input.c @@ -65,16 +65,16 @@ void ue_system( const char *cmd) { */ int mlyesno( const char *prompt) { - char c; /* input character */ + int c ; /* input character */ for (;;) { /* prompt the user */ mlwrite( "%s (y/n)? ", prompt) ; /* get the response */ - c = tgetc(); + c = get1key() ; - if (c == ectoc(abortc)) /* Bail out! */ + if( c == abortc) /* Bail out! */ return ABORT; if (c == 'y' || c == 'Y') @@ -147,13 +147,14 @@ int newmlargt( char **outbufref, const char *prompt, int size) { * expanded character to character * collapse the CONTROL and SPEC flags back into an ascii code */ -int ectoc(int c) -{ - if (c & CONTROL) - c = c & ~(CONTROL | 0x40); - if (c & SPEC) - c = c & 255; - return c; +int ectoc( int c) { + if( c & CONTROL) + c ^= CONTROL | 0x40 ; + + if( c & SPEC) + c &= 255 ; + + return c ; } /* @@ -284,7 +285,7 @@ fn_t getname(void) TTflush(); /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ } else { - if (cpos < NSTRING - 1 && c > ' ') { + if( cpos < NSTRING - 1 && (islower( c) || c == '-')) { buf[cpos++] = c; echoc( c) ; TTflush(); @@ -344,29 +345,18 @@ int tgetc(void) return c; } -/* GET1KEY: Get one keystroke. The only prefixs legal here - are the SPEC and CONTROL prefixes. - */ - -int get1key(void) -{ - int c; +/* GET1KEY: Get one keystroke. The only prefixs legal here are the SPEC + and CONTROL prefixes. */ +int get1key( void) { + int c ; /* get a keystroke */ c = tgetc(); -#if MSDOS - if (c == 0) { /* Apply SPEC prefix */ - c = tgetc(); - if (c >= 0x00 && c <= 0x1F) /* control key? */ - c = CONTROL | (c + '@'); - return SPEC | c; - } -#endif + if( (c >= 0x00 && c <= 0x1F) || c == 0x7F) /* C0 control -> C- */ + c ^= CONTROL | 0x40 ; - if (c >= 0x00 && c <= 0x1F) /* C0 control -> C- */ - c = CONTROL | (c + '@'); - return c; + return c ; } /* GETCMD: Get a command from the keyboard. Process all applicable