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 <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2013-07-08 16:27:55 +02:00
parent 897a98be55
commit c7a6ff9317
2 changed files with 20 additions and 12 deletions

View File

@ -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);

View File

@ -19,10 +19,11 @@
* 4. This notice may not be removed or altered.
*/
#include "editline.h"
#include <signal.h>
#include <errno.h>
#include <ctype.h>
#include <signal.h>
#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));
}
/**