Raw Terminal I/O in lisp
- From: fungsin.lui@xxxxxxxxx
- Date: 30 May 2006 18:29:51 -0700
Hi all,
I'd appreciate any help for c programmer like me who is new to lisp.
My platform is linux 2.6 (sbcl or lispworks). I'm trying to figure out
how to do terminal I/O in noncanonical mode with lisp.
Below is a simplied version of the example code in APUE.
Here's what I think I need to do:
1. Export the tty_raw function via FFI.
2. Build a console lisp program executable with LW's delivery function
or sbcl's (sb-ext:save-lisp-and-die :executable t)
But I am not quite sure how to write that "main" program in lisp, with
the standard file descriptor opened and pass that descriptor to the
tty_raw FFI function. (I assume that the C file number 0 1 2 doesn't
mean anything in lisp)
Any help would be appreciated!
TIA,
fungsin.
/* raw_term_io.c */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
int tty_raw (int fd) /* put terminal into a raw mode */
{
int err;
struct termios buf;
/* Echo off, canonical mode off, extended input
processing off, signal chars off. */
buf.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
/* No SIGINT on BREAK, CR-to-NL off, input parity
check off, don't strip 8th bit on input, output
flow control off. */
buf.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
/* Clear size bits, parity checking off. */
buf.c_cflag &= ~(CSIZE | PARENB);
/* Set 8 bits/char.*/
buf.c_cflag |= CS8;
/* Output processing off. */
buf.c_oflag &= ~(OPOST);
/* 1 byte at a time, no timer. */
buf.c_cc[VMIN] = 1;
buf.c_cc[VTIME] = 0;
if (tcsetattr(fd, TCSAFLUSH, &buf) < 0)
return(-1);
return(0);
}
int main (int argc, char *argv[])
{
int i;
char c;
if (tty_raw(STDIN_FILENO) < 0)
exit(-1);
printf("Enter raw mode characters, terminate with DELETE\n");
while ((i = read(STDIN_FILENO, &c, 1)) == 1) {
if ((c &= 255) == 0177) /* 0177 = ASCII DELETE */
break;
printf("%o\n", c);
}
exit(0);
}
.
- Follow-Ups:
- Re: Raw Terminal I/O in lisp
- From: Nikodemus Siivola
- Re: Raw Terminal I/O in lisp
- Prev by Date: SBCL on OS X - bad magic number in core file?
- Next by Date: Re: Just can't hear enough about Cells?
- Previous by thread: Easy migration of SBCL/SLIME from Linux to OS X Intel?
- Next by thread: Re: Raw Terminal I/O in lisp
- Index(es):
Relevant Pages
|