forked from jiyuneel/minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minishell.c
67 lines (59 loc) · 2.05 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
64
65
66
67
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jihykim2 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/30 19:51:59 by jiyunlee #+# #+# */
/* Updated: 2023/09/29 18:49:04 by jihykim2 ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/minishell.h"
int g_exit_code;
static void _init_term(t_shell_info *shell_info, int argc, char **argv);
static void _set_origin_term(t_shell_info *shell_info);
int main(int argc, char **argv, char **envp)
{
t_shell_info shell_info;
char *str;
_init_term(&shell_info, argc, argv);
env_init(&shell_info.env, envp);
while (TRUE)
{
str = readline("jijishell$ ");
if (!str)
break ;
if (!str[0])
{
free(str);
continue ;
}
if (!shell_init(&shell_info, str))
execute(&shell_info);
add_history(str);
free(str);
}
_set_origin_term(&shell_info);
return (g_exit_code);
}
static void _init_term(t_shell_info *shell_info, int argc, char **argv)
{
struct termios term;
(void) argv;
if (argc != 1)
exit (EXIT_FAILURE);
g_exit_code = 0;
tcgetattr(STDIN_FILENO, &shell_info->origin_term);
tcgetattr(STDIN_FILENO, &term);
term.c_lflag &= ~(ECHOCTL);
tcsetattr(STDIN_FILENO, TCSANOW, &term);
set_signal(JIJI, JIJI);
}
static void _set_origin_term(t_shell_info *shell_info)
{
free_env_info(shell_info->env);
printf("\x1b[1A\033[11Cexit\n", STDOUT_FILENO);
set_signal(DEFAULT, DEFAULT);
tcsetattr(STDIN_FILENO, TCSANOW, &shell_info->origin_term);
}