-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildin.c
75 lines (67 loc) · 1.86 KB
/
buildin.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* buildin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 17:10:48 by ggiannit #+# #+# */
/* Updated: 2023/04/13 19:27:44 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_echo(t_mish *meta, t_cmd *node)
{
int flag;
int i;
(void)meta;
flag = ft_strncmp(node->pot[1], "-n\0", 3);
i = 1;
if (!flag)
i++;
while (node->pot[i])
{
if (!flag && !node->pot[i + 1])
printf("%s", node->pot[i]);
else
printf("%s ", node->pot[i]);
i += 1;
}
if (flag)
printf("\n");
}
void ft_pwd(t_mish *meta)
{
printf("%s\n", meta->curdir);
}
void ft_history(t_mish *meta, t_cmd *node)
{
int i;
char *hline;
i = 1;
close(meta->fd_history);
if (!ft_strncmp(node->pot[1], "-c", 3))
{
unlink(meta->path_history);
rl_clear_history();
}
meta->fd_history = open(meta->path_history,
O_RDWR | O_CREAT | O_APPEND, 0644);
hline = get_next_line(meta->fd_history);
while (hline)
{
printf("%4i %s", i, hline);
i++;
ft_free((void **)&hline);
hline = get_next_line(meta->fd_history);
}
}
void ft_env(t_mish *meta, t_cmd *node)
{
int i;
i = 0;
if (node->pot[1])
return ;
while (meta->env[i])
printf("%s\n", meta->env[i++]);
}