-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils2.c
More file actions
70 lines (59 loc) · 1.77 KB
/
utils2.c
File metadata and controls
70 lines (59 loc) · 1.77 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamoussa <mamoussa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/03 11:32:17 by mbani #+# #+# */
/* Updated: 2020/12/11 12:39:01 by mamoussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
void add_to_str(char **tmp, char c)
{
char *temp;
temp = ft_strdup(*tmp);
free(*tmp);
tmp[0] = ft_calloc(ft_strlen(temp) + 1, ft_strlen(temp) + 1);
ft_strlcpy(tmp[0], temp, ft_strlen(temp));
ft_strlcat(tmp[0], &c, 1);
}
void rm_backslash(char **temp, char **str, char **tmp, int *i)
{
char *tmp1;
temp[0][0] = str[0][*i + 1];
tmp1 = tmp[0];
tmp[0] = ft_strjoin(tmp[0], temp[0]);
free(tmp1);
*i += 1;
}
void join(char **temp, char **tmp)
{
char *tmp1;
tmp1 = tmp[0];
tmp[0] = ft_strjoin(tmp[0], temp[0]);
free(tmp1);
}
int not_escaped(char *line, int i)
{
int res;
res = 0;
if (i)
while (line[i] && line[i - 1] && line[--i] == '\\')
{
res++;
}
if (res % 2 == 0 || res == 0)
return (1);
else
return (0);
}
void add_to_list(char **tmp, enum e_type t)
{
t_cmd *new;
new = ft_lstnew_cmd(*tmp, t);
ft_lstadd_backcmd(&g_cmd_head, new);
free(*tmp);
*tmp = NULL;
}