-
Notifications
You must be signed in to change notification settings - Fork 1
/
checker.c
77 lines (70 loc) · 1.83 KB
/
checker.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
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ccharrie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/07 12:13:56 by ccharrie #+# #+# */
/* Updated: 2018/01/20 13:56:58 by ccharrie ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_checkpath(char **args)
{
if (ft_strchr(args[0], '/'))
return (1);
else
return (0);
}
int ft_checkargs(char **args)
{
if (!(args[0]))
{
ft_del2dtab(args);
return (1);
}
return (0);
}
int ft_checkcmdorbuilt(char *cmd)
{
char **args;
args = ft_splitwhitespaces(cmd);
if (ft_checkargs(args) == 1)
return (-1);
if (ft_strcmp(args[0], "cd") == 0 || ft_strcmp(args[0], "exit") == 0 ||
ft_strcmp(args[0], "echo") == 0)
{
ft_del2dtab(args);
return (0);
}
else if (ft_strcmp(args[0], "env") == 0 ||
ft_strcmp(args[0], "setenv") == 0)
{
ft_del2dtab(args);
return (0);
}
else if (ft_strcmp(args[0], "unsetenv") == 0)
{
ft_del2dtab(args);
return (0);
}
ft_del2dtab(args);
return (1);
}
int ft_checkvarname(t_env *env, char *args)
{
t_env *begin;
begin = env;
while (env)
{
if (ft_strcmp(env->name, args) == 0)
{
env = begin;
return (1);
}
env = env->next;
}
env = begin;
return (0);
}