-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_linechange.c
100 lines (91 loc) · 2.22 KB
/
ft_linechange.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_linechange.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pferry <pferry@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/03/05 17:07:14 by pferry #+# #+# */
/* Updated: 2014/03/24 15:36:00 by pferry ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "shell.h"
t_list *lst;
static void ft_linedel(char *str)
{
sleep(2);
str = str;
// tputs(tgetstr("ei", NULL), 1, tputs_char);
tputs(tgetstr("ch", NULL), 1, tputs_char);
// tputs(tgetstr("im", NULL), 1, tputs_char);
// tputs(tgetstr("nd", NULL), 1, tputs_char);
// tputs(tgetstr("nd", NULL), 1, tputs_char);
sleep(2);
tputs(tgetstr("ce", NULL), 1, tputs_char);
}
/*
static int ft_lstlen(t_list *lst)
{
int n;
t_list *tmp;
tmp = lst;
while (tmp)
{
tmp = tmp->next;
n++;
}
return (n);
}
*/
char *ft_linechange(char *buff, size_t len, char *line)
{
char *new;
static int i;
i = 0;
new = ft_strnew(1);
if (!lst)
{
ft_putstr("aieaiei");
lst = NULL;
}
if (line == NULL)
{
if (*(int *)buff == UP && lst)
{
if (lst->next && lst->prev)
{
lst = lst->next;
ft_linedel(lst->content);
ft_putstr(lst->content);
i++;
}
else if (lst && !(lst->prev))
{
ft_linedel(lst->content);
ft_putstr(lst->content);
if (lst->next)
lst = lst->next;
}
}
else if (*(int *)buff == DOWN && lst && i > 0)
{
lst = lst->prev;
if (lst)
{
ft_linedel(lst->content);
ft_putstr(lst->content);
}
i--;
}
}
else if (line[0] != '\0')
{
i = 0;
while (lst && lst->prev)
lst = lst->prev;
ft_putstr("oups");
ft_lstadd(&lst, ft_lstnew(line, len));
}
return (new);
}