-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtins.c
69 lines (63 loc) · 1.38 KB
/
builtins.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
/*
** builtins.c for in /home/fernan_w/Téléchargements/backup/builtins
**
** Made by
** Login <fernan_w@epitech.net>
**
** Started on Thu Jun 2 22:52:08 2016
** Last update Wed Jun 8 10:55:26 2016
*/
#include <string.h>
#include "tools.h"
#include "builtins.h"
#include "my.h"
static const t_opec g_bul[] =
{
{"exit", &my_exit},
{"cd", &my_cd},
{"fg", &my_fg},
{"bg", &my_bg},
{"jobs", &my_jobs},
{"unset", &my_unset},
{"export", &my_export},
{"disown", &my_disown},
{"source", &my_source},
{"env", &my_env},
{"echo", &my_echo},
{NULL, NULL},
};
int builtins(t_mini *shell, t_process *proc)
{
if (g_bul[proc->is_builtin].str)
return (g_bul[proc->is_builtin].funct(shell, proc));
else
return (my_egal_env(shell, proc));
}
int check_builtins(t_process *proc)
{
int index;
index = 0;
proc->is_builtin = -1;
while (g_bul[index].str)
{
if (proc->cmd && strcmp(proc->cmd, g_bul[index].str) == 0)
{
proc->is_builtin = index;
return (SUCCESS);
}
index++;
}
if (is_in_str(proc->cmd, '=') == SUCCESS)
{
proc->is_builtin = index;
return (SUCCESS);
}
return (FAILURE);
}
int built_no_fork(t_process *proc, t_mini *shell)
{
if (proc->is_builtin < MAX_BUILT_FORK - 1)
return (g_bul[proc->is_builtin].funct(shell, proc));
else
return (builtins(shell, proc));
}