diplay working (improvement)
authorLaurent Mazet <mazet@softndesign.org>
Thu, 2 Jan 2025 08:36:58 +0000 (09:36 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Thu, 2 Jan 2025 08:36:58 +0000 (09:36 +0100)
display.c
fm.c
function.c

index bf9244b2294d4afe68cdd7103720ccd0fbf74299..8199fcca1d05bd39c721ae595de1e00094a91acf 100644 (file)
--- a/display.c
+++ b/display.c
@@ -121,8 +121,14 @@ void displaywindow (window_t *win, list_t *list, int index)
 {
     int i;
     int nbcols = win->xsize / (list->width + 1);
+    VERBOSE (DEBUG, fprintf (stderr, "nbcols: %d\n", nbcols));
     int width = win->xsize / nbcols;
+    VERBOSE (DEBUG, fprintf (stderr, "width: %d\n", width));
     int n = (list->nb + nbcols - 1) / nbcols;
+    VERBOSE (DEBUG, fprintf (stderr, "n: %d\n", n));
+    _dobound (win->xsize, win->ysize, win->xoffset, win->yoffset);
+    int rem = list->nb - nbcols * n;
+
     for (i = 0; i < list->nb; i++) {
         int j = (i % n) - index;
         if ((j >= 0) && (j < win->ysize)) {
@@ -153,7 +159,7 @@ void displaywindow (window_t *win, list_t *list, int index)
                set_color (red);
                break;
             }
-            mvaddstr (win->yoffset + j, win->xoffset + (i / n) * (width + 1), elem->name);
+            mvaddstr (win->yoffset + j, win->xoffset + (i / n) * width, elem->name);
             set_color (white);
         }
     }
diff --git a/fm.c b/fm.c
index fc1301f5d8832494ac39b15e6d4eb551e8ce5a8c..d4e81ff19a8663efcca2c7f540128f6a3c3d252f 100644 (file)
--- a/fm.c
+++ b/fm.c
@@ -108,7 +108,9 @@ int main (int argc, char *argv[])
     windir->xoffset = xoffset;
     windir->yoffset = yoffset;
     windir->xsize = COLS - 2 * xoffset;
+    VERBOSE (DEBUG, fprintf (stderr, "xsize: %d\n", windir->xsize));
     windir->ysize = LINES - 2 * yoffset;
+    VERBOSE (DEBUG, fprintf (stderr, "ysize: %d\n", windir->ysize));
 
     list_t *list  = NULL;
     int index = 0;
index 287a0ed410cbaf3fc4daac5e7eb89a99789fcbf8..8bab6e14c6ee6b7e48b23d33653793747d779fd1 100644 (file)
@@ -30,18 +30,17 @@ list_t *alloclist (void)
 {
     list_t *list = (list_t *) calloc (1, sizeof (list_t));
     CHECKALLOC (list);
-    list->nb = 0;
-    list->tab = NULL;
 
     return list;
 }
 
 list_t *_addelement (list_t *list, char *dirname, char *filename, type_t type)
 {
+    int i;
     size_t size = 0;
 
     if ((type == type_unkn_e) || (type == type_reg_e)) {
-        char *name = (char *) calloc (strlen (dirname) + strlen (filename) + 1 + 1, 1);
+        char *name = (char *) calloc (strlen (dirname) + strlen (filename) + strlen (SEPARATOR) + 1, 1);
         CHECKALLOC (name);
         strcat (strcat(strcpy (name, dirname), SEPARATOR), filename);
 
@@ -85,7 +84,17 @@ list_t *_addelement (list_t *list, char *dirname, char *filename, type_t type)
     list->nb++;
     list->tab = (elem_t *) realloc (list->tab, list->nb * sizeof (elem_t));
     CHECKALLOC (list->tab);
-    elem_t * elem = list->tab + list->nb - 1;
+    elem_t * elem = list->tab;
+    for (i = list->nb - 1; i > 0; i--) {
+        if (strcmp ((list->tab + i - 1)->name, filename) < 0) {
+            elem = list->tab + i;
+            break;
+        } else {
+            (list->tab + i)->name = (list->tab + i - 1)->name;
+            (list->tab + i)->size = (list->tab + i - 1)->size;
+            (list->tab + i)->type = (list->tab + i - 1)->type;
+        }
+    }
     elem->name = strdup (filename);
     elem->size = size;
     elem->type = type;
@@ -138,6 +147,8 @@ list_t *exploredir (char *dirname)
     }
     closedir(dir);
 
+    VERBOSE (DEBUG, fprintf (stderr, "list->width: %d\n", list->width));
+
     return list;
 }