-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmore_help_functions2.c
62 lines (53 loc) · 1.16 KB
/
more_help_functions2.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
#include "holberton.h"
/**
* new_help_alias - help builtin command alias
* @vars: if command matches a builtin name, text file is sent to stdout
* Return: 0 if sucess
*/
void new_help_alias(vars_t *vars)
{
char *file;
int fd, r;
char *s;
if (_strcmpr(vars->array_tokens[1], "alias") == 0)
{
file = "/home/shell_test/shelltestenviroment/helpfiles/alias";
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_else(vars);
}
/**
* new_help_else -error message if not command found
* @vars: if command matches a builtin name, text file is sent to stdout
* Return: 0 if sucess
*/
void new_help_else(vars_t *vars)
{
prints_error_msg(vars, ": no help topics match: `");
_puts_error(vars->array_tokens[1]);
_puts_error("'. Try `help help' or `man -k ");
_puts_error(vars->array_tokens[1]);
_puts_error("' or `info ");
_puts_error(vars->array_tokens[1]);
_puts_error("'.");
_puts_error("\n");
}