display list
authorLaurent Mazet <mazet@softndesign.org>
Sun, 29 Dec 2024 17:52:06 +0000 (18:52 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 29 Dec 2024 17:52:06 +0000 (18:52 +0100)
display.c
function.c
function.h
type.h

index fdbc5e5cf8168d34b9475ddd55733bb5f47b42f5..ec43d04655e9c2f2d39ce31d17a7409a83d2193b 100644 (file)
--- 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);
index 3571da204da7899c2b5765a6b2f2493e42f4040b..4a1dfd34fbfaa870ba5d8cfb22f6063ee2617dec 100644 (file)
@@ -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: */
index a73de3aec89753ef37c56df3930e83b93e14ad0d..c3165d34eff809e13a49bbba38b9a5dc4d13b9fe 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __FUNCTION_H__
 #define __FUNCTION_H__
 
+#include "type.h"
+
 #define CHECKALLOC(ptr) \
     do { \
         if ((ptr) == NULL) { \
 
 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 1375039e5c52c7a55906960f3e55e3193a7a95b1..57060dca8e54547fb928f545cabb72a326de7df3 100644 (file)
--- 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: */