-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_fct1.c
136 lines (126 loc) · 4.24 KB
/
move_fct1.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_fct1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wtrembla <wtrembla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/03/05 16:56:29 by wtrembla #+# #+# */
/* Updated: 2014/03/27 23:11:32 by sboeuf ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static int check_pos(t_historic **historic, int win_size, int test)
{
if (test == 1 && (((*historic)->copy->comline->col + 1)
>= (win_size + (*historic)->prompt)))
return (1);
else if (test == 2 && (((*historic)->copy->comline->col + 1) >= win_size))
return (1);
else if (test == -1 && ((*historic)->copy->size
- (*historic)->copy->comline->col
+ (*historic)->prompt + 1) >= win_size)
return (1);
else if (test == -2 && (((*historic)->copy->size
- (*historic)->copy->comline->col
+ (*historic)->prompt + 1) % win_size
+ ((*historic)->copy->comline->col + 1) % win_size)
>= win_size)
{
return (1);
}
return (0);
}
void apply_moveup(t_historic **historic)
{
int col;
struct winsize size;
ioctl(0, TIOCGWINSZ, &size);
if (check_pos(historic, size.ws_col, 1))
{
tputs(tgetstr("up", NULL), 1, aff_c);
col = (*historic)->copy->comline->col - size.ws_col;
while ((*historic)->copy->comline->col != col)
(*historic)->copy->comline = (*historic)->copy->comline->left;
}
else if (check_pos(historic, size.ws_col, 2)
&& (*historic)->copy->comline->left)
{
tputs(tgetstr("up", NULL), 1, aff_c);
tputs(tgoto(tgetstr("ch", NULL), 0, (*historic)->prompt), 1, aff_c);
while ((*historic)->copy->comline->c != '\0')
(*historic)->copy->comline = (*historic)->copy->comline->left;
}
}
void apply_movedown(t_historic **historic)
{
int col;
struct winsize size;
ioctl(0, TIOCGWINSZ, &size);
if (check_pos(historic, size.ws_col, -1))
{
tputs(tgetstr("do", NULL), 1, aff_c);
tputs(tgoto(tgetstr("ch", NULL), 0, (*historic)->copy->comline->col
% size.ws_col + 1), 1, aff_c);
col = (*historic)->copy->comline->col + size.ws_col;
while ((*historic)->copy->comline->col != col)
(*historic)->copy->comline = (*historic)->copy->comline->right;
}
else if (check_pos(historic, size.ws_col, -2)
&& (*historic)->copy->comline->right->right)
{
tputs(tgetstr("do", NULL), 1, aff_c);
while ((*historic)->copy->comline->right)
(*historic)->copy->comline = (*historic)->copy->comline->right;
tputs(tgoto(tgetstr("ch", NULL), 0, (*historic)->copy->comline->col
% size.ws_col + 1), 1, aff_c);
}
}
void apply_movenext(t_historic **historic)
{
t_comline *tmp;
tmp = (*historic)->copy->comline;
if (tmp->c == ' ')
tmp = tmp->right;
while (tmp && tmp->c != ' ')
tmp = tmp->right;
while (tmp && tmp->c == ' ')
tmp = tmp->right;
if (tmp)
tmp = tmp->left;
if (tmp && tmp->c == ' ')
{
while ((*historic)->copy->comline->col != tmp->col)
{
tputs(tgetstr("nd", NULL), 1, aff_c);
(*historic)->copy->comline = (*historic)->copy->comline->right;
if (check_ending((*historic)->copy->comline))
tputs(tgetstr("do", NULL), 1, aff_c);
}
}
}
void apply_moveprev(t_historic **historic)
{
struct winsize size;
t_comline *tmp;
ioctl(0, TIOCGWINSZ, &size);
tmp = (*historic)->copy->comline;
if (tmp->c != '\0')
{
while (tmp->c != '\0' && tmp->c == ' ')
tmp = tmp->left;
while (tmp->c != '\0' && tmp->c != ' ')
tmp = tmp->left;
while ((*historic)->copy->comline->col != tmp->col)
{
(*historic)->copy->comline = (*historic)->copy->comline->left;
if (check_beginning((*historic)->copy->comline))
{
tputs(tgetstr("up", NULL), 1, aff_c);
tputs(tgoto(tgetstr("ch", NULL), 0, size.ws_col), 1, aff_c);
}
else
tputs(tgetstr("le", NULL), 1, aff_c);
}
}
}