/* * POSIX library for Lua 5.1, 5.2 & 5.3. * (c) Gary V. Vaughan , 2013-2015 * (c) Reuben Thomas 2010-2013 * (c) Natanael Copa 2008-2010 * Clean up and bug fixes by Leo Razoumov 2006-10-11 * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 * Based on original by Claudio Terra for Lua 3.x. * With contributions by Roberto Ierusalimschy. * With documentation from Steve Donovan 2012 */ /*** Control Terminal I/O. Functions and constants for controlling terminal behaviour. @module posix.termio */ #include #include #include "_helpers.c" /*** Control characters. The field names below are not strings, but index constants each referring to a terminal control character. @table ccs @int VINTR interrupt control character @int VQUIT quit control character @int WERASE erase control character @int VKILL kill control character @int VEOF end-of-file control character @int VEOL end-of-line control charactor @int VEOL2 another end-of-line control charactor @int VMIN 1 @int VTIME 0 @int VSTART xon/xoff start control character @int VSTOP xon/xoff stop control character @int VSUSP suspend control character */ /*** Terminal attributes. The constants named below are all available in this submodule's namespace, as long as they are supported by the underlying system. @table termios @int cflag bitwise OR of zero or more of `B0`, `B50`, `B75`, `B110`, `B134`, `B150`, `B200`, `B300`, `B600`, `B1200`, `B1800`, `B2400`, `B4800`, `B9600`, `B19200`, `B38400`, `B57600`, `B115200`, `CSIZE`, `CS5`, `CS6`, `CS7`, `CS8`, `CSTOPB`, `CREAD`, `PARENB`, `PARODD`, `HUPCL`, `CLOCAL` and `CRTSCTS` @int iflag input flags; bitwise OR of zero or more of `IGNBRK`, `BRKINT`, `IGNPAR`, `PARMRK`, `INPCK`, `ISTRIP`, `INLCR`, `IGNCR`, `ICRNL`, `IXON`, `IXOFF`, `IXANY`, `IMAXBEL` and `IUTF8` @int lflags local flags; bitwise OR of zero or more of `ISIG`, `ICANON`, `ECHO`, `ECHOE`, `ECHOK', 'ECHONL`, `NOFLSH`, `IEXTEN` and `TOSTOP` @int oflag output flags; bitwise OR of zero or more of `OPOST`, `ONLCR`, `OXTABS`, `ONOEOT`, `OCRNL`, `ONOCR`, `ONLRET`, `OFILL`, `NLDLY`, `TABDLY`, `CRDLY`, `FFDLY`, `BSDLY`, `VTDLY` and `OFDEL` @tfield ccs cc array of terminal control characters */ /*** Wait for all written output to reach the terminal. @function tcdrain @int fd terminal descriptor to act on @treturn[1] int `0`, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see tcdrain(3) */ static int Ptcdrain(lua_State *L) { int fd = checkint(L, 1); checknargs(L, 1); return pushresult(L, tcdrain(fd), NULL); } /*** Suspend transmission or receipt of data. @function tcflow @int fd terminal descriptor to act on @int action one of `TCOOFF`, `TCOON`, `TCIOFF` or `TCION` @treturn[1] int `0`, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see tcflow(3) */ static int Ptcflow(lua_State *L) { int fd = checkint(L, 1); int action = checkint(L, 2); checknargs(L, 2); return pushresult(L, tcflow(fd, action), NULL); } /*** Discard any data already written but not yet sent to the terminal. @function tcflush @int fd terminal descriptor to act on @int action one of `TCIFLUSH`, `TCOFLUSH`, `TCIOFLUSH` @treturn[1] int `0`, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see tcflush(3) */ static int Ptcflush(lua_State *L) { int fd = checkint(L, 1); int qs = checkint(L, 2); checknargs(L, 2); return pushresult(L, tcflush(fd, qs), NULL); } /*** Get termios state. @function tcgetattr @int fd terminal descriptor @treturn[1] termios terminal attributes, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @return error message if failed @see tcgetattr(3) @usage local termios, errmsg = tcgetattr (fd) */ static int Ptcgetattr(lua_State *L) { int r, i; struct termios t; int fd = checkint(L, 1); checknargs(L, 1); r = tcgetattr(fd, &t); if (r == -1) return pusherror(L, NULL); lua_newtable(L); pushintegerfield("iflag", t.c_iflag); pushintegerfield("oflag", t.c_oflag); pushintegerfield("lflag", t.c_lflag); pushintegerfield("cflag", t.c_cflag); lua_newtable(L); for (i=0; i