-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils2.c
122 lines (109 loc) · 2.48 KB
/
utils2.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
116
117
118
119
120
121
122
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wilhelmfermey <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/13 14:18:01 by wilhelmfermey #+# #+# */
/* Updated: 2022/05/31 13:41:14 by wilhelmfermey ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char **add_line(char **tabb, char *str)
{
int i;
int j;
char **new_tab;
char *tmp;
i = 0;
while (tabb[i])
i++;
new_tab = malloc((i + 2) * sizeof(char *));
if (new_tab)
return (NULL);
j = 1;
if(!ft_strcmp(tabb[0], "1.PIPE"))
{
free(tabb[0]);
tabb[0] = ft_substr(str, 0, ft_strlen(str));
tmp = ft_substr("1.PIPE", 0, 6);
new_tab[0] = ft_substr(tmp, 0, ft_strlen(tmp));
}
else
new_tab[0] = ft_substr(str, 0, ft_strlen(str));
while (j < i + 1)
{
new_tab[j] = ft_substr(tabb[j - 1], 0, ft_strlen(tabb[j - 1]));
j++;
}
new_tab[j] = NULL;
free_table(tabb);
return (new_tab);
}
void ft_print_list(t_list **head)
{
t_list *tmp;
tmp = *head;
while (tmp)
{
printf("%s\n", (char *)(tmp->content));
tmp = tmp->next;
}
}
void del_content(t_list **head, char *content)
{
t_list *tmp;
t_list *prev;
tmp = *head;
prev = *head;
while (tmp
&& ft_strncmp((char *)tmp->content, content, ft_strlen(content)))
{
prev = tmp;
tmp = tmp->next;
}
if (tmp)
{
prev->next = tmp->next;
tmp->next = NULL;
ft_lstdelone(tmp, free);
}
}
char **add_line_end(char **tabb, char *str)
{
int i;
int j;
char **new_tab;
i = 0;
if (tabb[0])
{
while (tabb[i])
i++;
}
else
i = 0;
new_tab = malloc((i + 2) * sizeof(char *));
if (!new_tab)
return (NULL);
j = 0;
while (j < i)
{
new_tab[j] = ft_substr(tabb[j], 0, ft_strlen(tabb[j]));
j++;
}
new_tab[j++] = ft_substr(str, 0, ft_strlen(str));
new_tab[j] = NULL;
free_table(tabb);
return (new_tab);
}
void print_table(char **str)
{
int i;
i = 0;
if (str)
{
while (str[i])
printf("%s\n", str[i++]);
}
}