-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtins_list.c
35 lines (33 loc) · 954 Bytes
/
builtins_list.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
#include "simpleshell.h"
/**
* builtins_list - search for match and execute the associate builtin
* @data: struct for the program's data
* Return: Returns the return of the function executed is there is a match,
* otherwise returns -1.
**/
int builtins_list(data_of_program *data)
{
int iterator;
builtins options[] = {
{"exit", builtin_exit},
{"help", builtin_help},
{"cd", builtin_cd},
{"alias", builtin_alias},
{"env", builtin_env},
{"setenv", builtin_set_env},
{"unsetenv", builtin_unset_env},
{NULL, NULL}
};
/*walk through the structure*/
for (iterator = 0; options[iterator].builtin != NULL; iterator++)
{
/*if there is a match between the given command and a builtin,*/
if (str_compare(options[iterator].builtin, data->command_name, 0))
{
/*execute the function, and return the return value of the function*/
return (options[iterator].function(data));
}
/*if there is no match return -1 */
}
return (-1);
}