From 3abccb92c9b88ec2ad5eaab58c647f94c1591697 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Thu, 2 Jan 2025 09:36:58 +0100 Subject: [PATCH] diplay working (improvement) --- display.c | 8 +++++++- fm.c | 2 ++ function.c | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/display.c b/display.c index bf9244b..8199fcc 100644 --- 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 fc1301f..d4e81ff 100644 --- 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; diff --git a/function.c b/function.c index 287a0ed..8bab6e1 100644 --- a/function.c +++ b/function.c @@ -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; } -- 2.30.2