-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.c
115 lines (106 loc) · 2.57 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
107
108
109
110
111
112
113
114
115
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dmoureu- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/06 12:10:28 by dmoureu- #+# #+# */
/* Updated: 2016/02/11 16:34:06 by dmoureu- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void print_ents_l(char *path, t_ent *ent, t_column *col, int type)
{
t_ent *sent;
sent = ent;
seekcolumnsize(ent, path, col);
if (type)
{
ft_putstr("total ");
ft_putnbr(col->block);
ft_putendl("");
}
ent = sent;
printcolumns(ent, col, path);
}
void print_ents(char *path, t_ent *ent, t_ls *ls, int type)
{
t_column col;
col.link = 0;
col.user = 0;
col.group = 0;
col.size = 0;
col.block = 0;
if (ent)
{
if (!ls->opts['l'])
{
while (ent)
{
if (type == 0)
ls->out++;
ft_putstr(ent->name);
ft_putchar('\n');
ent = ent->next;
}
}
else
print_ents_l(path, ent, &col, type);
}
}
void print_arg_ent(t_arg *arg, t_ls *ls)
{
if (ls->out > 0)
ft_putendl("");
if ((arglen(ls->args) > 1 || ls->out > 0))
{
ft_putstr(arg->path);
ft_putstr(":\n");
}
if (ls->sort_alpha)
sortents(arg->ent, ls->sort_alpha);
if (ls->sort_time)
sortentstime(arg->ent, ls->sort_time);
print_ents(arg->path, arg->ent, ls, 1);
}
void print_arg_deny(t_arg *arg, t_ls *ls)
{
if (ls->out > 0)
ft_putendl("");
if ((arglen(ls->args) > 1 || ls->out > 0))
{
ft_putstr(arg->path);
ft_putstr(":\n");
}
ft_putstr_fd("ls:", 2);
ft_putstr_fd(arg->path, 2);
ft_putstr_fd(": ", 2);
ft_putendl_fd("Permission denied", 2);
}
void print_args(t_arg *args, t_ls *ls)
{
t_arg *arg;
arg = args;
while (arg)
{
if (!arg->read)
{
if (arg->deny)
print_arg_deny(arg, ls);
else if (arg->ent)
print_arg_ent(arg, ls);
else if (!arg->empty)
{
if (ls->out > 0)
ft_putendl("");
if ((arglen(ls->args) > 1 || ls->out > 0))
ft_putstrpathdir(arg->path);
}
if (arg->sub)
print_args(arg->sub, ls);
ls->out++;
}
arg = arg->next;
}
}