1
/* $NetBSD: key.c,v 1.15 2003/10/18 23:48:42 christos Exp $ */
1
/* $NetBSD: key.c,v 1.19 2006/03/23 20:22:51 christos Exp $ */
4
4
* Copyright (c) 1992, 1993
36
#if !defined(lint) && !defined(SCCSID)
38
static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
41
#endif /* not lint && not SCCSID */
38
44
* key.c: This module contains the procedures for maintaining
39
45
* the extended-key map.
41
47
* An extended-key (key) is a sequence of keystrokes introduced
42
* with an sequence introducer and consisting of an arbitrary
48
* with a sequence introducer and consisting of an arbitrary
43
49
* number of characters. This module maintains a map (the el->el_key.map)
44
50
* to convert these extended-key sequences into input strs
45
51
* (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
78
84
private int node__try(EditLine *, key_node_t *, const char *,
79
85
key_value_t *, int);
80
86
private key_node_t *node__get(int);
87
private void node__free(key_node_t *);
81
88
private void node__put(EditLine *, key_node_t *);
82
89
private int node__delete(EditLine *, key_node_t **, const char *);
83
90
private int node_lookup(EditLine *, const char *, key_node_t *,
85
92
private int node_enum(EditLine *, key_node_t *, int);
86
private int key__decode_char(char *, int, int);
88
94
#define KEY_BUFSIZ EL_BUFSIZ
483
495
/* If match put this char into el->el_key.buf. Recurse */
484
496
if (ptr->ch == *str) {
485
497
/* match found */
486
ncnt = key__decode_char(el->el_key.buf, cnt,
498
ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
487
499
(unsigned char) ptr->ch);
488
500
if (ptr->next != NULL)
489
501
/* not yet at leaf */
539
551
/* put this char at end of str */
540
ncnt = key__decode_char(el->el_key.buf, cnt, (unsigned char) ptr->ch);
552
ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
553
(unsigned char)ptr->ch);
541
554
if (ptr->next == NULL) {
542
555
/* print this key and function */
543
556
el->el_key.buf[ncnt + 1] = '"';
571
(void) fprintf(el->el_outfile, fmt, key,
572
key__decode_str(val->str, unparsbuf,
573
ntype == XK_STR ? "\"\"" : "[]"));
584
(void) key__decode_str(val->str, unparsbuf,
586
ntype == XK_STR ? "\"\"" : "[]");
587
(void) fprintf(el->el_outfile, fmt, key, unparsbuf);
576
590
for (fp = el->el_map.help; fp->name; fp++)
598
617
/* key__decode_char():
599
618
* Put a printable form of char in buf.
602
key__decode_char(char *buf, int cnt, int ch)
621
key__decode_char(char *buf, int cnt, int off, int ch)
623
char *sb = buf + off;
624
char *eb = buf + cnt;
609
631
if (iscntrl(ch)) {
611
633
if (ch == '\177')
614
buf[cnt] = ch | 0100;
615
637
} else if (ch == '^') {
618
640
} else if (ch == '\\') {
621
643
} else if (ch == ' ' || (el_isprint(ch) && !isspace(ch))) {
625
buf[cnt++] = (((unsigned int) ch >> 6) & 7) + '0';
626
buf[cnt++] = (((unsigned int) ch >> 3) & 7) + '0';
627
buf[cnt] = (ch & 7) + '0';
647
ADDC((((unsigned int) ch >> 6) & 7) + '0');
648
ADDC((((unsigned int) ch >> 3) & 7) + '0');
649
ADDC((ch & 7) + '0');
633
655
/* key__decode_str():
634
656
* Make a printable version of the ey
637
key__decode_str(const char *str, char *buf, const char *sep)
659
key__decode_str(const char *str, char *buf, int len, const char *sep)
661
char *b = buf, *eb = b + len;
648
if (sep[0] != '\0' && sep[1] != '\0')
665
if (sep[0] != '\0') {
671
if (sep[0] != '\0' && sep[1] != '\0') {
653
676
for (p = str; *p != 0; p++) {
654
677
if (iscntrl((unsigned char) *p)) {
660
684
} else if (*p == '^' || *p == '\\') {
663
687
} else if (*p == ' ' || (el_isprint((unsigned char) *p) &&
664
688
!isspace((unsigned char) *p))) {
668
*b++ = (((unsigned int) *p >> 6) & 7) + '0';
669
*b++ = (((unsigned int) *p >> 3) & 7) + '0';
670
*b++ = (*p & 7) + '0';
692
ADDC((((unsigned int) *p >> 6) & 7) + '0');
693
ADDC((((unsigned int) *p >> 3) & 7) + '0');
694
ADDC((*p & 7) + '0');
673
if (sep[0] != '\0' && sep[1] != '\0')
676
return (buf); /* should check for overflow */
697
if (sep[0] != '\0' && sep[1] != '\0') {