-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolumns.c
59 lines (54 loc) · 1.75 KB
/
columns.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* columns.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ihermell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/24 05:09:40 by ihermell #+# #+# */
/* Updated: 2014/12/04 17:14:06 by ihermell ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void print_columns_data_lst(t_data *lst)
{
int *sizes;
int count;
int width;
if (!lst)
return ;
sizes = (int*)malloc(sizeof(int) * 2);
bzero(sizes, sizeof(int) * 2);
width = get_name_len(lst);
count = lst_count(lst);
sizes[1] = g_settings[S_WIN_COLS] / (width + 1);
sizes[0] = (count + sizes[1] - 1) / sizes[1];
print_mcolumns(lst, sizes, count, width);
}
void print_mcolumns(t_data *lst, int *sizes, int count, int width)
{
int i;
int j;
int len;
int tmp;
t_data *file;
i = -1;
while (++i < sizes[0])
{
j = -1;
tmp = sizes[1];
while (++j < tmp)
{
if (j * sizes[0] + i >= count)
continue ;
file = lst_at(j * sizes[0] + i, lst);
ft_putstr(file->d_name);
len = ft_strlen(file->d_name);
if ((j + 1) * sizes[0] + i < count)
while (len++ <= width)
ft_putchar(' ');
}
ft_putchar('\n');
}
free(sizes);
}