-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_run_echo.c
52 lines (47 loc) · 1.69 KB
/
ft_run_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_run_echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbourdon <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/07/18 23:18:40 by pbourdon #+# #+# */
/* Updated: 2016/09/03 13:43:14 by pbourdon ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_echo_var_env(int index, char *arg, t_dlist *list)
{
char *tmp;
tmp = ft_strjoin(arg + index + 1, "=");
if (arg[index] == '$' && ft_search_list(list, tmp) != 0)
{
ft_putstr(get_ele(list, ft_search_list(list, tmp)) +
ft_strlen(arg + index));
ft_putchar('\n');
}
free(tmp);
}
void ft_run_echo(char *arg, t_dlist *list)
{
int index;
index = 4;
while (arg[index] == '\t' || arg[index] == '\n' || arg[index] == '\r' ||
arg[index] == ' ')
index++;
if (arg[index] == '$')
ft_echo_var_env(index, arg, list);
else if (arg[index] == '-' && arg[index + 1] == 'n')
{
index = index + 2;
while (arg[index] == '\t' || arg[index] == '\n' || arg[index] == '\r'
|| arg[index] == ' ')
index++;
ft_putstr(arg + index);
}
else
{
ft_putstr(arg + index);
ft_putchar('\n');
}
}