Use a macro to determine the size of arrays
Use following macro instead of "sizeof(x) / sizeof(x[0])" everywhere: #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
370c4031be
commit
ce93fa8adb
@ -230,6 +230,8 @@
|
|||||||
#define UTF8_ISCONT(ch) ((unsigned char)ch >= 0x80 && \
|
#define UTF8_ISCONT(ch) ((unsigned char)ch >= 0x80 && \
|
||||||
(unsigned char)ch <= 0xBF)
|
(unsigned char)ch <= 0xBF)
|
||||||
|
|
||||||
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ static const struct confvar confmap[] = {
|
|||||||
|
|
||||||
struct config_save_status {
|
struct config_save_status {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int done[sizeof(confmap) / sizeof(confmap[0])];
|
int done[ARRAY_SIZE(confmap)];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int (*config_fn_walk_cb_t) (const char *, const char *, void *);
|
typedef int (*config_fn_walk_cb_t) (const char *, const char *, void *);
|
||||||
@ -284,7 +284,7 @@ static int config_set_conf(const char *key, const char *value)
|
|||||||
if (!key)
|
if (!key)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
|
for (i = 0; i < ARRAY_SIZE(confmap); i++) {
|
||||||
if (!strcmp(confmap[i].key, key))
|
if (!strcmp(confmap[i].key, key))
|
||||||
return confmap[i].fn_parse(confmap[i].target,
|
return confmap[i].fn_parse(confmap[i].target,
|
||||||
value);
|
value);
|
||||||
@ -447,7 +447,7 @@ config_serialize_conf(char *buf, const char *key,
|
|||||||
if (!key)
|
if (!key)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
|
for (i = 0; i < ARRAY_SIZE(confmap); i++) {
|
||||||
if (!strcmp(confmap[i].key, key)) {
|
if (!strcmp(confmap[i].key, key)) {
|
||||||
if (confmap[i].
|
if (confmap[i].
|
||||||
fn_serialize(buf, confmap[i].target)) {
|
fn_serialize(buf, confmap[i].target)) {
|
||||||
@ -617,7 +617,7 @@ unsigned config_save(void)
|
|||||||
(void *)&status);
|
(void *)&status);
|
||||||
|
|
||||||
/* Set variables that were missing from the configuration file. */
|
/* Set variables that were missing from the configuration file. */
|
||||||
for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
|
for (i = 0; i < ARRAY_SIZE(confmap); i++) {
|
||||||
if (!status.done[i])
|
if (!status.done[i])
|
||||||
config_save_cb(confmap[i].key, NULL, &status);
|
config_save_cb(confmap[i].key, NULL, &status);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ static void layout_selection_bar(void)
|
|||||||
struct binding *bindings[] = {
|
struct binding *bindings[] = {
|
||||||
&quit, &select, &up, &down, &left, &right, &help
|
&quit, &select, &up, &down, &left, &right, &help
|
||||||
};
|
};
|
||||||
int bindings_size = sizeof(bindings) / sizeof(bindings[0]);
|
int bindings_size = ARRAY_SIZE(bindings);
|
||||||
|
|
||||||
keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
|
keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
|
||||||
bindings_size, NULL);
|
bindings_size, NULL);
|
||||||
@ -307,7 +307,7 @@ void custom_sidebar_config(void)
|
|||||||
"can't be smaller than %d characters wide.\n\n");
|
"can't be smaller than %d characters wide.\n\n");
|
||||||
int ch, bindings_size;
|
int ch, bindings_size;
|
||||||
|
|
||||||
bindings_size = sizeof(bindings) / sizeof(bindings[0]);
|
bindings_size = ARRAY_SIZE(bindings);
|
||||||
|
|
||||||
keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
|
keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
|
||||||
bindings_size, NULL);
|
bindings_size, NULL);
|
||||||
@ -401,7 +401,7 @@ static void color_selection_bar(void)
|
|||||||
struct binding *bindings[] = {
|
struct binding *bindings[] = {
|
||||||
&quit, &nocolor, &up, &down, &left, &right, &select
|
&quit, &nocolor, &up, &down, &left, &right, &select
|
||||||
};
|
};
|
||||||
int bindings_size = sizeof(bindings) / sizeof(bindings[0]);
|
int bindings_size = ARRAY_SIZE(bindings);
|
||||||
|
|
||||||
keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
|
keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
|
||||||
bindings_size, NULL);
|
bindings_size, NULL);
|
||||||
@ -926,7 +926,7 @@ static void custom_keys_config_bar(void)
|
|||||||
struct binding *bindings[] = {
|
struct binding *bindings[] = {
|
||||||
&quit, &info, &add, &del, &up, &down, &left, &right
|
&quit, &info, &add, &del, &up, &down, &left, &right
|
||||||
};
|
};
|
||||||
int bindings_size = sizeof(bindings) / sizeof(bindings[0]);
|
int bindings_size = ARRAY_SIZE(bindings);
|
||||||
|
|
||||||
keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
|
keys_display_bindings_bar(win[STA].p, bindings, bindings_size, 0,
|
||||||
bindings_size, NULL);
|
bindings_size, NULL);
|
||||||
|
@ -307,7 +307,7 @@ int utf8_width(char *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
low = 0;
|
low = 0;
|
||||||
high = sizeof(utf8_widthtab) / sizeof(utf8_widthtab[0]);
|
high = ARRAY_SIZE(utf8_widthtab);
|
||||||
do {
|
do {
|
||||||
cur = (low + high) / 2;
|
cur = (low + high) / 2;
|
||||||
if (val >= utf8_widthtab[cur].min) {
|
if (val >= utf8_widthtab[cur].min) {
|
||||||
|
@ -678,18 +678,15 @@ void wins_status_bar(void)
|
|||||||
switch (active_panel) {
|
switch (active_panel) {
|
||||||
case CAL:
|
case CAL:
|
||||||
bindings = bindings_cal;
|
bindings = bindings_cal;
|
||||||
bindings_size =
|
bindings_size = ARRAY_SIZE(bindings_cal);
|
||||||
sizeof(bindings_cal) / sizeof(bindings_cal[0]);
|
|
||||||
break;
|
break;
|
||||||
case APP:
|
case APP:
|
||||||
bindings = bindings_apoint;
|
bindings = bindings_apoint;
|
||||||
bindings_size =
|
bindings_size = ARRAY_SIZE(bindings_apoint);
|
||||||
sizeof(bindings_apoint) / sizeof(bindings_apoint[0]);
|
|
||||||
break;
|
break;
|
||||||
case TOD:
|
case TOD:
|
||||||
bindings = bindings_todo;
|
bindings = bindings_todo;
|
||||||
bindings_size =
|
bindings_size = ARRAY_SIZE(bindings_todo);
|
||||||
sizeof(bindings_todo) / sizeof(bindings_todo[0]);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
EXIT(_("unknown panel"));
|
EXIT(_("unknown panel"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user