-
Notifications
You must be signed in to change notification settings - Fork 1
/
minishell.c
63 lines (57 loc) · 1.74 KB
/
minishell.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aarbaoui <aarbaoui@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/10 11:35:46 by aarbaoui #+# #+# */
/* Updated: 2023/03/25 20:51:43 by aarbaoui ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *prompt(t_shell *shell)
{
char *pwd;
char *prompt;
char *temp;
pwd = getcwd(NULL, 0);
if (ft_strcmp(pwd, get_env(shell, "HOME")) == 0)
{
free(pwd);
pwd = ft_strdup("~");
}
prompt = GREEN "minishell[" BLUE;
temp = ft_strjoin(prompt, pwd);
prompt = ft_strjoin(temp, GREEN "]~> " RESET);
free(temp);
free(pwd);
return (prompt);
}
g_sigflag = 0;
int main(int ac, char **av, char **env)
{
t_shell *shell;
char *prompt_str;
(void)ac;
(void)av;
prompt_str = NULL;
shell = ft_calloc(1, sizeof(t_shell));
init_shell(shell, env);
while (1337)
{
prompt_str = prompt(shell);
init_signals();
shell->line = readline(prompt_str);
free(prompt_str);
find_path(shell, 0, 0);
if (ft_lexer(shell) == SUCCESS)
{
if (parsing(shell, 0) == SUCCESS)
run(shell, 0, NULL);
}
free_all(shell);
}
clear_history();
return (SUCCESS);
}