implement support for PC scancodes à la CHR$(0)+CHR$(&h48)

superseding an mksh-os2 patch which confirmed this is needed

Reference: my copy of the Schneider EURO PC manual 50032 for
Microsoft® GW-BASIC
This commit is contained in:
tg 2015-07-10 18:41:07 +00:00
parent 5613d6a04a
commit 0fd9337123
3 changed files with 64 additions and 18 deletions

53
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.288 2015/07/10 17:31:09 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.289 2015/07/10 18:41:05 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -887,7 +887,7 @@ struct x_defbindings {
/* Separator for motion */
#define is_mfs(c) (!(ksh_isalnux(c) || (c) == '$' || ((c) & 0x80)))
#define X_NTABS 3 /* normal, meta1, meta2 */
#define X_NTABS 4 /* normal, meta1, meta2, pc */
#define X_TABSZ 256 /* size of keydef tables etc */
/*-
@ -1099,9 +1099,28 @@ static struct x_defbindings const x_defbindings[] = {
{ XFUNC_mv_end | 0x80, 2, '8' },
{ XFUNC_mv_end, 2, 'F' },
{ XFUNC_del_char | 0x80, 2, '3' },
{ XFUNC_del_char, 2, 'P' },
{ XFUNC_del_char, 2, 'P' },
{ XFUNC_search_hist_up | 0x80, 2, '5' },
{ XFUNC_search_hist_dn | 0x80, 2, '6' },
#endif
/* PC scancodes */
#if !defined(MKSH_SMALL) || defined(__OS2__)
{ XFUNC_meta3, 0, 0 },
{ XFUNC_mv_begin, 3, 71 },
{ XFUNC_prev_com, 3, 72 },
#ifndef MKSH_SMALL
{ XFUNC_search_hist_up, 3, 73 },
#endif
{ XFUNC_mv_back, 3, 75 },
{ XFUNC_mv_forw, 3, 77 },
{ XFUNC_mv_end, 3, 79 },
{ XFUNC_next_com, 3, 80 },
#ifndef MKSH_SMALL
{ XFUNC_search_hist_dn, 3, 81 },
#endif
{ XFUNC_del_char, 3, 83 },
#endif
#ifndef MKSH_SMALL
/* more non-standard ones */
{ XFUNC_edit_line, 2, 'e' }
#endif
@ -2215,6 +2234,13 @@ x_meta2(int c MKSH_A_UNUSED)
return (KSTD);
}
static int
x_meta3(int c MKSH_A_UNUSED)
{
x_curprefix = 3;
return (KSTD);
}
static int
x_kill(int c MKSH_A_UNUSED)
{
@ -2413,8 +2439,8 @@ x_print(int prefix, int key)
if (prefix)
/* prefix == 1 || prefix == 2 */
shf_puts(x_mapout(prefix == 1 ?
CTRL('[') : CTRL('X')), shl_stdout);
shf_puts(x_mapout(prefix == 1 ? CTRL('[') :
prefix == 2 ? CTRL('X') : 0), shl_stdout);
#ifdef MKSH_SMALL
shprintf("%s = ", x_mapout(key));
#else
@ -2479,6 +2505,8 @@ x_bind(const char *a1, const char *a2,
prefix = 1;
else if (f == XFUNC_meta2)
prefix = 2;
else if (f == XFUNC_meta3)
prefix = 3;
else
break;
}
@ -3618,6 +3646,18 @@ vi_hook(int ch)
switch (state) {
case VNORMAL:
/* PC scancodes */
if (!ch) switch (cmdlen = 0, (ch = x_getc())) {
case 71: ch = '0'; goto pseudo_vi_command;
case 72: ch = 'k'; goto pseudo_vi_command;
case 73: ch = 'A'; goto vi_xfunc_search_up;
case 75: ch = 'h'; goto pseudo_vi_command;
case 77: ch = 'l'; goto pseudo_vi_command;
case 79: ch = '$'; goto pseudo_vi_command;
case 80: ch = 'j'; goto pseudo_vi_command;
case 83: ch = 'x'; goto pseudo_vi_command;
default: ch = 0; goto vi_insert_failed;
}
if (insert != 0) {
if (ch == CTRL('v')) {
state = VLIT;
@ -3625,6 +3665,7 @@ vi_hook(int ch)
}
switch (vi_insert(ch)) {
case -1:
vi_insert_failed:
vi_error();
state = VNORMAL;
break;
@ -3647,6 +3688,7 @@ vi_hook(int ch)
argc1 = ksh_numdig(ch);
state = VARG1;
} else {
pseudo_vi_command:
curcmd[cmdlen++] = ch;
state = nextstate(ch);
if (state == VSEARCH) {
@ -3815,6 +3857,7 @@ vi_hook(int ch)
break;
case VPREFIX2:
vi_xfunc_search_up:
state = VFAIL;
switch (ch) {
case 'A':

View File

@ -1,5 +1,5 @@
#if defined(EMACSFN_DEFNS)
__RCSID("$MirOS: src/bin/mksh/emacsfn.h,v 1.5 2010/07/17 22:09:33 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/emacsfn.h,v 1.6 2015/07/10 18:41:07 tg Exp $");
#define FN(cname,sname,flags) static int x_##cname(int);
#elif defined(EMACSFN_ENUMS)
#define FN(cname,sname,flags) XFUNC_##cname,
@ -52,6 +52,7 @@ FN(list_file, "list-file", 0)
FN(literal, "quote", 0)
FN(meta1, "prefix-1", XF_PREFIX)
FN(meta2, "prefix-2", XF_PREFIX)
FN(meta3, "prefix-3", XF_PREFIX)
FN(meta_yank, "yank-pop", 0)
FN(mv_back, "backward-char", XF_ARG)
FN(mv_begin, "beginning-of-line", 0)

26
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.375 2015/07/09 20:20:43 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.376 2015/07/10 18:41:07 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -74,7 +74,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
.Dd $Mdocdate: July 9 2015 $
.Dd $Mdocdate: July 10 2015 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
@ -5398,7 +5398,7 @@ Simply causes the character to appear as literal input.
Most ordinary characters are bound to this.
.It Xo backward\-char:
.Op Ar n
.No \*(haB , \*(haXD , ANSI-CurLeft
.No \*(haB , \*(haXD , ANSI-CurLeft , PC-CurLeft
.Xc
Moves the cursor backward
.Ar n
@ -5415,7 +5415,7 @@ and dollar sign
characters.
.It beginning\-of\-history: \*(ha[\*(Lt
Moves to the beginning of the history.
.It beginning\-of\-line: \*(haA, ANSI-Home
.It beginning\-of\-line: \*(haA, ANSI-Home, PC-Home
Moves the cursor to the beginning of the edited input line.
.It Xo capitalise\-word:
.Op Ar n
@ -5471,7 +5471,7 @@ Deletes
characters before the cursor.
.It Xo delete\-char\-forward:
.Op Ar n
.No ANSI-Del
.No ANSI-Del , PC-Del
.Xc
Deletes
.Ar n
@ -5492,7 +5492,7 @@ Deletes characters after the cursor up to the end of
words.
.It Xo down\-history:
.Op Ar n
.No \*(haN , \*(haXB , ANSI-CurDown
.No \*(haN , \*(haXB , ANSI-CurDown , PC-CurDown
.Xc
Scrolls the history buffer forward
.Ar n
@ -5524,7 +5524,7 @@ The actual command executed is
.Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
.It end\-of\-history: \*(ha[\*(Gt
Moves to the end of the history.
.It end\-of\-line: \*(haE, ANSI-End
.It end\-of\-line: \*(haE, ANSI-End, PC-End
Moves the cursor to the end of the input line.
.It eot: \*(ha_
Acts as an end-of-file; this is useful because edit-mode input disables
@ -5549,7 +5549,7 @@ globbing on the word.
If no files match the pattern, the bell is rung.
.It Xo forward\-char:
.Op Ar n
.No \*(haF , \*(haXC , ANSI-CurRight
.No \*(haF , \*(haXC , ANSI-CurRight , PC-CurRight
.Xc
Moves the cursor forward
.Ar n
@ -5663,12 +5663,12 @@ commands continue searching backward to the next previous occurrence of the
pattern.
The history buffer retains only a finite number of lines; the oldest
are discarded as necessary.
.It search\-history\-up: ANSI-PgUp
.It search\-history\-up: ANSI-PgUp, PC-PgUp
Search backwards through the history buffer for commands whose beginning match
the portion of the input line before the cursor.
When used on an empty line, this has the same effect as
.Ic up\-history .
.It search\-history\-down: ANSI-PgDn
.It search\-history\-down: ANSI-PgDn, PC-PgDn
Search forwards through the history buffer for commands whose beginning match
the portion of the input line before the cursor.
When used on an empty line, this has the same effect as
@ -5688,7 +5688,7 @@ exchanges the previous and current characters and moves the cursor one
character to the right.
.It Xo up\-history:
.Op Ar n
.No \*(haP , \*(haXA , ANSI-CurUp
.No \*(haP , \*(haXA , ANSI-CurUp , PC-CurUp
.Xc
Scrolls the history buffer backward
.Ar n
@ -6116,7 +6116,7 @@ Search for the
.Ar n Ns th
occurrence of the last search string;
the direction of the search is the opposite of the last search.
.It Ar ANSI-CurUp
.It Ar ANSI-CurUp , PC-PgUp
Take the characters from the beginning of the line to the current
cursor position as search string and do a backwards history search
for lines beginning with this string; keep the cursor position.
@ -6267,6 +6267,8 @@ times.
Undo the last edit command.
.It U
Undo all changes that have been made to the current line.
.It PC Home, End, Del, and cursor keys
They move as expected, both in insert and command mode.
.It Ar intr No and Ar quit
The interrupt and quit terminal characters cause the current line to be
deleted and a new prompt to be printed.