mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
improve & fix libc termios bindings (#2372)
* improve & fix libc termios bindings
This commit is contained in:
@@ -64,116 +64,194 @@ extern fn CInt sigaction(CInt signum, Sigaction *action, Sigaction *oldaction);
|
||||
|
||||
module libc::termios @if(env::LIBC &&& env::POSIX);
|
||||
|
||||
typedef Cc = char;
|
||||
typedef Speed = CUInt;
|
||||
typedef Tcflags = CUInt;
|
||||
typedef Tcactions = CInt;
|
||||
bitstruct Tc_iflags : CUInt
|
||||
{
|
||||
bool ignbrk;
|
||||
bool brkint;
|
||||
bool ignpar;
|
||||
bool parmrk;
|
||||
bool inpck;
|
||||
bool istrip;
|
||||
bool inlcr;
|
||||
bool igncr;
|
||||
bool icrnl;
|
||||
bool iuclc;
|
||||
bool ixon;
|
||||
bool ixany;
|
||||
bool ixoff;
|
||||
bool imaxbel;
|
||||
bool iutf8;
|
||||
}
|
||||
|
||||
const Tcactions TCOOFF = 0;
|
||||
const Tcactions TCOON = 1;
|
||||
const Tcactions TCIOFF = 2;
|
||||
const Tcactions TCION = 3;
|
||||
const Tcactions TCIFLUSH = 0;
|
||||
const Tcactions TCOFLUSH = 1;
|
||||
const Tcactions TCIOFLUSH = 2;
|
||||
const Tcactions TCSANOW = 0;
|
||||
const Tcactions TCSADRAIN = 1;
|
||||
const Tcactions TCSAFLUSH = 2;
|
||||
const Speed B0 = 0000000;
|
||||
const Speed B50 = 0000001;
|
||||
const Speed B75 = 0000002;
|
||||
const Speed B110 = 0000003;
|
||||
const Speed B134 = 0000004;
|
||||
const Speed B150 = 0000005;
|
||||
const Speed B200 = 0000006;
|
||||
const Speed B300 = 0000007;
|
||||
const Speed B600 = 0000010;
|
||||
const Speed B1200 = 0000011;
|
||||
const Speed B1800 = 0000012;
|
||||
const Speed B2400 = 0000013;
|
||||
const Speed B4800 = 0000014;
|
||||
const Speed B9600 = 0000015;
|
||||
const Speed B19200 = 0000016;
|
||||
const Speed B38400 = 0000017;
|
||||
const Speed B57600 = 0010001;
|
||||
const Speed B115200 = 0010002;
|
||||
const Speed B230400 = 0010003;
|
||||
const Speed B460800 = 0010004;
|
||||
const Speed B500000 = 0010005;
|
||||
const Speed B576000 = 0010006;
|
||||
const Speed B921600 = 0010007;
|
||||
const Speed B1000000 = 0010010;
|
||||
const Speed B1152000 = 0010011;
|
||||
const Speed B1500000 = 0010012;
|
||||
const Speed B2000000 = 0010013;
|
||||
const Speed B2500000 = 0010014;
|
||||
const Speed B3000000 = 0010015;
|
||||
const Speed B3500000 = 0010016;
|
||||
const Speed B4000000 = 0010017;
|
||||
const Speed MAX_BAUD = B4000000;
|
||||
const Tcflags VINTR = 0;
|
||||
const Tcflags VQUIT = 1;
|
||||
const Tcflags VERASE = 2;
|
||||
const Tcflags VKILL = 3;
|
||||
const Tcflags VEOF = 4;
|
||||
const Tcflags VTIME = 5;
|
||||
const Tcflags VMIN = 6;
|
||||
const Tcflags VSWTC = 7;
|
||||
const Tcflags VSTART = 8;
|
||||
const Tcflags VSTOP = 9;
|
||||
const Tcflags VSUSP = 10;
|
||||
const Tcflags VEOL = 11;
|
||||
const Tcflags VREPRINT = 12;
|
||||
const Tcflags VDISCARD = 13;
|
||||
const Tcflags VWERASE = 14;
|
||||
const Tcflags VLNEXT = 15;
|
||||
const Tcflags VEOL2 = 16;
|
||||
const Tcflags ISIG = 0000001;
|
||||
const Tcflags ICANON = 0000002;
|
||||
const Tcflags ECHO = 0000010;
|
||||
const Tcflags ECHOE = 0000020;
|
||||
const Tcflags ECHOK = 0000040;
|
||||
const Tcflags ECHONL = 0000100;
|
||||
const Tcflags NOFLSH = 0000200;
|
||||
const Tcflags TOSTOP = 0000400;
|
||||
const Tcflags IEXTEN = 0100000;
|
||||
const Tcflags CSIZE = 0000060;
|
||||
const Tcflags CS5 = 0000000;
|
||||
const Tcflags CS6 = 0000020;
|
||||
const Tcflags CS7 = 0000040;
|
||||
const Tcflags CS8 = 0000060;
|
||||
const Tcflags CSTOPB = 0000100;
|
||||
const Tcflags CREAD = 0000200;
|
||||
const Tcflags PARENB = 0000400;
|
||||
const Tcflags PARODD = 0001000;
|
||||
const Tcflags HUPCL = 0002000;
|
||||
const Tcflags CLOCAL = 0004000;
|
||||
const Tcflags OPOST = 0000001;
|
||||
const Tcflags OLCUC = 0000002;
|
||||
const Tcflags ONLCR = 0000004;
|
||||
const Tcflags OCRNL = 0000010;
|
||||
const Tcflags ONOCR = 0000020;
|
||||
const Tcflags ONLRET = 0000040;
|
||||
const Tcflags OFILL = 0000100;
|
||||
const Tcflags OFDEL = 0000200;
|
||||
const Tcflags VTDLY = 0040000;
|
||||
const Tcflags VT0 = 0000000;
|
||||
const Tcflags VT1 = 0040000;
|
||||
const Tcflags IGNBRK = 0000001;
|
||||
const Tcflags BRKINT = 0000002;
|
||||
const Tcflags IGNPAR = 0000004;
|
||||
const Tcflags PARMRK = 0000010;
|
||||
const Tcflags INPCK = 0000020;
|
||||
const Tcflags ISTRIP = 0000040;
|
||||
const Tcflags INLCR = 0000100;
|
||||
const Tcflags IGNCR = 0000200;
|
||||
const Tcflags ICRNL = 0000400;
|
||||
const Tcflags IUCLC = 0001000;
|
||||
const Tcflags IXON = 0002000;
|
||||
const Tcflags IXANY = 0004000;
|
||||
const Tcflags IXOFF = 0010000;
|
||||
const Tcflags IMAXBEL = 0020000;
|
||||
const Tcflags IUTF8 = 0040000;
|
||||
bitstruct Tc_oflags : CUInt
|
||||
{
|
||||
bool opost : 0;
|
||||
bool olcuc : 1;
|
||||
bool onlcr : 2;
|
||||
bool ocrnl : 3;
|
||||
bool onocr : 4;
|
||||
bool onlret : 5;
|
||||
bool ofill : 6;
|
||||
bool ofdel : 7;
|
||||
T_nldly nldly : 8..8;
|
||||
T_crdly crdly : 9..10;
|
||||
T_tabdly tabdly : 11..12;
|
||||
T_bsdly bsdly : 13..13;
|
||||
T_vtdly vtdly : 14..14;
|
||||
T_ffdly ffdly : 15..15;
|
||||
}
|
||||
|
||||
bitstruct Tc_cflags : CUInt
|
||||
{
|
||||
T_csize csize : 4..5;
|
||||
bool cstopb : 6;
|
||||
bool cread : 7;
|
||||
bool parenb : 8;
|
||||
bool parodd : 9;
|
||||
bool hupcl : 10;
|
||||
bool clocal : 11;
|
||||
bool addrb : 29;
|
||||
}
|
||||
|
||||
bitstruct Tc_lflags : CUInt
|
||||
{
|
||||
bool isig : 0;
|
||||
bool icanon : 1;
|
||||
bool xcase : 2;
|
||||
bool echo : 3;
|
||||
bool echoe : 4;
|
||||
bool echok : 5;
|
||||
bool echonl : 6;
|
||||
bool noflsh : 7;
|
||||
bool tostop : 8;
|
||||
bool echoctl : 9;
|
||||
bool echoprt : 10;
|
||||
bool echoke : 11;
|
||||
bool flusho : 12;
|
||||
bool pendin : 14;
|
||||
bool iexten : 15;
|
||||
bool extproc : 16;
|
||||
}
|
||||
|
||||
enum T_nldly : const char
|
||||
{
|
||||
NL0 = 0b0,
|
||||
NL1 = 0b1,
|
||||
}
|
||||
|
||||
enum T_crdly : const char
|
||||
{
|
||||
CR0 = 0b00,
|
||||
CR1 = 0b01,
|
||||
CR2 = 0b10,
|
||||
CR3 = 0b11,
|
||||
}
|
||||
|
||||
enum T_tabdly : const char
|
||||
{
|
||||
TAB0 = 0b00,
|
||||
TAB1 = 0b01,
|
||||
TAB2 = 0b10,
|
||||
TAB3 = 0b11,
|
||||
XTABS = TAB3,
|
||||
}
|
||||
|
||||
enum T_bsdly : const char
|
||||
{
|
||||
BS0 = 0b0,
|
||||
BS1 = 0b1,
|
||||
}
|
||||
|
||||
enum T_ffdly : const char
|
||||
{
|
||||
FF0 = 0b0,
|
||||
FF1 = 0b1,
|
||||
}
|
||||
|
||||
enum T_vtdly : const char
|
||||
{
|
||||
VT0 = 0b0,
|
||||
VT1 = 0b1,
|
||||
}
|
||||
|
||||
enum T_csize : const char
|
||||
{
|
||||
CS5 = 0b00,
|
||||
CS6 = 0b01,
|
||||
CS7 = 0b10,
|
||||
CS8 = 0b11,
|
||||
}
|
||||
|
||||
enum Speed : const CUInt
|
||||
{
|
||||
B0 = 0o0000000,
|
||||
B50 = 0o0000001,
|
||||
B75 = 0o0000002,
|
||||
B110 = 0o0000003,
|
||||
B134 = 0o0000004,
|
||||
B150 = 0o0000005,
|
||||
B200 = 0o0000006,
|
||||
B300 = 0o0000007,
|
||||
B600 = 0o0000010,
|
||||
B1200 = 0o0000011,
|
||||
B1800 = 0o0000012,
|
||||
B2400 = 0o0000013,
|
||||
B4800 = 0o0000014,
|
||||
B9600 = 0o0000015,
|
||||
B19200 = 0o0000016,
|
||||
B38400 = 0o0000017,
|
||||
B57600 = 0o0010001,
|
||||
B115200 = 0o0010002,
|
||||
B230400 = 0o0010003,
|
||||
B460800 = 0o0010004,
|
||||
B500000 = 0o0010005,
|
||||
B576000 = 0o0010006,
|
||||
B921600 = 0o0010007,
|
||||
B1000000 = 0o0010010,
|
||||
B1152000 = 0o0010011,
|
||||
B1500000 = 0o0010012,
|
||||
B2000000 = 0o0010013,
|
||||
B2500000 = 0o0010014,
|
||||
B3000000 = 0o0010015,
|
||||
B3500000 = 0o0010016,
|
||||
B4000000 = 0o0010017,
|
||||
MAX_BAUD = B4000000,
|
||||
}
|
||||
|
||||
enum Cc : const char
|
||||
{
|
||||
VINTR = 0,
|
||||
VQUIT = 1,
|
||||
VERASE = 2,
|
||||
VKILL = 3,
|
||||
VEOF = 4,
|
||||
VTIME = 5,
|
||||
VMIN = 6,
|
||||
VSWTC = 7,
|
||||
VSTART = 8,
|
||||
VSTOP = 9,
|
||||
VSUSP = 10,
|
||||
VEOL = 11,
|
||||
VREPRINT = 12,
|
||||
VDISCARD = 13,
|
||||
VWERASE = 14,
|
||||
VLNEXT = 15,
|
||||
VEOL2 = 16,
|
||||
}
|
||||
|
||||
enum Tcactions : const CInt
|
||||
{
|
||||
TCOOFF = 0,
|
||||
TCOON = 1,
|
||||
TCIOFF = 2,
|
||||
TCION = 3,
|
||||
TCIFLUSH = 0,
|
||||
TCOFLUSH = 1,
|
||||
TCIOFLUSH = 2,
|
||||
TCSANOW = 0,
|
||||
TCSADRAIN = 1,
|
||||
TCSAFLUSH = 2,
|
||||
}
|
||||
|
||||
extern fn CInt tcgetattr(Fd fd, Termios* self);
|
||||
extern fn CInt tcsetattr(Fd fd, Tcactions optional_actions, Termios* self);
|
||||
@@ -189,13 +267,119 @@ extern fn CInt cfsetispeed(Termios* self, Speed speed);
|
||||
const CInt NCCS = 32;
|
||||
struct Termios
|
||||
{
|
||||
Tcflags c_iflag;
|
||||
Tcflags c_oflag;
|
||||
Tcflags c_cflag;
|
||||
Tcflags c_lflag;
|
||||
Tc_iflags c_iflag;
|
||||
Tc_oflags c_oflag;
|
||||
Tc_cflags c_cflag;
|
||||
Tc_lflags c_lflag;
|
||||
Cc c_line;
|
||||
Cc[NCCS] c_cc;
|
||||
Speed c_ispeed;
|
||||
Speed c_ospeed;
|
||||
}
|
||||
}
|
||||
|
||||
const Tcactions TCOOFF @deprecated = 0;
|
||||
const Tcactions TCOON @deprecated = 1;
|
||||
const Tcactions TCIOFF @deprecated = 2;
|
||||
const Tcactions TCION @deprecated = 3;
|
||||
const Tcactions TCIFLUSH @deprecated = 0;
|
||||
const Tcactions TCOFLUSH @deprecated = 1;
|
||||
const Tcactions TCIOFLUSH @deprecated = 2;
|
||||
const Tcactions TCSANOW @deprecated = 0;
|
||||
const Tcactions TCSADRAIN @deprecated = 1;
|
||||
const Tcactions TCSAFLUSH @deprecated = 2;
|
||||
const Speed B0 @deprecated = 0o0000000;
|
||||
const Speed B50 @deprecated = 0o0000001;
|
||||
const Speed B75 @deprecated = 0o0000002;
|
||||
const Speed B110 @deprecated = 0o0000003;
|
||||
const Speed B134 @deprecated = 0o0000004;
|
||||
const Speed B150 @deprecated = 0o0000005;
|
||||
const Speed B200 @deprecated = 0o0000006;
|
||||
const Speed B300 @deprecated = 0o0000007;
|
||||
const Speed B600 @deprecated = 0o0000010;
|
||||
const Speed B1200 @deprecated = 0o0000011;
|
||||
const Speed B1800 @deprecated = 0o0000012;
|
||||
const Speed B2400 @deprecated = 0o0000013;
|
||||
const Speed B4800 @deprecated = 0o0000014;
|
||||
const Speed B9600 @deprecated = 0o0000015;
|
||||
const Speed B19200 @deprecated = 0o0000016;
|
||||
const Speed B38400 @deprecated = 0o0000017;
|
||||
const Speed B57600 @deprecated = 0o0010001;
|
||||
const Speed B115200 @deprecated = 0o0010002;
|
||||
const Speed B230400 @deprecated = 0o0010003;
|
||||
const Speed B460800 @deprecated = 0o0010004;
|
||||
const Speed B500000 @deprecated = 0o0010005;
|
||||
const Speed B576000 @deprecated = 0o0010006;
|
||||
const Speed B921600 @deprecated = 0o0010007;
|
||||
const Speed B1000000 @deprecated = 0o0010010;
|
||||
const Speed B1152000 @deprecated = 0o0010011;
|
||||
const Speed B1500000 @deprecated = 0o0010012;
|
||||
const Speed B2000000 @deprecated = 0o0010013;
|
||||
const Speed B2500000 @deprecated = 0o0010014;
|
||||
const Speed B3000000 @deprecated = 0o0010015;
|
||||
const Speed B3500000 @deprecated = 0o0010016;
|
||||
const Speed B4000000 @deprecated = 0o0010017;
|
||||
const Speed MAX_BAUD @deprecated = B4000000;
|
||||
const Cc VINTR @deprecated = 0;
|
||||
const Cc VQUIT @deprecated = 1;
|
||||
const Cc VERASE @deprecated = 2;
|
||||
const Cc VKILL @deprecated = 3;
|
||||
const Cc VEOF @deprecated = 4;
|
||||
const Cc VTIME @deprecated = 5;
|
||||
const Cc VMIN @deprecated = 6;
|
||||
const Cc VSWTC @deprecated = 7;
|
||||
const Cc VSTART @deprecated = 8;
|
||||
const Cc VSTOP @deprecated = 9;
|
||||
const Cc VSUSP @deprecated = 10;
|
||||
const Cc VEOL @deprecated = 11;
|
||||
const Cc VREPRINT @deprecated = 12;
|
||||
const Cc VDISCARD @deprecated = 13;
|
||||
const Cc VWERASE @deprecated = 14;
|
||||
const Cc VLNEXT @deprecated = 15;
|
||||
const Cc VEOL2 @deprecated = 16;
|
||||
const Tc_lflags ISIG @deprecated = {.isig};
|
||||
const Tc_lflags ICANON @deprecated = {.icanon};
|
||||
const Tc_lflags ECHO @deprecated = {.echo};
|
||||
const Tc_lflags ECHOE @deprecated = {.echoe};
|
||||
const Tc_lflags ECHOK @deprecated = {.echok};
|
||||
const Tc_lflags ECHONL @deprecated = {.echonl};
|
||||
const Tc_lflags NOFLSH @deprecated = {.noflsh};
|
||||
const Tc_lflags TOSTOP @deprecated = {.tostop};
|
||||
const Tc_lflags IEXTEN @deprecated = {.iexten};
|
||||
const Tc_cflags CSIZE @deprecated = {.csize = CS8};
|
||||
const Tc_cflags CS5 @deprecated = {.csize = CS5};
|
||||
const Tc_cflags CS6 @deprecated = {.csize = CS6};
|
||||
const Tc_cflags CS7 @deprecated = {.csize = CS7};
|
||||
const Tc_cflags CS8 @deprecated = {.csize = CS8};
|
||||
const Tc_cflags CSTOPB @deprecated = {.cstopb};
|
||||
const Tc_cflags CREAD @deprecated = {.cread};
|
||||
const Tc_cflags PARENB @deprecated = {.parenb};
|
||||
const Tc_cflags PARODD @deprecated = {.parodd};
|
||||
const Tc_cflags HUPCL @deprecated = {.hupcl};
|
||||
const Tc_cflags CLOCAL @deprecated = {.clocal};
|
||||
const Tc_oflags OPOST @deprecated = {.opost};
|
||||
const Tc_oflags OLCUC @deprecated = {.olcuc};
|
||||
const Tc_oflags ONLCR @deprecated = {.onlcr};
|
||||
const Tc_oflags OCRNL @deprecated = {.ocrnl};
|
||||
const Tc_oflags ONOCR @deprecated = {.onocr};
|
||||
const Tc_oflags ONLRET @deprecated = {.onlret};
|
||||
const Tc_oflags OFILL @deprecated = {.ofill};
|
||||
const Tc_oflags OFDEL @deprecated = {.ofdel};
|
||||
const Tc_oflags VTDLY @deprecated = {.vtdly = VT1};
|
||||
const Tc_oflags VT0 @deprecated = {.vtdly = VT0};
|
||||
const Tc_oflags VT1 @deprecated = {.vtdly = VT1};
|
||||
const Tc_iflags IGNBRK @deprecated = {.ignbrk};
|
||||
const Tc_iflags BRKINT @deprecated = {.brkint};
|
||||
const Tc_iflags IGNPAR @deprecated = {.ignpar};
|
||||
const Tc_iflags PARMRK @deprecated = {.parmrk};
|
||||
const Tc_iflags INPCK @deprecated = {.inpck};
|
||||
const Tc_iflags ISTRIP @deprecated = {.istrip};
|
||||
const Tc_iflags INLCR @deprecated = {.inlcr};
|
||||
const Tc_iflags IGNCR @deprecated = {.igncr};
|
||||
const Tc_iflags ICRNL @deprecated = {.icrnl};
|
||||
const Tc_iflags IUCLC @deprecated = {.iuclc};
|
||||
const Tc_iflags IXON @deprecated = {.ixon};
|
||||
const Tc_iflags IXANY @deprecated = {.ixany};
|
||||
const Tc_iflags IXOFF @deprecated = {.ixoff};
|
||||
const Tc_iflags IMAXBEL @deprecated = {.imaxbel};
|
||||
const Tc_iflags IUTF8 @deprecated = {.iutf8};
|
||||
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
module libc::termios @if(env::LIBC &&& env::POSIX);
|
||||
|
||||
fn int sendBreak(Fd fd, int duration) => tcsendbreak(fd, duration);
|
||||
fn int send_break(Fd fd, int duration) => tcsendbreak(fd, duration);
|
||||
fn int drain(Fd fd) => tcdrain(fd);
|
||||
fn int flush(Fd fd, int queue_selector) => tcflush(fd, queue_selector);
|
||||
fn int flow(Fd fd, int action) => tcflow(fd, action);
|
||||
fn Speed Termios.getOSpeed(Termios* self) => cfgetospeed(self);
|
||||
fn Speed Termios.getISpeed(Termios* self) => cfgetispeed(self);
|
||||
fn int Termios.setOSpeed(Termios* self, Speed speed) => cfsetospeed(self, speed);
|
||||
fn int Termios.setISpeed(Termios* self, Speed speed) => cfsetispeed(self, speed);
|
||||
fn int Termios.getAttr(Termios* self, Fd fd) => tcgetattr(fd, self);
|
||||
fn int Termios.setAttr(Termios* self, Fd fd, Tcactions optional_actions) => tcsetattr(fd, optional_actions, self);
|
||||
fn Speed Termios.get_ospeed(&self) => cfgetospeed(self);
|
||||
fn Speed Termios.get_ispeed(&self) => cfgetispeed(self);
|
||||
fn int Termios.set_ospeed(&self, Speed speed) => cfsetospeed(self, speed);
|
||||
fn int Termios.set_ispeed(&self, Speed speed) => cfsetispeed(self, speed);
|
||||
fn int Termios.get_attr(&self, Fd fd) => tcgetattr(fd, self);
|
||||
fn int Termios.set_attr(&self, Fd fd, Tcactions optional_actions) => tcsetattr(fd, optional_actions, self);
|
||||
|
||||
fn int sendBreak(Fd fd, int duration) @deprecated => send_break(fd, duration);
|
||||
fn Speed Termios.getOSpeed(&self) @deprecated => self.get_ospeed();
|
||||
fn Speed Termios.getISpeed(&self) @deprecated => self.get_ispeed();
|
||||
fn int Termios.setOSpeed(&self, Speed speed) @deprecated => self.set_ospeed(speed);
|
||||
fn int Termios.setISpeed(&self, Speed speed) @deprecated => self.set_ispeed(speed);
|
||||
fn int Termios.getAttr(&self, Fd fd) @deprecated => self.get_attr(fd);
|
||||
fn int Termios.setAttr(&self, Fd fd, Tcactions optional_actions) @deprecated => self.set_attr(fd, optional_actions);
|
||||
|
||||
module libc::termios @if(!env::LIBC ||| !env::POSIX);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user