-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_line.c
53 lines (46 loc) · 1.52 KB
/
get_line.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fayan <42istanbul.com.tr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/10 21:31:01 by dayan #+# #+# */
/* Updated: 2022/11/24 14:37:49 by dayan ### ########.tr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *get_input(void)
{
char *input;
char *prompt;
prompt = ft_strdup("|your command| -> ");
input = readline(prompt);
if (!input)
return (input);
free(prompt);
return (input);
}
char *take_line(void)
{
char *line;
connectsignals();
line = get_input();
signal(SIGINT, nothing);
if (!line)
exit(1);
return (line);
}
void get_line(void)
{
char *line;
line = take_line();
g_data.all_line = ft_strdup(line);
free(line);
if (is_command(g_data.all_line))
add_history(g_data.all_line);
line = ft_strtrim(g_data.all_line, " \t\r\v\f\n");
free(g_data.all_line);
g_data.all_line = ft_strdup(line);
free(line);
}