/****************************************************************************
 *
 * $Source: /usr/local/cvsroot/unixlib/source/clib/sys/h/tty,v $
 * $Date: 1997/12/17 22:02:53 $
 * $Revision: 1.6 $
 * $State: Exp $
 * $Author: unixlib $
 *
 ***************************************************************************/

#ifndef __SYS_TTY_H
#define __SYS_TTY_H

#ifndef __TERMIOS_H
#include <termios.h>
#endif

#ifndef __SYS_IOCTL_H
#include <sys/ioctl.h>
#endif

#define __TTY_STATIC_BUFS

#ifdef __TTY_STATIC_BUFS
/* #error static tty bufs not implemented completely */
#ifndef __SYS_PARAM_H
#include <sys/param.h>
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

#define MAXTTY	2

#define TTY_CON 0
#define TTY_423 1

struct tty
  {
  struct termios t[1];
  struct winsize w[1];
  int (*out) (int);
  int (*in) (void);
  int (*scan) (int);
  int (*init) (void);
  int (*flush) (void);
#ifdef __TTY_STATIC_BUFS
  int sx,cx;		/* screen x, character x */
  int cnt;		/* number of characters in input buffer */
  char *ptr;		/* read pointer in input buffer */
  char buf[MAX_INPUT];  /* input buffer */
  char del[MAX_INPUT];  /* number of displayed characters for character cx */
#else
  char *buf, *ptr;
  int cnt;		/* number of characters in input buffer */
  char *del;
  int sx,cx;		/* screen x, character x */
#endif
  int lookahead;	/* [1 byte or -1] lookahead to allow select() */
  };

/* Note, the buf and del buffers are declared statically in the tty struct.
   This is so that an exec'd process which shares the tty struct doesn't
   free something allocated by the parent process.  Such a call to free would
   confuse the memory allocation system since the buffer wouldn't have been
   allocated by that process but by the parent process.  We could check the
   address of the buffer against __lomem and __break, but we might aswell
   just live with the statically allocated memory compared to the extra code
   we would need to have.  Lazy, probably, but it works okay and only costs
   MAXTTY * MAX_INPUT * 2 (= 1024 bytes in current implementation).  */

#ifdef __cplusplus
	}
#endif

#endif
