Refactor, simplify helper macro

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2018-09-21 07:12:24 +02:00
parent 59fa265d91
commit ebefa8b890
2 changed files with 6 additions and 4 deletions

View File

@ -1933,12 +1933,12 @@ static el_status_t el_bind_key_in_map(int key, el_keymap_func_t function, el_key
el_status_t el_bind_key(int key, el_keymap_func_t function)
{
return el_bind_key_in_map(key, function, Map, ARRAY_ELEMENTS(Map));
return el_bind_key_in_map(key, function, Map, NELEMS(Map));
}
el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function)
{
return el_bind_key_in_map(key, function, MetaMap, ARRAY_ELEMENTS(MetaMap));
return el_bind_key_in_map(key, function, MetaMap, NELEMS(MetaMap));
}
/**

View File

@ -57,8 +57,10 @@
#define MEM_INC 64
#define SCREEN_INC 256
/* http://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array/1598827#1598827 */
#define ARRAY_ELEMENTS(arr) ((sizeof(arr)/sizeof(0[arr])) / ((size_t)(!(sizeof(arr) % sizeof(0[arr])))))
/* From The Practice of Programming, by Kernighan and Pike */
#ifndef NELEMS
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
#endif
/*
** Variables and routines internal to this package.