-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_search.c
More file actions
67 lines (61 loc) · 1.47 KB
/
command_search.c
File metadata and controls
67 lines (61 loc) · 1.47 KB
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
/*
** EPITECH PROJECT, 2020
** B-PSU-210-MPL-2-1-minishell2-guillaume.boudaille
** File description:
** command_search.c
*/
#include "include/my.h"
void print_command_not_found(char *str)
{
char **command = get_command(str);
write(2, command[0], my_strlen(command[0]));
write(2, ": Command not found.\n", 21);
}
int is_second_command(char *line)
{
int i = 0;
for (i = 0; line[i]; i++) {
if (line[i] == ';' || (line[i] == '&' && line[i + 1] == '&'))
return (i);
}
return (0);
}
int is_command_2(char *line, t_char_list **list, int tkt)
{
t_char_list *env = *list;
if (is_setenv(line) == 1) {
add_env(&env, line);
return (1);
}
if (is_unsetenv(line) == 1) {
rem_env(list, line);
return (1);
}
if (is_access(line, env) == 1)
return (1);
print_command_not_found(line);
return (0);
}
int is_command(char *line, t_char_list **list, int tkt)
{
t_char_list *env = *list;
int n = 0;
tkt = is_second_command(line);
if (tkt != 0) {
if (line[tkt] == '&')
n = 1;
line[tkt] = 0;
if (is_command(line, &env, 0) == 0 && n == 1)
return (0);
line = line + tkt + 1 + n;
}
if (is_cd(line) == 1)
return (cd_command(&env, get_command(line)));
if (is_exit(line) == 1)
exit (0);
if (is_env(line) == 1) {
print_env(env);
return (1);
}
return (is_command_2(line, &env, tkt));
}