{
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)) {
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);
}
}
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;
{
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);
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;
}
closedir(dir);
+ VERBOSE (DEBUG, fprintf (stderr, "list->width: %d\n", list->width));
+
return list;
}