diff options
author | David E. O'Brien <obrien@FreeBSD.org> | 2011-03-31 01:13:05 +0000 |
---|---|---|
committer | David E. O'Brien <obrien@FreeBSD.org> | 2011-03-31 01:13:05 +0000 |
commit | 75d35a370343c1fb6f274d4631225321e727287f (patch) | |
tree | f34dc8a2bb54570a6798ff5be267407e132ef117 /key.c | |
parent | f592be44eb2190db09b8cee428090a232d528910 (diff) | |
download | src-75d35a370343c1fb6f274d4631225321e727287f.tar.gz src-75d35a370343c1fb6f274d4631225321e727287f.zip |
Vendor import NetBSD's libedit of "2005/08/02 12:11:14 UTC".vendor/NetBSD/libedit/2005-08-02
Obtained from: NetBSD
Notes
Notes:
svn path=/vendor/NetBSD/libedit/dist/; revision=220178
svn path=/vendor/NetBSD/libedit/2005-08-02/; revision=220179; tag=vendor/NetBSD/libedit/2005-08-02
Diffstat (limited to 'key.c')
-rw-r--r-- | key.c | 53 |
1 files changed, 29 insertions, 24 deletions
@@ -1,4 +1,4 @@ -/* $NetBSD: key.c,v 1.12 2001/05/17 01:02:17 christos Exp $ */ +/* $NetBSD: key.c,v 1.16 2005/07/06 21:13:02 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +15,7 @@ * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,12 +32,12 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> +#include "config.h" #if !defined(lint) && !defined(SCCSID) #if 0 static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: key.c,v 1.12 2001/05/17 01:02:17 christos Exp $"); +__RCSID("$NetBSD: key.c,v 1.16 2005/07/06 21:13:02 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -66,7 +62,6 @@ __RCSID("$NetBSD: key.c,v 1.12 2001/05/17 01:02:17 christos Exp $"); * 1) It is not possible to have one key that is a * substr of another. */ -#include "sys.h" #include <string.h> #include <stdlib.h> @@ -90,9 +85,11 @@ private int node_trav(EditLine *, key_node_t *, char *, 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 **, char *); -private int node_lookup(EditLine *, char *, key_node_t *, int); +private int node__delete(EditLine *, key_node_t **, const char *); +private int node_lookup(EditLine *, const char *, key_node_t *, + int); private int node_enum(EditLine *, key_node_t *, int); private int key__decode_char(char *, int, int); @@ -114,7 +111,6 @@ key_init(EditLine *el) return (0); } - /* key_end(): * Free the key maps */ @@ -124,8 +120,7 @@ key_end(EditLine *el) el_free((ptr_t) el->el_key.buf); el->el_key.buf = NULL; - /* XXX: provide a function to clear the keys */ - el->el_key.map = NULL; + node__free(el->el_key.map); } @@ -219,7 +214,7 @@ key_add(EditLine *el, const char *key, key_value_t *val, int ntype) * */ protected void -key_clear(EditLine *el, el_action_t *map, char *in) +key_clear(EditLine *el, el_action_t *map, const char *in) { if ((map[(unsigned char)*in] == ED_SEQUENCE_LEAD_IN) && @@ -236,7 +231,7 @@ key_clear(EditLine *el, el_action_t *map, char *in) * they exists. */ protected int -key_delete(EditLine *el, char *key) +key_delete(EditLine *el, const char *key) { if (key[0] == '\0') { @@ -257,7 +252,7 @@ key_delete(EditLine *el, char *key) * Print entire el->el_key.map if null */ protected void -key_print(EditLine *el, char *key) +key_print(EditLine *el, const char *key) { /* do nothing if el->el_key.map is empty and null key specified */ @@ -356,7 +351,8 @@ node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int break; case XK_STR: case XK_EXE: - ptr->val.str = strdup(val->str); + if ((ptr->val.str = el_strdup(val->str)) == NULL) + return -1; break; default: EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype)); @@ -376,7 +372,7 @@ 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, char *str) +node__delete(EditLine *el, key_node_t **inptr, const char *str) { key_node_t *ptr; key_node_t *prev_ptr = NULL; @@ -471,14 +467,22 @@ node__get(int ch) return (ptr); } - +private void +node__free(key_node_t *k) +{ + if (k == NULL) + return; + node__free(k->sibling); + node__free(k->next); + el_free((ptr_t) k); +} /* node_lookup(): * look for the str starting at node ptr. * Print if last node */ private int -node_lookup(EditLine *el, char *str, key_node_t *ptr, int cnt) +node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt) { int ncnt; @@ -568,7 +572,7 @@ node_enum(EditLine *el, key_node_t *ptr, int cnt) * function specified by val */ protected void -key_kprint(EditLine *el, char *key, key_value_t *val, int ntype) +key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype) { el_bindings_t *fp; char unparsbuf[EL_BUFSIZ]; @@ -644,9 +648,10 @@ key__decode_char(char *buf, int cnt, int ch) * Make a printable version of the ey */ protected char * -key__decode_str(char *str, char *buf, char *sep) +key__decode_str(const char *str, char *buf, const char *sep) { - char *b, *p; + char *b; + const char *p; b = buf; if (sep[0] != '\0') |