-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.c
More file actions
106 lines (95 loc) · 1.89 KB
/
help.c
File metadata and controls
106 lines (95 loc) · 1.89 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
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
#include "holberton.h"
/**
* helpFunc - retrieves instruction on how to use builtin
* @ssh: input ssh
* Return: Always 1
*/
int helpFunc(_unix *ssh)
{
cmd _arr[] = {
{"exit", hExit},
{"env", hEnv},
{"history", hHistory},
{"alias", _Halias},
{"cd", hCd},
{"setenv", hSetenv},
{"unsetenv", hUnsetenv},
{"help", _Help},
{NULL, NULL}
};
register int i = 0, j = 1, argCount = Arguments(ssh->args);
_Bool foundCommand = false;
if (argCount == 1)
return (displayHelpMenu());
while (j < argCount)
{
i = 0;
while (_arr[i].command)
{
if (_strcmp(ssh->args[j], _arr[i].command) == 0)
{
foundCommand = true;
_arr[i].func(ssh);
break;
}
i++;
}
j++;
}
if (foundCommand == false)
{
errno = EBUILT;
_getError(ssh);
}
return (1);
}
/**
* displayHelpMenu - displays available help options
* Return: Always 1
*/
int displayHelpMenu(void)
{
char str[81] = "Type help [built-in]\n\nIncluded built-ins:";
char *str2 = "\n\n\texit\n\tenv\n\tcd\n\tsetenv\n\tunsetenv\n\thelp\n";
_strcat(str, str2);
write(STDOUT_FILENO, str, _strlen(str));
return (1);
}
/**
* hExit - instructions on how to exit
* @ssh: input ssh
* Return: Always 1
*/
int hExit(_unix *ssh)
{
char str[82] = "exit: exit [n]\n\tExit the shell.\n\n\t";
char *str2 = "Exit with a status of n, or if n is omitted, 0.\n";
(void)ssh;
_strcat(str, str2);
write(STDOUT_FILENO, str, _strlen(str));
return (1);
}
/**
* hEnv - instructions on how to exit
* @ssh: input ssh
* Return: Always 1
*/
int hEnv(_unix *ssh)
{
char str[] = "env: env\n\tPrint the environment.\n";
(void)ssh;
write(STDOUT_FILENO, str, _strlen(str));
return (1);
}
/**
* hHistory - instructions on how to exit
* @ssh: input ssh
* Return: Always 1
*/
int hHistory(_unix *ssh)
{
char str[] = "history: history\n\tNot supported in this version.\n";
(void)ssh;
write(STDOUT_FILENO, str, _strlen(str));
return (1);
}