aboutsummaryrefslogtreecommitdiff
path: root/termios.scm.c
blob: 939c357468854002275f6624056a3e39ebaf2d61 (plain)
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
#include <libguile.h>
#include <unistd.h>
#include <termios.h>
#include <stdio.h>

static struct termios *oldt, *newt;

SCM_DEFINE(termios_lflags_and, "c-lflags-disable!", 2, 0, 0,
           (SCM _fd, SCM _bits),
           "")
{

	int fd   = scm_to_int (_fd);
	int bits = scm_to_int (_bits);

	printf("Setting bits [%x]\n", bits);

	tcgetattr(fd, oldt);
	*newt = *oldt;

	// Make the terminal not echo back,
	// along with enabling cononical mode
	newt->c_lflag &= ~ bits;
	tcsetattr(fd, TCSANOW, newt);
	return SCM_UNSPECIFIED;
}

SCM_DEFINE(termios_restore, "c-lflag-restore!", 1, 0, 0,
           (SCM _fd),
           "")
{
	int fd   = scm_to_int (_fd);
	tcsetattr(fd, TCSANOW, oldt);
	return SCM_UNSPECIFIED;
}

void init_termios (void) {
	oldt = scm_gc_malloc(sizeof(*oldt), "Termios");
	newt = scm_gc_malloc(sizeof(*newt), "Termios");

#ifndef SCM_MAGIC_SNARFER
#include "termios.x"
#endif
}