📄 terminal.texi
字号:
When a member contains a collection of independent flags, as the@code{c_iflag}, @code{c_oflag} and @code{c_cflag} members do, evensetting the entire member is a bad idea, because particular operatingsystems have their own flags. Instead, you should start with thecurrent value of the member and alter only the flags whose values matterin your program, leaving any other flags unchanged.Here is an example of how to set one flag (@code{ISTRIP}) in the@code{struct termios} structure while properly preserving all the otherdata in the structure:@smallexample@groupintset_istrip (int desc, int value)@{ struct termios settings; int result;@end group@group result = tcgetattr (desc, &settings); if (result < 0) @{ perror ("error in tcgetattr"); return 0; @}@end group@group settings.c_iflag &= ~ISTRIP; if (value) settings.c_iflag |= ISTRIP;@end group@group result = tcsetattr (desc, TCSANOW, &settings); if (result < 0) @{ perror ("error in tcgetattr"); return; @} return 1;@}@end group@end smallexample@node Input Modes@subsection Input ModesThis section describes the terminal attribute flags that controlfairly low-level aspects of input processing: handling of parity errors,break signals, flow control, and @key{RET} and @key{LFD} characters.All of these flags are bits in the @code{c_iflag} member of the@code{struct termios} structure. The member is an integer, and youchange flags using the operators @code{&}, @code{|} and @code{^}. Don'ttry to specify the entire value for @code{c_iflag}---instead, changeonly specific flags and leave the rest untouched (@pxref{SettingModes}).@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t INPCK@cindex parity checkingIf this bit is set, input parity checking is enabled. If it is not set,no checking at all is done for parity errors on input; thecharacters are simply passed through to the application.Parity checking on input processing is independent of whether paritydetection and generation on the underlying terminal hardware is enabled;see @ref{Control Modes}. For example, you could clear the @code{INPCK}input mode flag and set the @code{PARENB} control mode flag to ignoreparity errors on input, but still generate parity on output.If this bit is set, what happens when a parity error is detected dependson whether the @code{IGNPAR} or @code{PARMRK} bits are set. If neitherof these bits are set, a byte with a parity error is passed to theapplication as a @code{'\0'} character.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t IGNPARIf this bit is set, any byte with a framing or parity error is ignored.This is only useful if @code{INPCK} is also set.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t PARMRKIf this bit is set, input bytes with parity or framing errors are markedwhen passed to the program. This bit is meaningful only when@code{INPCK} is set and @code{IGNPAR} is not set.The way erroneous bytes are marked is with two preceding bytes,@code{377} and @code{0}. Thus, the program actually reads three bytesfor one erroneous byte received from the terminal.If a valid byte has the value @code{0377}, and @code{ISTRIP} (see below)is not set, the program might confuse it with the prefix that marks aparity error. So a valid byte @code{0377} is passed to the program astwo bytes, @code{0377} @code{0377}, in this case.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t ISTRIPIf this bit is set, valid input bytes are stripped to seven bits;otherwise, all eight bits are available for programs to read.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t IGNBRKIf this bit is set, break conditions are ignored.@cindex break condition, detectingA @dfn{break condition} is defined in the context of asynchronousserial data transmission as a series of zero-value bits longer than asingle byte.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t BRKINTIf this bit is set and @code{IGNBRK} is not set, a break conditionclears the terminal input and output queues and raises a @code{SIGINT}signal for the foreground process group associated with the terminal.If neither @code{BRKINT} nor @code{IGNBRK} are set, a break condition ispassed to the application as a single @code{'\0'} character if@code{PARMRK} is not set, or otherwise as a three-character sequence @code{'\377'}, @code{'\0'}, @code{'\0'}.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t IGNCRIf this bit is set, carriage return characters (@code{'\r'}) arediscarded on input. Discarding carriage return may be useful onterminals that send both carriage return and linefeed when you type the@key{RET} key.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t ICRNLIf this bit is set and @code{IGNCR} is not set, carriage return characters(@code{'\r'}) received as input are passed to the application as newlinecharacters (@code{'\n'}).@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t INLCRIf this bit is set, newline characters (@code{'\n'}) received as inputare passed to the application as carriage return characters (@code{'\r'}).@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t IXOFFIf this bit is set, start/stop control on input is enabled. In otherwords, the computer sends STOP and START characters as necessary toprevent input from coming in faster than programs are reading it. Theidea is that the actual terminal hardware that is generating the inputdata responds to a STOP character by suspending transmission, and to aSTART character by resuming transmission. @xref{Start/Stop Characters}.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t IXONIf this bit is set, start/stop control on output is enabled. In otherwords, if the computer receives a STOP character, it suspends outputuntil a START character is received. In this case, the STOP and STARTcharacters are never passed to the application program. If this bit isnot set, then START and STOP can be read as ordinary characters.@xref{Start/Stop Characters}.@c !!! mention this interferes with using C-s and C-q for programs like emacs@end deftypevr@comment termios.h@comment BSD@deftypevr Macro tcflag_t IXANYIf this bit is set, any input character restarts output when output hasbeen suspended with the STOP character. Otherwise, only the STARTcharacter restarts output.This is a BSD extension; it exists only on BSD systems and the GNU system.@end deftypevr@comment termios.h@comment BSD@deftypevr Macro tcflag_t IMAXBELIf this bit is set, then filling up the terminal input buffer sends aBEL character (code @code{007}) to the terminal to ring the bell.This is a BSD extension.@end deftypevr@node Output Modes@subsection Output ModesThis section describes the terminal flags and fields that control howoutput characters are translated and padded for display. All of theseare contained in the @code{c_oflag} member of the @w{@code{struct termios}}structure.The @code{c_oflag} member itself is an integer, and you change the flagsand fields using the operators @code{&}, @code{|}, and @code{^}. Don'ttry to specify the entire value for @code{c_oflag}---instead, changeonly specific flags and leave the rest untouched (@pxref{SettingModes}).@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t OPOSTIf this bit is set, output data is processed in some unspecified way sothat it is displayed appropriately on the terminal device. Thistypically includes mapping newline characters (@code{'\n'}) ontocarriage return and linefeed pairs.If this bit isn't set, the characters are transmitted as-is.@end deftypevrThe following three bits are BSD features, and they exist only BSDsystems and the GNU system. They are effective only if @code{OPOST} isset.@comment termios.h@comment BSD@deftypevr Macro tcflag_t ONLCRIf this bit is set, convert the newline character on output into a pairof characters, carriage return followed by linefeed.@end deftypevr@comment termios.h@comment BSD@deftypevr Macro tcflag_t OXTABSIf this bit is set, convert tab characters on output into the appropriatenumber of spaces to emulate a tab stop every eight columns.@end deftypevr@comment termios.h@comment BSD@deftypevr Macro tcflag_t ONOEOTIf this bit is set, discard @kbd{C-d} characters (code @code{004}) onoutput. These characters cause many dial-up terminals to disconnect.@end deftypevr@node Control Modes@subsection Control ModesThis section describes the terminal flags and fields that controlparameters usually associated with asynchronous serial datatransmission. These flags may not make sense for other kinds ofterminal ports (such as a network connection pseudo-terminal). All ofthese are contained in the @code{c_cflag} member of the @code{structtermios} structure.The @code{c_cflag} member itself is an integer, and you change the flagsand fields using the operators @code{&}, @code{|}, and @code{^}. Don'ttry to specify the entire value for @code{c_cflag}---instead, changeonly specific flags and leave the rest untouched (@pxref{SettingModes}).@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t CLOCALIf this bit is set, it indicates that the terminal is connected``locally'' and that the modem status lines (such as carrier detect)should be ignored.@cindex modem status lines@cindex carrier detectOn many systems if this bit is not set and you call @code{open} withoutthe @code{O_NONBLOCK} flag set, @code{open} blocks until a modemconnection is established.If this bit is not set and a modem disconnect is detected, a@code{SIGHUP} signal is sent to the controlling process group for theterminal (if it has one). Normally, this causes the process to exit;see @ref{Signal Handling}. Reading from the terminal after a disconnectcauses an end-of-file condition, and writing causes an @code{EIO} errorto be returned. The terminal device must be closed and reopened toclear the condition.@cindex modem disconnect@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t HUPCLIf this bit is set, a modem disconnect is generated when all processesthat have the terminal device open have either closed the file or exited.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t CREADIf this bit is set, input can be read from the terminal. Otherwise,input is discarded when it arrives.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t CSTOPBIf this bit is set, two stop bits are used. Otherwise, only one stop bitis used.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t PARENBIf this bit is set, generation and detection of a parity bit are enabled.@xref{Input Modes}, for information on how input parity errors are handled.If this bit is not set, no parity bit is added to output characters, andinput characters are not checked for correct parity.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t PARODDThis bit is only useful if @code{PARENB} is set. If @code{PARODD} is set,odd parity is used, otherwise even parity is used.@end deftypevrThe control mode flags also includes a field for the number of bits percharacter. You can use the @code{CSIZE} macro as a mask to extract thevalue, like this: @code{settings.c_cflag & CSIZE}.@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t CSIZEThis is a mask for the number of bits per character.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t CS5This specifies five bits per byte.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t CS6This specifies six bits per byte.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t CS7This specifies seven bits per byte.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro tcflag_t CS8
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -