From 58403ace4534caefd70b0229d222e03b9db6eaf4 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Sun, 29 Dec 2024 18:52:06 +0100 Subject: [PATCH] display list --- display.c | 12 ++++++++++++ function.c | 29 ++++++++++++++++++++++++++--- function.h | 12 ++++++++++++ type.h | 10 ++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/display.c b/display.c index fdbc5e5..ec43d04 100644 --- a/display.c +++ b/display.c @@ -117,6 +117,18 @@ int helpwindow (char *msg, int xoffset, int yoffset) return j; } +void displaywindow (list_t *list, window_t *win, int index) +{ + int i; + int n = (list->nb + win->nbcols - 1) / win->nbcols; + for (i = 0; i < list->nb; i++) { + int j = (i % n) - index; + if ((j >= 0) && (j < win->nbrows)) { + mvaddstr (win->yoffset + j, win->xoffset + (i % n) * win->width, (list->tab + i)->name); + } + } +} + char *getwindow (int length, int xoffset, int yoffset) { char *name = (char *) calloc (1, length + 1); diff --git a/function.c b/function.c index 3571da2..4a1dfd3 100644 --- a/function.c +++ b/function.c @@ -26,7 +26,7 @@ int strmaxlen (char *str, char ch) return len; } -list_t *alloclist () +list_t *alloclist (void) { list_t *list = (list_t *) malloc (sizeof (list_t)); CHECKALLOC (list); @@ -36,7 +36,7 @@ list_t *alloclist () return list; } -list_t *addelement (list_t *list, char *dirname, char *filename, type_t type) +list_t *_addelement (list_t *list, char *dirname, char *filename, type_t type) { size_t size = 0; @@ -129,11 +129,34 @@ list_t *exporedir (char *dirname) type = type_socket_e; break; } - addelement (list, dirname, dp->d_name, type); + _addelement (list, dirname, dp->d_name, type); } closedir(dir); return list; } +void freelist (list_t *list) +{ + if (list) { + while (list->nb--) { + free ((list->tab + list->nb)->name); + } + free (list->tab); + } + free (list); +} + +window_t *allocwindow (void) +{ + window_t *win = (window_t *) calloc (sizeof (window_t), 1); + CHECKALLOC (win); + return win; +} + +void freewindow (window_t *win) +{ + free (win); +} + /* vim: set ts=4 sw=4 et: */ diff --git a/function.h b/function.h index a73de3a..c3165d3 100644 --- a/function.h +++ b/function.h @@ -1,6 +1,8 @@ #ifndef __FUNCTION_H__ #define __FUNCTION_H__ +#include "type.h" + #define CHECKALLOC(ptr) \ do { \ if ((ptr) == NULL) { \ @@ -15,6 +17,16 @@ int strmaxlen (char *str, char ch); +list_t *alloclist (void); + +list_t *exporedir (char *dirname); + +void freelist (list_t *list); + +window_t *allocwindow (void); + +void freewindow (window_t *win); + #endif /* __FUNCTION_H__ */ /* vim: set ts=4 sw=4 et: */ diff --git a/type.h b/type.h index 1375039..57060dc 100644 --- a/type.h +++ b/type.h @@ -26,6 +26,16 @@ typedef struct { elem_t *tab; } list_t; +typedef struct { + int xoffset; + int yoffset; + int xsize; + int ysize; + int nbcols; + int nbrows; + int width; +} window_t; + #endif /* __TYPE_H__ */ /* vim: set ts=4 sw=4 et: */ -- 2.30.2