MODULE LinTermios ["libc.so.70.0"];

	(*
		A. V. Shiryaev, 2012.11, 2013.08

		OpenBSD 5.4
		32-bit
	*)

	CONST
		VEOF* = 0; (* ICANON *)
		VEOL* = 1; (* ICANON *)
		VERASE* = 3; (* ICANON *)
		VKILL* = 5; (* ICANON *)
		VINTR* = 8; (* ISIG *)
		VQUIT* = 9; (* ISIG *)
		VSUSP* = 10; (* ISIG *)
		VSTART* = 12; (* IXON, IXOFF *)
		VSTOP* = 13; (* IXON, IXOFF *)
		VMIN* = 16; (* !ICANON *)
		VTIME* = 17; (* !ICANON *)
		NCCS* = 20;
		IGNBRK* = 00000001H; (* {0} *) (* ignore BREAK condition *)
		BRKINT* = 00000002H; (* {1} *) (* map BREAK to SIGINT *)
		IGNPAR* = 00000004H; (* {2} *) (* ignore (discard) parity errors *)
		PARMRK* = 00000008H; (* {3} *) (* mark parity and framing errors *)
		INPCK* = 00000010H; (* {4} *) (* enable checking of parity errors *)
		ISTRIP* = 00000020H; (* {5} *) (* strip 8th bit off chars *)
		INLCR* = 00000040H; (* {6} *) (* map NL into CR *)
		IGNCR* = 00000080H; (* {7} *) (* ignore CR *)
		ICRNL* = 00000100H; (* {8} *) (* map CR to NL (ala CRMOD) *)
		IXON* = 00000200H; (* {9} *) (* enable output flow control *)
		IXOFF* = 00000400H; (* {10} *) (* enable input flow control *)
		OPOST* = 00000001H; (* {0} *) (* enable following output processing *)
		CSIZE* = 00000300H; (* {8,9} *) (* character size mask *)
		CS5* = 00000000H; (* {} *) (* 5 bits (pseudo) *)
		CS6* = 00000100H; (* {8} *) (* 6 bits *)
		CS7* = 00000200H; (* {9} *) (* 7 bits *)
		CS8* = 00000300H; (* {8,9} *) (* 8 bits *)
		CSTOPB* = 00000400H; (* {10} *) (* send 2 stop bits *)
		CREAD* = 00000800H; (* {11} *) (* enable receiver *)
		PARENB* = 00001000H; (* {12} *) (* parity enable *)
		PARODD* = 00002000H; (* {13} *) (* odd parity, else even *)
		HUPCL* = 00004000H; (* {14} *) (* hang up on last close *)
		CLOCAL* = 00008000H; (* {15} *) (* ignore modem status lines *)
		ECHOE* = 00000002H; (* {1} *) (* visually erase chars *)
		ECHOK* = 00000004H; (* {2} *) (* echo NL after line kill *)
		ECHO* = 00000008H; (* {3} *) (* enable echoing *)
		ECHONL* = 00000010H; (* {4} *) (* echo NL even if ECHO is off *)
		ISIG* = 00000080H; (* {7} *) (* enable signals INTR, QUIT, [D]SUSP *)
		ICANON* = 00000100H; (* {8} *) (* canonicalize input lines *)
		IEXTEN* = 00000400H; (* {10} *) (* enable DISCARD and LNEXT *)
		EXTPROC* = 00000800H; (* {11} *) (* external processing *)
		TOSTOP* = 00400000H; (* {22} *) (* stop background jobs from output *)
		NOFLSH* = 80000000H; (* {31} *) (* don't flush after interrupt *)
		TCSANOW* = 0; (* make change immediate *)
		TCSADRAIN* = 1; (* drain output, then change *)
		TCSAFLUSH* = 2; (* drain output, flush input *)
		B0* = 0;
		B50* = 50;
		B75* = 75;
		B110* = 110;
		B134* = 134;
		B150* = 150;
		B200* = 200;
		B300* = 300;
		B600* = 600;
		B1200* = 1200;
		B1800* = 1800;
		B2400* = 2400;
		B4800* = 4800;
		B9600* = 9600;
		B19200* = 19200;
		B38400* = 38400;
		VEOL2* = 2; (* ICANON *)
		VWERASE* = 4; (* ICANON *)
		VREPRINT* = 6; (* ICANON *)
		VDSUSP* = 11; (* ISIG *)
		VLNEXT* = 14; (* IEXTEN *)
		VDISCARD* = 15; (* IEXTEN *)
		VSTATUS* = 18; (* ICANON *)
		IXANY* = 00000800H; (* {11} *) (* any char will restart after stop *)
		IUCLC* = 00001000H; (* {12} *) (* translate upper to lower case *)
		IMAXBEL* = 00002000H; (* {13} *) (* ring bell on input queue full *)
		ONLCR* = 00000002H; (* {1} *) (* map NL to CR-NL (ala CRMOD) *)
		OXTABS* = 00000004H; (* {2} *) (* expand tabs to spaces *)
		ONOEOT* = 00000008H; (* {3} *) (* discard EOT's (^D) on output *)
		OCRNL* = 00000010H; (* {4} *) (* map CR to NL *)
		OLCUC* = 00000020H; (* {5} *) (* translate lower case to upper case *)
		ONOCR* = 00000040H; (* {6} *) (* No CR output at column 0 *)
		ONLRET* = 00000080H; (* {7} *) (* NL performs the CR function *)
		CIGNORE* = 00000001H; (* {0} *) (* ignore control flags *)
		CRTSCTS* = 00010000H; (* {16} *) (* RTS/CTS full-duplex flow control *)
		MDMBUF* = 00100000H; (* {20} *) (* DTR/DCD hardware flow control *)
		ECHOKE* = 00000001H; (* {0} *) (* visual erase for line kill *)
		ECHOPRT* = 00000020H; (* {5} *) (* visual erase mode for hardcopy *)
		ECHOCTL* = 00000040H; (* {6} *) (* echo control chars as ^(Char) *)
		ALTWERASE* = 00000200H; (* {9} *) (* use alternate WERASE algorithm *)
		FLUSHO* = 00800000H; (* {23} *) (* output being flushed (state) *)
		XCASE* = 01000000H; (* {24} *) (* canonical upper/lower case *)
		NOKERNINFO* = 02000000H; (* {25} *) (* no kernel output from VSTATUS *)
		PENDIN* = 20000000H; (* {29} *) (* XXX retype pending input (state) *)
		TCSASOFT* = 10H; (* {4} *) (* flag - don't alter h.w. state *)
		B7200* = 7200;
		B14400* = 14400;
		B28800* = 28800;
		B57600* = 57600;
		B76800* = 76800;
		B115200* = 115200;
		B230400* = 230400;
		EXTA* = 19200;
		EXTB* = 38400;
		TCIFLUSH* = 1;
		TCOFLUSH* = 2;
		TCIOFLUSH* = 3;
		TCOOFF* = 1;
		TCOON* = 2;
		TCIOFF* = 3;
		TCION* = 4;

	TYPE
		tcflag_t* = INTEGER; (* unsigned int *)
		cc_t* = SHORTCHAR; (* unsigned char *)
		speed_t* = INTEGER; (* unsigned int *)
		termios* = RECORD [untagged]
			c_iflag*: tcflag_t; (* input flags *)
			c_oflag*: tcflag_t; (* output flags *)
			c_cflag*: tcflag_t; (* control flags *)
			c_lflag*: tcflag_t; (* local flags *)
			c_cc*: ARRAY [untagged] NCCS OF cc_t; (* control chars *)
			c_ispeed*: INTEGER; (* input speed *)
			c_ospeed*: INTEGER; (* output speed *)
		END;

	(* POSIX.1 *)
		PROCEDURE [ccall] cfgetispeed* (VAR tp: termios): speed_t;
		PROCEDURE [ccall] cfsetispeed* (VAR tp: termios; ispeed: speed_t): INTEGER;
		PROCEDURE [ccall] cfgetospeed* (VAR tp: termios): speed_t;
		PROCEDURE [ccall] cfsetospeed* (VAR tp: termios; ospeed: speed_t): INTEGER;
		PROCEDURE [ccall] tcgetattr* (fd: INTEGER; VAR tp: termios): INTEGER;
		PROCEDURE [ccall] tcsetattr* (fd: INTEGER; action: INTEGER; VAR tp: termios): INTEGER;

		PROCEDURE [ccall] tcdrain* (fd: INTEGER): INTEGER;
		PROCEDURE [ccall] tcflow* (fd: INTEGER; action: INTEGER): INTEGER;
		PROCEDURE [ccall] tcflush* (fd: INTEGER; action: INTEGER): INTEGER;
		PROCEDURE [ccall] tcsendbreak* (fd: INTEGER; len: INTEGER): INTEGER;

	(* extensions *)
(*
		PROCEDURE [ccall] cfsetspeed* (VAR tp: termios; speed: speed_t): INTEGER;
		PROCEDURE [ccall] cfmakeraw* (VAR tp: termios);
*)

END LinTermios.
