home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / nindy-share / ttycntl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  3.7 KB  |  117 lines

  1. /******************************************************************************
  2.  * Copyright 1990, 1992 Free Software Foundation, Inc.
  3.  *
  4.  * This code was donated by Intel Corp.
  5.  *
  6.  * This include file provides BSD/USG-compatible tty control for a host utility
  7.  * that interacts with NINDY.  As of this writing, it is used by the gdb960
  8.  * remote communications module (remote.c) and the comm960 utility.
  9.  * 
  10.  * It is assumed that 'USG' is defined on the compiler invocation line if the
  11.  * code should compile and run on a USG/SysV system.  Otherwise, BSD is assumed.
  12.  *
  13.  * The application code has access to these macros:
  14.  *
  15.  *    TTY_STRUCT    Data type used by tty functions (ioctls and the
  16.  *            following macros).
  17.  *
  18.  *    TTY_NINDYTERM(tty)
  19.  *            'tty' is assumed to be a TTY_STRUCT describing the
  20.  *            terminal.  It is modified as appropriate to allow
  21.  *            all user input to be passed through unmodified to NINDY
  22.  *            as soon as it is typed, and to allow all NINDY output
  23.  *            to be passed through unmodified to the display as soon
  24.  *            as it is received.
  25.  *
  26.  *    TTY_REMOTE(tty,baud)
  27.  *            'tty' is assumed to be a TTY_STRUCT describing the
  28.  *            serial connection between the host and NINDY.  It is
  29.  *            initialized as appropriate to allow communications
  30.  *            between the host and NINDY at the specified baud rate
  31.  *            (which must be one of the "B..." defined constants).
  32.  *
  33.  *    TTY_FLUSH(fd)    flush all pending input and output on the tty whose
  34.  *            file descriptor is 'fd'.
  35.  *
  36.  *    TTY_NBREAD(fd,n,bufptr)
  37.  *            Performs non-blocking read of 'n' characters on the
  38.  *            file descriptor 'fd'.  Sets the integer 'n' to the
  39.  *            number of characters actually read.  The characters
  40.  *            are read into the buffer pointed at by bufptr.
  41.  *
  42.  * In addition, the BSD ioctl commands TIOCGETP and TIOCSETP are defined to
  43.  * have the same meanings under USG: retrieve and set (respectively) the
  44.  * parameters of a tty.
  45.  ******************************************************************************/
  46.  
  47. #ifdef USG
  48.  
  49. #    include <termio.h>
  50. #    define TTY_STRUCT    struct termio
  51. #    define TIOCGETP        TCGETA
  52. #    define TIOCSETP        TCSETAF
  53.  
  54.     /* NOTE!:
  55.      *    Remove CLOCAL from following macro if you will be accessing
  56.      *    the i960 system via a modem.
  57.      */
  58. #       define TTY_REMOTE(tty,baud) {                   \
  59.                 tty.c_iflag = IXON | IXOFF;             \
  60.                 tty.c_oflag = 0;                        \
  61.                 tty.c_cflag = baud|CS8|CREAD|CLOCAL;    \
  62.                 tty.c_lflag = 0;                        \
  63.                 tty.c_cc[VEOF] = 1;                     \
  64.                 tty.c_cc[VEOL] = 0;                     \
  65.         }
  66.  
  67. #    define TTY_NINDYTERM(tty) {        \
  68.         tty.c_iflag = 0;        \
  69.         tty.c_oflag = 0;        \
  70.         tty.c_lflag = ISIG;        \
  71.         tty.c_cc[VEOF] = 1;        \
  72.         tty.c_cc[VEOL] = 0;        \
  73.     }
  74.  
  75. #    define TTY_FLUSH(fd)    ioctl(fd,TCFLSH,2);
  76.  
  77. #       define TTY_NBREAD(fd,n,bufptr) {            \
  78.         int _saveflags_;                \
  79.         _saveflags_ = fcntl( fd, F_GETFL, 0 );        \
  80.         fcntl( fd, F_SETFL, _saveflags_ | O_NDELAY );    \
  81.         n = read( fd, bufptr, n );            \
  82.         fcntl( fd, F_SETFL, _saveflags_ );        \
  83.     }
  84.  
  85. #else    /* BSD */
  86.  
  87. #    include <sys/ioctl.h>
  88. #    define TTY_STRUCT    struct sgttyb
  89. #       define TTY_REMOTE(tty,baud){            \
  90.                 tty.sg_flags = RAW | TANDEM;    \
  91.                 tty.sg_ispeed = baud;           \
  92.                 tty.sg_ospeed = baud;           \
  93.         }
  94.  
  95. #    define TTY_NINDYTERM(tty)    {    \
  96.         tty.sg_flags |= CBREAK;        \
  97.         tty.sg_flags &= ~(ECHO|CRMOD);    \
  98.     }
  99.  
  100. #    define TTY_FLUSH(fd)    { int _i_ = 0; ioctl(fd,TIOCFLUSH,&_i_); }
  101.  
  102. #       define TTY_NBREAD(fd,n,bufptr) {        \
  103.         int _n_;                \
  104.         ioctl(fd,FIONREAD,&_n_);        \
  105.         n = (_n_>0) ? read(fd,bufptr,n) : 0;    \
  106.     }
  107. #endif
  108.  
  109.  
  110.  
  111. #ifndef B19200
  112. #    define B19200 EXTA
  113. #endif
  114. #ifndef B38400
  115. #    define B38400 EXTB
  116. #endif
  117.