diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-12 19:03:48 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-12 19:03:48 +0100 |
commit | d9d646d6442392d60d5c9253706cceb1c9928f5b (patch) | |
tree | bc010c23a3d6997668c2814bd83dda38b2eeaa5c | |
parent | Add sample fetch.scm. (diff) | |
download | calp-d9d646d6442392d60d5c9253706cceb1c9928f5b.tar.gz calp-d9d646d6442392d60d5c9253706cceb1c9928f5b.tar.xz |
Add termios bindings from C.
Diffstat (limited to '')
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | termios.scm.c | 44 |
2 files changed, 46 insertions, 2 deletions
@@ -19,7 +19,7 @@ X_FILES = $(SCM_C_FILES:.scm.c=.x) O_FILES = $(C_FILES:%.c=obj/%.o) -all: parse libguile-calendar.so +all: parse libguile-calendar.so libtermios.so parse: $(O_FILES) $(CC) -o $@ $^ $(LDFLAGS) @@ -38,7 +38,7 @@ $(OBJDIR)/%.o : %.c # $(H_FILES) $(X_FILES) $(OBJDIR): mkdir -p $(OBJDIR) -libguile-calendar.so: $(O_FILES) +%.so: $(O_FILES) $(CC) -shared -o $@ $^ $(LDFLAGS) .SECONDARY += %.dot diff --git a/termios.scm.c b/termios.scm.c new file mode 100644 index 00000000..939c3574 --- /dev/null +++ b/termios.scm.c @@ -0,0 +1,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 +} |