-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage_cols.c
97 lines (88 loc) · 1.9 KB
/
manage_cols.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
/*
** manage_cols.c for my_select in /home/sebastien/travaux/my_select
**
** Made by sebastien
** Login <[email protected]>
**
** Started on Thu Jan 16 17:27:36 2014 sebastien
** Last update Thu Jan 16 17:32:43 2014 sebastien
*/
#include <sys/ioctl.h>
#include <stdlib.h>
#include <curses.h>
#include <term.h>
#include "my_select.h"
static int get_size_from_to(int begin, int end, t_list *root)
{
t_list *tmp;
int size_max;
int i;
i = 0;
tmp = root;
size_max = 0;
while (i <= begin)
{
tmp = tmp->next;
i = i + 1;
}
while (i <= end)
{
if (tmp->size_str > size_max)
size_max = tmp->size_str;
tmp = tmp->next;
i = i + 1;
}
if (tmp->size_str > size_max)
size_max = tmp->size_str;
return (size_max);
}
static int get_size_max(int i, int ws_row, t_list *root)
{
int j;
int num_col;
int size_max;
int col_total;
j = 0;
size_max = 0;
col_total = (root->nb_elem) / ws_row;
num_col = i / ws_row;
while (j < num_col)
{
size_max += get_size_from_to(ws_row * j, (ws_row * (j + 1) - 1), root);
j = j + 1;
}
return (size_max);
}
static int get_size_elem(t_list *root, int i)
{
t_list *tmp;
int counter;
counter = 0;
tmp = root->next;
while (counter < i)
counter += 1;
return (tmp->size_str + 1);
}
int manage_col(int i, t_list *root)
{
struct winsize win;
int nb_lines;
int row;
int tmp;
nb_lines = 0;
ioctl(fd_tty, TIOCGWINSZ, &win);
win.ws_row -= 1;
if (win.ws_row == 0
|| get_size_from_to(0, root->nb_elem - 1, root) > win.ws_col
|| ((row = get_size_max(i, win.ws_row, root))
+ get_size_elem(root, i) > win.ws_col))
{
my_tputs(tgetstr("cl", NULL));
my_tputs(tgoto(tgetstr("cm", NULL), 0, 0));
my_tputs("Window is too little, please resize it\n");
return (-1);
}
if (i >= win.ws_row)
my_tputs(tgoto(tgetstr("cm", NULL), row, i % (win.ws_row)));
return (0);
}