From c7a6ff9317680a776fcb8ae7a810925e05c45906 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 8 Jul 2013 16:27:55 +0200 Subject: [PATCH] Return el_status_t from el_bind_key() and el_bind_key_in_metamap() The two functions el_bind_key() and el_bind_key_in_metamap() should not print status message on stderr, but rather return the status of the key binding operation. Signed-off-by: Joachim Nilsson --- include/editline.h | 11 ++++++++--- src/editline.c | 21 ++++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/editline.h b/include/editline.h index 28aa7b9..0682ffb 100644 --- a/include/editline.h +++ b/include/editline.h @@ -31,7 +31,12 @@ /* Command status codes. */ typedef enum { - CSdone, CSeof, CSmove, CSdispatch, CSstay, CSsignal + CSdone = 0, /* OK */ + CSeof, /* Error, or EOF */ + CSmove, + CSdispatch, + CSstay, + CSsignal } el_status_t; /* Editline specific types, despite rl_ prefix. From Heimdal project. */ @@ -52,8 +57,8 @@ extern void el_print_columns(int ac, char **av); extern el_status_t el_ring_bell(void); extern el_status_t el_del_char(void); -extern void el_bind_key(int key, el_keymap_func_t function); -extern void el_bind_key_in_metamap(int key, el_keymap_func_t function); +extern el_status_t el_bind_key(int key, el_keymap_func_t function); +extern el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function); extern char *rl_complete(char *token, int *match); extern int rl_list_possib(char *token, char ***av); diff --git a/src/editline.c b/src/editline.c index 6bf67e5..824cfff 100644 --- a/src/editline.c +++ b/src/editline.c @@ -19,10 +19,11 @@ * 4. This notice may not be removed or altered. */ -#include "editline.h" -#include #include #include +#include + +#include "editline.h" /* ** Manifest constants. @@ -1643,13 +1644,13 @@ static int is_ctl_map_key(int key) return mapsz != find_key_in_map(key, Map, mapsz); } -static void el_bind_key_in_map(int key, el_keymap_func_t function, el_keymap_t map[], size_t mapsz) +static el_status_t el_bind_key_in_map(int key, el_keymap_func_t function, el_keymap_t map[], size_t mapsz) { size_t creat, pos = find_key_in_map(key, map, mapsz); if (pos == mapsz) { - fprintf(stderr,"editline: Failed binding key 0x%x, keymap full.\n", key); - return; + errno = ENOMEM; + return CSeof; } /* Add at end, create new? */ @@ -1664,16 +1665,18 @@ static void el_bind_key_in_map(int key, el_keymap_func_t function, el_keymap_t m map[pos + 1].Key = 0; map[pos + 1].Function = NULL; } + + return CSdone; } -void el_bind_key(int key, el_keymap_func_t function) +el_status_t el_bind_key(int key, el_keymap_func_t function) { - el_bind_key_in_map(key, function, Map, ARRAY_ELEMENTS(Map)); + return el_bind_key_in_map(key, function, Map, ARRAY_ELEMENTS(Map)); } -void el_bind_key_in_metamap(int key, el_keymap_func_t function) +el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function) { - el_bind_key_in_map(key, function, MetaMap, ARRAY_ELEMENTS(MetaMap)); + return el_bind_key_in_map(key, function, MetaMap, ARRAY_ELEMENTS(MetaMap)); } /**