forked from x25today/xotclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tty.c
96 lines (83 loc) · 1.25 KB
/
tty.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
#include <stdio.h>
#include <sys/types.h>
#include <curses.h>
#include <stdlib.h>
#include "x25.h"
static FILE *logfile = NULL;
static WINDOW *scr;
static int doecho = 0;
static int
startlog() {
if(logfile)
return 1;
logfile = fopen(LOGFILE, "a");
return (logfile != NULL);
}
static void
stoplog()
{
if(logfile)
fclose(logfile);
logfile = NULL;
}
void
lputchar(unsigned char c, unsigned char from_input)
{
if(logfile)
fputc(c, logfile);
if(doecho || !from_input)
putchar(c);
}
char *
my_fgets(unsigned char *string, int bufsz, FILE *fp)
{
int i, b;
for(i = 0; i < bufsz-1; ++i)
{
b = getch();
if(b == KEY_F(2))
startlog();
else if(b == KEY_F(3))
stoplog();
else if(b == KEY_F(10)) {
printf("EXITING!\n");
return NULL;
} else {
string[i] = (unsigned char)(b & 0xFF);
if(string[i] == '\n') {
++i;
break;
}
}
}
string[i] = 0;
return string;
}
void
tty_start() {
scr = initscr();
keypad(scr, 1);
noecho();
wclear(scr);
wrefresh(scr);
}
void
tty_stop()
{
stoplog();
echo();
keypad(scr, 0);
endwin();
}
void
pad_control(unsigned char code, unsigned char param)
{
switch(code) {
case 0x02: /* ECHO */
doecho = param;
break;
default:
/* not supported or not implemented */
break;
}
}