-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyse.c
114 lines (106 loc) · 2.92 KB
/
analyse.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* analyse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbaldy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/12 11:41:34 by dbaldy #+# #+# */
/* Updated: 2016/01/07 15:26:00 by dbaldy ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void calcul_sa(t_car_list *temp, int flag)
{
if ((flag & OPT_A) == OPT_A)
return (calcul_a(temp));
while (temp != NULL && temp->name[0] == '.')
temp = temp->next;
if (temp == NULL)
return ;
g_max[0] = nb_ch(temp->links);
g_max[1] = ft_strlen(temp->mode);
g_max[2] = ft_strlen(temp->user);
g_max[3] = ft_strlen(temp->group);
g_max[4] = nb_ch(temp->size);
while (temp != NULL)
{
if (temp->name[0] != '.')
fill_max(temp);
temp = temp->next;
}
}
void calcul_a(t_car_list *temp)
{
if (temp == NULL)
return ;
g_max[0] = nb_ch(temp->links);
g_max[1] = ft_strlen(temp->mode);
g_max[2] = ft_strlen(temp->user);
g_max[3] = ft_strlen(temp->group);
g_max[4] = nb_ch(temp->size);
while (temp != NULL)
{
fill_max(temp);
temp = temp->next;
}
}
void check_flags(char *str)
{
int j;
j = 1;
while (str[j])
{
if ((g_flag & OPT_L) == OPT_L && str[j] == '1')
g_flag = g_flag - OPT_L;
if ((g_flag & OPT_L) != OPT_L && (str[j] == 'l' || str[j] == 'g'
|| str[j] == 'o'))
g_flag = g_flag + OPT_L;
if ((g_flag & OPT_A) != OPT_A)
g_flag = (str[j] == 'a') ? g_flag + OPT_A : g_flag;
if ((g_flag & OPT_R) != OPT_R)
g_flag = (str[j] == 'R') ? g_flag + OPT_R : g_flag;
if ((g_flag & OPT_MINR) != OPT_MINR)
g_flag = (str[j] == 'r') ? g_flag + OPT_MINR : g_flag;
if ((g_flag & OPT_T) != OPT_T)
g_flag = (str[j] == 't') ? g_flag + OPT_T : g_flag;
j++;
}
}
int analyse(char **argv, int *i, int argc)
{
while (*i < argc && argv[*i][0] == '-' && argv[*i][1] != '\0'
&& (ft_strcmp(argv[*i], "--") != 0))
{
g_c = wrong_flags(argv[*i]);
check_flags(argv[*i]);
check_add_flags(argv[*i]);
if (g_c != 0)
return (0);
(*i)++;
}
if ((*i) < argc && (ft_strcmp(argv[*i], "--") == 0))
(*i)++;
if (*i != argc)
g_flag += MTPL_AG;
else
g_flag += POINT;
return (g_flag);
}
void ft_class(t_car_list **debut)
{
t_car_list *a;
t_car_list *b;
a = *debut;
b = a->next;
while (b != NULL)
{
if (ft_strcmp(b->name, a->name) < 0)
revert(&a, &b, debut);
else
{
b = b->next;
a = a->next;
}
}
}