scsh-0.5/scsh/tc1.c

56 lines
1.5 KiB
C

/*
* Scheme48/scsh terminal control interface.
* Routines that require custom C support.
* Copyright (c) 1995 by Brian D. Carlstrom
*/
#include "cstuff.h"
#include <termios.h>
#include <memory.h>
int scheme_tcgetattr(int fd,
char control_chars[NCCS],
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;
int result=tcgetattr(fd,&t);
if (result == -1)
return result;
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);
return result;
}
int scheme_tcsetattr(int fd,
int option,
int iflag_hi8, int iflag_lo24,
int oflag_hi8, int oflag_lo24,
int cflag_hi8, int cflag_lo24,
int lflag_hi8, int lflag_lo24,
char *control_chars,
int ispeed, int ospeed)
{
struct termios t;
memcpy(t.c_cc,control_chars,NCCS);
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;
cfsetispeed(&t, ispeed);
cfsetospeed(&t, ospeed);
return(tcsetattr(fd,option,&t));
}