-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.c
More file actions
69 lines (64 loc) · 1.93 KB
/
Copy pathinput.c
File metadata and controls
69 lines (64 loc) · 1.93 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ezalos <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/06 12:15:02 by ezalos #+# #+# */
/* Updated: 2019/09/29 18:30:07 by ezalos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/head.h"
void fast_terminal(int on_off)
{
static struct termios old = {0};
if (on_off)
{
if (tcgetattr(0, &old) < 0)
perror("tcsetattr()");
old.c_lflag &= ~ICANON;
old.c_lflag &= ~ECHO;
old.c_cc[VMIN] = 1;
old.c_cc[VTIME] = 0;
if (tcsetattr(0, TCSANOW, &old) < 0)
perror("tcsetattr ICANON");
}
else
{
old.c_lflag |= ICANON;
old.c_lflag |= ECHO;
if (tcsetattr(0, TCSADRAIN, &old) < 0)
perror ("tcsetattr ~ICANON");
}
}
int get_input(t_connect *c_four)
{
// DEBUG_FUNC;
char buffer[2];
int move;
int r_v;
r_v = 1;
// print_board(c_four);
fast_terminal(1);
move = UNSET;
buffer[1] = '\0';
while (move == UNSET && r_v)
{
// DEBUG_FUNC;
if ((r_v = read(0, buffer, 1)) > 0)
{
// ft_printf("BUF->%c\n", buffer[0]);
if (ft_isdigit(buffer[0]))
{
move = ft_atoi(buffer);
// ft_printf("Atoi say: %d\n", move);
if (play_move(c_four, move - 1) == FAILURE)
move = UNSET;
}
}
// ft_printf("OUT IF BUFF->%c\nmove: %d\tr_v: %d\n", buffer[0], move, r_v);
}
fast_terminal(0);
return (r_v);
}