diff --git a/Makefile b/Makefile index 68c00d0..2b0b739 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: sxiv -VERSION = git-20110904 +VERSION = git-20110906 CC = gcc DESTDIR = diff --git a/main.c b/main.c index f756e0c..8f73fdd 100644 --- a/main.c +++ b/main.c @@ -136,7 +136,7 @@ void remove_file(int n, unsigned char silent) { void set_timeout(timeout_f handler, int time, int overwrite) { int i; - for (i = 0; i < LEN(timeouts); i++) { + for (i = 0; i < ARRLEN(timeouts); i++) { if (timeouts[i].handler == handler) { if (!timeouts[i].active || overwrite) { gettimeofday(&timeouts[i].when, 0); @@ -151,7 +151,7 @@ void set_timeout(timeout_f handler, int time, int overwrite) { void reset_timeout(timeout_f handler) { int i; - for (i = 0; i < LEN(timeouts); i++) { + for (i = 0; i < ARRLEN(timeouts); i++) { if (timeouts[i].handler == handler) { timeouts[i].active = False; return; @@ -164,7 +164,7 @@ int check_timeouts(struct timeval *t) { struct timeval now; gettimeofday(&now, 0); - while (i < LEN(timeouts)) { + while (i < ARRLEN(timeouts)) { if (timeouts[i].active) { tdiff = TIMEDIFF(&timeouts[i].when, &now); if (tdiff <= 0) { @@ -260,7 +260,7 @@ void reset_cursor() { cursor_t cursor = CURSOR_NONE; if (mode == MODE_IMAGE) { - for (i = 0; i < LEN(timeouts); i++) { + for (i = 0; i < ARRLEN(timeouts); i++) { if (timeouts[i].handler == reset_cursor) { if (timeouts[i].active) cursor = CURSOR_ARROW; @@ -305,7 +305,7 @@ void on_keypress(XKeyEvent *kev) { XLookupString(kev, &key, 1, &ksym, NULL); - for (i = 0; i < LEN(keys); i++) { + for (i = 0; i < ARRLEN(keys); i++) { if (keys[i].ksym == ksym && keymask(&keys[i], kev->state)) { if (keys[i].cmd && keys[i].cmd(keys[i].arg)) redraw(); @@ -324,7 +324,7 @@ void on_buttonpress(XButtonEvent *bev) { win_set_cursor(&win, CURSOR_ARROW); set_timeout(reset_cursor, TO_CURSOR_HIDE, 1); - for (i = 0; i < LEN(buttons); i++) { + for (i = 0; i < ARRLEN(buttons); i++) { if (buttons[i].button == bev->button && buttonmask(&buttons[i], bev->state)) { diff --git a/util.c b/util.c index e2d2867..8b65c27 100644 --- a/util.c +++ b/util.c @@ -91,9 +91,9 @@ void size_readable(float *size, const char **unit) { const char *units[] = { "", "K", "M", "G" }; int i; - for (i = 0; i < LEN(units) && *size > 1024; i++) + for (i = 0; i < ARRLEN(units) && *size > 1024; i++) *size /= 1024; - *unit = units[MIN(i, LEN(units) - 1)]; + *unit = units[MIN(i, ARRLEN(units) - 1)]; } char* absolute_path(const char *filename) { diff --git a/util.h b/util.h index e762675..9d5dc1d 100644 --- a/util.h +++ b/util.h @@ -23,10 +23,14 @@ #include #include -#define ABS(a) ((a) < 0 ? (-(a)) : (a)) +#ifndef MIN #define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif +#ifndef MAX #define MAX(a,b) ((a) > (b) ? (a) : (b)) -#define LEN(a) (sizeof(a) / sizeof(a[0])) +#endif + +#define ARRLEN(a) (sizeof(a) / sizeof(a[0])) #define TIMEDIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec) * 1000 + \ ((t1)->tv_usec - (t2)->tv_usec) / 1000)