Updated libedit to NetBSD upstream
Note: This unconditionally assumes wchar_t support. May need revision if some platforms prove problematic.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: map.c,v 1.25 2009/12/30 22:37:40 christos Exp $ */
|
||||
/* $NetBSD: map.c,v 1.51 2016/05/09 21:46:56 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@@ -37,30 +37,40 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: map.c,v 1.25 2009/12/30 22:37:40 christos Exp $");
|
||||
__RCSID("$NetBSD: map.c,v 1.51 2016/05/09 21:46:56 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
/*
|
||||
* map.c: Editor function definitions
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include "el.h"
|
||||
#include <string.h>
|
||||
|
||||
private void map_print_key(EditLine *, el_action_t *, const Char *);
|
||||
private void map_print_some_keys(EditLine *, el_action_t *, Int, Int);
|
||||
private void map_print_all_keys(EditLine *);
|
||||
private void map_init_nls(EditLine *);
|
||||
private void map_init_meta(EditLine *);
|
||||
#include "el.h"
|
||||
#include "common.h"
|
||||
#include "emacs.h"
|
||||
#include "vi.h"
|
||||
#include "fcns.h"
|
||||
#include "func.h"
|
||||
#include "help.h"
|
||||
#include "parse.h"
|
||||
|
||||
static void map_print_key(EditLine *, el_action_t *, const wchar_t *);
|
||||
static void map_print_some_keys(EditLine *, el_action_t *, wint_t, wint_t);
|
||||
static void map_print_all_keys(EditLine *);
|
||||
static void map_init_nls(EditLine *);
|
||||
static void map_init_meta(EditLine *);
|
||||
|
||||
/* keymap tables ; should be N_KEYS*sizeof(KEYCMD) bytes long */
|
||||
|
||||
|
||||
private const el_action_t el_map_emacs[] = {
|
||||
static const el_action_t el_map_emacs[] = {
|
||||
/* 0 */ EM_SET_MARK, /* ^@ */
|
||||
/* 1 */ ED_MOVE_TO_BEG, /* ^A */
|
||||
/* 2 */ ED_PREV_CHAR, /* ^B */
|
||||
/* 3 */ ED_TTY_SIGINT, /* ^C */
|
||||
/* 3 */ ED_IGNORE, /* ^C */
|
||||
/* 4 */ EM_DELETE_OR_LIST, /* ^D */
|
||||
/* 5 */ ED_MOVE_TO_END, /* ^E */
|
||||
/* 6 */ ED_NEXT_CHAR, /* ^F */
|
||||
@@ -72,21 +82,21 @@ private const el_action_t el_map_emacs[] = {
|
||||
/* 12 */ ED_CLEAR_SCREEN, /* ^L */
|
||||
/* 13 */ ED_NEWLINE, /* ^M */
|
||||
/* 14 */ ED_NEXT_HISTORY, /* ^N */
|
||||
/* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */
|
||||
/* 15 */ ED_IGNORE, /* ^O */
|
||||
/* 16 */ ED_PREV_HISTORY, /* ^P */
|
||||
/* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
|
||||
/* 17 */ ED_IGNORE, /* ^Q */
|
||||
/* 18 */ ED_REDISPLAY, /* ^R */
|
||||
/* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
|
||||
/* 19 */ ED_IGNORE, /* ^S */
|
||||
/* 20 */ ED_TRANSPOSE_CHARS, /* ^T */
|
||||
/* 21 */ EM_KILL_LINE, /* ^U */
|
||||
/* 22 */ ED_QUOTED_INSERT, /* ^V */
|
||||
/* 23 */ EM_KILL_REGION, /* ^W */
|
||||
/* 24 */ ED_SEQUENCE_LEAD_IN, /* ^X */
|
||||
/* 25 */ EM_YANK, /* ^Y */
|
||||
/* 26 */ ED_TTY_SIGTSTP, /* ^Z */
|
||||
/* 26 */ ED_IGNORE, /* ^Z */
|
||||
/* 27 */ EM_META_NEXT, /* ^[ */
|
||||
/* 28 */ ED_TTY_SIGQUIT, /* ^\ */
|
||||
/* 29 */ ED_TTY_DSUSP, /* ^] */
|
||||
/* 28 */ ED_IGNORE, /* ^\ */
|
||||
/* 29 */ ED_IGNORE, /* ^] */
|
||||
/* 30 */ ED_UNASSIGNED, /* ^^ */
|
||||
/* 31 */ ED_UNASSIGNED, /* ^_ */
|
||||
/* 32 */ ED_INSERT, /* SPACE */
|
||||
@@ -323,7 +333,7 @@ private const el_action_t el_map_emacs[] = {
|
||||
* insert mode characters are in the normal keymap, and command mode
|
||||
* in the extended keymap.
|
||||
*/
|
||||
private const el_action_t el_map_vi_insert[] = {
|
||||
static const el_action_t el_map_vi_insert[] = {
|
||||
#ifdef KSHVI
|
||||
/* 0 */ ED_UNASSIGNED, /* ^@ */
|
||||
/* 1 */ ED_INSERT, /* ^A */
|
||||
@@ -342,9 +352,9 @@ private const el_action_t el_map_vi_insert[] = {
|
||||
/* 14 */ ED_INSERT, /* ^N */
|
||||
/* 15 */ ED_INSERT, /* ^O */
|
||||
/* 16 */ ED_INSERT, /* ^P */
|
||||
/* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
|
||||
/* 17 */ ED_IGNORE, /* ^Q */
|
||||
/* 18 */ ED_INSERT, /* ^R */
|
||||
/* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
|
||||
/* 19 */ ED_IGNORE, /* ^S */
|
||||
/* 20 */ ED_INSERT, /* ^T */
|
||||
/* 21 */ VI_KILL_LINE_PREV, /* ^U */
|
||||
/* 22 */ ED_QUOTED_INSERT, /* ^V */
|
||||
@@ -354,7 +364,7 @@ private const el_action_t el_map_vi_insert[] = {
|
||||
/* 25 */ ED_INSERT, /* ^Y */
|
||||
/* 26 */ ED_INSERT, /* ^Z */
|
||||
/* 27 */ VI_COMMAND_MODE, /* ^[ */ /* [ Esc ] key */
|
||||
/* 28 */ ED_TTY_SIGQUIT, /* ^\ */
|
||||
/* 28 */ ED_IGNORE, /* ^\ */
|
||||
/* 29 */ ED_INSERT, /* ^] */
|
||||
/* 30 */ ED_INSERT, /* ^^ */
|
||||
/* 31 */ ED_INSERT, /* ^_ */
|
||||
@@ -368,7 +378,7 @@ private const el_action_t el_map_vi_insert[] = {
|
||||
/* 0 */ ED_UNASSIGNED, /* ^@ */
|
||||
/* 1 */ ED_MOVE_TO_BEG, /* ^A */
|
||||
/* 2 */ ED_PREV_CHAR, /* ^B */
|
||||
/* 3 */ ED_TTY_SIGINT, /* ^C */
|
||||
/* 3 */ ED_IGNORE, /* ^C */
|
||||
/* 4 */ VI_LIST_OR_EOF, /* ^D */
|
||||
/* 5 */ ED_MOVE_TO_END, /* ^E */
|
||||
/* 6 */ ED_NEXT_CHAR, /* ^F */
|
||||
@@ -380,20 +390,20 @@ private const el_action_t el_map_vi_insert[] = {
|
||||
/* 12 */ ED_CLEAR_SCREEN, /* ^L */
|
||||
/* 13 */ ED_NEWLINE, /* ^M */
|
||||
/* 14 */ ED_NEXT_HISTORY, /* ^N */
|
||||
/* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */
|
||||
/* 15 */ ED_IGNORE, /* ^O */
|
||||
/* 16 */ ED_PREV_HISTORY, /* ^P */
|
||||
/* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
|
||||
/* 17 */ ED_IGNORE, /* ^Q */
|
||||
/* 18 */ ED_REDISPLAY, /* ^R */
|
||||
/* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
|
||||
/* 19 */ ED_IGNORE, /* ^S */
|
||||
/* 20 */ ED_TRANSPOSE_CHARS, /* ^T */
|
||||
/* 21 */ VI_KILL_LINE_PREV, /* ^U */
|
||||
/* 22 */ ED_QUOTED_INSERT, /* ^V */
|
||||
/* 23 */ ED_DELETE_PREV_WORD, /* ^W */
|
||||
/* 24 */ ED_UNASSIGNED, /* ^X */
|
||||
/* 25 */ ED_TTY_DSUSP, /* ^Y */
|
||||
/* 26 */ ED_TTY_SIGTSTP, /* ^Z */
|
||||
/* 25 */ ED_IGNORE, /* ^Y */
|
||||
/* 26 */ ED_IGNORE, /* ^Z */
|
||||
/* 27 */ VI_COMMAND_MODE, /* ^[ */
|
||||
/* 28 */ ED_TTY_SIGQUIT, /* ^\ */
|
||||
/* 28 */ ED_IGNORE, /* ^\ */
|
||||
/* 29 */ ED_UNASSIGNED, /* ^] */
|
||||
/* 30 */ ED_UNASSIGNED, /* ^^ */
|
||||
/* 31 */ ED_UNASSIGNED, /* ^_ */
|
||||
@@ -624,11 +634,11 @@ private const el_action_t el_map_vi_insert[] = {
|
||||
/* 255 */ ED_INSERT /* M-^? */
|
||||
};
|
||||
|
||||
private const el_action_t el_map_vi_command[] = {
|
||||
static const el_action_t el_map_vi_command[] = {
|
||||
/* 0 */ ED_UNASSIGNED, /* ^@ */
|
||||
/* 1 */ ED_MOVE_TO_BEG, /* ^A */
|
||||
/* 2 */ ED_UNASSIGNED, /* ^B */
|
||||
/* 3 */ ED_TTY_SIGINT, /* ^C */
|
||||
/* 3 */ ED_IGNORE, /* ^C */
|
||||
/* 4 */ ED_UNASSIGNED, /* ^D */
|
||||
/* 5 */ ED_MOVE_TO_END, /* ^E */
|
||||
/* 6 */ ED_UNASSIGNED, /* ^F */
|
||||
@@ -640,11 +650,11 @@ private const el_action_t el_map_vi_command[] = {
|
||||
/* 12 */ ED_CLEAR_SCREEN, /* ^L */
|
||||
/* 13 */ ED_NEWLINE, /* ^M */
|
||||
/* 14 */ ED_NEXT_HISTORY, /* ^N */
|
||||
/* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */
|
||||
/* 15 */ ED_IGNORE, /* ^O */
|
||||
/* 16 */ ED_PREV_HISTORY, /* ^P */
|
||||
/* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
|
||||
/* 17 */ ED_IGNORE, /* ^Q */
|
||||
/* 18 */ ED_REDISPLAY, /* ^R */
|
||||
/* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
|
||||
/* 19 */ ED_IGNORE, /* ^S */
|
||||
/* 20 */ ED_UNASSIGNED, /* ^T */
|
||||
/* 21 */ VI_KILL_LINE_PREV, /* ^U */
|
||||
/* 22 */ ED_UNASSIGNED, /* ^V */
|
||||
@@ -653,7 +663,7 @@ private const el_action_t el_map_vi_command[] = {
|
||||
/* 25 */ ED_UNASSIGNED, /* ^Y */
|
||||
/* 26 */ ED_UNASSIGNED, /* ^Z */
|
||||
/* 27 */ EM_META_NEXT, /* ^[ */
|
||||
/* 28 */ ED_TTY_SIGQUIT, /* ^\ */
|
||||
/* 28 */ ED_IGNORE, /* ^\ */
|
||||
/* 29 */ ED_UNASSIGNED, /* ^] */
|
||||
/* 30 */ ED_UNASSIGNED, /* ^^ */
|
||||
/* 31 */ ED_UNASSIGNED, /* ^_ */
|
||||
@@ -887,7 +897,7 @@ private const el_action_t el_map_vi_command[] = {
|
||||
/* map_init():
|
||||
* Initialize and allocate the maps
|
||||
*/
|
||||
protected int
|
||||
libedit_private int
|
||||
map_init(EditLine *el)
|
||||
{
|
||||
|
||||
@@ -903,26 +913,25 @@ map_init(EditLine *el)
|
||||
EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
|
||||
#endif
|
||||
|
||||
el->el_map.alt = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
|
||||
el->el_map.alt = el_malloc(sizeof(*el->el_map.alt) * N_KEYS);
|
||||
if (el->el_map.alt == NULL)
|
||||
return (-1);
|
||||
el->el_map.key = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
|
||||
return -1;
|
||||
el->el_map.key = el_malloc(sizeof(*el->el_map.key) * N_KEYS);
|
||||
if (el->el_map.key == NULL)
|
||||
return (-1);
|
||||
return -1;
|
||||
el->el_map.emacs = el_map_emacs;
|
||||
el->el_map.vic = el_map_vi_command;
|
||||
el->el_map.vii = el_map_vi_insert;
|
||||
el->el_map.help = (el_bindings_t *) el_malloc(sizeof(el_bindings_t) *
|
||||
EL_NUM_FCNS);
|
||||
el->el_map.help = el_malloc(sizeof(*el->el_map.help) * EL_NUM_FCNS);
|
||||
if (el->el_map.help == NULL)
|
||||
return (-1);
|
||||
(void) memcpy(el->el_map.help, help__get(),
|
||||
sizeof(el_bindings_t) * EL_NUM_FCNS);
|
||||
el->el_map.func = (el_func_t *)el_malloc(sizeof(el_func_t) *
|
||||
EL_NUM_FCNS);
|
||||
return -1;
|
||||
(void) memcpy(el->el_map.help, el_func_help,
|
||||
sizeof(*el->el_map.help) * EL_NUM_FCNS);
|
||||
el->el_map.func = el_malloc(sizeof(*el->el_map.func) * EL_NUM_FCNS);
|
||||
if (el->el_map.func == NULL)
|
||||
return (-1);
|
||||
memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS);
|
||||
return -1;
|
||||
memcpy(el->el_map.func, el_func, sizeof(*el->el_map.func)
|
||||
* EL_NUM_FCNS);
|
||||
el->el_map.nfunc = EL_NUM_FCNS;
|
||||
|
||||
#ifdef VIDEFAULT
|
||||
@@ -930,27 +939,27 @@ map_init(EditLine *el)
|
||||
#else
|
||||
map_init_emacs(el);
|
||||
#endif /* VIDEFAULT */
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* map_end():
|
||||
* Free the space taken by the editor maps
|
||||
*/
|
||||
protected void
|
||||
libedit_private void
|
||||
map_end(EditLine *el)
|
||||
{
|
||||
|
||||
el_free((ptr_t) el->el_map.alt);
|
||||
el_free(el->el_map.alt);
|
||||
el->el_map.alt = NULL;
|
||||
el_free((ptr_t) el->el_map.key);
|
||||
el_free(el->el_map.key);
|
||||
el->el_map.key = NULL;
|
||||
el->el_map.emacs = NULL;
|
||||
el->el_map.vic = NULL;
|
||||
el->el_map.vii = NULL;
|
||||
el_free((ptr_t) el->el_map.help);
|
||||
el_free(el->el_map.help);
|
||||
el->el_map.help = NULL;
|
||||
el_free((ptr_t) el->el_map.func);
|
||||
el_free(el->el_map.func);
|
||||
el->el_map.func = NULL;
|
||||
}
|
||||
|
||||
@@ -958,7 +967,7 @@ map_end(EditLine *el)
|
||||
/* map_init_nls():
|
||||
* Find all the printable keys and bind them to self insert
|
||||
*/
|
||||
private void
|
||||
static void
|
||||
map_init_nls(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
@@ -966,7 +975,7 @@ map_init_nls(EditLine *el)
|
||||
el_action_t *map = el->el_map.key;
|
||||
|
||||
for (i = 0200; i <= 0377; i++)
|
||||
if (Isprint(i))
|
||||
if (iswprint(i))
|
||||
map[i] = ED_INSERT;
|
||||
}
|
||||
|
||||
@@ -974,10 +983,10 @@ map_init_nls(EditLine *el)
|
||||
/* map_init_meta():
|
||||
* Bind all the meta keys to the appropriate ESC-<key> sequence
|
||||
*/
|
||||
private void
|
||||
static void
|
||||
map_init_meta(EditLine *el)
|
||||
{
|
||||
Char buf[3];
|
||||
wchar_t buf[3];
|
||||
int i;
|
||||
el_action_t *map = el->el_map.key;
|
||||
el_action_t *alt = el->el_map.alt;
|
||||
@@ -995,7 +1004,7 @@ map_init_meta(EditLine *el)
|
||||
} else
|
||||
map = alt;
|
||||
}
|
||||
buf[0] = (Char) i;
|
||||
buf[0] = (wchar_t)i;
|
||||
buf[2] = 0;
|
||||
for (i = 0200; i <= 0377; i++)
|
||||
switch (map[i]) {
|
||||
@@ -1005,7 +1014,7 @@ map_init_meta(EditLine *el)
|
||||
break;
|
||||
default:
|
||||
buf[1] = i & 0177;
|
||||
key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD);
|
||||
keymacro_add(el, buf, keymacro_map_cmd(el, (int) map[i]), XK_CMD);
|
||||
break;
|
||||
}
|
||||
map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
|
||||
@@ -1015,7 +1024,7 @@ map_init_meta(EditLine *el)
|
||||
/* map_init_vi():
|
||||
* Initialize the vi bindings
|
||||
*/
|
||||
protected void
|
||||
libedit_private void
|
||||
map_init_vi(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
@@ -1027,7 +1036,7 @@ map_init_vi(EditLine *el)
|
||||
el->el_map.type = MAP_VI;
|
||||
el->el_map.current = el->el_map.key;
|
||||
|
||||
key_reset(el);
|
||||
keymacro_reset(el);
|
||||
|
||||
for (i = 0; i < N_KEYS; i++) {
|
||||
key[i] = vii[i];
|
||||
@@ -1038,25 +1047,25 @@ map_init_vi(EditLine *el)
|
||||
map_init_nls(el);
|
||||
|
||||
tty_bind_char(el, 1);
|
||||
term_bind_arrow(el);
|
||||
terminal_bind_arrow(el);
|
||||
}
|
||||
|
||||
|
||||
/* map_init_emacs():
|
||||
* Initialize the emacs bindings
|
||||
*/
|
||||
protected void
|
||||
libedit_private void
|
||||
map_init_emacs(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
Char buf[3];
|
||||
wchar_t buf[3];
|
||||
el_action_t *key = el->el_map.key;
|
||||
el_action_t *alt = el->el_map.alt;
|
||||
const el_action_t *emacs = el->el_map.emacs;
|
||||
|
||||
el->el_map.type = MAP_EMACS;
|
||||
el->el_map.current = el->el_map.key;
|
||||
key_reset(el);
|
||||
keymacro_reset(el);
|
||||
|
||||
for (i = 0; i < N_KEYS; i++) {
|
||||
key[i] = emacs[i];
|
||||
@@ -1069,84 +1078,84 @@ map_init_emacs(EditLine *el)
|
||||
buf[0] = CONTROL('X');
|
||||
buf[1] = CONTROL('X');
|
||||
buf[2] = 0;
|
||||
key_add(el, buf, key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
|
||||
keymacro_add(el, buf, keymacro_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
|
||||
|
||||
tty_bind_char(el, 1);
|
||||
term_bind_arrow(el);
|
||||
terminal_bind_arrow(el);
|
||||
}
|
||||
|
||||
|
||||
/* map_set_editor():
|
||||
* Set the editor
|
||||
*/
|
||||
protected int
|
||||
map_set_editor(EditLine *el, Char *editor)
|
||||
libedit_private int
|
||||
map_set_editor(EditLine *el, wchar_t *editor)
|
||||
{
|
||||
|
||||
if (Strcmp(editor, STR("emacs")) == 0) {
|
||||
if (wcscmp(editor, L"emacs") == 0) {
|
||||
map_init_emacs(el);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
if (Strcmp(editor, STR("vi")) == 0) {
|
||||
if (wcscmp(editor, L"vi") == 0) {
|
||||
map_init_vi(el);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* map_get_editor():
|
||||
* Retrieve the editor
|
||||
*/
|
||||
protected int
|
||||
map_get_editor(EditLine *el, const Char **editor)
|
||||
libedit_private int
|
||||
map_get_editor(EditLine *el, const wchar_t **editor)
|
||||
{
|
||||
|
||||
if (editor == NULL)
|
||||
return (-1);
|
||||
return -1;
|
||||
switch (el->el_map.type) {
|
||||
case MAP_EMACS:
|
||||
*editor = STR("emacs");
|
||||
return (0);
|
||||
*editor = L"emacs";
|
||||
return 0;
|
||||
case MAP_VI:
|
||||
*editor = STR("vi");
|
||||
return (0);
|
||||
*editor = L"vi";
|
||||
return 0;
|
||||
}
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* map_print_key():
|
||||
* Print the function description for 1 key
|
||||
*/
|
||||
private void
|
||||
map_print_key(EditLine *el, el_action_t *map, const Char *in)
|
||||
static void
|
||||
map_print_key(EditLine *el, el_action_t *map, const wchar_t *in)
|
||||
{
|
||||
char outbuf[EL_BUFSIZ];
|
||||
el_bindings_t *bp, *ep;
|
||||
|
||||
if (in[0] == '\0' || in[1] == '\0') {
|
||||
(void) key__decode_str(in, outbuf, sizeof(outbuf), "");
|
||||
(void) keymacro__decode_str(in, outbuf, sizeof(outbuf), "");
|
||||
ep = &el->el_map.help[el->el_map.nfunc];
|
||||
for (bp = el->el_map.help; bp < ep; bp++)
|
||||
if (bp->func == map[(unsigned char) *in]) {
|
||||
(void) fprintf(el->el_outfile,
|
||||
"%s\t->\t" FSTR "\n", outbuf, bp->name);
|
||||
"%s\t->\t%ls\n", outbuf, bp->name);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
key_print(el, in);
|
||||
keymacro_print(el, in);
|
||||
}
|
||||
|
||||
|
||||
/* map_print_some_keys():
|
||||
* Print keys from first to last
|
||||
*/
|
||||
private void
|
||||
map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
|
||||
static void
|
||||
map_print_some_keys(EditLine *el, el_action_t *map, wint_t first, wint_t last)
|
||||
{
|
||||
el_bindings_t *bp, *ep;
|
||||
Char firstbuf[2], lastbuf[2];
|
||||
wchar_t firstbuf[2], lastbuf[2];
|
||||
char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ];
|
||||
|
||||
firstbuf[0] = first;
|
||||
@@ -1155,7 +1164,7 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
|
||||
lastbuf[1] = 0;
|
||||
if (map[first] == ED_UNASSIGNED) {
|
||||
if (first == last) {
|
||||
(void) key__decode_str(firstbuf, unparsbuf,
|
||||
(void) keymacro__decode_str(firstbuf, unparsbuf,
|
||||
sizeof(unparsbuf), STRQQ);
|
||||
(void) fprintf(el->el_outfile,
|
||||
"%-15s-> is undefined\n", unparsbuf);
|
||||
@@ -1166,17 +1175,17 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
|
||||
for (bp = el->el_map.help; bp < ep; bp++) {
|
||||
if (bp->func == map[first]) {
|
||||
if (first == last) {
|
||||
(void) key__decode_str(firstbuf, unparsbuf,
|
||||
(void) keymacro__decode_str(firstbuf, unparsbuf,
|
||||
sizeof(unparsbuf), STRQQ);
|
||||
(void) fprintf(el->el_outfile, "%-15s-> " FSTR "\n",
|
||||
(void) fprintf(el->el_outfile, "%-15s-> %ls\n",
|
||||
unparsbuf, bp->name);
|
||||
} else {
|
||||
(void) key__decode_str(firstbuf, unparsbuf,
|
||||
(void) keymacro__decode_str(firstbuf, unparsbuf,
|
||||
sizeof(unparsbuf), STRQQ);
|
||||
(void) key__decode_str(lastbuf, extrabuf,
|
||||
(void) keymacro__decode_str(lastbuf, extrabuf,
|
||||
sizeof(extrabuf), STRQQ);
|
||||
(void) fprintf(el->el_outfile,
|
||||
"%-4s to %-7s-> " FSTR "\n",
|
||||
"%-4s to %-7s-> %ls\n",
|
||||
unparsbuf, extrabuf, bp->name);
|
||||
}
|
||||
return;
|
||||
@@ -1184,14 +1193,14 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
|
||||
}
|
||||
#ifdef MAP_DEBUG
|
||||
if (map == el->el_map.key) {
|
||||
(void) key__decode_str(firstbuf, unparsbuf,
|
||||
(void) keymacro__decode_str(firstbuf, unparsbuf,
|
||||
sizeof(unparsbuf), STRQQ);
|
||||
(void) fprintf(el->el_outfile,
|
||||
"BUG!!! %s isn't bound to anything.\n", unparsbuf);
|
||||
(void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
|
||||
first, el->el_map.key[first]);
|
||||
} else {
|
||||
(void) key__decode_str(firstbuf, unparsbuf,
|
||||
(void) keymacro__decode_str(firstbuf, unparsbuf,
|
||||
sizeof(unparsbuf), STRQQ);
|
||||
(void) fprintf(el->el_outfile,
|
||||
"BUG!!! %s isn't bound to anything.\n", unparsbuf);
|
||||
@@ -1206,7 +1215,7 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
|
||||
/* map_print_all_keys():
|
||||
* Print the function description for all keys.
|
||||
*/
|
||||
private void
|
||||
static void
|
||||
map_print_all_keys(EditLine *el)
|
||||
{
|
||||
int prev, i;
|
||||
@@ -1232,31 +1241,31 @@ map_print_all_keys(EditLine *el)
|
||||
map_print_some_keys(el, el->el_map.alt, prev, i - 1);
|
||||
|
||||
(void) fprintf(el->el_outfile, "Multi-character bindings\n");
|
||||
key_print(el, STR(""));
|
||||
keymacro_print(el, L"");
|
||||
(void) fprintf(el->el_outfile, "Arrow key bindings\n");
|
||||
term_print_arrow(el, STR(""));
|
||||
terminal_print_arrow(el, L"");
|
||||
}
|
||||
|
||||
|
||||
/* map_bind():
|
||||
* Add/remove/change bindings
|
||||
*/
|
||||
protected int
|
||||
map_bind(EditLine *el, int argc, const Char **argv)
|
||||
libedit_private int
|
||||
map_bind(EditLine *el, int argc, const wchar_t **argv)
|
||||
{
|
||||
el_action_t *map;
|
||||
int ntype, rem;
|
||||
const Char *p;
|
||||
Char inbuf[EL_BUFSIZ];
|
||||
Char outbuf[EL_BUFSIZ];
|
||||
const Char *in = NULL;
|
||||
Char *out = NULL;
|
||||
const wchar_t *p;
|
||||
wchar_t inbuf[EL_BUFSIZ];
|
||||
wchar_t outbuf[EL_BUFSIZ];
|
||||
const wchar_t *in = NULL;
|
||||
wchar_t *out;
|
||||
el_bindings_t *bp, *ep;
|
||||
int cmd;
|
||||
int key;
|
||||
|
||||
if (argv == NULL)
|
||||
return (-1);
|
||||
return -1;
|
||||
|
||||
map = el->el_map.key;
|
||||
ntype = XK_CMD;
|
||||
@@ -1271,11 +1280,6 @@ map_bind(EditLine *el, int argc, const Char **argv)
|
||||
case 's':
|
||||
ntype = XK_STR;
|
||||
break;
|
||||
#ifdef notyet
|
||||
case 'c':
|
||||
ntype = XK_EXE;
|
||||
break;
|
||||
#endif
|
||||
case 'k':
|
||||
key = 1;
|
||||
break;
|
||||
@@ -1286,136 +1290,138 @@ map_bind(EditLine *el, int argc, const Char **argv)
|
||||
|
||||
case 'v':
|
||||
map_init_vi(el);
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
case 'e':
|
||||
map_init_emacs(el);
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
case 'l':
|
||||
ep = &el->el_map.help[el->el_map.nfunc];
|
||||
for (bp = el->el_map.help; bp < ep; bp++)
|
||||
(void) fprintf(el->el_outfile,
|
||||
"" FSTR "\n\t" FSTR "\n",
|
||||
"%ls\n\t%ls\n",
|
||||
bp->name, bp->description);
|
||||
return (0);
|
||||
return 0;
|
||||
default:
|
||||
(void) fprintf(el->el_errfile,
|
||||
"" FSTR ": Invalid switch `%c'.\n",
|
||||
argv[0], p[1]);
|
||||
"%ls: Invalid switch `%lc'.\n",
|
||||
argv[0], (wint_t)p[1]);
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
if (argv[argc] == NULL) {
|
||||
map_print_all_keys(el);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
if (key)
|
||||
in = argv[argc++];
|
||||
else if ((in = parse__string(inbuf, argv[argc++])) == NULL) {
|
||||
(void) fprintf(el->el_errfile,
|
||||
"" FSTR ": Invalid \\ or ^ in instring.\n",
|
||||
"%ls: Invalid \\ or ^ in instring.\n",
|
||||
argv[0]);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
if (rem) {
|
||||
if (key) {
|
||||
(void) term_clear_arrow(el, in);
|
||||
return (-1);
|
||||
(void) terminal_clear_arrow(el, in);
|
||||
return -1;
|
||||
}
|
||||
if (in[1])
|
||||
(void) key_delete(el, in);
|
||||
(void) keymacro_delete(el, in);
|
||||
else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
|
||||
(void) key_delete(el, in);
|
||||
(void) keymacro_delete(el, in);
|
||||
else
|
||||
map[(unsigned char) *in] = ED_UNASSIGNED;
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
if (argv[argc] == NULL) {
|
||||
if (key)
|
||||
term_print_arrow(el, in);
|
||||
terminal_print_arrow(el, in);
|
||||
else
|
||||
map_print_key(el, map, in);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
#ifdef notyet
|
||||
if (argv[argc + 1] != NULL) {
|
||||
bindkey_usage();
|
||||
return (-1);
|
||||
bindkeymacro_usage();
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (ntype) {
|
||||
case XK_STR:
|
||||
case XK_EXE:
|
||||
if ((out = parse__string(outbuf, argv[argc])) == NULL) {
|
||||
(void) fprintf(el->el_errfile,
|
||||
"" FSTR ": Invalid \\ or ^ in outstring.\n", argv[0]);
|
||||
return (-1);
|
||||
"%ls: Invalid \\ or ^ in outstring.\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (key)
|
||||
term_set_arrow(el, in, key_map_str(el, out), ntype);
|
||||
terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
|
||||
else
|
||||
key_add(el, in, key_map_str(el, out), ntype);
|
||||
keymacro_add(el, in, keymacro_map_str(el, out), ntype);
|
||||
map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
|
||||
break;
|
||||
|
||||
case XK_CMD:
|
||||
if ((cmd = parse_cmd(el, argv[argc])) == -1) {
|
||||
(void) fprintf(el->el_errfile,
|
||||
"" FSTR ": Invalid command `" FSTR "'.\n",
|
||||
"%ls: Invalid command `%ls'.\n",
|
||||
argv[0], argv[argc]);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
if (key)
|
||||
term_set_arrow(el, in, key_map_str(el, out), ntype);
|
||||
terminal_set_arrow(el, in, keymacro_map_cmd(el, cmd), ntype);
|
||||
else {
|
||||
if (in[1]) {
|
||||
key_add(el, in, key_map_cmd(el, cmd), ntype);
|
||||
keymacro_add(el, in, keymacro_map_cmd(el, cmd), ntype);
|
||||
map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
|
||||
} else {
|
||||
key_clear(el, map, in);
|
||||
map[(unsigned char) *in] = cmd;
|
||||
keymacro_clear(el, map, in);
|
||||
map[(unsigned char) *in] = (el_action_t)cmd;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* coverity[dead_error_begin] */
|
||||
default:
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* map_addfunc():
|
||||
* add a user defined function
|
||||
*/
|
||||
protected int
|
||||
map_addfunc(EditLine *el, const Char *name, const Char *help, el_func_t func)
|
||||
libedit_private int
|
||||
map_addfunc(EditLine *el, const wchar_t *name, const wchar_t *help,
|
||||
el_func_t func)
|
||||
{
|
||||
void *p;
|
||||
int nf = el->el_map.nfunc + 1;
|
||||
size_t nf = el->el_map.nfunc + 1;
|
||||
|
||||
if (name == NULL || help == NULL || func == NULL)
|
||||
return (-1);
|
||||
return -1;
|
||||
|
||||
if ((p = el_realloc(el->el_map.func, nf * sizeof(el_func_t))) == NULL)
|
||||
return (-1);
|
||||
el->el_map.func = (el_func_t *) p;
|
||||
if ((p = el_realloc(el->el_map.help, nf * sizeof(el_bindings_t)))
|
||||
if ((p = el_realloc(el->el_map.func, nf *
|
||||
sizeof(*el->el_map.func))) == NULL)
|
||||
return -1;
|
||||
el->el_map.func = p;
|
||||
if ((p = el_realloc(el->el_map.help, nf * sizeof(*el->el_map.help)))
|
||||
== NULL)
|
||||
return (-1);
|
||||
el->el_map.help = (el_bindings_t *) p;
|
||||
return -1;
|
||||
el->el_map.help = p;
|
||||
|
||||
nf = el->el_map.nfunc;
|
||||
nf = (size_t)el->el_map.nfunc;
|
||||
el->el_map.func[nf] = func;
|
||||
|
||||
el->el_map.help[nf].name = name;
|
||||
el->el_map.help[nf].func = nf;
|
||||
el->el_map.help[nf].func = (int)nf;
|
||||
el->el_map.help[nf].description = help;
|
||||
el->el_map.nfunc++;
|
||||
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user