aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.h2
-rw-r--r--src/config.c8
-rw-r--r--src/custom.c8
-rw-r--r--src/utf8.c2
-rw-r--r--src/wins.c9
5 files changed, 14 insertions, 15 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index 1dfd648..da1f447 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -230,6 +230,8 @@
#define UTF8_ISCONT(ch) ((unsigned char)ch >= 0x80 && \
(unsigned char)ch <= 0xBF)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
diff --git a/src/config.c b/src/config.c
index 39ac338..da6b049 100644
--- a/src/config.c
+++ b/src/config.c
@@ -112,7 +112,7 @@ static const struct confvar confmap[] = {
struct config_save_status {
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 *);
@@ -284,7 +284,7 @@ static int config_set_conf(const char *key, const char *value)
if (!key)
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))
return confmap[i].fn_parse(confmap[i].target,
value);
@@ -447,7 +447,7 @@ config_serialize_conf(char *buf, const char *key,
if (!key)
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 (confmap[i].
fn_serialize(buf, confmap[i].target)) {
@@ -617,7 +617,7 @@ unsigned config_save(void)
(void *)&status);
/* 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])
config_save_cb(confmap[i].key, NULL, &status);
}
diff --git a/src/custom.c b/src/custom.c
index 6ae8abc..da632bf 100644
--- a/src/custom.c
+++ b/src/custom.c
@@ -135,7 +135,7 @@ static void layout_selection_bar(void)
struct binding *bindings[] = {
&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,
bindings_size, NULL);
@@ -307,7 +307,7 @@ void custom_sidebar_config(void)
"can't be smaller than %d characters wide.\n\n");
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,
bindings_size, NULL);
@@ -401,7 +401,7 @@ static void color_selection_bar(void)
struct binding *bindings[] = {
&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,
bindings_size, NULL);
@@ -926,7 +926,7 @@ static void custom_keys_config_bar(void)
struct binding *bindings[] = {
&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,
bindings_size, NULL);
diff --git a/src/utf8.c b/src/utf8.c
index 9b9f341..723c121 100644
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -307,7 +307,7 @@ int utf8_width(char *s)
}
low = 0;
- high = sizeof(utf8_widthtab) / sizeof(utf8_widthtab[0]);
+ high = ARRAY_SIZE(utf8_widthtab);
do {
cur = (low + high) / 2;
if (val >= utf8_widthtab[cur].min) {
diff --git a/src/wins.c b/src/wins.c
index 0a3f48f..bcc5a90 100644
--- a/src/wins.c
+++ b/src/wins.c
@@ -678,18 +678,15 @@ void wins_status_bar(void)
switch (active_panel) {
case CAL:
bindings = bindings_cal;
- bindings_size =
- sizeof(bindings_cal) / sizeof(bindings_cal[0]);
+ bindings_size = ARRAY_SIZE(bindings_cal);
break;
case APP:
bindings = bindings_apoint;
- bindings_size =
- sizeof(bindings_apoint) / sizeof(bindings_apoint[0]);
+ bindings_size = ARRAY_SIZE(bindings_apoint);
break;
case TOD:
bindings = bindings_todo;
- bindings_size =
- sizeof(bindings_todo) / sizeof(bindings_todo[0]);
+ bindings_size = ARRAY_SIZE(bindings_todo);
break;
default:
EXIT(_("unknown panel"));