1995-10-16 18:19:16 -04:00
|
|
|
/* To do:
|
|
|
|
* - Replace explicit 8/24 splits with macros.
|
1995-10-22 08:34:53 -04:00
|
|
|
* - We need to pass the control-chars vecs in as Scheme
|
|
|
|
* strings, and test the length before doing the memcpy.
|
1995-10-16 18:19:16 -04:00
|
|
|
*/
|
|
|
|
|
1995-10-13 23:34:21 -04:00
|
|
|
/*
|
|
|
|
* Scheme48/scsh terminal control interface.
|
|
|
|
* Routines that require custom C support.
|
|
|
|
* Copyright (c) 1995 by Brian D. Carlstrom
|
1995-10-19 04:22:56 -04:00
|
|
|
* Re-written by Olin.
|
1995-10-13 23:34:21 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <termios.h>
|
1995-10-16 18:19:16 -04:00
|
|
|
#include <string.h>
|
1995-10-13 23:34:21 -04:00
|
|
|
|
1995-10-22 08:34:53 -04:00
|
|
|
#include "tty1.h" /* Make sure the .h interface agrees with the code. */
|
|
|
|
|
|
|
|
int scheme_tcgetattr(int fd, char *control_chars,
|
1995-10-13 23:34:21 -04:00
|
|
|
int *iflag_hi8, int *iflag_lo24,
|
|
|
|
int *oflag_hi8, int *oflag_lo24,
|
|
|
|
int *cflag_hi8, int *cflag_lo24,
|
|
|
|
int *lflag_hi8, int *lflag_lo24,
|
|
|
|
int *ispeed, int *ospeed)
|
|
|
|
{
|
|
|
|
struct termios t;
|
1995-10-16 18:19:16 -04:00
|
|
|
int result = tcgetattr(fd, &t);
|
1995-10-13 23:34:21 -04:00
|
|
|
|
1995-10-16 18:19:16 -04:00
|
|
|
if (result != -1) {
|
|
|
|
memcpy(control_chars, t.c_cc, NCCS);
|
|
|
|
*iflag_hi8 =t.c_iflag >> 24; *iflag_lo24=t.c_iflag & 0xffffff;
|
|
|
|
*oflag_hi8 =t.c_oflag >> 24; *oflag_lo24=t.c_oflag & 0xffffff;
|
|
|
|
*cflag_hi8 =t.c_cflag >> 24; *cflag_lo24=t.c_cflag & 0xffffff;
|
|
|
|
*lflag_hi8 =t.c_lflag >> 24; *lflag_lo24=t.c_lflag & 0xffffff;
|
|
|
|
*ispeed=cfgetispeed(&t);
|
|
|
|
*ospeed=cfgetospeed(&t);
|
|
|
|
}
|
|
|
|
|
1995-10-13 23:34:21 -04:00
|
|
|
return result;
|
1995-10-16 18:19:16 -04:00
|
|
|
}
|
|
|
|
|
1995-10-13 23:34:21 -04:00
|
|
|
|
1995-10-16 18:19:16 -04:00
|
|
|
int scheme_tcsetattr(int fd, int option,
|
1995-10-22 08:34:53 -04:00
|
|
|
const char *control_chars,
|
1995-10-13 23:34:21 -04:00
|
|
|
int iflag_hi8, int iflag_lo24,
|
|
|
|
int oflag_hi8, int oflag_lo24,
|
|
|
|
int cflag_hi8, int cflag_lo24,
|
|
|
|
int lflag_hi8, int lflag_lo24,
|
1995-10-16 18:19:16 -04:00
|
|
|
int ispeed, int ospeed,
|
|
|
|
int min, int time)
|
1995-10-13 23:34:21 -04:00
|
|
|
{
|
|
|
|
struct termios t;
|
|
|
|
|
1995-10-16 18:19:16 -04:00
|
|
|
memcpy(t.c_cc, control_chars, NCCS);
|
1995-10-19 04:22:56 -04:00
|
|
|
|
|
|
|
/* This first clause of this conditional test will hopefully
|
|
|
|
** resolve the branch at compile time. However, since VMIN/VEOF
|
|
|
|
** and VTIME/VEOL are allowed by POSIX to colllide, we have to check.
|
|
|
|
** If they do collide, we set EOF & EOL in canonical mode, and MIN & TIME
|
|
|
|
** in raw mode. Ah, Unix.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( (VMIN != VEOF && VTIME != VEOL) || !(t.c_lflag & ICANON) ) {
|
|
|
|
t.c_cc[VMIN] = min;
|
|
|
|
t.c_cc[VTIME] = time;
|
|
|
|
}
|
|
|
|
|
1995-10-13 23:34:21 -04:00
|
|
|
t.c_iflag = (iflag_hi8 << 24) | iflag_lo24;
|
|
|
|
t.c_oflag = (oflag_hi8 << 24) | oflag_lo24;
|
|
|
|
t.c_cflag = (cflag_hi8 << 24) | cflag_lo24;
|
|
|
|
t.c_lflag = (lflag_hi8 << 24) | lflag_lo24;
|
1995-10-19 04:22:56 -04:00
|
|
|
|
1995-10-13 23:34:21 -04:00
|
|
|
cfsetispeed(&t, ispeed);
|
|
|
|
cfsetospeed(&t, ospeed);
|
|
|
|
|
1995-10-16 18:19:16 -04:00
|
|
|
return tcsetattr(fd, option, &t);
|
1995-10-13 23:34:21 -04:00
|
|
|
}
|