-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.c
63 lines (59 loc) · 1.77 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* shell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ysarac <ysarac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 11:33:38 by ulyildiz #+# #+# */
/* Updated: 2024/06/08 16:16:53 by ysarac ### ########.fr */
/* */
/* ************************************************************************** */
#include "functions.h"
#include "42-libft/libft.h"
#include <stdio.h>
#include <readline/history.h>
#include <readline/readline.h>
#include <stdlib.h>
#include <unistd.h>
static int line_read(t_main *shell)
{
shell->cmd_line = readline(shell->prompt);
if (!shell->cmd_line)
return (clear_history(), perror("Readline"), 2);
else if (!is_space(shell->cmd_line))
return (free(shell->cmd_line), 0);
add_history(shell->cmd_line);
return (1);
}
void start_shell(t_main *shell)
{
int i;
t_tokens *t;
while(1)
{
i = line_read(shell);
if (!i)
continue ;
else if (i == 2)
break;
if (!lexer(shell))
break;
if (!expender(shell))
break;
//printf("\n");
/* t = shell->token;
while(t)
{
printf("-%s-\n", t->value);
t = t->next;
}
printf("\n"); */
if (!parser(shell, shell->token, 0))
break;
if (!executor(shell))
break;
//update veya free?
shell->control = 1;
}
}