-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecho.c
76 lines (69 loc) · 1.66 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emohamed <emohamed@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/07 19:49:04 by haarab #+# #+# */
/* Updated: 2023/09/30 21:38:18 by emohamed ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int check_n(char *args)
{
int i;
i = 1;
if (args[0] == '-')
{
if (args[0] == '-' && args[1] == '\0')
return (1);
if (args[1] != '\0')
{
while (args[i] && args[i] == 'n')
{
i++;
}
}
if (args[i] == '\0')
return (0);
}
return (1);
}
void print_echo(char **args, int i)
{
int j;
j = 0;
while (args[i][j])
{
printf("%c", args[i][j]);
j++;
}
if (args[i] != NULL && args[i + 1] != NULL)
printf(" ");
}
void run_echo(char **args)
{
int i;
int check;
check = 0;
i = 1;
while (args[i])
{
while (args[i] && check_n(args[i]) == 0)
{
check = 1;
i++;
}
if (args[i] && check_n(args[i]) == 1)
g_exit_status = 0;
while (args[i])
{
print_echo(args, i);
i++;
}
g_exit_status = 0;
}
if (check == 0)
printf("\n");
}