-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_is_arrow.c
More file actions
79 lines (71 loc) · 1.96 KB
/
ft_is_arrow.c
File metadata and controls
79 lines (71 loc) · 1.96 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_arrow.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sid-bell <sid-bell@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/04 00:33:37 by sid-bell #+# #+# */
/* Updated: 2019/02/24 05:47:46 by sid-bell ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/*
** A => UP, B => DOWN, C => RIGHT, D LEFT
*/
static void ft_helper2(t_params *params, char **str, char c)
{
int len;
len = ft_strlen(*str);
if (c == LEFT)
{
params->pos += 1;
*str = ft_delchar(str, len - params->pos);
}
else
{
*str = ft_delchar(str, len - params->pos - 1);
params->pos -= 1;
}
if (c == UP || c == DOWN)
ft_browshistory(str, c, params);
}
static int ft_helper1(t_params *params, char *last, char **str, char c)
{
int len;
int result;
result = 0;
if (last[0] == 27 && last[1] == 91)
{
if (c >= 'A' && c <= 'D')
{
ft_helper2(params, str, c);
result = 1;
len = ft_strlen(*str);
if (params->pos > len)
params->pos = len;
else if (params->pos < 0)
params->pos = 0;
ft_put_to_stdin(*str, params, 0);
}
}
last[2] = last[0];
last[0] = last[1];
last[1] = c;
last[2] = 0;
return (result);
}
int ft_is_arrow(char c, char *last, t_params *params, char **str)
{
int y;
y = 0;
if (!last[0])
last[0] = c;
else if (!last[1])
last[1] = c;
else
{
return (ft_helper1(params, last, str, c));
}
return (0);
}