-
Notifications
You must be signed in to change notification settings - Fork 5
/
conion.old
executable file
·71 lines (60 loc) · 1.13 KB
/
conion.old
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
#include <stdio.h>
#include "conion.h"
#ifdef STD_CONSOLE_INPUT
void initialize_console_io()
{
}
void restore_console_io()
{
}
int kbhit(void)
{
return 0;
}
int getch(void)
{
return getchar();
}
#else
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
static struct termios oldt;
static int oldf;
static int lastkey = EOF;
static int initialized = 0;
void initialize_console_io()
{
struct termios newt;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
initialized = 1;
}
void restore_console_io()
{
if (initialized)
{
initialized = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
}
}
int kbhit(void)
{
if (lastkey == EOF)
lastkey = getchar();
return (lastkey != EOF);
}
int getch(void)
{
int ch;
while (!kbhit());
ch = lastkey;
lastkey = EOF;
return ch;
}
#endif