forked from sebascastel/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.c
121 lines (115 loc) · 3.65 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
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
#include "holberton.h"
/**
* help_help - aux function of _help
* prints msg tp stdout
*/
void help_help(void)
{
char *msg = "help: help\n\tSee all Shell's Bells builtin commands.\n";
yellow();
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "\n help [BUILTIN NAME]\n\tSee specific information on each ";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "built-in command.\n";
write(STDOUT_FILENO, msg, _strlen(msg));
resetb();
}
/**
* help_alias - aux function of _help
* prints msg tp stdout
*/
void help_alias(void)
{
char *msg = "\n alias: alias\n\tDefine or display aliases.\n";
yellow();
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "\n alias [-p] [name[=value]...]\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "Without arguments, `alias' prints the list of aliases\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "Otherwise, an alias is defined for each NAME whose VALUE is given\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "trailing space in VAL causes next word to be checked for alias\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "substitution when the alias is expanded.\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "built-in command.\n";
write(STDOUT_FILENO, msg, _strlen(msg));
resetb();
}
/**
* help_history - aux function of _help
* prints msg tp stdout
*/
void help_history(void)
{
char *msg = "\n history: history\n\tDefine or display history commands.\n";
yellow();
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "\n history fc [-e ename] [-lnr] [first] [last]\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "Many programs read input from the user a line at a time\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "The GNU History library is able to keep track of those lines,\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "associate arbitrary data with each line\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "and utilize info from previous lines in composing new ones.\n\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "built-in command.\n";
write(STDOUT_FILENO, msg, _strlen(msg));
resetb();
}
/**
* help_all - aux function of _help
* prints a collection of msgs to stdout
*/
void help_all(void)
{
char *msg = "Shell's Bells\nThese shell commands are defined internally.\n";
green();
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "Type 'help' to see this list.\nType 'help name' to find ";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "out more about the function 'name'.\n\n alias \t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "alias [NAME[='VALUE'] ...]\n cd \tcd ";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "[DIRECTORY]\n exit \texit [STATUS]\n env \tenv";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "\n setenv \tsetenv [VARIABLE] [VALUE]\n unsetenv\t";
write(STDOUT_FILENO, msg, _strlen(msg));
msg = "unsetenv [VARIABLE]\t history\n";
write(STDOUT_FILENO, msg, _strlen(msg));
resetb();
}
/**
* _help - function _help, prompts a quick help for built-in commands
* @args: arguments to be prompted help feature
* Return: Always 0
*/
int _help(char **args)
{
char *a = "no help command found for this option\n";
if (!args[1])
help_all();
else if (_strcmp(args[1], "cd") == 0)
help_cd();
else if (_strcmp(args[1], "alias") == 0)
help_alias();
else if (_strcmp(args[1], "exit") == 0)
help_exit();
else if (_strcmp(args[1], "env") == 0)
help_env();
else if (_strcmp(args[1], "setenv") == 0)
help_setenv();
else if (_strcmp(args[1], "unsetenv") == 0)
help_unsetenv();
else if (_strcmp(args[1], "history") == 0)
help_history();
else if (_strcmp(args[1], "help") == 0)
help_help();
else
write(STDERR_FILENO, a, _strlen(a));
return (0);
}