-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.c
69 lines (53 loc) · 1.03 KB
/
shell.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
#include "main.h"
/**
* main - A function to check if our shell is interactive
*
* Return: 0 on success
*/
int main(void)
{
if (isatty(STDIN_FILENO) == 1) /* isatty func to see if shell is interactive*/
myshell_works(); /* lets check if our shell is interactive*/
else
myshell_isnot(); /* lets see if the shell is not interactive*/
return (0);
}
/**
* myshell_works - A function to print a prompt for the shell to work
*
* Return: void
*/
void myshell_works(void)
{
char *line;
char **args;
int status = -1;
do {
write(STDOUT_FILENO, "henry$$ ", 8);
line = scan_line();
args = divide_line(line);
status = exec_arg(args);
free(line);
free(args);
} while (status != -2);
}
/**
* myshell_isnot - A function for non interactive shell
*
* Return: void
*/
void myshell_isnot(void)
{
char *line;
char **args;
int status;
do {
line = get_stream();
args = divide_line(line);
status = exec_arg(args);
free(line);
free(args);
if (status >= 0 || status == -2)
break;
} while (status == -1);
}