-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.c
106 lines (98 loc) · 2.94 KB
/
print.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ihermell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/23 22:51:51 by ihermell #+# #+# */
/* Updated: 2014/12/04 17:14:36 by ihermell ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void print_data_lst(t_data *data_lst)
{
if (data_lst != NULL)
g_settings[S_PRINT]++;
if (g_flags[FLAG_F])
data_lst = sort(data_lst, &sort_f);
else if (g_flags[FLAG_SS])
data_lst = sort(data_lst, &sort_by_size);
else if (g_flags[FLAG_T] && g_flags[FLAG_UU])
data_lst = sort(data_lst, &sort_by_birthtime);
else if (g_flags[FLAG_T] && g_flags[FLAG_C])
data_lst = sort(data_lst, &sort_by_ctime);
else if (g_flags[FLAG_T] && g_flags[FLAG_U])
data_lst = sort(data_lst, &sort_by_atime);
else if (g_flags[FLAG_T])
data_lst = sort(data_lst, &sort_by_mtime);
else
data_lst = sort(data_lst, &sort_by_d_name);
if (g_flags[FLAG_L])
print_detailled_data_lst(data_lst);
else if (g_flags[FLAG_CC])
print_columns_data_lst(data_lst);
else
print_basic_data_lst(data_lst);
lst_pseudo_free(data_lst);
}
void print_dirs(t_data *dirs)
{
t_data *data_lst;
t_data *dirs_lst;
while (dirs)
{
g_settings[S_CALL]++;
if (is_printable_dir(dirs))
print_header_dir(dirs);
data_lst = get_dir_data_lst(dirs);
if (is_printable_dir(dirs))
print_printable_dir(data_lst);
if (g_flags[FLAG_RR])
{
dirs_lst = lst_include(data_lst, &is_explorable_dir);
print_dirs(sort(dirs_lst, &sort_by_d_name));
lst_pseudo_free(dirs_lst);
}
lst_free(data_lst);
dirs = dirs->next;
}
lst_pseudo_free(lst_find_head(dirs));
}
void print_header_dir(t_data *dir)
{
if (g_settings[S_PRINT] > 0)
ft_putchar('\n');
if (g_settings[S_PRINT] > 0 || g_settings[S_NB_ARGS] > 1)
{
ft_putstr(dir->path);
ft_putendl(":");
}
}
void print_basic_data_lst(t_data *data_lst)
{
while (data_lst)
{
if (data_lst->error)
e_file_error(data_lst);
else
print_basic_file(data_lst);
data_lst = data_lst->next;
}
}
void print_detailled_data_lst(t_data *data_lst)
{
int *width;
width = lst_max_properties_length(data_lst);
if (data_lst && g_settings[S_CALL] > 0)
print_block_size(data_lst);
while (data_lst)
{
if (data_lst->error)
e_file_error(data_lst);
else
print_detailled_file(data_lst, width);
data_lst = data_lst->next;
}
free(width);
}