home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / sys / tty.h < prev    next >
Text File  |  1993-10-19  |  8KB  |  252 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software License Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  */
  7.  
  8. /*
  9.  * Copyright (c) 1982, 1986 Regents of the University of California.
  10.  * All rights reserved.  The Berkeley software License Agreement
  11.  * specifies the terms and conditions for redistribution.
  12.  *
  13.  *    @(#)tty.h    7.1 (Berkeley) 6/4/86
  14.  */
  15.  
  16. /*HISTORY
  17.  *  7-Jan-93  Mac Gillon (mgillon) at NeXT
  18.  *    Integrated POSIX support
  19.  */
  20.  
  21. #ifndef    _SYS_TTY_H_
  22. #define    _SYS_TTY_H_
  23.  
  24. #import <sys/types.h>
  25. #import <sys/ttychars.h>
  26. #import <sys/ttydev.h>
  27. #import <sys/ioctl.h>
  28.  
  29. /*
  30.  * A clist structure is the head of a linked list queue
  31.  * of characters.  The characters are stored in blocks
  32.  * containing a link and CBSIZE (param.h) characters. 
  33.  * The routines in tty_subr.c manipulate these structures.
  34.  */
  35. struct clist {
  36.     int    c_cc;        /* character count */
  37.     char    *c_cf;        /* pointer to first char */
  38.     char    *c_cl;        /* pointer to last char */
  39. };
  40.  
  41. /*
  42.  * Per-tty structure.
  43.  *
  44.  * Should be split in two, into device and tty drivers.
  45.  * Glue could be masks of what to echo and circular buffer
  46.  * (low, high, timeout).
  47.  */
  48. struct tty {
  49.     union {
  50.         struct {
  51.             struct    clist T_rawq;
  52.             struct    clist T_canq;
  53.         } t_t;
  54. #define    t_rawq    t_nu.t_t.T_rawq        /* raw characters or partial line */
  55. #define    t_canq    t_nu.t_t.T_canq        /* raw characters or partial line */
  56.         struct {
  57.             struct    buf *T_bufp;
  58.             char    *T_cp;
  59.             int    T_inbuf;
  60.             int    T_rec;
  61.         } t_n;
  62. #define    t_bufp    t_nu.t_n.T_bufp        /* buffer allocated to protocol */
  63. #define    t_cp    t_nu.t_n.T_cp        /* pointer into the ripped off buffer */
  64. #define    t_inbuf    t_nu.t_n.T_inbuf    /* number chars in the buffer */
  65. #define    t_rec    t_nu.t_n.T_rec        /* have a complete record */
  66.     } t_nu;
  67.     struct    clist t_outq;        /* device */
  68.     int    (*t_oproc)();        /* device */
  69.     struct    proc *t_rsel;        /* tty */
  70.     struct    proc *t_wsel;
  71.                 caddr_t    T_LINEP;    /* ### */
  72.     caddr_t    t_addr;            /* ??? */
  73.     dev_t    t_dev;            /* device */
  74.     int    t_flags;        /* some of both */
  75.     int    t_state;        /* some of both */
  76.     short    t_pgrp;            /* tty */
  77.     char    t_delct;        /* tty */
  78.     char    t_line;            /* glue */
  79.     char    t_col;            /* tty */
  80.     char    t_ispeed, t_ospeed;    /* device */
  81.     char    t_rocount, t_rocol;    /* tty */
  82.     struct    ttychars t_chars;    /* tty */
  83.     struct    winsize t_winsize;    /* window size */
  84.     int    t_spec[8];        /* cooked mode accelerator */
  85.     void    *t_ldisc_data;        /* for custom line disciplines */
  86. /* be careful of tchars & co. */
  87. #ifndef    NO_T_CHARS_DEFINES
  88. #define    t_erase        t_chars.tc_erase
  89. #define    t_kill        t_chars.tc_kill
  90. #define    t_intrc        t_chars.tc_intrc
  91. #define    t_quitc        t_chars.tc_quitc
  92. #define    t_startc    t_chars.tc_startc
  93. #define    t_stopc        t_chars.tc_stopc
  94. #define    t_eofc        t_chars.tc_eofc
  95. #define    t_brkc        t_chars.tc_brkc
  96. #define    t_suspc        t_chars.tc_suspc
  97. #define    t_dsuspc    t_chars.tc_dsuspc
  98. #define    t_rprntc    t_chars.tc_rprntc
  99. #define    t_flushc    t_chars.tc_flushc
  100. #define    t_werasc    t_chars.tc_werasc
  101. #define    t_lnextc    t_chars.tc_lnextc
  102. #endif    NO_T_CHARS_DEFINES
  103. };
  104.  
  105. #define    TTIPRI    28
  106. #define    TTOPRI    29
  107.  
  108. /* limits */
  109. #define    NSPEEDS    32
  110. #define    TTMASK    31
  111. #define    OBUFSIZ    100
  112. #ifdef KERNEL
  113. short    tthiwat[NSPEEDS], ttlowat[NSPEEDS], tthog[NSPEEDS];
  114. #define    TTHIWAT(tp)    tthiwat[(tp)->t_ospeed&TTMASK]
  115. #define    TTLOWAT(tp)    ttlowat[(tp)->t_ospeed&TTMASK]
  116. #define    TTYHOG(tp)    1024
  117. extern    struct ttychars ttydefaults;
  118. #endif
  119.  
  120. /* internal state bits */
  121. #define    TS_TIMEOUT    0x00000001    /* delay timeout in progress */
  122. #define    TS_WOPEN    0x00000002    /* waiting for open to complete */
  123. #define    TS_ISOPEN    0x00000004    /* device is open */
  124. #define    TS_FLUSH    0x00000008    /* outq has been flushed during DMA */
  125. #define    TS_CARR_ON    0x00000010    /* software copy of carrier-present */
  126. #define    TS_BUSY        0x00000020    /* output in progress */
  127. #define    TS_ASLEEP    0x00000040    /* wakeup when output done */
  128. #define    TS_XCLUDE    0x00000080    /* exclusive-use flag against open */
  129. #define    TS_TTSTOP    0x00000100    /* output stopped by ctl-s */
  130. #define    TS_HUPCLS    0x00000200    /* hang up upon last close */
  131. #define    TS_TBLOCK    0x00000400    /* tandem queue blocked */
  132. #define    TS_RCOLL    0x00000800    /* collision in read select */
  133. #define    TS_WCOLL    0x00001000    /* collision in write select */
  134. #define    TS_NBIO        0x00002000    /* tty in non-blocking mode */
  135. #define    TS_ASYNC    0x00004000    /* tty in async i/o mode */
  136. #define    TS_ONDELAY    0x00008000    /* device is open; software copy of 
  137.                       * carrier is not present */
  138. /* state for intra-line fancy editing work */
  139. #define    TS_BKSL        0x00010000    /* state for lowercase \ work */
  140. #define    TS_QUOT        0x00020000    /* last character input was \ */
  141. #define    TS_ERASE    0x00040000    /* within a \.../ for PRTRUB */
  142. #define    TS_LNCH        0x00080000    /* next character is literal */
  143. #define    TS_TYPEN    0x00100000    /* retyping suspended input (PENDIN) */
  144. #define    TS_CNTTB    0x00200000    /* counting tab width; leave FLUSHO alone */
  145. #define    TS_EXTPROC    0x00400000    /* external processing of data */
  146. #define    TS_INPUTFULL    0x00800000    /* hint to dev to throttle input */
  147. #define    TS_INPUTAVAIL    0x01000000    /* driver has buffered data */
  148. #if    NeXT
  149. #define    TS_OUTPUTBUSY    0x02000000    /* output in progress (was TS_BUSY) */
  150. #define    TS_OUTPUTFULL    0x04000000    /* output buffers full */
  151. #endif    NeXT
  152.  
  153. #define    TS_LOCAL    (TS_BKSL|TS_QUOT|TS_ERASE|TS_LNCH|TS_TYPEN|TS_CNTTB)
  154.  
  155. /* define partab character types */
  156. #define    ORDINARY    0
  157. #define    CONTROL        1
  158. #define    BACKSPACE    2
  159. #define    NEWLINE        3
  160. #define    TAB        4
  161. #define    VTAB        5
  162. #define    RETURN        6
  163.  
  164. /*
  165.  * Flags on character passed to ttyinput
  166.  */
  167. #define TTY_CHARMASK    0x000000ff      /* Character mask */
  168. #define TTY_QUOTE       0x00000100      /* Character quoted */
  169. #define TTY_ERRORMASK   0xff000000      /* Error mask */
  170. #define TTY_FE          0x01000000      /* Framing error or BREAK condition */
  171. #define TTY_PE          0x02000000      /* Parity error */
  172.  
  173. /*
  174.  * Structure for Posix termios
  175.  */
  176. struct nty {
  177.     struct    tty *t;            /* associated tty structure */
  178.     struct nty *t_nforw;        /* link to next nty structure */
  179. #if POSIX_KERN
  180.     struct session *t_session;    /* point to current session */
  181.     struct pgrp *t_posix_pgrp;    /* point to foreground pgrp, if any */
  182. #endif /* POSIX_KERN */
  183.     long    t_pflags;        /* for termios, see below */
  184.     u_char    t_quote;
  185.     u_char    t_min;
  186.     u_char    t_time;
  187. };
  188. struct nty *ttynty();
  189.  
  190.  
  191. #define TP_ECHONL    0x00000002
  192. #define TP_ECHOK    0x00000004
  193. #define TP_ISIG        0x00000008
  194. #define TP_IEXTEN    0x00000010
  195. #define TP_ALTWERASE    0x00000020
  196.  
  197. #define TP_CSIZE    0x00000300
  198. #define TP_CS5        0x00000000
  199. #define TP_CS6        0x00000100
  200. #define TP_CS7        0x00000200
  201. #define TP_CS8        0x00000300
  202. #define TP_CSTOPB    0x00000400
  203. #define TP_CREAD    0x00000800
  204. #define TP_PARENB    0x00001000
  205. #define TP_CLOCAL    0x00008000
  206. #define TP_CSTOPB110    0x00010000
  207.  
  208. #define TP_IGNBRK    0x00020000
  209. #define TP_BRKINT    0x00040000
  210. #define TP_IGNPAR    0x00080000
  211. #define TP_PARMRK    0x00100000
  212. #define TP_INPCK    0x00200000
  213. #define TP_ISTRIP    0x00400000
  214. #define TP_INLCR    0x00800000
  215. #define TP_IGNCR    0x01000000
  216. #define TP_ICRNL    0x02000000
  217. #define TP_IXON        0x04000000
  218. #define TP_IMAXBEL    0x08000000
  219.  
  220. #define TP_OPOST    0x10000000
  221. #define TP_ONLCR    0x20000000
  222.  
  223. /*
  224.  * We don't want TP_ICRNL or TP_ONLCR because we want CRMOD
  225.  * to have the original behavior by default.
  226.  * Most of the other flags are set up for cooked mode.
  227.  * They are overridden by RAW, CBREAK, LITOUT, PASS8, and PASS8OUT.
  228.  * The rest are just compatible behavior.
  229.  */
  230. #define TP_DEFAULT \
  231.     (TP_ECHOK|TP_ISIG|TP_IEXTEN|\
  232.      TP_CS7|TP_CREAD|TP_PARENB|TP_CSTOPB110|\
  233.      TP_BRKINT|TP_INPCK|TP_IXON|TP_IMAXBEL|\
  234.      TP_OPOST)
  235. #define NTYDEFAULTS(np) (\
  236.     (np)->t_pflags = TP_DEFAULT, \
  237.     (np)->t_quote = '\\', \
  238.     (np)->t_min = 1, \
  239.     (np)->t_time = 0)
  240.  
  241. #if POSIX_KERN
  242. #import <sys/proc.h>
  243. /*
  244.  * Is tp controlling terminal for p
  245.  */
  246. #define isctty(p, px, np)   ((px)->p_session == (np)->t_session && \
  247.                          (p)->p_flag&SCTTY)
  248. #endif /* POSIX_KERN */
  249.  
  250. #endif    _SYS_TTY_H_
  251.  
  252.