-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple_shell.c
More file actions
46 lines (43 loc) · 874 Bytes
/
simple_shell.c
File metadata and controls
46 lines (43 loc) · 874 Bytes
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
#include "shell.h"
/**
* main - get a line containing a command, parses it and executes
*
* Return: always 0
*/
int main(void)
{
char *line;
/* int i;*/
node_t *pathl;
char **enva;
int check;
node_t *histl;
char *remainder;
char *buffer;
int e_o_f;
histl = NULL;
buffer = NULL;
e_o_f = 0;
check = initialize_shell(&enva, &pathl, &histl, &remainder);
if (check == -1)
return (0);
while (1)
{
set_to_catch();
line = prompt(&buffer, &remainder, enva, pathl, histl, &e_o_f);
if (line != NULL)
/*line is NULL if nothing or only comments, EOF caught before*/
{
/* printf("simple shell: The line is %s\n", line);*/
add_node_end(&histl, line, NULL);
execute_command(line, &enva, &pathl, &histl);
}
if (e_o_f && remainder == NULL)
break;
}
_history_write(&histl);
free_enva(enva);
free_list(pathl);
free_list(histl);
return (0);
}