-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_error-help.c
More file actions
72 lines (65 loc) · 1.53 KB
/
Copy pathget_error-help.c
File metadata and controls
72 lines (65 loc) · 1.53 KB
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
#include "header.h"
/**
* get_error - calls the error according the builtin, syntax or permission
* @datash: data structure that contains arguments
* @eval: error value
* Return: error
*/
int get_error(data_shell *datash, int eval)
{
char *error;
switch (eval)
{
case -1:
error = error_env(datash);
break;
case 126:
error = error_path_126(datash);
break;
case 127:
error = error_not_found(datash);
break;
case 2:
if (_strcmp("exit", datash->args[0]) == 0)
error = error_exit_shell(datash);
else if (_strcmp("cd", datash->args[0]) == 0)
error = error_get_cd(datash);
break;
}
if (error)
{
write(STDERR_FILENO, error, _strlen(error));
free(error);
}
datash->status = eval;
return (eval);
}
/**
* get_help - function that retrieves help messages according builtin
* @datash: data structure (args and input)
* Return: Return 0
*/
int get_help(data_shell *datash)
{
if (datash->args[1] == 0)
aux_help_general();
else if (_strcmp(datash->args[1], "setenv") == 0)
aux_help_setenv();
else if (_strcmp(datash->args[1], "env") == 0)
aux_help_env();
else if (_strcmp(datash->args[1], "unsetenv") == 0)
aux_help_unsetenv();
else if (_strcmp(datash->args[1], "help") == 0)
aux_help();
else if (_strcmp(datash->args[1], "exit") == 0)
aux_help_exit();
else if (_strcmp(datash->args[1], "cd") == 0)
aux_help_cd();
else if (_strcmp(datash->args[1], "alias") == 0)
aux_help_alias();
else
write(STDERR_FILENO, datash->args[0],
_strlen(datash->args[0]));
datash->status = 0;
return (1);
}