1: /*      tty.h - Terminals       */
   2: 
   3: #define TTY_IN_BYTES     256    /* tty input queue size */
   4: #define TAB_SIZE           8    /* distance between tab stops */
   5: #define TAB_MASK           7    /* mask to compute a tab stop position */
   6: 
   7: #define ESC             '\33'   /* escape */
   8: 
   9: #define O_NOCTTY       00400    /* from <fcntl.h>, or cc will choke */
  10: #define O_NONBLOCK     04000
  11: 
  12: typedef _PROTOTYPE( void (*devfun_t), (struct tty *tp) );
  13: typedef _PROTOTYPE( void (*devfunarg_t), (struct tty *tp, int c) );
  14: 
  15: typedef struct tty {
  16:   int tty_events;               /* set when TTY should inspect this line */
  17: 
  18:   /* Input queue.  Typed characters are stored here until read by a program. */
  19:   u16_t *tty_inhead;            /* pointer to place where next char goes */
  20:   u16_t *tty_intail;            /* pointer to next char to be given to prog */
  21:   int tty_incount;              /* # chars in the input queue */
  22:   int tty_eotct;                /* number of "line breaks" in input queue */
  23:   devfun_t tty_devread;         /* routine to read from low level buffers */
  24:   devfun_t tty_icancel;         /* cancel any device input */
  25:   int tty_min;                  /* minimum requested #chars in input queue */
  26:   clock_t tty_time;             /* time when the input is available */
  27:   struct tty *tty_timenext;     /* for a list of ttys with active timers */
  28: 
  29:   /* Output section. */
  30:   devfun_t tty_devwrite;        /* routine to start actual device output */
  31:   devfunarg_t tty_echo;         /* routine to echo characters input */
  32:   devfun_t tty_ocancel;         /* cancel any ongoing device output */
  33:   devfun_t tty_break;           /* let the device send a break */
  34: 
  35:   /* Terminal parameters and status. */
  36:   int tty_position;             /* current position on the screen for echoing */
  37:   char tty_reprint;             /* 1 when echoed input messed up, else 0 */
  38:   char tty_escaped;             /* 1 when LNEXT (^V) just seen, else 0 */
  39:   char tty_inhibited;           /* 1 when STOP (^S) just seen (stops output) */
  40:   char tty_pgrp;                /* slot number of controlling process */
  41:   char tty_openct;              /* count of number of opens of this tty */
  42: 
  43:   /* Information about incomplete I/O requests is stored here. */
  44:   char tty_inrepcode;           /* reply code, TASK_REPLY or REVIVE */
  45:   char tty_incaller;            /* process that made the call (usually FS) */
  46:   char tty_inproc;              /* process that wants to read from tty */
  47:   vir_bytes tty_in_vir;         /* virtual address where data is to go */
  48:   int tty_inleft;               /* how many chars are still needed */
  49:   int tty_incum;                /* # chars input so far */
  50:   char tty_outrepcode;          /* reply code, TASK_REPLY or REVIVE */
  51:   char tty_outcaller;           /* process that made the call (usually FS) */
  52:   char tty_outproc;             /* process that wants to write to tty */
  53:   vir_bytes tty_out_vir;        /* virtual address where data comes from */
  54:   int tty_outleft;              /* # chars yet to be output */
  55:   int tty_outcum;               /* # chars output so far */
  56:   char tty_iocaller;            /* process that made the call (usually FS) */
  57:   char tty_ioproc;              /* process that wants to do an ioctl */
  58:   int tty_ioreq;                /* ioctl request code */
  59:   vir_bytes tty_iovir;          /* virtual address of ioctl buffer */
  60: 
  61:   /* Miscellaneous. */
  62:   devfun_t tty_ioctl;           /* set line speed, etc. at the device level */
  63:   devfun_t tty_close;           /* tell the device that the tty is closed */
  64:   void *tty_priv;               /* pointer to per device private data */
  65:   struct termios tty_termios;   /* terminal attributes */
  66:   struct winsize tty_winsize;   /* window size (#lines and #columns) */
  67: 
  68:   u16_t tty_inbuf[TTY_IN_BYTES];/* tty input buffer */
  69: } tty_t;
  70: 
  71: EXTERN tty_t tty_table[NR_CONS+NR_RS_LINES+NR_PTYS];
  72: 
  73: /* Values for the fields. */
  74: #define NOT_ESCAPED        0    /* previous character is not LNEXT (^V) */
  75: #define ESCAPED            1    /* previous character was LNEXT (^V) */
  76: #define RUNNING            0    /* no STOP (^S) has been typed to stop output */
  77: #define STOPPED            1    /* STOP (^S) has been typed to stop output */
  78: 
  79: /* Fields and flags on characters in the input queue. */
  80: #define IN_CHAR       0x00FF    /* low 8 bits are the character itself */
  81: #define IN_LEN        0x0F00    /* length of char if it has been echoed */
  82: #define IN_LSHIFT          8    /* length = (c & IN_LEN) >> IN_LSHIFT */
  83: #define IN_EOT        0x1000    /* char is a line break (^D, LF) */
  84: #define IN_EOF        0x2000    /* char is EOF (^D), do not return to user */
  85: #define IN_ESC        0x4000    /* escaped by LNEXT (^V), no interpretation */
  86: 
  87: /* Times and timeouts. */
  88: #define TIME_NEVER      ((clock_t) -1 < 0 ? (clock_t) LONG_MAX : (clock_t) -1)
  89: #define force_timeout() ((void) (tty_timeout = 0))
  90: 
  91: EXTERN tty_t *tty_timelist;     /* list of ttys with active timers */
  92: 
  93: /* Number of elements and limit of a buffer. */
  94: #define buflen(buf)     (sizeof(buf) / sizeof((buf)[0]))
  95: #define bufend(buf)     ((buf) + buflen(buf))