diff --git a/lib/util.h b/lib/util.h index f52f2adcf..1613bfb54 100644 --- a/lib/util.h +++ b/lib/util.h @@ -54,6 +54,9 @@ */ #define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2))) +/* Difference of zero */ +#define DOZ(a, b) ((a) > (b) ? (a) - (b) : 0) + /*** enums ***************************************************************************************/ /* Pathname canonicalization */ diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index 6748cbaf8..198193e4a 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -639,8 +639,8 @@ listbox_select_last (WListbox * l) length = listbox_get_length (l); - l->pos = length > 0 ? length - 1 : 0; - l->top = length > lines ? length - lines : 0; + l->pos = DOZ (length, 1); + l->top = DOZ (length, lines); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/ascii.c b/src/viewer/ascii.c index 505130ef7..de12c7ebe 100644 --- a/src/viewer/ascii.c +++ b/src/viewer/ascii.c @@ -1038,7 +1038,7 @@ mcview_ascii_moveto_eol (WView * view) /* Get the width of the topmost paragraph. */ mcview_state_machine_init (&state, view->dpy_start); mcview_display_line (view, &state, -1, NULL, &linewidth); - view->dpy_text_column = mcview_offset_doz (linewidth, (off_t) view->data_area.width); + view->dpy_text_column = DOZ (linewidth, (off_t) view->data_area.width); } } diff --git a/src/viewer/display.c b/src/viewer/display.c index c2cdb7c72..edad99129 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -268,8 +268,8 @@ mcview_compute_areas (WView * view) view_area.top = view->dpy_frame_size; view_area.left = view->dpy_frame_size; - view_area.height = mcview_dimen_doz (WIDGET (view)->lines, 2 * view->dpy_frame_size); - view_area.width = mcview_dimen_doz (WIDGET (view)->cols, 2 * view->dpy_frame_size); + view_area.height = DOZ ((screen_dimen) WIDGET (view)->lines, 2 * view->dpy_frame_size); + view_area.width = DOZ ((screen_dimen) WIDGET (view)->cols, 2 * view->dpy_frame_size); /* Most coordinates of the areas equal those of the whole viewer */ view->status_area = view_area; diff --git a/src/viewer/inlines.h b/src/viewer/inlines.h index 84edab6ed..3f90abb1d 100644 --- a/src/viewer/inlines.h +++ b/src/viewer/inlines.h @@ -18,15 +18,6 @@ /*** inline functions ****************************************************************************/ -/* difference or zero */ -static inline off_t -mcview_offset_doz (off_t a, off_t b) -{ - return (a >= b) ? a - b : 0; -} - -/* --------------------------------------------------------------------------------------------- */ - static inline off_t mcview_offset_rounddown (off_t a, off_t b) { @@ -36,15 +27,6 @@ mcview_offset_rounddown (off_t a, off_t b) /* --------------------------------------------------------------------------------------------- */ -/* difference or zero */ -static inline screen_dimen -mcview_dimen_doz (screen_dimen a, screen_dimen b) -{ - return (a >= b) ? a - b : 0; -} - -/* --------------------------------------------------------------------------------------------- */ - /* {{{ Simple Primitive Functions for WView }}} */ static inline gboolean mcview_is_in_panel (WView * view) diff --git a/src/viewer/move.c b/src/viewer/move.c index 4a9704f82..b27186c76 100644 --- a/src/viewer/move.c +++ b/src/viewer/move.c @@ -118,7 +118,7 @@ mcview_move_up (WView * view, off_t lines) view->hex_cursor -= bytes; if (view->hex_cursor < view->dpy_start) { - view->dpy_start = mcview_offset_doz (view->dpy_start, bytes); + view->dpy_start = DOZ (view->dpy_start, bytes); view->dpy_paragraph_skip_lines = 0; view->dpy_wrap_dirty = TRUE; } @@ -148,7 +148,7 @@ mcview_move_down (WView * view, off_t lines) { off_t i, limit; - limit = mcview_offset_doz (last_byte, (off_t) view->bytes_per_line); + limit = DOZ (last_byte, (off_t) view->bytes_per_line); for (i = 0; i < lines && view->hex_cursor < limit; i++) { @@ -189,7 +189,7 @@ mcview_move_left (WView * view, off_t columns) view->hexedit_lownibble = !view->hexedit_lownibble; } else if (!view->mode_flags.wrap) - view->dpy_text_column = mcview_offset_doz (view->dpy_text_column, columns); + view->dpy_text_column = DOZ (view->dpy_text_column, columns); mcview_movement_fixups (view, FALSE); } @@ -203,7 +203,8 @@ mcview_move_right (WView * view, off_t columns) off_t last_byte; off_t old_cursor = view->hex_cursor; - last_byte = mcview_offset_doz (mcview_get_filesize (view), 1); + last_byte = mcview_get_filesize (view); + last_byte = DOZ (last_byte, 1); g_assert (columns == 1); @@ -252,7 +253,7 @@ mcview_moveto_bottom (WView * view) if (view->mode_flags.hex) { - view->hex_cursor = mcview_offset_doz (filesize, 1); + view->hex_cursor = DOZ (filesize, 1); mcview_movement_fixups (view, TRUE); } else @@ -302,7 +303,7 @@ mcview_moveto_eol (WView * view) else { filesize = mcview_get_filesize (view); - view->hex_cursor = mcview_offset_doz (filesize, 1); + view->hex_cursor = DOZ (filesize, 1); } } else