diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-01-29 19:32:35 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-01-29 19:32:35 +0000 |
commit | e0c1d4afae755ee97ea414016a0eb90c04bae5ac (patch) | |
tree | 94ad0ccab65041a45cc6c3446974d3d9439f2f36 /lib/libedit | |
parent | ead7befaa50eb741fc37b35b4430859c93cd5c7d (diff) |
Second step in synching with NetBSD:
* Rename some types from *key*_t to *keymacro*_t.
* Rename struct editline member el_key to el_keymacro.
* Rename some functions in keymacro.c from key*() to keymacro*().
This removes the conflict of key_clear(), key_end(), and key_print()
with macros in <term.h>. No functional change.
This makes keymacro.h identical to the NetBSD version.
It reduces the remaining diff from +2640 -1998 to +2446 -1805.
OK czarkoff@
Diffstat (limited to 'lib/libedit')
-rw-r--r-- | lib/libedit/el.c | 6 | ||||
-rw-r--r-- | lib/libedit/el.h | 4 | ||||
-rw-r--r-- | lib/libedit/keymacro.c | 234 | ||||
-rw-r--r-- | lib/libedit/keymacro.h | 46 | ||||
-rw-r--r-- | lib/libedit/map.c | 42 | ||||
-rw-r--r-- | lib/libedit/read.c | 6 | ||||
-rw-r--r-- | lib/libedit/terminal.c | 70 | ||||
-rw-r--r-- | lib/libedit/terminal.h | 7 | ||||
-rw-r--r-- | lib/libedit/tty.c | 10 |
9 files changed, 213 insertions, 212 deletions
diff --git a/lib/libedit/el.c b/lib/libedit/el.c index 8721f4944c2..94a939b20fc 100644 --- a/lib/libedit/el.c +++ b/lib/libedit/el.c @@ -1,4 +1,4 @@ -/* $OpenBSD: el.c,v 1.20 2015/01/16 16:48:51 deraadt Exp $ */ +/* $OpenBSD: el.c,v 1.21 2016/01/29 19:32:33 schwarze Exp $ */ /* $NetBSD: el.c,v 1.61 2011/01/27 23:11:40 christos Exp $ */ /*- @@ -91,7 +91,7 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr) free(el); return NULL; } - (void) key_init(el); + (void) keymacro_init(el); (void) map_init(el); if (tty_init(el) == -1) el->el_flags |= NO_TTY; @@ -119,7 +119,7 @@ el_end(EditLine *el) el_reset(el); term_end(el); - key_end(el); + keymacro_end(el); map_end(el); tty_end(el); ch_end(el); diff --git a/lib/libedit/el.h b/lib/libedit/el.h index a54e2e54556..8074bc38313 100644 --- a/lib/libedit/el.h +++ b/lib/libedit/el.h @@ -1,4 +1,4 @@ -/* $OpenBSD: el.h,v 1.10 2016/01/29 17:23:21 schwarze Exp $ */ +/* $OpenBSD: el.h,v 1.11 2016/01/29 19:32:33 schwarze Exp $ */ /* $NetBSD: el.h,v 1.21 2009/12/31 15:58:26 christos Exp $ */ /*- @@ -130,7 +130,7 @@ struct editline { el_prompt_t el_rprompt; /* Prompt stuff */ el_chared_t el_chared; /* Characted editor stuff */ el_map_t el_map; /* Key mapping stuff */ - el_key_t el_key; /* Key binding stuff */ + el_keymacro_t el_keymacro; /* Key binding stuff */ el_history_t el_history; /* History stuff */ el_search_t el_search; /* Search stuff */ el_signal_t el_signal; /* Signal handling stuff */ diff --git a/lib/libedit/keymacro.c b/lib/libedit/keymacro.c index cc577b7f87d..b409aa270fa 100644 --- a/lib/libedit/keymacro.c +++ b/lib/libedit/keymacro.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keymacro.c,v 1.1 2016/01/29 17:23:21 schwarze Exp $ */ +/* $OpenBSD: keymacro.c,v 1.2 2016/01/29 19:32:33 schwarze Exp $ */ /* $NetBSD: key.c,v 1.23 2009/12/30 22:37:40 christos Exp $ */ /*- @@ -41,15 +41,16 @@ * * An extended-key (key) is a sequence of keystrokes introduced * with a sequence introducer and consisting of an arbitrary - * number of characters. This module maintains a map (the el->el_key.map) + * number of characters. This module maintains a map (the + * el->el_keymacro.map) * to convert these extended-key sequences into input strs * (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE). * * Warning: * If key is a substr of some other keys, then the longer * keys are lost!! That is, if the keys "abcd" and "abcef" - * are in el->el_key.map, adding the key "abc" will cause the first two - * definitions to be lost. + * are in el->el_keymacro.map, adding the key "abc" will cause + * the first two definitions to be lost. * * Restrictions: * ------------- @@ -62,103 +63,104 @@ #include "el.h" /* - * The Nodes of the el->el_key.map. The el->el_key.map is a linked list - * of these node elements + * The Nodes of the el->el_keymacro.map. The el->el_keymacro.map is a + * linked list of these node elements */ -struct key_node_t { +struct keymacro_node_t { Char ch; /* single character of key */ int type; /* node type */ - key_value_t val; /* command code or pointer to str, */ + keymacro_value_t val; /* command code or pointer to str, */ /* if this is a leaf */ - struct key_node_t *next; /* ptr to next char of this key */ - struct key_node_t *sibling; /* ptr to another key with same prefix*/ + struct keymacro_node_t *next; /* ptr to next char of this key */ + struct keymacro_node_t *sibling;/* ptr to another key with same prefix*/ }; -private int node_trav(EditLine *, key_node_t *, Char *, - key_value_t *); -private int node__try(EditLine *, key_node_t *, const Char *, - key_value_t *, int); -private key_node_t *node__get(Int); -private void node__free(key_node_t *); -private void node__put(EditLine *, key_node_t *); -private int node__delete(EditLine *, key_node_t **, const Char *); -private int node_lookup(EditLine *, const Char *, key_node_t *, - size_t); -private int node_enum(EditLine *, key_node_t *, size_t); +private int node_trav(EditLine *, keymacro_node_t *, Char *, + keymacro_value_t *); +private int node__try(EditLine *, keymacro_node_t *, const Char *, + keymacro_value_t *, int); +private keymacro_node_t *node__get(Int); +private void node__free(keymacro_node_t *); +private void node__put(EditLine *, keymacro_node_t *); +private int node__delete(EditLine *, keymacro_node_t **, + const Char *); +private int node_lookup(EditLine *, const Char *, + keymacro_node_t *, size_t); +private int node_enum(EditLine *, keymacro_node_t *, size_t); #define KEY_BUFSIZ EL_BUFSIZ -/* key_init(): +/* keymacro_init(): * Initialize the key maps */ protected int -key_init(EditLine *el) +keymacro_init(EditLine *el) { - el->el_key.buf = reallocarray(NULL, KEY_BUFSIZ, - sizeof(*el->el_key.buf)); - if (el->el_key.buf == NULL) + el->el_keymacro.buf = reallocarray(NULL, KEY_BUFSIZ, + sizeof(*el->el_keymacro.buf)); + if (el->el_keymacro.buf == NULL) return (-1); - el->el_key.map = NULL; - key_reset(el); + el->el_keymacro.map = NULL; + keymacro_reset(el); return (0); } -/* key_end(): +/* keymacro_end(): * Free the key maps */ protected void -key_end(EditLine *el) +keymacro_end(EditLine *el) { - free((ptr_t) el->el_key.buf); - el->el_key.buf = NULL; - node__free(el->el_key.map); + free(el->el_keymacro.buf); + el->el_keymacro.buf = NULL; + node__free(el->el_keymacro.map); } -/* key_map_cmd(): +/* keymacro_map_cmd(): * Associate cmd with a key value */ -protected key_value_t * -key_map_cmd(EditLine *el, int cmd) +protected keymacro_value_t * +keymacro_map_cmd(EditLine *el, int cmd) { - el->el_key.val.cmd = (el_action_t) cmd; - return (&el->el_key.val); + el->el_keymacro.val.cmd = (el_action_t) cmd; + return &el->el_keymacro.val; } -/* key_map_str(): +/* keymacro_map_str(): * Associate str with a key value */ -protected key_value_t * -key_map_str(EditLine *el, Char *str) +protected keymacro_value_t * +keymacro_map_str(EditLine *el, Char *str) { - el->el_key.val.str = str; - return (&el->el_key.val); + el->el_keymacro.val.str = str; + return &el->el_keymacro.val; } -/* key_reset(): - * Takes all nodes on el->el_key.map and puts them on free list. Then - * initializes el->el_key.map with arrow keys +/* keymacro_reset(): + * Takes all nodes on el->el_keymacro.map and puts them on free list. + * Then initializes el->el_keymacro.map with arrow keys * [Always bind the ansi arrow keys?] */ protected void -key_reset(EditLine *el) +keymacro_reset(EditLine *el) { - node__put(el, el->el_key.map); - el->el_key.map = NULL; + node__put(el, el->el_keymacro.map); + el->el_keymacro.map = NULL; return; } -/* key_get(): - * Calls the recursive function with entry point el->el_key.map +/* keymacro_get(): + * Calls the recursive function with entry point el->el_keymacro.map * Looks up *ch in map and then reads characters until a * complete match is found or a mismatch occurs. Returns the * type of the match found (XK_STR, XK_CMD, or XK_EXE). @@ -166,49 +168,49 @@ key_reset(EditLine *el) * The last character read is returned in *ch. */ protected int -key_get(EditLine *el, Char *ch, key_value_t *val) +keymacro_get(EditLine *el, Char *ch, keymacro_value_t *val) { - return (node_trav(el, el->el_key.map, ch, val)); + return node_trav(el, el->el_keymacro.map, ch, val); } -/* key_add(): - * Adds key to the el->el_key.map and associates the value in val with it. - * If key is already is in el->el_key.map, the new code is applied to the - * existing key. Ntype specifies if code is a command, an - * out str or a unix command. +/* keymacro_add(): + * Adds key to the el->el_keymacro.map and associates the value in + * val with it. If key is already is in el->el_keymacro.map, the new + * code is applied to the existing key. Ntype specifies if code is a + * command, an out str or a unix command. */ protected void -key_add(EditLine *el, const Char *key, key_value_t *val, int ntype) +keymacro_add(EditLine *el, const Char *key, keymacro_value_t *val, int ntype) { if (key[0] == '\0') { (void) fprintf(el->el_errfile, - "key_add: Null extended-key not allowed.\n"); + "keymacro_add: Null extended-key not allowed.\n"); return; } if (ntype == XK_CMD && val->cmd == ED_SEQUENCE_LEAD_IN) { (void) fprintf(el->el_errfile, - "key_add: sequence-lead-in command not allowed\n"); + "keymacro_add: sequence-lead-in command not allowed\n"); return; } - if (el->el_key.map == NULL) + if (el->el_keymacro.map == NULL) /* tree is initially empty. Set up new node to match key[0] */ - el->el_key.map = node__get(key[0]); + el->el_keymacro.map = node__get(key[0]); /* it is properly initialized */ - /* Now recurse through el->el_key.map */ - (void) node__try(el, el->el_key.map, key, val, ntype); + /* Now recurse through el->el_keymacro.map */ + (void) node__try(el, el->el_keymacro.map, key, val, ntype); return; } -/* key_clear(): +/* keymacro_clear(): * */ protected void -key_clear(EditLine *el, el_action_t *map, const Char *in) +keymacro_clear(EditLine *el, el_action_t *map, const Char *in) { #ifdef WIDECHAR if (*in > N_KEYS) /* can't be in the map */ @@ -219,48 +221,48 @@ key_clear(EditLine *el, el_action_t *map, const Char *in) el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) || (map == el->el_map.alt && el->el_map.key[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN))) - (void) key_delete(el, in); + (void) keymacro_delete(el, in); } -/* key_delete(): +/* keymacro_delete(): * Delete the key and all longer keys staring with key, if * they exists. */ protected int -key_delete(EditLine *el, const Char *key) +keymacro_delete(EditLine *el, const Char *key) { if (key[0] == '\0') { (void) fprintf(el->el_errfile, - "key_delete: Null extended-key not allowed.\n"); + "keymacro_delete: Null extended-key not allowed.\n"); return (-1); } - if (el->el_key.map == NULL) + if (el->el_keymacro.map == NULL) return (0); - (void) node__delete(el, &el->el_key.map, key); + (void) node__delete(el, &el->el_keymacro.map, key); return (0); } -/* key_print(): +/* keymacro_print(): * Print the binding associated with key key. - * Print entire el->el_key.map if null + * Print entire el->el_keymacro.map if null */ protected void -key_print(EditLine *el, const Char *key) +keymacro_print(EditLine *el, const Char *key) { - /* do nothing if el->el_key.map is empty and null key specified */ - if (el->el_key.map == NULL && *key == 0) + /* do nothing if el->el_keymacro.map is empty and null key specified */ + if (el->el_keymacro.map == NULL && *key == 0) return; - el->el_key.buf[0] = '"'; - if (node_lookup(el, key, el->el_key.map, 1) <= -1) + el->el_keymacro.buf[0] = '"'; + if (node_lookup(el, key, el->el_keymacro.map, 1) <= -1) /* key is not bound */ - (void) fprintf(el->el_errfile, "Unbound extended key \"" FSTR "\"\n", - key); + (void) fprintf(el->el_errfile, "Unbound extended key \"" FSTR + "\"\n", key); return; } @@ -270,7 +272,7 @@ key_print(EditLine *el, const Char *key) * found. May read in more characters. */ private int -node_trav(EditLine *el, key_node_t *ptr, Char *ch, key_value_t *val) +node_trav(EditLine *el, keymacro_node_t *ptr, Char *ch, keymacro_value_t *val) { if (ptr->ch == *ch) { @@ -307,11 +309,12 @@ node_trav(EditLine *el, key_node_t *ptr, Char *ch, key_value_t *val) * Find a node that matches *str or allocate a new one */ private int -node__try(EditLine *el, key_node_t *ptr, const Char *str, key_value_t *val, int ntype) +node__try(EditLine *el, keymacro_node_t *ptr, const Char *str, + keymacro_value_t *val, int ntype) { if (ptr->ch != *str) { - key_node_t *xm; + keymacro_node_t *xm; for (xm = ptr; xm->sibling != NULL; xm = xm->sibling) if (xm->sibling->ch == *str) @@ -369,15 +372,15 @@ node__try(EditLine *el, key_node_t *ptr, const Char *str, key_value_t *val, int * Delete node that matches str */ private int -node__delete(EditLine *el, key_node_t **inptr, const Char *str) +node__delete(EditLine *el, keymacro_node_t **inptr, const Char *str) { - key_node_t *ptr; - key_node_t *prev_ptr = NULL; + keymacro_node_t *ptr; + keymacro_node_t *prev_ptr = NULL; ptr = *inptr; if (ptr->ch != *str) { - key_node_t *xm; + keymacro_node_t *xm; for (xm = ptr; xm->sibling != NULL; xm = xm->sibling) if (xm->sibling->ch == *str) @@ -417,7 +420,7 @@ node__delete(EditLine *el, key_node_t **inptr, const Char *str) * Puts a tree of nodes onto free list using free(3). */ private void -node__put(EditLine *el, key_node_t *ptr) +node__put(EditLine *el, keymacro_node_t *ptr) { if (ptr == NULL) return; @@ -446,14 +449,14 @@ node__put(EditLine *el, key_node_t *ptr) /* node__get(): - * Returns pointer to a key_node_t for ch. + * Returns pointer to a keymacro_node_t for ch. */ -private key_node_t * +private keymacro_node_t * node__get(Int ch) { - key_node_t *ptr; + keymacro_node_t *ptr; - ptr = malloc(sizeof(key_node_t)); + ptr = malloc(sizeof(*ptr)); if (ptr == NULL) return NULL; ptr->ch = ch; @@ -465,7 +468,7 @@ node__get(Int ch) } private void -node__free(key_node_t *k) +node__free(keymacro_node_t *k) { if (k == NULL) return; @@ -479,7 +482,7 @@ node__free(key_node_t *k) * Print if last node */ private int -node_lookup(EditLine *el, const Char *str, key_node_t *ptr, size_t cnt) +node_lookup(EditLine *el, const Char *str, keymacro_node_t *ptr, size_t cnt) { ssize_t used; @@ -491,10 +494,10 @@ node_lookup(EditLine *el, const Char *str, key_node_t *ptr, size_t cnt) (void) node_enum(el, ptr, cnt); return (0); } else { - /* If match put this char into el->el_key.buf. Recurse */ + /* If match put this char into el->el_keymacro.buf. Recurse */ if (ptr->ch == *str) { /* match found */ - used = ct_visual_char(el->el_key.buf + cnt, + used = ct_visual_char(el->el_keymacro.buf + cnt, KEY_BUFSIZ - cnt, ptr->ch); if (used == -1) return (-1); /* ran out of buffer space */ @@ -505,9 +508,9 @@ node_lookup(EditLine *el, const Char *str, key_node_t *ptr, size_t cnt) else { /* next node is null so key should be complete */ if (str[1] == 0) { - el->el_key.buf[cnt + used ] = '"'; - el->el_key.buf[cnt + used + 1] = '\0'; - key_kprint(el, el->el_key.buf, + el->el_keymacro.buf[cnt+used ] = '"'; + el->el_keymacro.buf[cnt+used+1] = '\0'; + keymacro_kprint(el, el->el_keymacro.buf, &ptr->val, ptr->type); return (0); } else @@ -530,16 +533,17 @@ node_lookup(EditLine *el, const Char *str, key_node_t *ptr, size_t cnt) * Traverse the node printing the characters it is bound in buffer */ private int -node_enum(EditLine *el, key_node_t *ptr, size_t cnt) +node_enum(EditLine *el, keymacro_node_t *ptr, size_t cnt) { ssize_t used; if (cnt >= KEY_BUFSIZ - 5) { /* buffer too small */ - el->el_key.buf[++cnt] = '"'; - el->el_key.buf[++cnt] = '\0'; + el->el_keymacro.buf[++cnt] = '"'; + el->el_keymacro.buf[++cnt] = '\0'; (void) fprintf(el->el_errfile, "Some extended keys too long for internal print buffer"); - (void) fprintf(el->el_errfile, " \"" FSTR "...\"\n", el->el_key.buf); + (void) fprintf(el->el_errfile, " \"" FSTR "...\"\n", + el->el_keymacro.buf); return (0); } if (ptr == NULL) { @@ -550,12 +554,13 @@ node_enum(EditLine *el, key_node_t *ptr, size_t cnt) return (-1); } /* put this char at end of str */ - used = ct_visual_char(el->el_key.buf + cnt, KEY_BUFSIZ - cnt, ptr->ch); + used = ct_visual_char(el->el_keymacro.buf + cnt, KEY_BUFSIZ - cnt, + ptr->ch); if (ptr->next == NULL) { /* print this key and function */ - el->el_key.buf[cnt + used ] = '"'; - el->el_key.buf[cnt + used + 1] = '\0'; - key_kprint(el, el->el_key.buf, &ptr->val, ptr->type); + el->el_keymacro.buf[cnt + used ] = '"'; + el->el_keymacro.buf[cnt + used + 1] = '\0'; + keymacro_kprint(el, el->el_keymacro.buf, &ptr->val, ptr->type); } else (void) node_enum(el, ptr->next, cnt + used); @@ -566,12 +571,12 @@ node_enum(EditLine *el, key_node_t *ptr, size_t cnt) } -/* key_kprint(): +/* keymacro_kprint(): * Print the specified key and its associated * function specified by val */ protected void -key_kprint(EditLine *el, const Char *key, key_value_t *val, int ntype) +keymacro_kprint(EditLine *el, const Char *key, keymacro_value_t *val, int ntype) { el_bindings_t *fp; char unparsbuf[EL_BUFSIZ]; @@ -581,7 +586,7 @@ key_kprint(EditLine *el, const Char *key, key_value_t *val, int ntype) switch (ntype) { case XK_STR: case XK_EXE: - (void) key__decode_str(val->str, unparsbuf, + (void) keymacro__decode_str(val->str, unparsbuf, sizeof(unparsbuf), ntype == XK_STR ? "\"\"" : "[]"); (void) fprintf(el->el_outfile, fmt, @@ -618,11 +623,11 @@ key_kprint(EditLine *el, const Char *key, key_value_t *val, int ntype) *b++ = c; \ else \ b++ -/* key__decode_str(): +/* keymacro__decode_str(): * Make a printable version of the ey */ protected size_t -key__decode_str(const Char *str, char *buf, size_t len, const char *sep) +keymacro__decode_str(const Char *str, char *buf, size_t len, const char *sep) { char *b = buf, *eb = b + len; const Char *p; @@ -657,4 +662,3 @@ add_endsep: buf[len - 1] = '\0'; return (size_t)(b - buf); } - diff --git a/lib/libedit/keymacro.h b/lib/libedit/keymacro.h index c38f9419517..3b6aed8c563 100644 --- a/lib/libedit/keymacro.h +++ b/lib/libedit/keymacro.h @@ -1,5 +1,5 @@ -/* $OpenBSD: keymacro.h,v 1.1 2016/01/29 17:23:21 schwarze Exp $ */ -/* $NetBSD: key.h,v 1.13 2009/12/30 22:37:40 christos Exp $ */ +/* $OpenBSD: keymacro.h,v 1.2 2016/01/29 19:32:33 schwarze Exp $ */ +/* $NetBSD: keymacro.h,v 1.2 2011/07/28 03:44:36 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,41 +41,37 @@ #ifndef _h_el_keymacro #define _h_el_keymacro -typedef union key_value_t { +typedef union keymacro_value_t { el_action_t cmd; /* If it is a command the # */ Char *str; /* If it is a string... */ -} key_value_t; +} keymacro_value_t; -typedef struct key_node_t key_node_t; +typedef struct keymacro_node_t keymacro_node_t; -typedef struct el_key_t { +typedef struct el_keymacro_t { Char *buf; /* Key print buffer */ - key_node_t *map; /* Key map */ - key_value_t val; /* Local conversion buffer */ -} el_key_t; + keymacro_node_t *map; /* Key map */ + keymacro_value_t val; /* Local conversion buffer */ +} el_keymacro_t; #define XK_CMD 0 #define XK_STR 1 #define XK_NOD 2 #define XK_EXE 3 -#undef key_end -#undef key_clear -#undef key_print - -protected int key_init(EditLine *); -protected void key_end(EditLine *); -protected key_value_t *key_map_cmd(EditLine *, int); -protected key_value_t *key_map_str(EditLine *, Char *); -protected void key_reset(EditLine *); -protected int key_get(EditLine *, Char *, key_value_t *); -protected void key_add(EditLine *, const Char *, key_value_t *, int); -protected void key_clear(EditLine *, el_action_t *, const Char *); -protected int key_delete(EditLine *, const Char *); -protected void key_print(EditLine *, const Char *); -protected void key_kprint(EditLine *, const Char *, key_value_t *, +protected int keymacro_init(EditLine *); +protected void keymacro_end(EditLine *); +protected keymacro_value_t *keymacro_map_cmd(EditLine *, int); +protected keymacro_value_t *keymacro_map_str(EditLine *, Char *); +protected void keymacro_reset(EditLine *); +protected int keymacro_get(EditLine *, Char *, keymacro_value_t *); +protected void keymacro_add(EditLine *, const Char *, keymacro_value_t *, int); +protected void keymacro_clear(EditLine *, el_action_t *, const Char *); +protected int keymacro_delete(EditLine *, const Char *); +protected void keymacro_print(EditLine *, const Char *); +protected void keymacro_kprint(EditLine *, const Char *, keymacro_value_t *, int); -protected size_t key__decode_str(const Char *, char *, size_t, +protected size_t keymacro__decode_str(const Char *, char *, size_t, const char *); #endif /* _h_el_keymacro */ diff --git a/lib/libedit/map.c b/lib/libedit/map.c index a9a6c0e7378..09d102feab1 100644 --- a/lib/libedit/map.c +++ b/lib/libedit/map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map.c,v 1.12 2014/10/17 06:07:50 deraadt Exp $ */ +/* $OpenBSD: map.c,v 1.13 2016/01/29 19:32:33 schwarze Exp $ */ /* $NetBSD: map.c,v 1.25 2009/12/30 22:37:40 christos Exp $ */ /*- @@ -999,7 +999,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; @@ -1021,7 +1021,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]; @@ -1050,7 +1050,7 @@ map_init_emacs(EditLine *el) 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]; @@ -1063,7 +1063,7 @@ 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); @@ -1120,7 +1120,7 @@ map_print_key(EditLine *el, el_action_t *map, const Char *in) 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]) { @@ -1129,7 +1129,7 @@ map_print_key(EditLine *el, el_action_t *map, const Char *in) return; } } else - key_print(el, in); + keymacro_print(el, in); } @@ -1149,7 +1149,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); @@ -1160,14 +1160,14 @@ 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", 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", @@ -1178,14 +1178,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); @@ -1226,7 +1226,7 @@ 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, STR("")); (void) fprintf(el->el_outfile, "Arrow key bindings\n"); term_print_arrow(el, STR("")); } @@ -1319,9 +1319,9 @@ map_bind(EditLine *el, int argc, const Char **argv) 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); @@ -1349,9 +1349,9 @@ map_bind(EditLine *el, int argc, const Char **argv) return (-1); } if (key) - term_set_arrow(el, in, key_map_str(el, out), ntype); + term_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; @@ -1363,13 +1363,13 @@ map_bind(EditLine *el, int argc, const Char **argv) return (-1); } if (key) - term_set_arrow(el, in, key_map_str(el, out), ntype); + term_set_arrow(el, in, keymacro_map_str(el, out), 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); + keymacro_clear(el, map, in); map[(unsigned char) *in] = cmd; } } diff --git a/lib/libedit/read.c b/lib/libedit/read.c index 20dcc7aa733..dccec9be36f 100644 --- a/lib/libedit/read.c +++ b/lib/libedit/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.15 2014/10/17 06:07:50 deraadt Exp $ */ +/* $OpenBSD: read.c,v 1.16 2016/01/29 19:32:33 schwarze Exp $ */ /* $NetBSD: read.c,v 1.57 2010/07/21 18:18:52 christos Exp $ */ /*- @@ -262,8 +262,8 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch) #endif cmd = el->el_map.current[(unsigned char) *ch]; if (cmd == ED_SEQUENCE_LEAD_IN) { - key_value_t val; - switch (key_get(el, ch, &val)) { + keymacro_value_t val; + switch (keymacro_get(el, ch, &val)) { case XK_CMD: cmd = val.cmd; break; diff --git a/lib/libedit/terminal.c b/lib/libedit/terminal.c index 57b5d52c450..ae6caa5b7dd 100644 --- a/lib/libedit/terminal.c +++ b/lib/libedit/terminal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: terminal.c,v 1.1 2016/01/29 17:23:21 schwarze Exp $ */ +/* $OpenBSD: terminal.c,v 1.2 2016/01/29 19:32:33 schwarze Exp $ */ /* $NetBSD: term.c,v 1.57 2009/12/30 22:37:40 christos Exp $ */ /*- @@ -1137,33 +1137,33 @@ term_reset_arrow(EditLine *el) static const Char stOH[] = {033, 'O', 'H', '\0'}; static const Char stOF[] = {033, 'O', 'F', '\0'}; - key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); - key_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); - key_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); - key_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); - key_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); - key_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); - key_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); - key_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); - key_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); - key_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); - key_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); - key_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); - - if (el->el_map.type == MAP_VI) { - key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); - key_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); - key_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); - key_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); - key_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); - key_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); - key_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); - key_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); - key_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); - key_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); - key_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); - key_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); - } + keymacro_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); + keymacro_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); + keymacro_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); + keymacro_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); + keymacro_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); + keymacro_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); + keymacro_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); + keymacro_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); + keymacro_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type); + keymacro_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type); + keymacro_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type); + keymacro_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type); + + if (el->el_map.type != MAP_VI) + return; + keymacro_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); + keymacro_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); + keymacro_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); + keymacro_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); + keymacro_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); + keymacro_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); + keymacro_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type); + keymacro_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type); + keymacro_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type); + keymacro_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type); + keymacro_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type); + keymacro_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type); } @@ -1171,7 +1171,7 @@ term_reset_arrow(EditLine *el) * Set an arrow key binding */ protected int -term_set_arrow(EditLine *el, const Char *name, key_value_t *fun, int type) +term_set_arrow(EditLine *el, const Char *name, keymacro_value_t *fun, int type) { fkey_t *arrow = el->el_term.t_fkey; int i; @@ -1216,8 +1216,8 @@ term_print_arrow(EditLine *el, const Char *name) for (i = 0; i < A_K_NKEYS; i++) if (*name == '\0' || Strcmp(name, arrow[i].name) == 0) if (arrow[i].type != XK_NOD) - key_kprint(el, arrow[i].name, &arrow[i].fun, - arrow[i].type); + keymacro_kprint(el, arrow[i].name, + &arrow[i].fun, arrow[i].type); } @@ -1267,19 +1267,19 @@ term_bind_arrow(EditLine *el) * unassigned key. */ if (arrow[i].type == XK_NOD) - key_clear(el, map, px); + keymacro_clear(el, map, px); else { if (p[1] && (dmap[j] == map[j] || map[j] == ED_SEQUENCE_LEAD_IN)) { - key_add(el, px, &arrow[i].fun, + keymacro_add(el, px, &arrow[i].fun, arrow[i].type); map[j] = ED_SEQUENCE_LEAD_IN; } else if (map[j] == ED_UNASSIGNED) { - key_clear(el, map, px); + keymacro_clear(el, map, px); if (arrow[i].type == XK_CMD) map[j] = arrow[i].fun.cmd; else - key_add(el, px, &arrow[i].fun, + keymacro_add(el, px, &arrow[i].fun, arrow[i].type); } } diff --git a/lib/libedit/terminal.h b/lib/libedit/terminal.h index dbad1adfeb1..0cee8b99184 100644 --- a/lib/libedit/terminal.h +++ b/lib/libedit/terminal.h @@ -1,4 +1,4 @@ -/* $OpenBSD: terminal.h,v 1.1 2016/01/29 17:23:21 schwarze Exp $ */ +/* $OpenBSD: terminal.h,v 1.2 2016/01/29 19:32:34 schwarze Exp $ */ /* $NetBSD: term.h,v 1.21 2009/12/30 22:37:40 christos Exp $ */ /*- @@ -46,7 +46,7 @@ typedef struct { /* Symbolic function key bindings */ const Char *name; /* name of the key */ int key; /* Index in termcap table */ - key_value_t fun; /* Function bound to it */ + keymacro_value_t fun; /* Function bound to it */ int type; /* Type of function */ } fkey_t; @@ -96,7 +96,8 @@ protected int term_init(EditLine *); protected void term_bind_arrow(EditLine *); protected void term_print_arrow(EditLine *, const Char *); protected int term_clear_arrow(EditLine *, const Char *); -protected int term_set_arrow(EditLine *, const Char *, key_value_t *, int); +protected int term_set_arrow(EditLine *, const Char *, keymacro_value_t *, + int); protected void term_end(EditLine *); protected void term_get(EditLine *, const char **); protected int term_set(EditLine *, const char *); diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c index 4873454dcd4..962baaa6829 100644 --- a/lib/libedit/tty.c +++ b/lib/libedit/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.14 2014/05/20 22:28:07 yasuoka Exp $ */ +/* $OpenBSD: tty.c,v 1.15 2016/01/29 19:32:34 schwarze Exp $ */ /* $NetBSD: tty.c,v 1.34 2011/01/27 23:11:40 christos Exp $ */ /*- @@ -899,15 +899,15 @@ tty_bind_char(EditLine *el, int force) if (new[0] == old[0] && !force) continue; /* Put the old default binding back, and set the new binding */ - key_clear(el, map, old); + keymacro_clear(el, map, old); map[UC(old[0])] = dmap[UC(old[0])]; - key_clear(el, map, new); + keymacro_clear(el, map, new); /* MAP_VI == 1, MAP_EMACS == 0... */ map[UC(new[0])] = tp->bind[el->el_map.type]; if (dalt) { - key_clear(el, alt, old); + keymacro_clear(el, alt, old); alt[UC(old[0])] = dalt[UC(old[0])]; - key_clear(el, alt, new); + keymacro_clear(el, alt, new); alt[UC(new[0])] = tp->bind[el->el_map.type + 1]; } } |