[comp.sources.games.bugs] Yet another GB3 question.

murphy@holstein.rtp.dg.com (John Murphy) (06/06/90)

You guys with compilation errors are lucky.  I keep having the following
trouble
in making the program.  1. FNDELAY not declared, 2. CBREAK, ECHO not declared.
I assume these are legal unix, but I'm not compatable.  any suggestions on code
to replace these "functions" with, or what they are in the first place??

-murphy.

dilvish@anasaz.UUCP (Dilvish the Damned) (06/07/90)

In article <1990Jun5.193736.20718@dg-rtp.dg.com> murphy@holstein.rtp.dg.com (John Murphy) writes:
>You guys with compilation errors are lucky.  I keep having the following
>trouble
>in making the program.  1. FNDELAY not declared, 2. CBREAK, ECHO not declared.
>I assume these are legal unix, but I'm not compatable.  any suggestions on code
>to replace these "functions" with, or what they are in the first place??
>
>-murphy.

You need to add the curses library.  CBREAK() and ECHO() are curses routines
just add -lcurses to your compilation line.  I don't know what FNDELAY is
but it may be curses also.


Dilvish the Damned

meissner@osf.org (Michael Meissner) (06/08/90)

In article <2389@anasaz.UUCP> dilvish@anasaz.UUCP (Dilvish the Damned)
writes:

| In article <1990Jun5.193736.20718@dg-rtp.dg.com> murphy@holstein.rtp.dg.com (John Murphy) writes:
| >You guys with compilation errors are lucky.  I keep having the following
| >trouble
| >in making the program.  1. FNDELAY not declared, 2. CBREAK, ECHO not declared.
| >I assume these are legal unix, but I'm not compatable.  any suggestions on code
| >to replace these "functions" with, or what they are in the first place??
| >
| >-murphy.
| 
| You need to add the curses library.  CBREAK() and ECHO() are curses routines
| just add -lcurses to your compilation line.  I don't know what FNDELAY is
| but it may be curses also.

Not quite.  FNDELAY, CBREAK, and ECHO not being defined are simptoms
of code based on BSD systems being compiled on System V.x (where x is
less than 4, presumably).  FNDELAY is usually the same as O_NDELAY.
For CBREAK, and ECHO, you will have to delve into the differences
between the System V and BSD terminal drivers and ioctl's.  POSIX
added a completely new set of routines, which are mostly based on the
System V ioctl's.  Ain't standards fun?

Anyway, CBREAK is generall equivalent to !ICANON in the System V
world, and ECHO is pretty much the same (though the include files
differ).  Perhaps the code already has support for System V (look for
#ifdef USG or some such).

For the gory details, keep on reading.


Here is the relavant man pages from an Ultrix DS2100 system about the
BSD side of the terminal world (the System V side will follow on the
next page; The POSIX man pages didn't format correctly; I have
obviously not checked these for accuracy, would DEC lie?):


     NAME
          tty - general terminal interface

     DESCRIPTION
          Terminal subsystem

          The terminal subsystem is the part of the operating system
          which allows users to read and write characters over
          asynchronous terminal lines.  An important aspect of this
          subsystem is to provide a means for the user to set and
          receive terminal attributes.  Terminal attributes involve
          such things as line speed (baud rate), character length,
          parity, flow control, modem control, as well as numerous
          character processing capabilities.

          The ULTRIX terminal interface allows the user to specify
          terminal attributes in a number of different ways.  Several
          different terminal interfaces exist to provide standard
          compliant terminal control.

          Terminal interface definitions

          The special file describes the standard Berkeley terminal
          interface. This interface is backward compatible with
          earlier versions of the ULTRIX operating system.

          The special file describes the terminal interface as defined
          by the System V Interface Definition.

          The special file describes the termios termio interface as
          defined by the IEEE P1003 POSIX specification.

          Functionally the three terminal interfaces are quite
          similar.  Major differences lie in how terminal attributes
          are specified, this includes the use of different data
          structures to represent terminal attributes as well as the
          means of setting and receiving attributes.

          It is possible to use combinations of the three terminal
          interface definitions.  Under these circumstances the
          attributes of one interface is mapped into the corresponding
          attributes of the other interfaces.  Combining aspects of
          different interfaces is discouraged because it prevents the
          development of portable programs.  For example, a program
          intended for use with the System V termio terminal interface
          will fail to be a standard compliant program if it sets
          terminal attributes which are specific to either of the
          other two terminal interfaces.

          Combinations of the different terminal interfaces should be
          used with extreme caution to avoid unwanted side-effects.
          For example, a program may have initially set up its
          terminal environment using the System V termio interface
          Suppose that the initial line settings are 7 bits even
          parity with input and output processing performed.  If this
          same program were to set the line to RAW mode as specified
          in the line would be set to 8 bits no parity with no input
          or output processing.  These settings would be reflected in
          the parameters as specified in This simple example is meant
          to illustrate the subtle side effects that can result from
          the use of combinations of terminal interfaces.

          Using combinations of terminal interfaces could also cause
          problems if attributes that are not common to all interfaces
          are used.  For example, the Berkeley terminal interface
          allows the user to set the value of the start and stop
          characters.  The System V termio interface defines that the
          start and stop characters shall be Control-Q and Control-S.
          As a result if a terminal changes the start and stop
          characters using the Berkeley terminal interface, those
          characters are reset if the terminal parameters are set
          using the System V termio interface.

          Terminal Interface Usage

          The three interfaces have been developed to provide standard
          compliant terminal behavior.  The interface type should be
          specified at the time of program compilation.  As described
          in , to compile a System V compliant program the -Y option
          (or setting PROG_ENV equal to SYSTEM_FIVE) should be used.
          Similarly the -YPOSIX option should be used to compile a
          POSIX compliant program.  Without the -Y or -YPOSIX compile
          option, the program intends to use the Berkeley terminal
          interface.  Refer to for specific details on compatibility
          modes.

     BERKELEY TERMINAL INTERFACE
          Line disciplines.

          The system provides different line disciplines for
          controlling communications lines.  In this version of the
          system, there are several disciplines available:

          old     The old (Version 7) terminal driver.  This is
                  sometimes used when using the standard shell and for
                  compatibility with other standard version 7 UNIX
                  systems.

          new     The standard terminal driver, with features for job
                  control. This must be used when using

          net     A line discipline used for networking and loading
                  data into the system over communications lines.  It
                  allows high speed input at low overhead and is
                  described in

          termio  This line discipline is intended for use by System V
                  programs which use the termio interface as described
                  in The termio line discipline is also used by
                  programs which require a POSIX IEEE P1003 termios
                  interface as described in

          Line discipline switching is accomplished with the TIOCSETD

               int ldisc = LDISC; ioctl(filedes, TIOCSETD, &ldisc);

          LDISC is OTTYDISC for the standard tty driver, NTTYDISC for
          the new driver, NETLDISC for the networking discipline, and
          TERMIODISC for System V termio and POSIX termios.  The
          standard tty driver is discipline 0 by convention.  Other
          disciplines may exist for special purposes.  The current
          line discipline can be obtained with the TIOCGETD ioctl.
          Pending input is discarded when the line discipline is
          changed.

          All of the low-speed asynchronous communications ports can
          use any of the available line disciplines, no matter what
          hardware is involved.  The remainder of this section
          discusses the old and new disciplines.

          The control terminal

          When a terminal file is opened, it causes the process to
          wait until a connection is established.  In practice, user
          programs seldom open these files; they are opened by or and
          become a user's standard input and output file.

          If a process that has no control terminal opens a terminal
          file, then that terminal file becomes the control terminal
          for that process.  The control terminal is thereafter
          inherited by a child process during a even if the control
          terminal is closed.

          The file is, in each process, a synonym for a control
          terminal associated with that process.  It is useful for
          programs that want to be sure of writing messages on the
          terminal, no matter how output has been redirected.  It can
          also be used for programs that demand a file name for
          output, when typed output is desired and it is tiresome to
          find out which terminal is currently in use.

          A process can remove the association it has with its
          controlling terminal by opening the file and issuing:

               ioctl(fildes, TIOCNOTTY, 0)

          This is often desirable in server processes.

          Process groups

          Command processors such as can arbitrate the terminal
          between different jobs by placing related jobs in a single
          process group and associating this process group with the
          terminal.  A terminal's associated process group may be set
          using the TIOCSPGRP

               ioctl(fildes, TIOCSPGRP, &pgrp)

          or examined using TIOCGPGRP rather than TIOCSPGRP, returning
          the current process group in pgrp. The new terminal driver
          aids in this arbitration by restricting access to the
          terminal by processes which are not in the current process
          group; see Job access control below.

          Modes

          The terminal drivers have three major modes, characterized
          by the amount of processing on the input and output
          characters:

          cooked    The normal mode.  In this mode, lines of input are
                    collected and input editing is done.  The edited
                    line is made available when it is completed by a
                    newline or when the t_brkc character (normally
                    undefined) or t_eofc character (normally an EOT,
                    CTRL/D) is entered.  A carriage return is usually
                    made synonymous with newline in this mode and
                    replaced with a newline whenever it is typed.  All
                    driver functions (input editing, interrupt
                    generation, output processing such as delay
                    generation and tab expansion, and so forth) are
                    available in this mode.

          CBREAK    This mode eliminates the character, word, and line
                    editing input facilities, making the input
                    character available to the user program as it is
                    typed.  Flow control, literal-next, and interrupt
                    processing are still done in this mode.  Output
                    processing is done.

          RAW       This mode eliminates all input processing and
                    makes all input characters available as they are
                    typed; no output processing is done either.

          The style of input processing can also be different when the
          terminal is put in nonblocking I/O mode. For further
          information, see the FNDELAY flag described in In this case,
          a from the control terminal will never block, but rather
          return an error indication (EWOULDBLOCK) if there is no
          input available.

          A process may also request a SIGIO signal be sent it
          whenever input is present and also whenever output queues
          fall below the low-water mark.  To enable this mode, the
          FASYNC flag should be set using

          Input editing

          An ULTRIX terminal ordinarily operates in full-duplex mode.
          Characters may be typed at any time, even while output is
          occurring, and are only lost when the system's character
          input buffers become completely choked, which is rare, or
          when the user has accumulated the maximum allowed number of
          input characters that have not yet been read by some
          program.  This limit is 256 characters.  In RAW mode, the
          terminal driver throws away all input and output without
          notice when the limit is reached.  In CBREAK mode or cooked
          mode, it refuses to accept any further input and, if in the
          new line discipline, rings the terminal bell.

          Input characters are normally accepted in either even or odd
          parity with the parity bit being stripped off before the
          character is given to the program.  By clearing either the
          EVEN or ODD bit in the flags word, it is possible to have
          input characters with that parity discarded (see the Summary
          below.)

          In all of the line disciplines, it is possible to simulate
          terminal input using the TIOCSTI ioctl, which takes, as its
          third argument, the address of a character.  The system
          pretends that this character was typed on the argument
          terminal, which must be the control terminal except for the
          superuser (this call is not in standard version 7 UNIX).

          Input characters are normally echoed by putting them in an
          output queue as they arrive.  This may be disabled by
          clearing the ECHO bit in the flags word using the call or
          the TIOCSETN or TIOCSETP ioctls (see the Summary below).

          In cooked mode, terminal input is processed in units of
          lines.  A program attempting to read is normally suspended
          until an entire line has been received (but see the
          description of SIGTTIN in Job access control below
           and FIONREAD in Summary of modes below.) No matter how many
          characters are requested in the read call, at most one line
          will be returned.  It is not, however, necessary to read a
          whole line at once; any number of characters may be
          requested in a read, even one, without losing information.

          During input, line editing is normally done, with the erase
          character sg_erase (by default, '#') logically erasing the
          last character typed and the sg_kill character (by default,
          `@') logically erasing the entire current input line.  These
          are often reset on CRTs, with CTRL/H replacing #, and CTRL/U
          replacing @.  These characters never erase beyond the
          beginning of the current input line or an EOF.  These
          characters may be entered literally by preceding them with
          `\'. In the old Teletype driver, both the `\' and the
          character entered literally appears on the screen; in the
          new driver, the `\' normally disappears.

          The drivers normally treat either a carriage return or a
          newline character as terminating an input line, replacing
          the return with a newline and echoing a return and a line
          feed.  If the CRMOD bit is cleared in the local mode word,
          then the processing for carriage return is disabled, and it
          is simply echoed as a return and does not terminate cooked
          mode input.

          In the new driver there is a literal-next character
          (normally CTRL/V), which can be typed in both cooked and
          CBREAK mode preceding any character to prevent its special
          meaning to the terminal handler. This is to be preferred to
          the use of `\' escaping erase and kill characters, but `\'
          is (at least temporarily) retained with its old function in
          the new driver for historical reasons.

          The new terminal driver also provides two other editing
          characters in normal mode.  The word-erase character,
          normally CTRL/W, erases the preceding word, but not any
          spaces before it.  For the purposes of CTRL/W, a word is
          defined as a sequence of nonblank characters, with tabs
          counted as blanks.  Finally, the reprint character, normally
          CTRL/R, retypes the pending input beginning on a new line.
          Retyping occurs automatically in cooked mode if characters
          that would normally be erased from the screen are fouled by
          program output.

          Input echoing and redisplay

          In the old terminal driver, nothing special occurs when an
          erase character is typed.  The erase character is simply
          echoed.  When a kill character is typed, it is echoed
          followed by a newline (even if the character is not killing
          the line, because it was preceded by a `\'!.)

          The new terminal driver has several modes for handling the
          echoing of terminal input, controlled by bits in a local
          mode word.

          Hardcopy terminals. When a hardcopy terminal is in use, the
          LPRTERA bit is normally set in the local mode word.
          Characters that are logically erased are then printed out
          backwards preceded by `\' and followed by `/' in this mode.

          CRT terminals When a CRT terminal is in use, the LCRTBS bit
          is normally set in the local mode word.  The terminal driver
          then echoes the proper number of erase characters when input
          is erased; in the normal case where the erase character is a
          CTRL/H, this causes the cursor of the terminal to back up to
          where it was before the logically erased character was
          typed.  If the input has become fouled due to interspersed
          asynchronous output, the input is automatically retyped.

          Erasing characters from a CRT When a CRT terminal is in use,
          the LCRTERA bit may be set to cause input to be erased from
          the screen with a backspace-space-backspace sequence when
          character or word deleting sequences are used.  LCRTERA must
          be used with LCRTBS for this functionality.  A LCRTKIL bit
          may be set as well, causing the input to be erased in this
          manner on line kill sequences as well.

          Echoing of control characters If the LCTLECH bit is set in
          the local state word, then nonprinting (control) characters
          are normally echoed as CTRL/X (for some X) rather than being
          echoed unmodified; delete is echoed as CTRL/?.

          The normal modes for using the new terminal driver on CRT
          terminals are speed dependent.  At speeds less than 1200
          baud, the LCRTERA and LCRTKILL processing is painfully slow,
          so normally just sets LCRTBS and LCTLECH; at speeds of 1200
          baud or greater, all of these bits are normally set.  The
          command summarizes these option settings and the use of the
          new terminal driver as newcrt.

          Output processing

          When one or more characters are written, they are actually
          transmitted to the terminal as soon as previously written
          characters have finished typing.  (As noted above, input
          characters are normally echoed by putting them in the output
          queue as they arrive.) When a process produces characters
          more rapidly than they can be typed, it is suspended when
          its output queue exceeds some limit.  When the queue has
          drained down to some threshold, the program is resumed.
          Even parity is normally generated on output.  The EOT
          character is not transmitted in cooked mode to prevent
          terminals that respond to it from hanging up; programs using
          RAW or CBREAK mode should be careful.

          The terminal drivers provide necessary processing for cooked
          and CBREAK mode output including delay generation for
          certain special characters and parity generation.   Delays
          are available after backspaces CTRL/H, form feeds CTRL/L,
          carriage returns CTRL/M, tabs CTRL/I and newlines CTRL/J.
          The driver also optionally expands tabs into spaces, where
          the tab stops are assumed to be set every eight columns.
          These functions are controlled by bits in the tty flags
          word.  (See Summary below.)

          The terminal drivers provide for mapping between uppercase
          and lowercase on terminals lacking lowercase, and for other
          special processing on deficient terminals.

          Finally, in the new terminal driver, there is an output
          flush character, normally CTRL/O, which sets the LFLUSHO bit
          in the local mode word, causing subsequent output to be
          flushed until it is cleared by a program or more input is
          typed.  This character has effect in both cooked and CBREAK
          modes and causes pending input to be retyped if there is any
          pending input.  An ioctl to flush the characters in the
          input and output queues, TIOCFLUSH, is also available.

          Uppercase terminals and Hazeltines

          If the LCASE bit is set in the tty flags, then all uppercase
          letters are mapped into the corresponding lowercase letter.
          The uppercase letter may be generated by preceding it by
          `\'.  If the new terminal driver is being used, then
          uppercase letters are preceded by a `\' when output.  In
          addition, the following escape sequences can be generated on
          output and accepted on input:

          for  `    |    ~    {    }
          use  \'   \!   \^   \(   \)

          To deal with Hazeltine terminals, which do not understand
          that ~ has been made into an ASCII character, the LTILDE bit
          may be set in the local mode word when using the new
          terminal driver; in this case, the character ~ will be
          replaced with the character ` on output.

          Flow control

          There are two characters (the stop character, normally
          CTRL/S, and the start character, normally CTRL/Q), which
          cause output to be suspended and resumed respectively.
          Extra stop characters typed when output is already stopped
          have no effect, unless the start and stop characters are
          made the same, in which case output resumes.

          A bit in the flags word may be set to put the terminal into
          TANDEM mode.  In this mode, the system produces a stop
          character (default CTRL/S) when the input queue is in danger
          of overflowing, and a start character (default CTRL/Q) when
          the input has drained sufficiently.  This mode is useful
          when the terminal is actually another machine that obeys the
          conventions.

          A bit in the local mode word may be set to put the terminal
          into AUTOFLOW mode.  In this mode, flow control characters
          are responded to at the hardware level.  Upon receipt of a
          stop character the hardware suspends output.  This allows
          for quick response to the stop character which prevents
          buffer overflow (in printers for example).  AUTOFLOW
          functionality is only provided if the start character is
          CTRL/Q and the stop character is CTRL/S.  The AUTOFLOW bit
          is cleared if the start or stop characters are not standard
          values, or if the terminal multiplexer does not support
          hardware monitored flow control.

          Use of eight bit characters

          There are three settings which allow for the use of eight
          bit characters.  These settings differ in the amount of
          input and output processing performed on the characters.
          Each of these three modes sets the line to eight bit
          characters with no parity.  Setting RAW mode in the sg_flags
          field allows eight bit characters in both input and output.
          RAW mode does no post processing on output, nor canonical
          input processing.  The LLITOUT option of the local mode word
          allows eight bit characters on output only.  LLTIOUT mode
          does no output processing.  Canonical input processing is
          performed when LLITOUT mode is selected.  The LPASS8 flag of
          the local mode word can be used to allow for eight bit
          characters.   While LPASS8 is set both input processing and
          output processing are performed if the RAW bit is not set.

          Line control and breaks

          There are several calls available to control the state of
          the terminal line.  The TIOCSBRK ioctl sets the break bit in
          the hardware interface causing a break condition to exist;
          this can be cleared by TIOCCBRK, usually after a delay with
          Break conditions in the input are reflected as a null
          character in RAW mode or as the interrupt character in
          cooked or CBREAK mode.  The TIOCCDTR ioctl clears the data
          terminal ready condition.  It can be set again by TIOCSDTR.

          When the carrier signal from the dataset drops (usually
          because the user has hung up his terminal), a SIGHUP hangup
          signal is sent to the processes in the distinguished process
          group of the terminal.  This usually causes them to
          terminate (the SIGHUP can be suppressed by setting the
          LNOHANG bit in the local state word of the driver.) Access
          to the terminal by other processes is then normally revoked,
          so any further reads will fail, and programs that read a
          terminal and test for end-of-file on their input will
          terminate appropriately.

          When using an ACU, it is possible to ask that the phone line
          be hung up on the last close with the TIOCHPCL ioctl.  This
          is normally done on the outgoing line.

          Interrupt characters

          There are several characters that generate interrupts in
          cooked and CBREAK mode.  All are sent the processes in the
          control group of the terminal, as if a TIOCGPGRP ioctl were
          done to get the process group and then a system call were
          done, except that these characters also flush pending input
          and output when typed at a terminal ('a`'la TIOCFLUSH).  The
          characters shown here are the defaults.  The field names in
          the structures (given below) are also shown.  The characters
          may be changed, although this is not often done.

          ^?   t_intrc (Delete) generates a SIGINT signal.  This is
               the normal way to stop a process that is no longer
               interesting or to regain control in an interactive
               program.

          ^\   t_quitc (FS) generates a SIGQUIT signal.  This is used
               to cause a program to terminate and produce a core
               image, if possible, in the file core in the current
               directory.

          ^Z   t_suspc (EM) generates a SIGTSTP signal that is used to
               suspend the current process group.

          ^Y   t_dsuspc (SUB) generates a SIGTSTP signal as CTRL/Z
               does, but the signal is sent when a program attempts to
               read the CTRL/Y, rather than when it is typed.

          Job access control

          When using the new terminal driver, if a process that is not
          in the distinguished process group of its control terminal
          attempts to read from that terminal, its process group is
          sent a SIGTTIN signal.  This signal normally causes the
          members of that process group to stop. If, however, the
          process is ignoring SIGTTIN, has SIGTTIN blocked, is an
          orphan process, or is in the middle of process creation
          using it is instead returned an end-of-file.  (An orphan
          process is a process whose parent has exited and has been
          inherited by the process.) Under older UNIX systems these
          processes would typically have had their input files reset
          to so this is a compatible change.

          When using the new terminal driver with the LTOSTOP bit set
          in the local modes, a process is prohibited from writing on
          its control terminal if it is not in the distinguished
          process group for that terminal.  Processes that are holding
          or ignoring SIGTTOU signals, which are orphans or which are
          in the middle of a are excepted and allowed to produce
          output.

          Modem control

          Ioctls have been added to provide more flexible modem
          control on tty lines. The new commands are summarized below.

          TIOCMODEM      Indicate to the system that this tty line has
                         a modem attached to it and should not ignore
                         modem signals. The argument to this ioctl is
                         the address of a word that contains either
                         zero or a nonzero value.  Zero indicates that
                         the effect of the ioctl is temporary and the
                         line is reset to its condition prior to the
                         ioctl when the tty line is closed.  Nonzero
                         indicates that the effect of the ioctl should
                         be permanent.  Root privilege is required to
                         effect a permanent change.

          TIOCNMODEM     Indicate to the system that modem
                         transmissions should be ignored on this line.
                         This is useful for connections that do not
                         implement the full RS-232 standard (most
                         direct connections to terminals).  The
                         argument to this ioctl is the address of a
                         word that contains either zero or a nonzero
                         value.  Zero indicates that the effect of
                         ioctl is temporary and the line is reset to
                         its condition prior to the ioctl when the tty
                         line is closed.  Nonzero indicates that the
                         effect of the ioctl should be permanent.
                         Root privilege is required to effect a
                         permanent change.

          TIOCNCAR       Ignore soft carrier when doing reads or
                         writes.  If carrier is not present on a modem
                         line,  then reads or writes will normally
                         fail.  This ioctl allows reads and writes to
                         succeed regardless of the state of this line.
                         This is useful for dealing with automatic
                         call units that send status messages before
                         carrier is present on the line.  The
                         alternative would be to use the TIOCNMODEM
                         ioctl and ignore all modem signals and force
                         soft carrier to be present. The latter
                         alternative is not desirable if full modem
                         control is required.

          TIOCCAR        The opposite effect of TIOCNCAR.  If carrier
                         is not present on modem lines, then
                         reads/writes fail.

          TIOCWONLINE    This ioctl blocks the process until carrier
                         is detected.

          The following example demonstrates how one might deal with a
          modem:
           /* open the line and don't wait for carrier */
           fd = open(dcname, O_RDWR|O_NDELAY);
           /* we are attached to a modem so don't ignore modem signals
          */
           ioctl(fd, TIOCMODEM, &temp);
           ioctl(fd, TIOCNCAR);    /* ignore soft carr while dialing
          number */
           /*
            * dial phone number and negotiate with auto call unit.
            */
           ioctl(fd, TIOCCAR);     /* don't ignore carrier anymore */
           alarm(40);
           ioctl(fd, TIOCWONLINE); /* wait for carrier */
           alarm(0);

          Shared tty lines

          The following ioctls are used by and to implement shared
          terminal lines:  TIOCSINUSE/FIOSINUSE, TIOCCINUSE/FIOCINUSE.
          Shared terminal lines can be used for both incoming and
          outgoing connections.  For further information, see the
          Guide to System Environment Setup. These ioctls can be used
          by any user process on any file type (they do not work on a
          socket).

          TIOCSINUSE     TIOCSINUSE is defined to FIOSINUSE.  This
                         command checks to see if the file is marked
                         "in use".  If the file is not "in use," it is
                         marked "in use" by the current process and
                         the ioctl succeeds.  If the file is already
                         "in use" by some other process, the ioctl
                         fails and errno is set to EALREADY. For
                         further information, see

          TIOCCINUSE     TIOCCINUSE is defined to FIOCINUSE.  This
                         command clears the "in use" flag on a file if
                         the current process was the one that set the
                         "in use" flag.  Any process that is blocked
                         and waiting for the "in use" flag to clear
                         will be resumed. For further information, see

          Summary of modes

          Unfortunately, due to the evolution of the terminal driver,
          there are four different structures that contain various
          portions of the driver data.  The first of these (sgttyb)
          contains that part of the information largely common between
          version 6 and version 7 UNIX systems.  The second contains
          additional control characters added in version 7.  The third
          is a word of local state peculiar to the new terminal
          driver, and the fourth is another structure of special
          characters added for the new driver.  In the future a single
          structure may be made available to programs which need to
          access all this information; most programs need not concern
          themselves with all this state.

          Basic modes: sgtty - The basic ioctls use the structure
          defined in <sgtty.h>:

          struct sgttyb {
                 char     sg_ispeed;
                 char     sg_ospeed;
                 char     sg_erase;
                 char     sg_kill;
                 short    sg_flags; };

          The sg_ispeed and sg_ospeed fields describe the input and
          output speeds of the device according to the following
          table, which corresponds to the speeds offered on most
          DIGITAL terminal multiplexers.  If other hardware is used,
          impossible speed changes are ignored.  Symbolic values in
          the table are as defined in <sgtty.h>.

          B0      0    (hang up dataphone)
          B50     1    50 baud
          B75     2    75 baud
          B110    3    110 baud
          B134    4    134.5 baud
          B150    5    150 baud
          B200    6    200 baud
          B300    7    300 baud
          B600    8    600 baud
          B1200   9    1200 baud
          B1800   10   1800 baud
          B2400   11   2400 baud
          B4800   12   4800 baud
          B9600   13   9600 baud
          EXTA    14   External A (19200 baud)
          EXTB    15   External B (38400 baud)

          Code conversion and line control required for IBM 2741s
          (134.5 baud) must be implemented by the user's program.  The
          half-duplex line discipline required for the 202 dataset
          (1200 baud) is not supplied; full-duplex 212 datasets work
          fine.

          The sg_erase and sg_kill fields of the argument structure
          specify the erase and kill characters respectively.
          (Defaults are # and @.)

          The sg_flags field of the argument structure contains
          several bits that determine the system's treatment of the
          terminal:

          ALLDELAY 0177400 Delay algorithm selection
          BSDELAY  0100000 Select backspace delays (not implemented):
          BS0      0
          BS1      0100000
          VTDELAY  0040000 Select form-feed and vertical-tab delays:
          FF0      0
          FF1      0100000
          CRDELAY  0030000 Select carriage-return delays:
          CR0      0
          CR1      0010000
          CR2      0020000
          CR3      0030000
          TBDELAY  0006000 Select tab delays:
          TAB0     0
          TAB1     0002000
          TAB2     0004000
          XTABS    0006000
          NLDELAY  0001400 Select new-line delays:
          NL0      0
          NL1      0000400
          NL2      0001000
          NL3      0001400
          EVENP    0000200 Even parity allowed on input (most terminals)
          ODDP     0000100 Odd parity allowed on input
          RAW      0000040 Raw mode: wake up on all characters, 8-bit interface
          CRMOD    0000020 Map CR into LF; echo LF or CR as CR-LF
          ECHO     0000010 Echo (full duplex)
          LCASE    0000004 Map uppercase to lowercase on input
          CBREAK   0000002 Return each character as soon as typed
          TANDEM   0000001 Automatic flow control

          The delay bits specify how long transmission stops to allow
          for mechanical or other movement when certain characters are
          sent to the terminal.  In all cases, a value of 0 indicates
          no delay.

          Backspace delays are ignored but might be used for Terminet
          300s.

          If a form-feed/vertical tab delay is specified, it lasts for
          about 2 seconds.

          Carriage-return delay type 1 lasts about .08 seconds and is
          suitable for the Terminet 300.  Delay type 2 lasts about .16
          seconds and is suitable for the VT05 and the TI 700.  Delay
          type 3 is suitable for the concept-100 and pads lines to be
          at least 9 characters at 9600 baud.

          New-line delay type 1 is dependent on the current column and
          is tuned for Teletype model 37s.  Type 2 is useful for the
          VT05 and is about .10 seconds.  Type 3 is unimplemented and
          is 0.

          Tab delay type 1 is dependent on the amount of movement and
          is tuned to the Teletype model 37.  Type 3, called XTABS, is
          not a delay at all but causes tabs to be replaced by the
          appropriate number of spaces on output.

          The flags for even and odd parity control parity checking on
          input and generation on output in cooked and CBREAK mode.
          Even parity is generated on output unless ODDP is set and
          EVENP is clear, in which case odd parity is generated.
          Input characters with the wrong parity, as determined by
          EVENP and ODDP, are ignored in cooked and CBREAK mode.

          RAW disables all processing save output flushing with
          LFLUSHO; full 8 bits of input are given as soon as it is
          available; all 8 bits are passed on output.  A break
          condition in the input is reported as a null character.  If
          the input queue overflows in raw mode, it is discarded; this
          applies to both new and old drivers.

          CRMOD causes input carriage returns to be turned into
          newlines; input of either CR or LF causes LF-CR both to be
          echoed (for terminals with a newline function).

          CBREAK is a sort of half-cooked mode.  Programs can read
          each character as soon as typed, instead of waiting for a
          full line; all processing is done except the input editing:
          character and word erase and line kill, input reprint, and
          the special treatment of \ or EOT are disabled.

          TANDEM mode causes the system to produce a stop character
          (default, CTRL/S), whenever the input queue is in danger of
          overflowing, and a start character (default CTRL/Q) when the
          input queue has drained sufficiently.  It is useful for flow
          control when the `terminal' is really another computer which
          understands the conventions.

          Basic ioctls - In addition to the TIOCSETD and TIOCGETD
          disciplines discussed in Line disciplines above, a large
          number of other calls apply to terminals and have the
          general form:

          #include <sgtty.h>

          ioctl(fildes, code, arg)
          struct sgttyb *arg;

          The applicable codes are:

          TIOCGETP       Fetch the basic parameters associated with
                         the terminal, and store in the pointed-to
                         sgttyb structure.

          TIOCSETP       Set the parameters according to the pointed-
                         to sgttyb structure.  The interface delays
                         until output is quiescent, then throws away
                         any unread characters, before changing the
                         modes.

          TIOCSETN       Set the parameters like TIOCSETP but do not
                         delay or flush input.  Input is not
                         preserved, however, when changing to or from
                         RAW.

          With the following codes the arg is ignored.

          TIOCEXCL       Set exclusive-use mode: all open calls to
                         this line have been closed. This setting does
                         not prevent super user opens of the terminal
                         line.

          TIOCNXCL       Turn off exclusive-use mode.

          TIOCHPCL       When the file is closed for the last time,
                         hang up the terminal.  This is useful when
                         the line is associated with an ACU used to
                         place outgoing calls.

          Setting the pointed-to integer parameter to the following
          values determines how TIOCFLUSH functions.

          TIOCFLUSH      FREAD flushes input queues.  FWRITE flushes
                         output queues. 0 flushes both.  FREAD and
                         FWRITE are defined in <sys/file.h>.

          In cases where arguments are required, they are described;
          arg should otherwise be given as 0.

          TIOCSTI        The argument is the address of a character
                         that the system pretends was typed on the
                         terminal.

          TIOCSBRK       The break bit is set in the terminal.

          TIOCCBRK       The break bit is cleared.

          TIOCSDTR       Data terminal ready is set.

          TIOCCDTR       Data terminal ready is cleared.

          TIOCSTOP       Output is stopped as if the stop character
                         had been typed.

          TIOCSTART      Output is restarted as if the start character
                         had been typed.

          TIOCGPGRP      arg is the address of a word into which is
                         placed the process group number of the
                         control terminal.

          TIOCSPGRP      arg is a word (typically a process ID) that
                         becomes the process group for the control
                         terminal.

          FIONREAD       Returns in the long integer whose address is
                         arg, the number of immediately readable
                         characters from the argument unit.

          Tchars - The second structure associated with each terminal
          specifies characters that are special in both the old and
          new terminal interfaces.  The following structure is defined
          in <sys/ioctl.h>, which is automatically included in
          <sgtty.h>:

          struct tchars {
                  char    t_intrc;    /* interrupt */
                  char    t_quitc;    /* quit */
                  char    t_startc;   /* start output */
                  char    t_stopc;    /* stop output */
                  char    t_eofc;      /* end-of-file */
                  char    t_brkc;     /* input delimiter (like nl) */
          };

          The default values for these characters are CTRL/?, CTRL/\,
          CTRL/Q, CTRL/S, CTRL/D, and -1.  A character value of -1
          eliminates the effect of that character.  The t_brkc
          character, by default -1, acts like a newline in that it
          terminates a `line,' is echoed, and is passed to the
          program.  The `stop' and `start' characters may be the same,
          to produce a toggle effect.  It is probably
          counterproductive to make other special characters
          (including erase and kill) identical.  The applicable ioctl
          calls are:

          TIOCGETC    Get the special characters and put them in the
                      specified structure.

          TIOCSETC    Set the special characters to those given in the
                      structure.

          Local mode - The third structure associated with each
          terminal is a local mode word.  The bits of the local mode
          word are:

          LCRTBS    0x0001    Backspace on erase rather than echoing erase
          LPRTERA   0x0002    Printing terminal erase mode
          LCRTERA   0x0004    Erase character echoes as backspace-space-backspace
          LTILDE    0x0008    Convert ~ to ` on output (for Hazeltine terminals)
          LLITOUT   0x0020    Suppress output translations
          LTOSTOP   0x0040    Send SIGTTOU for background output
          LFLUSHO   0x0080    Output is being flushed
          LNOHANG   0x0100    Don't send hangup when carrier drops
          LAUTOFLOW 0x0200    Hardware responds to flow control characters. See "Flow control"
          LCRTKIL   0x0400    BS-space-BS erase entire line on line kill
          LPASS8    0x0800    Allow eight bit characters in input and output
          LCTLECH   0x1000    Echo input control chars as CTRL/X, delete as CTRL/?
          LPENDIN   0x2000    Retype pending input at next read or input character
          LDECCTQ   0x4000    Only CTRL/Q restarts output after CTRL/S
          LNOFLSH   0x8000    Don't flush output on receipt of suspend or interrupt character

          The applicable functions are:

          TIOCLBIS       arg is the address of a mask is the bits to
                         be set in the local mode word.

          TIOCLBIC       arg is the address of a mask of bits to be
                         cleared in the local mode word.

          TIOCLSET       arg is the address of a mask to be placed in
                         the local mode word.

          TIOCLGET       arg is the address of a word into which the
                         current mask is placed.

          Local special characters - The final structure associated
          with each terminal is the structure that defines interrupt
          characters for the new terminal driver.  Its structure is:
          struct ltchars {
                  char    t_suspc;      /* stop process signal */
                  char    t_dsuspc;     /* delayed stop process signal
          */
                  char    t_rprntc;     /* reprint line */
                  char    t_flushc;     /* flush output (toggles) */
                  char    t_werasc;     /* word erase */
                  char    t_lnextc;     /* literal next character */
          };

          The default values for these characters are CTRL/Z, CTRL/Y,
          CTRL/R, CTRL/O, CTRL/W, and CTRL/V.  A value of -1 disables
          the character.

          The applicable ioctl functions are:

          TIOCSLTC    args is the address of a structure, which
                      defines the new local special characters.

          TIOCGLTC    args is the address of a structure into which is
                      placed the current set of local special
                      characters.

     RESTRICTIONS
          Half-duplex terminals are not supported.

     FILES
          /dev/tty
          /dev/tty*
          /dev/console

     SEE ALSO
          csh(1), stty(1), tset(1), ioctl(2), sigvec(2), stty(3c),
          termio(4), termios(4), getty(8), MAKEDEV(8)

And here is the System V side of the world, again from Ultrix:


     NAME
          termio - System V terminal interface

     DESCRIPTION
          This section specificaly describes the System V terminal
          interface.  A general description of the available terminal
          interfaces has been provided in

          When a terminal file is opened, it normally causes the
          process to wait until a connection is established.  In
          practice, users' programs seldom open these files; they are
          opened by getty and become a user's standard input, output,
          and error files.  The very first terminal file opened by the
          process group leader of a terminal file not already
          associated with a process group becomes the control terminal
          for that process group.  The control terminal plays a
          special role in handling quit and interrupt signals, as
          discussed below.  The control terminal is inherited by a
          child process during a A process can break this association
          by changing its process group using

          A terminal associated with one of these files ordinarily
          operates in full-duplex mode.  Characters may be typed at
          any time, even while output is occurring, and are only lost
          when the system's character input buffers become completely
          full, which is rare, or when the user has accumulated the
          maximum allowed number of input characters that have not yet
          been read by some program.  Currently, this limit is
          (MAX_INPUT) characters as defined in <limits.h>. When the
          input limit is reached, all the saved characters are thrown
          away without notice.

          Normally, terminal input is processed in units of lines.  A
          line is delimited by a new-line (ASCII LF) character, an
          end-of-file (ASCII EOT) character, or an end-of-line
          character.  This means that a program attempting to read
          will be suspended until an entire line has been typed.
          Also, no matter how many characters are requested in the
          read call, at most one line will be returned.  It is not,
          however, necessary to read a whole line at once; any number
          of characters may be requested in a read, even one, without
          losing information.

          Some characters have special meaning when input.  For
          example during input erase and kill processing is normally
          done. The erase character erases the last character typed,
          except that it will not erase beyond the beginning of a
          line.  Typically the erase character is the charcter #. The
          kill character kills (deletes) the entire input line, and
          optionally outputs a new-line charcter.  The default kill
          character is the character @.  Both characters operate on a
          key-stroke basis independently of any backspacing or
          tabbing.  Both the erase and kill characters may be entered
          literally by preceding them with the escape character (\).
          In this case the escape character is not read.  The erase
          and kill characters may be changed.

          Certain characters have special functions on input.  These
          functions and their default character values are summarized
          as follows:

          INTR    (Rubout or ASCII DEL) generates an interrupt signal
                  which is sent to all processes with the associated
                  control terminal.  Normally, each such process is
                  forced to terminate, but arrangements may be made
                  either to ignore the signal or to receive a trap to
                  an agreed-upon location; see

          QUIT    (Control-| or ASCII FS) generates a quit signal.
                  Its treatment is identical to the interrupt signal
                  except that, unless a receiving process has made
                  other arrangements, it will not only be terminated
                  but a core image file (called core) will be created
                  in the current working directory.

          ERASE   (#) erases the preceding character.  It will not
                  erase beyond the start of a line, as delimited by a
                  NL, EOF, or EOL character.

          KILL    (@) deletes the entire line, as delimited by a NL,
                  EOF, or EOL character.

          EOF     (Control-d or ASCII EOT) may be used to generate an
                  end-of-file from a terminal.  When received, all the
                  characters waiting to be read are immediately passed
                  to the program, without waiting for a new-line, and
                  the EOF is discarded.  Thus, if there are no
                  characters waiting, which is to say the EOF occurred
                  at the beginning of a line, zero characters will be
                  passed back, which is the standard end-of-file
                  indication.

          NL      (ASCII LF) is the normal line delimiter.  It can not
                  be changed or escaped.

          EOL     (ASCII NUL) is an additional line delimiter, like
                  NL.  It is not normally used.

          STOP    (Control-s or ASCII DC3) can be used to temporarily
                  suspend output.  It is useful with CRT terminals to
                  prevent output from disappearing before it can be
                  read.  While output is suspended, STOP characters
                  are ignored and not read.

          START   (Control-q or ASCII DC1) is used to resume output
                  which has been suspended by a STOP character.  While
                  output is not suspended, START characters are
                  ignored and not read.  The start/stop characters can
                  not be changed or escaped.

          MIN     Used to control terminal I/O when the ICANON flag is
                  not set in the c_lflag.  Input processing behaves as
                  described in the MIN/TIME Interaction section
                  (below).

          TIME    Used to control terminal I/O when the ICANON flag is
                  not set in the c_lflag.  Input processing behaves as
                  described in the MIN/TIME Interaction section
                  (below).

          The character values for INTR, QUIT, ERASE, KILL, EOF, MIN,
          TIME, and EOL may be changed to suit individual tastes.  The
          ERASE, KILL, and EOF characters may be escaped by a
          preceding \ character, in which case no special function is
          done.

          When one or more characters are written, they are
          transmitted to the terminal as soon as previously-written
          characters have finished typing.  Input characters are
          echoed by putting them in the output queue as they arrive.
          If a process produces characters more rapidly than they can
          be typed, it will be suspended when its output queue exceeds
          some limit.  When the queue has drained down to some
          threshold, the program is resumed.

          When the carrier signal from the data-set drops, a hang-up
          signal, SIGHUP, is sent to all processes that have this
          terminal as the control terminal.  Unless other arrangements
          have been made, this signal causes the processes to
          terminate.  If the hang-up signal is ignored, any subsequent
          read returns with an end-of-file indication.  Thus, programs
          that read a terminal and test for end-of-file can terminate
          appropriately when hung up on.

          Several system calls apply to terminal files.  The primary
          calls use the following structure, defined in <termio.h>:

               struct       termio {
                     unsigned    short   c_iflag;/* input modes */
                     unsigned    short   c_oflag;/* output modes */
                     unsigned    short   c_cflag;/* control modes */
                     unsigned    short   c_lflag;/* local modes */
                     char        c_line; /* line discipline */
                     unsigned    char    c_cc[NCC];/* control chars */
               };

          The special control characters are defined by the array
          c_cc.  The initial values for each function are as follows:
                   VINTR    DEL
                   VQUIT    FS
                   VERASE   #
                   VKILL    @
                   VEOF     EOT
                   VEOL     NUL
                   VMIN     6
                   VTIME    1

          The c_iflag field describes the basic terminal input
          control:

               IGNBRK  Ignore break condition.
               BRKINT  Signal interrupt on break.
               IGNPAR  Ignore characters with parity errors.
               PARMRK  Mark parity errors.
               INPCK   Enable input parity check.
               ISTRIP  Strip character.
               INLCR   Map NL to CR on input.
               IGNCR   Ignore CR.
               ICRNL   Map CR to NL on input.
               IUCLC   Map upper-case to lower-case on input.
               IXON    Enable start/stop output control.
               IXANY   Enable any character to restart output.
               IXOFF   Enable start/stop input control.

          If IGNBRK is set, the break condition (a character framing
          error with data all zeros) is ignored, that is, not put on
          the input queue and therefore not read by any process.
          Otherwise if BRKINT is set, the break condition will
          generate an interrupt signal and flush both the input and
          output queues.  If IGNPAR is set, characters with other
          framing and parity errors are ignored.

          If PARMRK is set, a character with a framing or parity error
          which is not ignored is read as the three-character
          sequence: 0377, 0, X, where X is the data of the character
          received in error.  To avoid ambiguity in this case, if
          ISTRIP is not set, a valid character of 0377 is read as
          0377, 0377.  If PARMRK is not set, a framing or parity error
          which is not ignored is read as the character NUL (0).

          If INPCK is set, input parity checking is enabled.  If INPCK
          is not set, input parity checking is disabled.  This allows
          output parity generation without input parity errors.

          If ISTRIP is set, valid input characters are first stripped
          to 7-bits, otherwise all 8-bits are processed.

          If INLCR is set, a received NL character is translated into
          a CR character.  If IGNCR is set, a received CR character is
          ignored (not read).  Otherwise if ICRNL is set, a received
          CR character is translated into a NL character.

          If IUCLC is set, a received upper-case alphabetic character
          is translated into the corresponding lower-case character.

          If IXON is set, start/stop output control is enabled.  A
          received STOP character will suspend output and a received
          START character will restart output.  All start/stop
          characters are ignored and not read.  If IXANY is set, any
          input character, will restart output which has been
          suspended.

          If IXOFF is set, the system will transmit START/STOP
          characters when the input queue is nearly empty/full.

          The initial input control value is all-bits-clear.

          The c_oflag field specifies the system treatment of output:

               OPOST   Postprocess output.
               OLCUC   Map lower case to upper on output.
               ONLCR   Map NL to CR-NL on output.
               OCRNL   Map CR to NL on output.
               ONOCR   No CR output at column 0.
               ONLRET  NL performs CR function.
               OFILL   Use fill characters for delay.
               OFDEL   Fill is DEL, else NUL.
               NLDLY   Select new-line delays:
               NL0     New-line delay type 0.
               NL1     New-line delay type 1.
               CRDLY   Select carriage-return delays:
               CR0     Carriage-return delay type 0.
               CR1     Carriage-return delay type 1.
               CR2     Carriage-return delay type 2.
               CR3     Carriage-return delay type 3.
               TABDLY  Select horizontal-tab delays:
               TAB0    Horizontal-tab delay type 0.
               TAB1    Horizontal-tab delay type 1.
               TAB2    Horizontal-tab delay type 2.
               TAB3    Expand tabs to spaces.
               BSDLY   Select backspace delays:
               BS0     Backspace delay type 0.
               BS1     Backspace delay type 1.
               VTDLY   Select vertical-tab delays:
               VT0     Vertical-tab delay type 0.
               VT1     Vertical-tab delay type 1.
               FFDLY   Select form-feed delays:
               FF0     Form-feed delay type 0.
               FF1     Form-feed delay type 1.

          If OPOST is set, output characters are post-processed as
          indicated by the remaining flags, otherwise characters are
          transmitted without change.

          If OLCUC is set, a lower-case alphabetic character is
          transmitted as the corresponding upper-case character.  This
          function is often used in conjunction with IUCLC.

          If ONLCR is set, the NL character is transmitted as the CR-
          NL character pair.  If OCRNL is set, the CR character is
          transmitted as the NL character.  If ONOCR is set, no CR
          character is transmitted when at column 0 (first position).
          If ONLRET is set, the NL character is assumed to do the
          carriage-return function; the column pointer will be set to
          0 and the delays specified for CR will be used.  Otherwise
          the NL character is assumed to do just the line-feed
          function; the column pointer will remain unchanged.  The
          column pointer is also set to 0 if the CR character is
          actually transmitted.

          The delay bits specify how long transmission stops to allow
          for mechanical or other movement when certain characters are
          sent to the terminal.  In all cases a value of 0 indicates
          no delay.  If OFILL is set, fill characters will be
          transmitted for delay instead of a timed delay.  This is
          useful for high baud rate terminals which need only a
          minimal delay.  If OFDEL is set, the fill character is DEL,
          otherwise NUL.

          If a form-feed or vertical-tab delay is specified, it lasts
          for about 2 seconds.

          New-line delay lasts about 0.10 seconds.  If ONLRET is set,
          the carriage-return delays are used instead of the new-line
          delays.  If OFILL is set, two fill characters will be
          transmitted.

          Carriage-return delay type 1 is dependent on the current
          column position, type 2 is about 0.10 seconds, and type 3 is
          about 0.15 seconds.  If OFILL is set, delay type 1 transmits
          two fill characters, and type 2, four fill characters.

          Horizontal-tab delay type 1 is dependent on the current
          column position.  Type 2 is about 0.10 seconds.  Type 3
          specifies that tabs are to be expanded into spaces.  If
          OFILL is set, two fill characters will be transmitted for
          any delay.

          Backspace delay lasts about 0.05 seconds.  If OFILL is set,
          one fill character will be transmitted.

          The actual delays depend on line speed and system load.

          The initial output control value is all bits clear.

          The c_cflag field describes the hardware control of the
          terminal:

               CBAUD   Baud rate:
               B0      Hang up
               B50     50 baud
               B75     75 baud
               B110    110 baud
               B134    134.5 baud
               B150    150 baud
               B200    200 baud
               B300    300 baud
               B600    600 baud
               B1200   1200 baud
               B1800   1800 baud
               B2400   2400 baud
               B4800   4800 baud
               B9600   9600 baud
               B19200  19200 baud
               B38400  38400 baud
               EXTA    External A (Same as B19200)
               EXTB    External B (Same as B38400)
               CSIZE   Character size:
               CS5     5 bits
               CS6     6 bits
               CS7     7 bits
               CS8     8 bits
               CSTOPB  Send two stop bits, else one.
               CREAD   Enable receiver.
               PARENB  Parity enable.
               PARODD  Odd parity, else even.
               HUPCL   Hang up on last close.
               CLOCAL  Local line, else dial-up.

          The CBAUD bits specify the baud rate.  The zero baud rate,
          B0, is used to hang up the connection.  If B0 is specified,
          the data-terminal-ready signal will not be asserted.
          Normally, this will disconnect the line.  For any particular
          hardware, impossible speed changes are ignored.

          The CSIZE bits specify the character size in bits for both
          transmission and reception.  This size does not include the
          parity bit, if any.  If CSTOPB is set, two stop bits are
          used, otherwise one stop bit.  For example, at 110 baud, two
          stops bits are required.

          If PARENB is set, parity generation and detection is enabled
          and a parity bit is added to each character.  If parity is
          enabled, the PARODD flag specifies odd parity if set,
          otherwise even parity is used.

          If CREAD is set, the receiver is enabled.  Otherwise no
          characters will be received.

          If HUPCL is set, the line will be disconnected when the last
          process with the line open closes it or terminates.  That
          is, the data-terminal-ready signal will not be asserted.

          If CLOCAL is set, the line is assumed to be a local, direct
          connection with no modem control.  Otherwise modem control
          is assumed.

          The initial hardware control value after open is B300, CS8,
          CREAD, HUPCL.

          The c_lflag field of the argument structure is used by the
          line discipline to control terminal functions.  The basic
          line discipline (0) provides the following:

               ISIG    Enable signals.
               ICANON  Canonical input (erase and kill processing).
               XCASE   Canonical upper/lower presentation.
               ECHO    Enable echo.
               ECHOE   Echo erase character as BS-SP-BS.
               ECHOK   Echo NL after kill character.
               ECHONL  Echo NL.
               NOFLSH  Disable flush after interrupt or quit.

          If ISIG is set, each input character is checked against the
          special control characters INTR, SWTCH, and QUIT.  If an
          input character matches one of these control characters, the
          function associated with 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.  These
          functions may be disabled individually by changing the value
          of the control character to an unlikely or impossible value
          (e.g., 0).

          If ICANON is set, canonical processing is enabled.  This
          enables the erase and kill edit functions, and the assembly
          of input characters into lines delimited by NL, EOF, and
          EOL.  If ICANON is not set, read requests are satisfied
          directly from the input queue.  A read will not be satisfied
          until at least MIN characters have been received or the
          timeout value TIME has expired between characters.  This
          allows fast bursts of input to be read efficiently while
          still allowing single character input.  The MIN and TIME
          values are stored in the position for the EOF and EOL
          characters, respectively.  The time value represents tenths
          of seconds.

          If XCASE is set, and if ICANON is set, an upper-case letter
          is accepted on input by preceding it with a \ character, and
          is output preceded by a \ character.  In this mode, the
          following escape sequences are generated on output and
          accepted on input:

          for  `    |    ~    {    }
          use  \'   \!   \^   \(   \)

          For example, A is input as \a, \n as \\n, and \N as \\\n.

          If ECHO is set, characters are echoed as received.

          When ICANON is set, the following echo functions are
          possible.  If ECHO and ECHOE are set, the erase character is
          echoed as ASCII BS SP BS, which will clear the last
          character from a CRT screen.  If ECHOE is set and ECHO is
          not set, the erase character is echoed as ASCII SP BS.  If
          ECHOK is set, the NL character will be echoed after the kill
          character to emphasize that the line will be deleted.  Note
          that an escape character preceding the erase or kill
          character removes any special function.  If ECHONL is set,
          the NL character will be echoed even if ECHO is not set.
          This is useful for terminals set to local echo (so-called
          half duplex).  Unless escaped, the EOF character is not
          echoed.  Because EOT is the default EOF character, this
          prevents terminals that respond to EOT from hanging up.

          If NOFLSH is set, the normal flush of the input and output
          queues associated with the quit, switch, and interrupt
          characters will not be done.

          The initial line-discipline control value is all bits clear.

          The c_line field of the argument structure is used to
          specify the line discipline.  Support is provided for the
          basic termio line discipline only.  For this reason the
          value of this field is irrelevant and should be set to (0)
          by convention.

          The primary system calls have the form:

               ioctl (fildes, command, arg)
               struct termio *arg;

          The commands using this form are:

               TCGETA    Get the parameters associated with the
                         terminal and store in the termio structure
                         referenced by arg.

               TCSETA    Set the parameters associated with the
                         terminal from the structure referenced by
                         arg.  The change is immediate.

               TCSETAW   Wait for the output to drain before setting
                         the new parameters.  This form should be used
                         when changing parameters that will affect
                         output.

               TCSETAF   Wait for the output to drain, then flush the
                         input queue and set the new parameters.

          Additional calls have the form:

               ioctl (fildes, command, arg)
               int arg;

          The commands using this form are:

               TCSBRK    Wait for the output to drain.  If arg is 0,
                         then send a break (zero bits for 0.25
                         seconds).

               TCXONC    Start/stop control.  If arg is 0, suspend
                         output; if 1, restart suspended output.

               TCFLSH    If arg is 0, flush the input queue; if 1,
                         flush the output queue; if 2, flush both the
                         input and output queues.

               MIN/TIME Interaction

               MIN represents the minimum number of characters that
               should be received when the read is satisfied (i.e.,
               the characters are returned to the user).  TIME is a
               timer of 0.10 second granularity used to time-out
               bursty and short-term data transmissions.  The four
               possible values for MIN and TIME and their interactions
               follow:

               1. MIN > 0, TIME > 0.  In this case, TIME serves as an
               inter-character timer activated after the first
               character is received, and reset upon receipt of each
               character.  MIN and TIME interact as follows:

               As soon as one character is received the inter-
               character timer is started.

               If MIN characters are received before the inter-
               character timer expires the read is satisfied.

               If the timer expires before MIN characters are received
               the characters received to that point are returned to
               the user.

               A operation will sleep until the MIN and TIME mechanism
               are activated by the receipt of the first character;
               thus, at least one character must be returned.

               2.  MIN > 0, TIME = 0 .  In this case because TIME=0 ,
               the timer plays no role and only MIN is signifigant.  A
               operation is not satisfied until MIN characters are
               received.

               3.  MIN = 0, TIME > 0 .  In this case, because MIN=0,
               TIME no longer serves as an inter-character timer, but
               now serves as a read timer that is activated as soon as
               the operation is processed. A operation is satisfied as
               soon as a single character is received or the timer
               expirees, in which case, the operation would not return
               any characters.

               4.  MIN = 0, TIME = 0 .  In this case, return is
               immediate.  If characters are present, they will be
               returned to the user.
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA

Catproof is an oxymoron, Childproof is nearly so