-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_path.c
103 lines (95 loc) · 2.69 KB
/
process_path.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_path.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mtacnet <mtacnet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/06/01 17:42:53 by mtacnet #+# #+# */
/* Updated: 2017/06/19 16:13:36 by mtacnet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
static void view_path(char *path, t_flags *flags, int i)
{
if (flags->view_path != 0 || flags->br_flag != 0)
{
if (flags->br_flag && i != 0)
{
ft_putstr(path);
ft_putendl(":");
}
else if (flags->view_path && ft_strcmp(path, "/tmp/") != 0)
{
ft_putstr(path);
ft_putendl(":");
}
}
}
static void process_dir(t_env *env, t_elem *lst_dname, t_elem *lst_dir,
t_flags *flags)
{
struct dirent *read;
struct stat stat;
char *str;
str = NULL;
while ((read = readdir(env->dir_path)) != NULL)
{
stat.st_mode = 0;
str = concat_str(str, read->d_name, env);
lstat(str, &stat);
if (flags->a_flag)
{
t_opt1(flags, &lst_dname, read->d_name, stat);
if (S_ISDIR(stat.st_mode))
t_opt2(flags, &lst_dir, read->d_name, stat);
}
else
{
if (read->d_name[0] != '.')
t_opt1(flags, &lst_dname, read->d_name, stat);
if (read->d_name[0] != '.' && S_ISDIR(stat.st_mode))
t_opt2(flags, &lst_dir, read->d_name, stat);
}
}
print(flags, lst_dname, lst_dir, env);
}
void process_path(char *path, t_flags *flags)
{
t_env *env;
t_elem *lst_dname;
t_elem *lst_dir;
static int i = 0;
struct stat stat;
errno = 0;
lst_dname = new_list();
lst_dir = new_list();
env = NULL;
env = (t_env*)malloc(sizeof(t_env));
process_env(env, path);
view_path(path, flags, i);
i++;
lstat(path, &stat);
if (errno != 0)
{
view_path_error(path);
perror("");
}
else
process_dir(env, lst_dname, lst_dir, flags);
freelst(lst_dname);
freelst(lst_dir);
free(env->path);
}
void rec_dir(char *init_path, char *path, t_flags *flags)
{
char *concat;
concat = "/";
if (ft_strcmp(path, ".") != 0 && ft_strcmp(path, "..") != 0)
{
init_path = ft_strjoin(init_path, concat);
init_path = ft_strjoin(init_path, path);
ft_putchar('\n');
process_path(init_path, flags);
}
}