summaryrefslogtreecommitdiffstats
path: root/src/ft_process_arg.c
blob: e1b6f8f490354ad1fa953ec473a22009a44cfffc (plain)
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
#include <libft.h>
#include <minishell.h>
#include <inttypes.h>

int
ft_not_found(const char *com)
{
	ft_putstr("joe-sh: ");
	ft_putstr(com);
	ft_putendl(": command not found");
	return (127);
}

int
ft_process_arg(const char *arg)
{
	char **com;
	uint8_t i;

	if (arg[0] == '\0')
		return (0);
	i = 0;
	com = ft_split(arg, ' ');
	while (com[i])
		i++;
	if (!ft_strncmp(com[0], "exit", ft_strlen(com[0])))
		return (8);
	else if (!ft_strncmp(com[0], "echo", ft_strlen(com[0])))
		ft_echo(com, i);
	else if (!ft_strncmp(com[0], "pwd", ft_strlen(com[0])))
		ft_pwd();
	else
		ft_not_found(com[0]);
	return (0);
}