termios.4
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 4 代码 · 共 1,622 行 · 第 1/4 页
4
1,622 行
.B Control Modes.PPThe c_cflag field describes the hardware control of the terminal:.PP.TStab(@);lw(1i) lw(2i)._.sp 6p.HBMask Name@Description.R.sp 6p_.sp 6pCSIZE@Character size:CS5@5 bitsCS6@6 bitsCS7@7 bitsCS8@8 bitsCSTOPB@T{Send two stop bits, else one.T}CREAD@Enable receiver.PARENB@Parity enable.PARODD@T{Odd parity, else even.T}HUPCL@T{Hung up on last close.T}CLOCAL@T{Ignore modem status lines.T}TAUTOFLOW@T{Use hardware monitored flow control.T}.sp 6p_.TE.PPIn addition, the input and output baud rates are also stored in the c_cflag field. The following values are supported:.PP.TStab(@);ll._.sp 6p.HBName@Description.R.sp 6p_.sp 6pB0@Hang upB50@50 baudB75@75 baudB110@110 baudB134@134.5 baudB150@150 baudB300@300 baudB600@600 baudB1200@1200 baudB1800@1800 baudB2400@2400 baudB4800@4800 baudB9600@9600 baudB19200@19200 baudB38400@38400 baud.sp 6p_.TE.PPThe following interfaces are provided for getting and setting the valuesof the input and output baud rates in the .PN termios structure. The effects onthe terminal device do not become effective until the .PN tcsetattr() function is successfully called..EXspeed_t cfgetospeed (termios_p)struct termios *termios_p; int cfsetospeed (termios_p, speed)struct termios *termios_p;speed_t speed;speed_t cfgetispeed (termios_p)struct termios *termios_p;int cfsetispeed (termios_p, speed)struct termios *termios_p;speed_t speed;.EEThe type speed_t is defined in .PN <termio.h> ..PPThe .I termios_p argument is a pointer to a termios structure that allowsthe c_cflag field to be manipulated.The cfgetospeed() returns the output baud rate stored in cflag..PPAdditionally, thecfsetospeed() sets the output baud rate stored in the cflag to speed.The zero baud rate, B0, is used to terminate theconnection. If B0 is specified, the modem control line can no longer beasserted. Normally, this disconnects the line.Both cfsetispeed() and cfsetospeed() return a value of zero if successfuland \-1 to indicate error..PPThe cfgetispeed() returns the input baud rate stored in cflag..PPThe cfsetispeed() sets the input baud rate stored in cflag to speed. If theinput baud rate is set to zero, the input baud rate is specified by thevalue of the output baud rate. For any particular hardware, unsupported baudrates are ignored. This refers to changes and baud rates not supported bythe hardware, and to changes setting the input and output baud rates todifferent values if the hardware does not support this..PPThe CSIZE bits specify the character size in bits for both transmission andreception. This size does not include the parity bit, if any. If CSTOPBis set, two stop bits are used, otherwise one stop bit. For example, at 110 baud, two stop bits are normally used..PPIf CREAD is set, the receiver is enabled. Otherwise, no characters are received..PPIf PARENB is set, parity generation and detection is enabled and a parity bit isadded to each character. If parity is enabled, PARODD specifies odd parity, ifset. Otherwise, even parity is used..PPIf TAUTOFLOW is set, hardware monitored flow control is performed, if thehardware supports this functionality. In this mode, the hardware terminalmultiplexer suspends output upon receipt of a STOP character (ASCII DC3).The hardware resumes output after a START character (ASCII DC1) has beenreceived. The advantage of this mode is that it provides quick response toflow control characters which would be useful in preventing overflowof the terminal device's input buffer. TAUTOFLOW is a local extension to thetermios specification..PPIf HUPCL is set, the modem control lines for the port are lowered when thelast process with the port open closes the port or the process terminates.The modem connection is broken. If HUPCL is not set, the control linesare not altered..PPIf CLOCAL is set, a connection does not depend on the state of the modem statuslines.If CLOCAL is clear, the modem status lines are monitored.CLOCAL is typically used by direct connect terminal lines..PPUnder normal circumstances, a call to the open(2) function waits for themodem connection to complete. However, if the O_NONBLOCK flag is set,or, if CLOCAL has been set, the .MS open 2function returns immediately without waiting for the connection.For further information, see.MS open 2 .For those files on which the connection has not been established, or on which a modem disconnect hasoccurred, and for which CLOCAL is not set, both .MS read 2and .MS write 2return a zero character count. For .MS read 2 ,this is equivalent to an end-of-file condition..PPThe initial hardware control value after open(2) is CS8, CREAD, HUPCL, B300..PP.B Local Modes.PPThe c_lflag field of the argument structure is used to control various functions..PP.TStab(@);lw(1i) lw(3i)._.sp 6p.HBMask Name@Description.R.sp 6p_.sp 6pISIG@Enable signalsICANON@T{Canonical input (erase and kill processing).T}NOFLSH@T{Disable flush after interrupt, quit, or suspend.T}TOSTOP@T{Send SIGTTOU for background output.T}ECHO@Enable echo.ECHOE@T{Echo ERASE as an error-correcting backspace.T}ECHOK@Echo KILL.ECHONL@Echo \\n.IEXTEN@Enable extended (implementation defined) functions.TCTLECH@T{Echo input control chars as ^char, delete as ^?.T}TCRTKIL@T{BS-space-BS erase entire line on kill.T}TPRTERA@T{Hard-copy terminal erase mode using \char.T}.sp 6p_.TE.PPIf ISIG is set, each input character is checked against the special controlcharacters INTR, QUIT, and SUSP. If an input character matches one of these control characters, the function associatedwith that character is performed. If ISIG is not set, no checking is done.Thus, these special input functions are possible only if ISIG is set..PPIf ICANON is set, canonical processing is enabled. This enables the erase, word erase, reprint,and kill edit functions, and the assembly of input characters into linesdelimited by NL, EOF, and EOL, as described in Canonical Mode Input Processing..PPIf ICANON is not set, .MS read 2requests are satisfied directly from the inputqueue. A .MS read 2is not satisfied until at least MIN characters have beenreceived or the timeout value TIME expired between characters. The time valuerepresents tenths of seconds. See the Noncanonical Mode Input Processing section for more details..PPIf NOFLSH is set, the normal flush of the input and output queues associated with the INTR, QUIT, and SUSP characters is not done..PPIf TOSTOP is set, the signal SIGTTOU is sent to theprocess group of a process that tries to write to its controlling terminal, ifit is not in the foreground process group for that terminal. This signal,by default, stops the members of the process group. Otherwise, the output generated by that process is output to the current output stream. Processesthat are holding or ignoring SIGTTOU signals are accepted and allowed to produce output and the SIGTTOU signal is not sent..PPIf ECHO is set, input characters are echoed back to the terminal. If ECHO is not set, input characters are not echoed..PPThe echo functions (ECHOE, ECHOK, ECHONL, TCTLECH, TCRTKIL, and TPRTERA) areperformed if ICANON is set..PPIf ECHOE and ICANON are set, the ERASE character causes the terminal to erase the lastcharacter in the current line from the display, if possible..PPIf ECHOK and ICANON are set, the KILL character, either the terminal erases theline from the display or echoes the \\n character after the KILL character..PPIf ECHONL and ICANON are set, the \\n character is echoed even if ECHO is not set..PPIf IEXTEN is set, implementation defined functions are recognized from the input data. In this manner the DSUSP, RPRNT, FLUSH, WERASE, LNEXT, and QUOTEspecial characters in the c_cc array are only recognized if the IEXTENflag is set. .PPIf TCTLECH is set, all control characters are echoed as ^X, where X is thecharacter obtained by adding the octal value of the character A (100) tothe octal code for the control character. In this context, a control characteris defined to be a character whose octal value is less than 37.The following control charactersare excluded from TCTLECH operations: ASCII NL, ASCII TAB, as well as controlcharacters that are defined in the c_cc array but are not returned to user programs (such as START and STOP). TCTLECH is a local extension to the local modes..PPIf TCRTKIL is set, the response to a kill character is to erase thepresent input line through a sequence of backspace-space-backspace.TCRTKIL is a local extension to the local modes..PPIf TCRTERA is set, characters that are logically erased are printed outbackwards preceded by a backslash (\\) and followed by a slash (/). This mode is useful when a hard-copy terminal is in use.TCRTERA is a local extension to the local modes..PPThe initial local control value after open (2) is 0 (all bits clear)..PP.B Special Control Characters.PPThe special control characters values are defined by the array c_cc. Thesubscript name and description for each element in both canonical andnoncanonical modes are as follows..PP.TStab(@);ll._.sp 6p.HBSubscript@Description.R.sp 6p_.sp 6pVINTR (INTR)@Interrupt characterVQUIT (QUIT)@Quit characterVERASE (ERASE)@Erase characterVKILL (KILL)@Kill characterVEOF (EOF)@T{End-of-file characterT}VEOL (EOL)@T{End-of-line characterT}VMIN (MIN)@T{Value for noncanonical readsT}VTIME (TIME)@T{Value for noncanonical readsT}VSTART (START)@Start characterVSTOP (STOP)@Stop characterVSUSP (SUSP)@Suspend characterVDSUSP (DSUSP)@T{Delayed suspend characterT}VRPRNT (RPRNT)@Reprint characterVFLUSH (FLUSH)@Flush characterVWERASE (WERASE)@Word erase characterVLNEXT (LNEXT)@T{Literal next characterT}VQUOTE (QUOTE)@T{Erase and kill quoting characterT}.sp 6p_.TE.PPThe following subscripts are local extensions to the c_cc array:VDSUSP, VRPRNT, VFLUSH, VWERASE, VLNEXT, and VQUOTE.The constant NCCS defines the total number of elements in the c_cc array..PPSetting the value of a special character to POSIX_V_DISABLE causes thatfunction to be disabled; that is, no input data will be recognized as thedisabled special character. If ICANON is not set, the value of POSIX_V_DISABLEhas no special meaning for the VMIN and VTIME entries of the c_cc array..PP.B Line Discipline.PPThe c_line field of the termios data structure is used tospecify the line discipline. Support is provided for thebasic termios line discipline only. For this reason, thevalue of this field should be set to the value TERMIODISC (the default value) by convention. The value of c_lineis reset to TERMIODISC by the system, if attempts aremade to set c_line to other values. This field is a localextension. .PP.SH Control Functions.PP The functions that are used to control the general terminal function are described in this section. Unless otherwise noted for a specific command, these functions are restrictedfrom use by background processes. Attempts to perform these operations cause the process group to be sent a SIGTTOU signal. If the calling process isblocking or ignoring SIGTTOU signals, the process is allowed to perform theoperation and the SIGTTOU signal is not sent..PPIn all the functions, .I fildes is an open file descriptor.However, the functions affect the underlying terminal file, not just theopen instance associated with the file descriptor..PP.B Get and Set State.PPFunctions: .PN tcgetattr() ,.PN tcsetattr().PP.B Syntax.EX#include <termios.h>int tcgetattr (fildes, termios_p)int fildes;struct termios *termios_p;int tcsetattr (fildes, optional_actions, termios_p)int fildes;int optional_actions;struct termios *termios_p;.EE.B Description
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?