-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls_print.c
58 lines (51 loc) · 2.1 KB
/
ls_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ls_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alischyn <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 18:53:45 by alischyn #+# #+# */
/* Updated: 2017/03/29 18:25:35 by alischyn ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
static void ls_print_list_callback(void *arg)
{
t_fileinfo *fi;
fi = (t_fileinfo *)arg;
ft_printf("%s", fi->fmt_perms);
ft_printf("%*s", fi->fmt_nlinks_pad, fi->fmt_nlinks);
ft_printf("%-*s", fi->fmt_owner_name_pad, fi->fmt_owner_name);
ft_printf("%-*s", fi->fmt_owner_group_pad, fi->fmt_owner_group);
ft_printf("%*s", fi->fmt_size_pad, fi->fmt_size);
ft_printf("%s", fi->fmt_mtime);
ft_printf("%s\n", fi->fmt_name);
}
static void ls_print_list_prepare_callback(void *arg)
{
t_fileinfo *fi;
fi = (t_fileinfo *)arg;
fileinfo_format(fi);
}
static void ls_print_list_prepare(t_list *list)
{
vec_iter(&list->items, ls_print_list_prepare_callback);
ls_print_list_prepare_nlinks_pad(list);
ls_print_list_prepare_owner_name_pad(list);
ls_print_list_prepare_owner_group_pad(list);
ls_print_list_prepare_size_pad(list);
ls_count_blocks(list);
}
void ls_print_list(t_list *list, bool no_total)
{
if (g_params['\n'])
ft_printf("\n");
ls_print_list_prepare(list);
if (list->print_path)
ft_printf("%s:\n", list->path);
if (list->path[0] && g_params['l'] && list->items.length > 0 && !no_total)
ft_printf("total %d\n", list->nblocks);
vec_iter(&list->items, ls_print_list_callback);
g_params['\n'] = true;
}