cleaner code
authorLaurent Mazet <mazet@softndesign.org>
Mon, 17 Mar 2025 06:42:19 +0000 (07:42 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Mon, 17 Mar 2025 06:42:19 +0000 (07:42 +0100)
fm.c
function.c
function.h

diff --git a/fm.c b/fm.c
index 8437c917de3535777a89571ef3ef88925326fb92..295afd9aed580aa2ff049fa2ecf5b0c2a7f5d6bd 100644 (file)
--- 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]);
 
index 1a44353f56f79beafb81e136e7d2a06d9ed15a12..a527d1ca8bed5fa07f9bb28c9317ec960c1efdb9 100644 (file)
@@ -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: */
index 8c65bcbfca3267eb30c6037976cce394f081fda6..4aad0480b6cfe69414aa8db9bb207496d8fd9065 100644 (file)
@@ -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: */