Consolidate duplicate implementations of compare_integers

Both Inertia and Twiddle previously included static implementations of this
exact same function, which was passed to `qsort()` as a comparator. With
this change, a single global implementation is provided in misc.c, which
will hopefully reduce code duplication going forward.

I'm refactoring this in preparation for the upcoming fallback polygon fill
function, which I'm about to add.
This commit is contained in:
Franklin Wei
2024-08-11 17:26:52 -04:00
committed by Simon Tatham
parent 1c1899ee1c
commit 2a57df6be9
5 changed files with 25 additions and 25 deletions

11
misc.c
View File

@ -351,6 +351,17 @@ void draw_rect_corners(drawing *dr, int cx, int cy, int r, int col)
draw_line(dr, cx + r, cy + r, cx + r/2, cy + r, col);
}
int compare_integers(const void *av, const void *bv) {
const int *a = (const int *)av;
const int *b = (const int *)bv;
if (*a < *b)
return -1;
else if (*a > *b)
return +1;
else
return 0;
}
char *move_cursor(int button, int *x, int *y, int maxw, int maxh, bool wrap,
bool *visible)
{