forked from erikaosgue/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltins.c
More file actions
44 lines (42 loc) · 865 Bytes
/
builtins.c
File metadata and controls
44 lines (42 loc) · 865 Bytes
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
#include "shell.h"
/**
* apply_builtins - function that search and aply builtins
* @args: Array of pointers (token)
* @line: String from prompt
* Return: 0 if find at coicidence or 1 if not
*/
int apply_builtins(char **args, char *line)
{
int i;
builtins_t all[] = {
/*{"exit", shellexit}, */
{"env", envshell},
/*{"setenv", _setenv}, */
{NULL, NULL}};
for (i = 0; all[i].arg != NULL; i++)
{
if (_strcmp(all[i].arg, args[0]) == 0)
{
all[i].f(args, line);
return (0);
}
}
return (1);
}
/**
* envshell - function that prints the environ
* @args: Array of pointers (token)
* @line: String from prompt
* Return: void
*/
void envshell(char **args, char *line)
{
int i;
for (i = 0; environ[i] != NULL; i++)
{
write(STDOUT_FILENO, environ[i], _strlen(environ[i]));
write(STDOUT_FILENO, "\n", 1);
}
(void)args;
(void)line;
}