-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyo_echo.c
56 lines (50 loc) · 1.62 KB
/
yo_echo.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* yo_echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abuzdin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 09:31:47 by abuzdin #+# #+# */
/* Updated: 2022/08/10 16:03:33 by abuzdin ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void echo_with_flag(t_cmd *com)
{
int i;
i = 2;
while (com->cmd[i] && !ft_strncmp(com->cmd[i], "-n", 2))
++i;
while (com->cmd[i])
{
write(com->out, com->cmd[i], ft_strlen(com->cmd[i]));
if (com->cmd[i + 1])
write(com->out, " ", 1);
++i;
}
}
static void echo_without_flag(t_cmd *com)
{
int i;
i = 1;
while (com->cmd[i])
{
write(com->out, com->cmd[i], ft_strlen(com->cmd[i]));
if (com->cmd[i + 1])
write(com->out, " ", 1);
++i;
}
write(com->out, "\n", 1);
}
int yo_echo(t_input *data)
{
if (!data->cmds->cmd[1])
write(data->cmds->out, "\n", 1);
else if (ft_strncmp(data->cmds->cmd[1], "-n", 2) == 0)
echo_with_flag(data->cmds);
else
echo_without_flag(data->cmds);
g_status = 0;
return (0);
}