From: Laurent Mazet Date: Mon, 17 Mar 2025 06:42:19 +0000 (+0100) Subject: cleaner code X-Git-Tag: v1.1~4 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=1bd3ebabf2f29fb138e874cf6799555415a44c2b;p=fm.git cleaner code --- diff --git a/fm.c b/fm.c index 8437c91..295afd9 100644 --- a/fm.c +++ b/fm.c @@ -239,28 +239,7 @@ int main (int argc, char *argv[]) /* display panel */ if ((mode) && (search[i])) { int n = (list[i]->nb + windir[i]->nbcols - 1) / windir[i]->nbcols; - int skip = index_x[i] * n + index_y[i]; - char **_list = (char **) calloc (list[i]->nb, sizeof (char *)); - CHECKALLOC (_list); - int j; - for (j = 0; j < list[i]->nb; j++) { - _list[j] = (list[i]->tab + j)->name; - } - skip = find (_list, list[i]->nb, skip, search[i]); - if (skip != -1) { - index_x[i] = skip / n; - index_y[i] = skip % n; - if (n > windir[i]->ysize) { - page[i] = index_y[i]; - if (page[i] + windir[i]->ysize > n) { - page[i] = n - windir[i]->ysize; - index_y[i] -= page[i]; - } else { - index_y[i] = 0; - } - } - } - free (_list); + jumpto (list[i], n, windir[i]->ysize, search[i], index_x + i, index_y + i, page + i); } displaywindow (windir[i], list[i], page[i], &index_x[i], &index_y[i], &index_f[i], search[i]); diff --git a/function.c b/function.c index 1a44353..a527d1c 100644 --- a/function.c +++ b/function.c @@ -804,4 +804,32 @@ int find (char **lines, int nblines, int skip, char *search) return -1; } +void jumpto (list_t *list, int height, int pageheight, char *search, int *x, int *y, int *page) +{ + //height: int n = (list[i]->nb + windir[i]->nbcols - 1) / windir[i]->nbcols; + int skip = *x * height + *y; + char **_list = (char **) calloc (list->nb, sizeof (char *)); + CHECKALLOC (_list); + int j; + for (j = 0; j < list->nb; j++) { + _list[j] = (list->tab + j)->name; + } + skip = find (_list, list->nb, skip, search); + if (skip != -1) { + *x = skip / height; + *y = skip % height; + if (height > pageheight) { + *page = *y; + if (*page + pageheight > height) { + *page = height - pageheight; + *y -= *page; + } else { + *y = 0; + } + } + } + + free (_list); +} + /* vim: set ts=4 sw=4 et: */ diff --git a/function.h b/function.h index 8c65bcb..4aad048 100644 --- a/function.h +++ b/function.h @@ -71,6 +71,8 @@ char **splithexalines (char *buffer, int length, int width); int find (char **lines, int nblines, int skip, char *search); +void jumpto (list_t *list, int height, int pageheight, char *search, int *x, int *y, int *page); + #endif /* __FUNCTION_H__ */ /* vim: set ts=4 sw=4 et: */