-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_fun.c
More file actions
57 lines (51 loc) · 888 Bytes
/
get_fun.c
File metadata and controls
57 lines (51 loc) · 888 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
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "shell.h"
/**
* get_comd_fun - compares the functions
* @vars: struct
* Return: 0
*/
void (*get_comd_fun(vars_t *vars)) (vars_t *vars)
{
unsigned int iter;
builtins_t comds[] = {
{"exit", get_exit},
{"env", get_env},
{NULL, NULL}
};
for (iter = 0; comds[iter].f != NULL; iter++)
{
if (_strcmp(vars->av[0], comds[iter].name) == 0)
break;
}
if (comds[iter].f != NULL)
comds[iter].f(vars);
return (comds[iter].f);
}
/**
* get_env - environment variables
* @vars: struct
* Return: env
*/
void get_env(vars_t *vars)
{
unsigned int iter;
for (iter = 0; vars->env[iter]; iter++)
{
_puts(vars->env[iter]);
_puts("\n");
}
vars->status = 0;
}
/**
* get_exit - function exit
* @vars: struct
* Return: 0
*/
void get_exit(vars_t *vars)
{
free(vars->buffer);
free(vars->av);
free(vars->commands);
free_env(vars->env);
exit(vars->status);
}