2017-03-18 21:41:53 +00:00
|
|
|
/* $Header: /p/tcsh/cvsroot/tcsh/tc.bind.c,v 3.46 2015/08/13 08:54:04 christos Exp $ */
|
2000-04-15 04:41:27 +00:00
|
|
|
/*
|
|
|
|
* tc.bind.c: Key binding functions
|
|
|
|
*/
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1980, 1991 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2002-07-24 16:23:10 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2000-04-15 04:41:27 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#include "sh.h"
|
|
|
|
|
2017-03-18 21:41:53 +00:00
|
|
|
RCSID("$tcsh: tc.bind.c,v 3.46 2015/08/13 08:54:04 christos Exp $")
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
#include "ed.h"
|
|
|
|
#include "ed.defns.h"
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
static void printkey (const KEYCMD *, CStr *);
|
|
|
|
static KEYCMD parsecmd (Char *);
|
|
|
|
static void bad_spec (const Char *);
|
|
|
|
static CStr *parsestring (const Char *, CStr *);
|
|
|
|
static CStr *parsebind (const Char *, CStr *);
|
|
|
|
static void print_all_keys (void);
|
|
|
|
static void printkeys (KEYCMD *, int, int);
|
|
|
|
static void bindkey_usage (void);
|
|
|
|
static void list_functions (void);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
extern int MapsAreInited;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
dobindkey(Char **v, struct command *c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
KEYCMD *map;
|
2005-04-24 19:41:08 +00:00
|
|
|
int ntype, no, removeb, key, bindk;
|
2000-04-15 04:41:27 +00:00
|
|
|
Char *par;
|
|
|
|
Char p;
|
|
|
|
KEYCMD cmd;
|
|
|
|
CStr in;
|
|
|
|
CStr out;
|
|
|
|
uChar ch;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (!MapsAreInited)
|
|
|
|
ed_InitMaps();
|
|
|
|
|
|
|
|
map = CcKeyMap;
|
|
|
|
ntype = XK_CMD;
|
2005-04-24 19:41:08 +00:00
|
|
|
key = removeb = bindk = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
for (no = 1, par = v[no];
|
|
|
|
par != NULL && (*par++ & CHAR) == '-'; no++, par = v[no]) {
|
|
|
|
if ((p = (*par & CHAR)) == '-') {
|
|
|
|
no++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
switch (p) {
|
|
|
|
case 'b':
|
2005-04-24 19:41:08 +00:00
|
|
|
bindk = 1;
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
key = 1;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
map = CcAltMap;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
ntype = XK_STR;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
ntype = XK_EXE;
|
|
|
|
break;
|
|
|
|
case 'r':
|
2005-04-24 19:41:08 +00:00
|
|
|
removeb = 1;
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
ed_InitVIMaps();
|
|
|
|
return;
|
|
|
|
case 'e':
|
|
|
|
ed_InitEmacsMaps();
|
|
|
|
return;
|
|
|
|
case 'd':
|
|
|
|
#ifdef VIDEFAULT
|
|
|
|
ed_InitVIMaps();
|
|
|
|
#else /* EMACSDEFAULT */
|
|
|
|
ed_InitEmacsMaps();
|
|
|
|
#endif /* VIDEFAULT */
|
|
|
|
return;
|
|
|
|
case 'l':
|
|
|
|
list_functions();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
bindkey_usage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!v[no]) {
|
|
|
|
print_all_keys();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key) {
|
|
|
|
if (!IsArrowKey(v[no]))
|
|
|
|
xprintf(CGETS(20, 1, "Invalid key name `%S'\n"), v[no]);
|
2007-03-11 22:33:41 +00:00
|
|
|
in.buf = Strsave(v[no++]);
|
2000-04-15 04:41:27 +00:00
|
|
|
in.len = Strlen(in.buf);
|
|
|
|
}
|
|
|
|
else {
|
2005-04-24 19:41:08 +00:00
|
|
|
if (bindk) {
|
2000-04-15 04:41:27 +00:00
|
|
|
if (parsebind(v[no++], &in) == NULL)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (parsestring(v[no++], &in) == NULL)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_push(in.buf, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2005-04-24 19:41:08 +00:00
|
|
|
#ifndef WINNT_NATIVE
|
|
|
|
if (in.buf[0] > 0xFF) {
|
|
|
|
bad_spec(in.buf);
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(in.buf);
|
2005-04-24 19:41:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2000-04-15 04:41:27 +00:00
|
|
|
ch = (uChar) in.buf[0];
|
|
|
|
|
2005-04-24 19:41:08 +00:00
|
|
|
if (removeb) {
|
2007-03-11 22:33:41 +00:00
|
|
|
if (key)
|
2000-04-15 04:41:27 +00:00
|
|
|
(void) ClearArrowKeys(&in);
|
2007-03-11 22:33:41 +00:00
|
|
|
else if (in.len > 1) {
|
2000-04-15 04:41:27 +00:00
|
|
|
(void) DeleteXkey(&in);
|
|
|
|
}
|
|
|
|
else if (map[ch] == F_XKEY) {
|
|
|
|
(void) DeleteXkey(&in);
|
|
|
|
map[ch] = F_UNASSIGNED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
map[ch] = F_UNASSIGNED;
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(in.buf);
|
2000-04-15 04:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!v[no]) {
|
|
|
|
if (key)
|
|
|
|
PrintArrowKeys(&in);
|
|
|
|
else
|
|
|
|
printkey(map, &in);
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(in.buf);
|
2000-04-15 04:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (v[no + 1]) {
|
|
|
|
bindkey_usage();
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(in.buf);
|
2000-04-15 04:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (ntype) {
|
|
|
|
case XK_STR:
|
|
|
|
case XK_EXE:
|
2007-03-11 22:33:41 +00:00
|
|
|
if (parsestring(v[no], &out) == NULL) {
|
|
|
|
cleanup_until(in.buf);
|
2000-04-15 04:41:27 +00:00
|
|
|
return;
|
2007-03-11 22:33:41 +00:00
|
|
|
}
|
|
|
|
cleanup_push(out.buf, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (key) {
|
|
|
|
if (SetArrowKeys(&in, XmapStr(&out), ntype) == -1)
|
2005-04-24 19:41:08 +00:00
|
|
|
xprintf(CGETS(20, 2, "Bad key name: %S\n"), in.buf);
|
2007-03-11 22:33:41 +00:00
|
|
|
else
|
|
|
|
cleanup_ignore(out.buf);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
AddXkey(&in, XmapStr(&out), ntype);
|
|
|
|
map[ch] = F_XKEY;
|
|
|
|
break;
|
|
|
|
case XK_CMD:
|
2007-03-11 22:33:41 +00:00
|
|
|
if ((cmd = parsecmd(v[no])) == 0) {
|
|
|
|
cleanup_until(in.buf);
|
2000-04-15 04:41:27 +00:00
|
|
|
return;
|
2007-03-11 22:33:41 +00:00
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
if (key)
|
|
|
|
(void) SetArrowKeys(&in, XmapCmd((int) cmd), ntype);
|
|
|
|
else {
|
|
|
|
if (in.len > 1) {
|
|
|
|
AddXkey(&in, XmapCmd((int) cmd), ntype);
|
|
|
|
map[ch] = F_XKEY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ClearXkey(map, &in);
|
|
|
|
map[ch] = cmd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(in.buf);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (key)
|
|
|
|
BindArrowKeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
printkey(const KEYCMD *map, CStr *in)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct KeyFuncs *fp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (in->len < 2) {
|
2007-03-11 22:33:41 +00:00
|
|
|
unsigned char *unparsed;
|
|
|
|
|
|
|
|
unparsed = unparsestring(in, STRQQ);
|
|
|
|
cleanup_push(unparsed, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
for (fp = FuncNames; fp->name; fp++) {
|
|
|
|
if (fp->func == map[(uChar) *(in->buf)]) {
|
2007-03-11 22:33:41 +00:00
|
|
|
xprintf("%s\t->\t%s\n", unparsed, fp->name);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(unparsed);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
else
|
2000-04-15 04:41:27 +00:00
|
|
|
PrintXkey(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
static KEYCMD
|
2007-03-11 22:33:41 +00:00
|
|
|
parsecmd(Char *str)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct KeyFuncs *fp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
for (fp = FuncNames; fp->name; fp++) {
|
|
|
|
if (strcmp(short2str(str), fp->name) == 0) {
|
|
|
|
return (KEYCMD) fp->func;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xprintf(CGETS(20, 3, "Bad command name: %S\n"), str);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
bad_spec(const Char *str)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
xprintf(CGETS(20, 4, "Bad key spec %S\n"), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CStr *
|
2007-03-11 22:33:41 +00:00
|
|
|
parsebind(const Char *s, CStr *str)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
struct Strbuf b = Strbuf_INIT;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_push(&b, Strbuf_cleanup);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (Iscntrl(*s)) {
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, *s);
|
|
|
|
goto end;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (*s) {
|
|
|
|
case '^':
|
|
|
|
s++;
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifdef IS_ASCII
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, (*s == '?') ? '\177' : ((*s & CHAR) & 0237));
|
2000-11-30 21:05:33 +00:00
|
|
|
#else
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, (*s == '?') ? CTL_ESC('\177')
|
|
|
|
: _toebcdic[_toascii[*s & CHAR] & 0237]);
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
case 'M':
|
|
|
|
case 'X':
|
|
|
|
case 'C':
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifdef WINNT_NATIVE
|
2000-04-15 04:41:27 +00:00
|
|
|
case 'N':
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif /* WINNT_NATIVE */
|
2007-03-11 22:33:41 +00:00
|
|
|
if (s[1] != '-' || s[2] == '\0')
|
|
|
|
goto bad_spec;
|
2000-04-15 04:41:27 +00:00
|
|
|
s += 2;
|
|
|
|
switch (s[-2]) {
|
|
|
|
case 'F': case 'f': /* Turn into ^[str */
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, CTL_ESC('\033'));
|
|
|
|
Strbuf_append(&b, s);
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C': case 'c': /* Turn into ^c */
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifdef IS_ASCII
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, (*s == '?') ? '\177' : ((*s & CHAR) & 0237));
|
2000-11-30 21:05:33 +00:00
|
|
|
#else
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, (*s == '?') ? CTL_ESC('\177')
|
|
|
|
: _toebcdic[_toascii[*s & CHAR] & 0237]);
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X' : case 'x': /* Turn into ^Xc */
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifdef IS_ASCII
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, 'X' & 0237);
|
2000-11-30 21:05:33 +00:00
|
|
|
#else
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, _toebcdic[_toascii['X'] & 0237]);
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, *s);
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M' : case 'm': /* Turn into 0x80|c */
|
|
|
|
if (!NoNLSRebind) {
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, CTL_ESC('\033'));
|
|
|
|
Strbuf_append1(&b, *s);
|
2000-04-15 04:41:27 +00:00
|
|
|
} else {
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifdef IS_ASCII
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, *s | 0x80);
|
2000-11-30 21:05:33 +00:00
|
|
|
#else
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, _toebcdic[_toascii[*s] | 0x80]);
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifdef WINNT_NATIVE
|
2000-04-15 04:41:27 +00:00
|
|
|
case 'N' : case 'n': /* NT */
|
|
|
|
{
|
|
|
|
Char bnt;
|
|
|
|
|
|
|
|
bnt = nt_translate_bindkey(s);
|
|
|
|
if (bnt != 0)
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, bnt);
|
2000-04-15 04:41:27 +00:00
|
|
|
else
|
|
|
|
bad_spec(s);
|
|
|
|
}
|
|
|
|
break;
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif /* WINNT_NATIVE */
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-03-11 22:33:41 +00:00
|
|
|
goto bad_spec;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
end:
|
|
|
|
cleanup_ignore(&b);
|
|
|
|
cleanup_until(&b);
|
|
|
|
Strbuf_terminate(&b);
|
|
|
|
str->buf = xrealloc(b.s, (b.len + 1) * sizeof (*str->buf));
|
|
|
|
str->len = b.len;
|
2000-04-15 04:41:27 +00:00
|
|
|
return str;
|
2007-03-11 22:33:41 +00:00
|
|
|
|
|
|
|
bad_spec:
|
|
|
|
bad_spec(s);
|
|
|
|
cleanup_until(&b);
|
|
|
|
return NULL;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CStr *
|
2007-03-11 22:33:41 +00:00
|
|
|
parsestring(const Char *str, CStr *buf)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
struct Strbuf b = Strbuf_INIT;
|
2000-04-15 04:41:27 +00:00
|
|
|
const Char *p;
|
2005-04-24 19:41:08 +00:00
|
|
|
eChar es;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (*str == 0) {
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 5, "Null string specification\n"));
|
2000-04-15 04:41:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_push(&b, Strbuf_cleanup);
|
2000-04-15 04:41:27 +00:00
|
|
|
for (p = str; *p != 0; p++) {
|
|
|
|
if ((*p & CHAR) == '\\' || (*p & CHAR) == '^') {
|
2007-03-11 22:33:41 +00:00
|
|
|
if ((es = parseescape(&p)) == CHAR_ERR) {
|
|
|
|
cleanup_until(&b);
|
2000-04-15 04:41:27 +00:00
|
|
|
return 0;
|
2007-03-11 22:33:41 +00:00
|
|
|
} else
|
|
|
|
Strbuf_append1(&b, es);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&b, *p & CHAR);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_ignore(&b);
|
|
|
|
cleanup_until(&b);
|
|
|
|
Strbuf_terminate(&b);
|
|
|
|
buf->buf = xrealloc(b.s, (b.len + 1) * sizeof (*buf->buf));
|
|
|
|
buf->len = b.len;
|
2000-04-15 04:41:27 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
print_all_keys(void)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
int prev, i;
|
|
|
|
CStr nilstr;
|
|
|
|
nilstr.buf = NULL;
|
|
|
|
nilstr.len = 0;
|
|
|
|
|
|
|
|
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 6, "Standard key bindings\n"));
|
2000-04-15 04:41:27 +00:00
|
|
|
prev = 0;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
if (CcKeyMap[prev] == CcKeyMap[i])
|
|
|
|
continue;
|
|
|
|
printkeys(CcKeyMap, prev, i - 1);
|
|
|
|
prev = i;
|
|
|
|
}
|
|
|
|
printkeys(CcKeyMap, prev, i - 1);
|
|
|
|
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 7, "Alternative key bindings\n"));
|
2000-04-15 04:41:27 +00:00
|
|
|
prev = 0;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
if (CcAltMap[prev] == CcAltMap[i])
|
|
|
|
continue;
|
|
|
|
printkeys(CcAltMap, prev, i - 1);
|
|
|
|
prev = i;
|
|
|
|
}
|
|
|
|
printkeys(CcAltMap, prev, i - 1);
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 8, "Multi-character bindings\n"));
|
2000-04-15 04:41:27 +00:00
|
|
|
PrintXkey(NULL); /* print all Xkey bindings */
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 9, "Arrow key bindings\n"));
|
2000-04-15 04:41:27 +00:00
|
|
|
PrintArrowKeys(&nilstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
printkeys(KEYCMD *map, int first, int last)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct KeyFuncs *fp;
|
2000-04-15 04:41:27 +00:00
|
|
|
Char firstbuf[2], lastbuf[2];
|
|
|
|
CStr fb, lb;
|
2007-03-11 22:33:41 +00:00
|
|
|
unsigned char *unparsed;
|
2000-04-15 04:41:27 +00:00
|
|
|
fb.buf = firstbuf;
|
|
|
|
lb.buf = lastbuf;
|
|
|
|
|
|
|
|
firstbuf[0] = (Char) first;
|
|
|
|
firstbuf[1] = 0;
|
|
|
|
lastbuf[0] = (Char) last;
|
|
|
|
lastbuf[1] = 0;
|
|
|
|
fb.len = 1;
|
|
|
|
lb.len = 1;
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
unparsed = unparsestring(&fb, STRQQ);
|
|
|
|
cleanup_push(unparsed, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (map[first] == F_UNASSIGNED) {
|
|
|
|
if (first == last)
|
2007-03-11 22:33:41 +00:00
|
|
|
xprintf(CGETS(20, 10, "%-15s-> is undefined\n"), unparsed);
|
|
|
|
cleanup_until(unparsed);
|
2000-04-15 04:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (fp = FuncNames; fp->name; fp++) {
|
|
|
|
if (fp->func == map[first]) {
|
2007-03-11 22:33:41 +00:00
|
|
|
if (first == last)
|
|
|
|
xprintf("%-15s-> %s\n", unparsed, fp->name);
|
2000-04-15 04:41:27 +00:00
|
|
|
else {
|
2007-03-11 22:33:41 +00:00
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
p = unparsestring(&lb, STRQQ);
|
|
|
|
cleanup_push(p, xfree);
|
|
|
|
xprintf("%-4s to %-7s-> %s\n", unparsed, p, fp->name);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(unparsed);
|
2000-04-15 04:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
xprintf(CGETS(20, 11, "BUG!!! %s isn't bound to anything.\n"), unparsed);
|
|
|
|
if (map == CcKeyMap)
|
2000-04-15 04:41:27 +00:00
|
|
|
xprintf("CcKeyMap[%d] == %d\n", first, CcKeyMap[first]);
|
2007-03-11 22:33:41 +00:00
|
|
|
else
|
2000-04-15 04:41:27 +00:00
|
|
|
xprintf("CcAltMap[%d] == %d\n", first, CcAltMap[first]);
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(unparsed);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
bindkey_usage(void)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 12,
|
2000-04-15 04:41:27 +00:00
|
|
|
"Usage: bindkey [options] [--] [KEY [COMMAND]]\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 13,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -a list or bind KEY in alternative key map\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 14,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -b interpret KEY as a C-, M-, F- or X- key name\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 15,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -s interpret COMMAND as a literal string to be output\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 16,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -c interpret COMMAND as a builtin or external command\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 17,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -v bind all keys to vi bindings\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 18,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -e bind all keys to emacs bindings\n"));
|
2017-03-18 21:41:53 +00:00
|
|
|
xprintf(CGETS(20, 19,
|
|
|
|
" -d bind all keys to default editor's bindings (%s)\n"),
|
|
|
|
#ifdef VIDEFAULT
|
|
|
|
"vi"
|
|
|
|
#else /* EMACSDEFAULT */
|
|
|
|
"emacs"
|
|
|
|
#endif /* VIDEFAULT */
|
|
|
|
);
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 20,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -l list editor commands with descriptions\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 21,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -r remove KEY's binding\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 22,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -k interpret KEY as a symbolic arrow-key name\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 23,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -- force a break from option processing\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 24,
|
2000-04-15 04:41:27 +00:00
|
|
|
" -u (or any invalid option) this message\n"));
|
|
|
|
xprintf("\n");
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 25,
|
2000-04-15 04:41:27 +00:00
|
|
|
"Without KEY or COMMAND, prints all bindings\n"));
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(20, 26,
|
2000-04-15 04:41:27 +00:00
|
|
|
"Without COMMAND, prints the binding for KEY.\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
list_functions(void)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
struct KeyFuncs *fp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
for (fp = FuncNames; fp->name; fp++) {
|
|
|
|
xprintf("%s\n %s\n", fp->name, fp->desc);
|
|
|
|
}
|
|
|
|
}
|