-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelp.c
More file actions
70 lines (66 loc) · 1.55 KB
/
Copy pathhelp.c
File metadata and controls
70 lines (66 loc) · 1.55 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
#include "shell.h"
/**
* _help_all - print out all help messages
* @array: array storing help messages
* Return: 0 for success
*/
int _help_all(bi_t *array)
{
int i;
i = 0;
while (array[i].name != NULL)
{
write(STDOUT_FILENO, array[i].help, _strlen(array[i].help));
i++;
}
return (0);
}
/**
* _help - help command
* @args: arguments
* @enva: environment array
* @pathl: path linked list
* @histl: history linked list
* Return: 0
*/
int _help(char **args, char ***enva, node_t **pathl, node_t **histl)
{
bi_t array[] = {
{"exit", "exit [status] - Exit the shell\n", _exit_},
{"env", "env - Print environment variables\n", _printenv},
{"getenv", "getenv VARIABLE - Return value of variable\n", bi_getenv},
{"setenv",
"setenv VARIABLE VALUE [0] - Create or modify environment variable\n",
_setenv_help},
{"unsetenv", "unsetenv VARIABLE - Remove environment variable\n",
_unsetenv_help},
{"cd", "cd [DIRECTORY] - Change directory to DIRECTORY or home\n", _cd},
{"help", "help [BUILTIN] - Displays information about BUILTIN or all\n",
_help},
{"history", "history - Displays list of past commands\n",
_history}, {NULL, NULL, NULL}
};
int i, j;
(void) enva; (void) pathl; (void) histl;
if (!args || !*args || !args[0])
return (101);
i = 0;
if (args[1] == NULL)
_help_all(array);
else
{
while (array[i].name != NULL)
{
if (_strcmp(args[1], array[i].name) == 0)
{
j = _strlen(array[i].help);
write(STDOUT_FILENO, array[i].help, j);
break;
}
i++;
}
}
if (i >= 8)
_help_all(array);
return (0);
}