-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisbuiltin.c
55 lines (49 loc) · 797 Bytes
/
isbuiltin.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
#include "shell.h"
/**
* isbuiltin - searches for builtin and finds it's corresponding handling fcn
* @token: tokenized string
* @envp : enviornment
* Return: 0 if command found, else 1.
*/
int isbuiltin(char *token, char *envp[])
{
int i;
builtin_t list[] = {
{"env", env_var},
{"exit", exit_fcn},
{NULL, NULL}
};
for (i = 0; list[i].command != NULL; i++)
{
if (_strcmp(token, list[i].command) == 0)
{
list[i].f(envp);
return (0);
}
}
return (1);
}
/**
* env_var - prints environment variable
* @envp: enviornment
*/
void env_var(char *envp[])
{
int i;
i = 0;
while (envp[i] != NULL)
{
_putstring(envp[i]);
_putchar('\n');
i++;
}
}
/**
* exit_fcn - exits function
* @envp: environment
*/
void exit_fcn(char *envp[])
{
(void)envp;
exit(0);
}