-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmore_help_functions.c
191 lines (181 loc) · 3.4 KB
/
more_help_functions.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "holberton.h"
/**
* new_help_history - help builtin command history
* @vars: if command matches a builtin name, text file is sent to stdout
* Return: 0 if sucess
*/
void new_help_history(vars_t *vars)
{
char *file;
int fd, r;
char *s;
if (_strcmpr(vars->array_tokens[1], "history") == 0)
{
file = "/home/shell_test/shelltestenviroment/helpfiles/history";
fd = open(file, O_RDWR);
s = malloc(300);
if (s == NULL)
{
_puts_error("Fatal Error");
return;
}
while ((r = read(fd, s, 300)) > 0)
{
r = write(1, s, r);
print_message("\n");
if (r == -1)
{
_puts_error("Fatal Error");
return;
}
}
free(s);
fd = close(fd);
}
else
new_help_unalias(vars);
}
/**
* new_help_unalias - help builtin command unalias
* @vars: if command matches a builtin name, text file is sent to stdout
* Return: 0 if sucess
*/
void new_help_unalias(vars_t *vars)
{
char *file;
int fd, r;
char *s;
if (_strcmpr(vars->array_tokens[1], "unalias") == 0)
{
file = "/home/shell_test/shelltestenviroment/helpfiles/unalias";
fd = open(file, O_RDWR);
s = malloc(300);
if (s == NULL)
{
_puts_error("Fatal Error");
return;
}
while ((r = read(fd, s, 300)) > 0)
{
r = write(1, s, r);
print_message("\n");
if (r == -1)
{
_puts_error("Fatal Error");
return;
}
}
free(s);
fd = close(fd);
}
else
new_help_unset(vars);
}
/**
* new_help_unset - help builtin command unset
* @vars: if command matches a builtin name, text file is sent to stdout
* Return: 0 if sucess
*/
void new_help_unset(vars_t *vars)
{
char *file;
int fd, r;
char *s;
if (_strcmpr(vars->array_tokens[1], "unset") == 0)
{
file = "/home/shell_test/shelltestenviroment/helpfiles/unset";
fd = open(file, O_RDWR);
s = malloc(300);
if (s == NULL)
{
_puts_error("Fatal Error");
return;
}
while ((r = read(fd, s, 300)) > 0)
{
r = write(1, s, r);
print_message("\n");
if (r == -1)
{
_puts_error("Fatal Error");
return;
}
}
free(s);
fd = close(fd);
}
else
new_help_unsetenv(vars);
}
/**
* new_help_unsetenv - help builtin command unsetenv
* @vars: if command matches a builtin name, text file is sent to stdout
* Return: 0 if sucess
*/
void new_help_unsetenv(vars_t *vars)
{
char *file;
int fd, r;
char *s;
if (_strcmpr(vars->array_tokens[1], "unsetenv") == 0)
{
file = "/home/shell_test/shelltestenviroment/helpfiles/unsetenv";
fd = open(file, O_RDWR);
s = malloc(300);
if (s == NULL)
{
_puts_error("Fatal Error");
return;
}
while ((r = read(fd, s, 300)) > 0)
{
r = write(1, s, r);
print_message("\n");
if (r == -1)
{
_puts_error("Fatal Error");
return;
}
}
free(s);
fd = close(fd);
}
else
new_help_setenv(vars);
}
/**
* new_help_setenv - help builtin command setenv
* @vars: if command matches a builtin name, text file is sent to stdout
* Return: 0 if sucess
*/
void new_help_setenv(vars_t *vars)
{
char *file;
int fd, r;
char *s;
if (_strcmpr(vars->array_tokens[1], "setenv") == 0)
{
file = "/home/shell_test/shelltestenviroment/helpfiles/setenv";
fd = open(file, O_RDWR);
s = malloc(300);
if (s == NULL)
{
_puts_error("Fatal Error");
return;
}
while ((r = read(fd, s, 300)) > 0)
{
r = write(1, s, r);
print_message("\n");
if (r == -1)
{
_puts_error("Fatal Error");
return;
}
}
free(s);
fd = close(fd);
}
else
new_help_alias(vars);
}