SBCL help with C
From
steve gonedes@21:1/5 to
All on Sat Apr 24 19:22:01 2021
I'm getting stuck with calling an ioctl in sbcl.
I am using the sb-unix:unix-open to get the file descriptor and use it
to initialize the termios. This is what I got so far.
(defun make-termios-device (name ttyname)
;; name is name of terminal, ttyname is a path to /dev/ttyx
(setq ttyname (namestring ttyname))
(let* ((hash (terminfo:get-terminal name)) ;; reads terminfo
(fd (sb-unix:unix-open ttyname 1
;; set the O_NOCTTY flag
(logior 04000 0100 0400)))
(out)
(oterm (sb-posix:tcgetattr fd (make-instance 'sb-posix:termios)))
(nterm (sb-posix:tcgetattr fd (make-instance 'sb-posix:termios)))
)
;;(sb-posix:cfgetispeed oterm)
(setq out
(sb-sys:make-fd-stream fd :external-format :ascii :buffering :none :output t :input nil :file ttyname ))
(setq *current-device*
(make-device :input *standard-input*
:output out :fdo fd :baud-rate 9600
:rows 0 :columns 0 :hash hash
:termiosold oterm :termiosnew nterm))))
This is working great, but I always get stuck with an io control or
signal issue. I think the signal handling is doable for me. This is
where I always get stuck.
I need to know the number of lines and columns on the screen. I know!
Yeah right - yes... I want to do this right so that I can eventually use
the linux frame buffer and event input device. Either way I need to call
the kernel for some io control. The mmappped files and shared memory
would be nice. I'm just sticking with a curses like thing...
I would like to take the termios instance from lisp and change it in C.
Also an ioctl call with a (char *) cast.. The pointer has to be 8 bits
wide I guess. I hate messing with termio.
This is the C that I can compile into a shared library and load it into
the sbcl. I cannot for the life of me figure out the alien eval thing
with casting. I just don't want to cons (or copy any strings).
void
tty_get_window_size (int fd, struct winsize *win)
{
ioctl (fd, TIOCGWINSZ, (char *) win);
}
void
tty_cbreak_mode (struct termios *tty)
{
tty->c_lflag &= ~ICANON;
tty->c_iflag &= ~ICRNL;
tty->c_lflag |= ISIG;
#ifdef IUTF8
tty->c_cflag &= ~IUTF8;
#endif
tty->c_cc[VMIN] = 1;
tty->c_cc[VTIME] = 0;
}
This is as far as I can get with lisp.
(define-alien-type nil
(struct c-winsize
(ws_row int)
(ws_col int)
(ws_xpixel int)
(ws_ypixel int)))
;; ? how => (define-alien-routine tty_get_window_size void
;; (with-alien ((win (struct c-winsize))
;; (winptr (* (struct c-winsize))))
;; (tty (sb-sys:fd-stream-fd *fd*) #x5413 winptr)
Any help is really helpful. I saw in the sources ansi-stream and native. Lowlevel access to a file descriptor without the hangups was a great
idea. The unix-open is all I need, but the signals look very useable.
thanks, and sbcl seems to love the new :fast-eval!
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)