-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkey_2.c
More file actions
107 lines (98 loc) · 2.3 KB
/
Copy pathkey_2.c
File metadata and controls
107 lines (98 loc) · 2.3 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* key_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ssamadi <ssamadi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/27 11:33:39 by fbouibao #+# #+# */
/* Updated: 2021/05/28 16:12:58 by ssamadi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell_hr.h"
int half_join_char(char *s, char c, char **str)
{
if (s == NULL)
{
*str = (char *)malloc(2);
if (*str == NULL)
return (0);
str[0][0] = c;
str[0][1] = '\0';
return (1);
}
return (-1);
}
char *ft_strjoinchar(char *s, char c)
{
int i;
char *str;
int r;
i = 0;
r = half_join_char(s, c, &str);
if (r == 1)
return (str);
else if (r == 0)
return (NULL);
while (s[i])
i++;
str = (char *)malloc(i + 2);
if (str == NULL)
return (0);
i = 0;
while (s[i] != '\0')
{
str[i] = s[i];
i++;
}
str[i] = c;
str[i + 1] = '\0';
free(s);
return (str);
}
char *termcap_khedma(t_history *history)
{
t_history *h_tmp;
int a;
int tm;
tm = 0;
a = 0;
while (1)
{
if (history->next == NULL)
break ;
history = history->next;
}
h_tmp = history;
g_all->line = NULL;
g_all->ret = NULL;
return (loop_termcap(&history, &h_tmp, tm, a));
}
void old_pwd(t_env *evp)
{
evp->test = search_in_env2("PWD", evp->my_env);
if (ft_strncmp(evp->test, "", 1) != 0)
g_all->old_pwd = search_in_env2("PWD", evp->my_env);
free(evp->test);
}
void key_remove(int d)
{
int i;
i = 0;
if (d == KEY_REMOVE)
{
if (ft_strlen(g_all->ret) > 0)
{
while (i < ((int)ft_strlen(g_all->ret) - 1))
i++;
g_all->ret[i] = '\0';
tputs(tgetstr("le", NULL), 1, ft_putc);
tputs(tgetstr("dc", NULL), 1, ft_putc);
}
if (ft_strlen(g_all->ret) == 0)
{
free(g_all->ret);
g_all->ret = NULL;
}
}
}