-
Notifications
You must be signed in to change notification settings - Fork 0
/
__help.c
49 lines (47 loc) · 1.13 KB
/
__help.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
#include "builtins.h"
/**
* __help - show help for builtins commands
* @info: shell info
* Return: status
*/
int __help(struct info *info)
{
const builtin_t *bp = NULL;
char * const *args = info->tokens + 1;
const char *desc = NULL;
size_t len = 0;
if (*args)
{
info->status = EXIT_FAILURE;
while (*args)
{
bp = get_builtin(*args);
if (bp)
{
write(STDOUT_FILENO, bp->name, _strlen(bp->name));
write(STDOUT_FILENO, ": ", 2);
write(STDOUT_FILENO, bp->help, _strlen(bp->help));
write(STDOUT_FILENO, "\n", 1);
for (desc = bp->desc; (len = _strlen(desc)); desc += len + 1)
{
write(STDOUT_FILENO, " ", 4);
write(STDOUT_FILENO, desc, len);
write(STDOUT_FILENO, "\n", 1);
}
info->status = EXIT_SUCCESS;
}
args += 1;
}
if (info->status == EXIT_FAILURE)
perrorl_default(*info->argv, info->lineno, "No topics match",
*info->tokens, *(args - 1), NULL);
return (info->status);
}
info->status = EXIT_SUCCESS;
for (bp = get_builtins(); bp->name; bp += 1)
{
write(STDOUT_FILENO, bp->help, _strlen(bp->help));
write(STDOUT_FILENO, "\n", 1);
}
return (info->status);
}