⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 terminal.texi

📁 一个C源代码分析器
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
significance of the next character the user types.  Even if thecharacter would normally perform some editting function or generate asignal, it is read as a plain character.  This is the analogue of the@kbd{C-q} command in Emacs.  ``LNEXT'' stands for ``literal next.''The LNEXT character is usually @kbd{C-v}.@end deftypevr@comment termios.h@comment BSD@deftypevr Macro int VDISCARD@cindex DISCARD characterThis is the subscript for the DISCARD character in the special controlcharacter array.  @code{@var{termios}.c_cc[VDISCARD]} holds the characteritself.The DISCARD character is recognized only when @code{IEXTEN} is set, butin both canonical and noncanonical mode.  Its effect is to toggle thediscard-output flag.  When this flag is set, all program output isdiscarded.  Setting the flag also discards all output currently in theoutput buffer.  Typing any other character resets the flag.@end deftypevr@comment termios.h@comment BSD@deftypevr Macro int VSTATUS@cindex STATUS characterThis is the subscript for the STATUS character in the special controlcharacter array.  @code{@var{termios}.c_cc[VSTATUS]} holds the characteritself.The STATUS character's effect is to print out a status message about howthe current process is running.The STATUS character is recognized only in canonical mode, and only if@code{NOKERNINFO} is not set.@end deftypevr@node Noncanonical Input@subsection Noncanonical InputIn noncanonical input mode, the special editing characters such asERASE and KILL are ignored.  The system facilities for the user to editinput are disabled in noncanonical mode, so that all input characters(unless they are special for signal or flow-control purposes) are passedto the application program exactly as typed.  It is up to theapplication program to give the user ways to edit the input, ifappropriate.Noncanonical mode offers special parameters called MIN and TIME forcontrolling whether and how long to wait for input to be available.  Youcan even use them to avoid ever waiting---to return immediately withwhatever input is available, or with no input.The MIN and TIME are stored in elements of the @code{c_cc} array, whichis a member of the @w{@code{struct termios}} structure.  Each element ofthis array has a particular role, and each element has a symbolicconstant that stands for the index of that element.  @code{VMIN} and@code{VMAX} are the names for the indices in the array of the MIN andTIME slots.@comment termios.h@comment POSIX.1@deftypevr Macro int VMIN@cindex MIN termios slotThis is the subscript for the MIN slot in the @code{c_cc} array.  Thus,@code{@var{termios}.c_cc[VMIN]} is the value itself.The MIN slot is only meaningful in noncanonical input mode; itspecifies the minimum number of bytes that must be available in theinput queue in order for @code{read} to return.@end deftypevr@comment termios.h@comment POSIX.1@deftypevr Macro int VTIME@cindex TIME termios slotThis is the subscript for the TIME slot in the @code{c_cc} array.  Thus,@code{@var{termios}.c_cc[VTIME]} is the value itself.The TIME slot is only meaningful in noncanonical input mode; itspecifies how long to wait for input before returning, in units of 0.1seconds.@end deftypevrThe MIN and TIME values interact to determine the criterion for when@code{read} should return; their precise meanings depend on which ofthem are nonzero.  There are four possible cases:@itemize @bullet@itemBoth TIME and MIN are nonzero.In this case, TIME specifies how long to wait after each input characterto see if more input arrives.  After the first character received,@code{read} keeps waiting until either MIN bytes have arrived in all, orTIME elapses with no further input.@code{read} always blocks until the first character arrives, even ifTIME elapses first.  @code{read} can return more than MIN characters ifmore than MIN happen to be in the queue.@item Both MIN and TIME are zero.In this case, @code{read} always returns immediately with as manycharacters as are available in the queue, up to the number requested.If no input is immediately available, @code{read} returns a value ofzero.@itemMIN is zero but TIME has a nonzero value.In this case, @code{read} waits for time TIME for input to becomeavailable; the availability of a single byte is enough to satisfy theread request and cause @code{read} to return.  When it returns, itreturns as many characters as are available, up to the number requested.If no input is available before the timer expires, @code{read} returns avalue of zero.@itemTIME is zero but MIN has a nonzero value.In this case, @code{read} waits until at least MIN bytes are availablein the queue.  At that time, @code{read} returns as many characters asare available, up to the number requested.  @code{read} can return morethan MIN characters if more than MIN happen to be in the queue.@end itemizeWhat happens if MIN is 50 and you ask to read just 10 bytes?Normally, @code{read} waits until there are 50 bytes in the buffer (or,more generally, the wait condition described above is satisfied), andthen reads 10 of them, leaving the other 40 buffered in the operatingsystem for a subsequent call to @code{read}.@strong{Portability note:} On some systems, the MIN and TIME slots areactually the same as the EOF and EOL slots.  This causes no seriousproblem because the MIN and TIME slots are used only in noncanonicalinput and the EOF and EOL slots are used only in canonical input, but itisn't very clean.  The GNU library allocates separate slots for theseuses.@comment termios.h@comment BSD@deftypefun int cfmakeraw (struct termios *@var{termios-p})This function provides an easy way to set up @code{*@var{termios-p}} forwhat has traditionally been called ``raw mode'' in BSD.  This usesnoncanonical input, and turns off most processing to give an unmodifiedchannel to the terminal.It does exactly this:@smallexample  @var{termios-p}->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP                                |INLCR|IGNCR|ICRNL|IXON);  @var{termios-p}->c_oflag &= ~OPOST;  @var{termios-p}->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);  @var{termios-p}->c_cflag &= ~(CSIZE|PARENB);  @var{termios-p}->c_cflag |= CS8;@end smallexample@end deftypefun@node Line Control@section Line Control Functions@cindex terminal line control functionsThese functions perform miscellaneous control actions on terminaldevices.  As regards terminal access, they are treated like doingoutput: if any of these functions is used by a background process on itscontrolling terminal, normally all processes in the process group aresent a @code{SIGTTOU} signal.  The exception is if the calling processitself is ignoring or blocking @code{SIGTTOU} signals, in which case theoperation is performed and no signal is sent.  @xref{Job Control}.@cindex break condition, generating@comment termios.h@comment POSIX.1@deftypefun int tcsendbreak (int @var{filedes}, int @var{duration})This function generates a break condition by transmitting a stream ofzero bits on the terminal associated with the file descriptor@var{filedes}.  The duration of the break is controlled by the@var{duration} argument.  If zero, the duration is between 0.25 and 0.5seconds.  The meaning of a nonzero value depends on the operating system.This function does nothing if the terminal is not an asynchronous serialdata port.The return value is normally zero.  In the event of an error, a valueof @code{-1} is returned.  The following @code{errno} error conditionsare defined for this function:@table @code@item EBADFThe @var{filedes} is not a valid file descriptor.@item ENOTTYThe @var{filedes} is not associated with a terminal device.@end table@end deftypefun@cindex flushing terminal output queue@cindex terminal output queue, flushing@comment termios.h@comment POSIX.1@deftypefun int tcdrain (int @var{filedes})The @code{tcdrain} function waits until all queuedoutput to the terminal @var{filedes} has been transmitted.The return value is normally zero.  In the event of an error, a valueof @code{-1} is returned.  The following @code{errno} error conditionsare defined for this function:@table @code@item EBADFThe @var{filedes} is not a valid file descriptor.@item ENOTTYThe @var{filedes} is not associated with a terminal device.@item EINTRThe operation was interrupted by delivery of a signal.@xref{Interrupted Primitives}.@end table@end deftypefun@cindex clearing terminal input queue@cindex terminal input queue, clearing@comment termios.h@comment POSIX.1@deftypefun int tcflush (int @var{filedes}, int @var{queue})The @code{tcflush} function is used to clear the input and/or outputqueues associated with the terminal file @var{filedes}.  The @var{queue}argument specifies which queue(s) to clear, and can be one of thefollowing values:@c Extra blank lines here make it look better.@table @code@vindex TCIFLUSH@item TCIFLUSHClear any input data received, but not yet read.@vindex TCOFLUSH@item TCOFLUSHClear any output data written, but not yet transmitted.@vindex TCIOFLUSH@item TCIOFLUSHClear both queued input and output.@end tableThe return value is normally zero.  In the event of an error, a valueof @code{-1} is returned.  The following @code{errno} error conditionsare defined for this function:@table @code@item EBADFThe @var{filedes} is not a valid file descriptor.@item ENOTTYThe @var{filedes} is not associated with a terminal device.@item EINVALA bad value was supplied as the @var{queue} argument.@end tableIt is unfortunate that this function is named @code{tcflush}, becausethe term ``flush'' is normally used for quite another operation---waitinguntil all output is transmitted---and using it for discarding input oroutput would be confusing.  Unfortunately, the name @code{tcflush} comesfrom POSIX and we cannot change it.@end deftypefun@cindex flow control, terminal@cindex terminal flow control@comment termios.h@comment POSIX.1@deftypefun int tcflow (int @var{filedes}, int @var{action})The @code{tcflow} function is used to perform operations relating toXON/XOFF flow control on the terminal file specified by @var{filedes}.The @var{action} argument specifies what operation to perform, and canbe one of the following values:@table @code@vindex TCOOFF@item TCOOFFSuspend transmission of output.@vindex TCOON@item TCOONRestart transmission of output.@vindex TCIOFF@item TCIOFFTransmit a STOP character.@vindex TCION@item TCIONTransmit a START character.@end tableFor more information about the STOP and START characters, see @ref{SpecialCharacters}.The return value is normally zero.  In the event of an error, a valueof @code{-1} is returned.  The following @code{errno} error conditionsare defined for this function:@table @code@vindex EBADF@item EBADFThe @var{filedes} is not a valid file descriptor.@vindex ENOTTY@item ENOTTYThe @var{filedes} is not associated with a terminal device.@vindex EINVAL@item EINVALA bad value was supplied as the @var{action} argument.@end table@end deftypefun@node Noncanon Example@section Noncanonical Mode ExampleHere is an example program that shows how you can set up a terminaldevice to read single characters in noncanonical input mode, withoutecho.@smallexample@include termios.c.texi@end smallexampleThis program is careful to restore the original terminal modes beforeexiting or terminating with a signal.  It uses the @code{atexit}function (@pxref{Cleanups on Exit}) to make sure this is doneby @code{exit}.@ignore@c !!!! the example doesn't handle any signals!The signals handled in the example are the ones that typically occur dueto actions of the user.  It might be desirable to handle other signalssuch as SIGSEGV that can result from bugs in the program.@end ignoreThe shell is supposed to take care of resetting the terminal modes whena process is stopped or continued; see @ref{Job Control}.  But someexisting shells do not actually do this, so you may wish to establishhandlers for job control signals that reset terminal modes.  The aboveexample does so.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -