From 3841da009d685487fb74c48422467a7cc71b137e Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sun, 3 Dec 2023 23:38:58 +0100 Subject: [PATCH] Remove use of FOREACH macros --- zathura/zathura.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/zathura/zathura.c b/zathura/zathura.c index c5e00c8..033cb95 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -974,41 +974,35 @@ typedef struct { int freq; } sample_t; -static int -document_page_size_comp(const void *a, const void *b) -{ +static int document_page_size_comp(const void* a, const void* b) { const sample_t* lhs = a; const sample_t* rhs = b; return rhs->freq - lhs->freq; } -static void -document_open_page_most_frequent_size(zathura_document_t *document, - unsigned int *width, - unsigned int *height) -{ - girara_list_t* samples = girara_list_new2(g_free); +static void document_open_page_most_frequent_size(zathura_document_t* document, unsigned int* width, + unsigned int* height) { + girara_list_t* samples = girara_list_new2(g_free); const unsigned int number_of_pages = zathura_document_get_number_of_pages(document); for (unsigned int page_id = 0; page_id < number_of_pages; ++page_id) { zathura_page_t* page = zathura_document_get_page(document, page_id); - const double w = zathura_page_get_width(page); - const double h = zathura_page_get_height(page); + const double w = zathura_page_get_width(page); + const double h = zathura_page_get_height(page); bool found = false; - GIRARA_LIST_FOREACH_BODY(samples, sample_t*, sample, + for (size_t idx = 0; idx != girara_list_size(samples) && !found; ++idx) { + sample_t* sample = girara_list_nth(samples, idx); if (fabs(sample->h - h) <= DBL_EPSILON && fabs(sample->w - w) <= DBL_EPSILON) { sample->freq++; - found = true; - break; } - ); + } if (found == false) { sample_t* sample = g_try_malloc0(sizeof(sample_t)); - sample->w = w; - sample->h = h; - sample->freq = 1; + sample->w = w; + sample->h = h; + sample->freq = 1; girara_list_append(samples, sample); } } @@ -1016,8 +1010,8 @@ document_open_page_most_frequent_size(zathura_document_t *document, girara_list_sort(samples, document_page_size_comp); sample_t* max_sample = girara_list_nth(samples, 0); - *width = max_sample->w; - *height = max_sample->h; + *width = max_sample->w; + *height = max_sample->h; girara_list_free(samples); }