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);
return len;
}
-list_t *alloclist ()
+list_t *alloclist (void)
{
list_t *list = (list_t *) malloc (sizeof (list_t));
CHECKALLOC (list);
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;
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: */
#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: */
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: */