forked from glyif/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltinA.c
122 lines (98 loc) · 2.02 KB
/
builtinA.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "header.h"
/**
* _env - writes env to stdout
* @arginv: arguments inventory
*
* Return: 0 on success
*/
int _env(arg_inventory_t *arginv)
{
env_t *envlist = arginv->envlist;
char **commands;
commands = (char **)arginv->commands;
if (commands[1] != NULL)
{
_perror("env: No such file or directory\n");
return (-1);
}
print_list(envlist);
return (EXT_SUCCESS);
}
/**
* _history - writes history to stdout
* @arginv: arguments inventory
*
* Return: 0 on success
*/
int _history(arg_inventory_t *arginv)
{
history_t *historylist = arginv->history;
write_history(historylist);
return (EXT_SUCCESS);
}
/**
* _setenv - sets new environmental variable
* @arginv: arguments inventory
*
* Return: 0 on success
*/
int _setenv(arg_inventory_t *arginv)
{
char **commands, *new_var, *new_val;
env_t *envlist = arginv->envlist;
commands = (char **)arginv->commands;
if (commands[1] == NULL || commands[2] == NULL)
{
_perror("setenv: missing parameters.\n");
return (-1);
}
if (commands[3] != NULL)
{
_perror("setenv: missing value.\n");
return (-1);
}
new_var = commands[1];
new_val = commands[2];
if (modify_node_env(&envlist, new_var, new_val) == EXT_FAILURE)
{
add_node_env(&envlist, new_var, new_val);
}
return (EXT_SUCCESS);
}
/**
* _unsetenv - sets new environmental variable
* @arginv: arguments inventory
*
* Return: 0 on success
*/
int _unsetenv(arg_inventory_t *arginv)
{
char **commands;
env_t *envlist = arginv->envlist;
commands = (char **)arginv->commands;
if (commands[1] == NULL)
{
_perror("unsetenv: missing parameters.\n");
return (-1);
}
if (commands[2] != NULL)
{
_perror("unsetenv: too many input commands.\n");
return (-1);
}
if (remove_node_env(&envlist, commands[1]))
return (EXT_FAILURE);
return (EXT_SUCCESS);
}
/**
* _arsine - prints mona lisa ascii art
* @arginv: arguments inventory
*
* Return: 0 on success
*/
int _arsine(arg_inventory_t *arginv)
{
(void)arginv;
_puts("AsH3 special thanks to Walter White");
return (EXT_SUCCESS);
}