-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unix_prompt.c
51 lines (44 loc) · 999 Bytes
/
Unix_prompt.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
#include "shell.h"
/**
* shell_prompt - function reads unix shell prompts and display inputs
* @file_check: pointer to the getline input
* Return: character to the prompt_input
*/
char *shell_prompt(ssize_t *file_check)
{
char *dis_prompt = "(?) ", *newline_pos;
char *prompt_input = NULL;
if (isatty(STDIN_FILENO))
{
write(1, dis_prompt, _strlen(dis_prompt));
}
prompt_input = get_line();
if (prompt_input == NULL)
{
if (isatty(STDIN_FILENO))
write(1, "Logging Out From simple shell (?) .....", 43);
exit(EXIT_SUCCESS);
}
*file_check = _strlen(prompt_input);
if (*file_check == -1)
{
if (isatty(STDIN_FILENO))
free(prompt_input);
exit(EXIT_SUCCESS);
}
else if (*file_check == -1)
{
free(prompt_input);
exit(EXIT_SUCCESS);
}
if (*file_check == 0)
{
if (isatty(STDIN_FILENO))
free(prompt_input);
return (shell_prompt(file_check));
}
newline_pos = _strchr(prompt_input, '\n');
if (newline_pos)
newline_pos = '\0';
return (prompt_input);
}