home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / readline / rltty.c < prev    next >
C/C++ Source or Header  |  2000-01-15  |  18KB  |  753 lines

  1. /* Modified by Klaus Gebhardt, October 1996 */
  2. /* rltty.c -- functions to prepare and restore the terminal for readline's
  3.    use. */
  4.  
  5. /* Copyright (C) 1992 Free Software Foundation, Inc.
  6.  
  7.    This file is part of the GNU Readline Library, a library for
  8.    reading lines of text with interactive input and history editing.
  9.  
  10.    The GNU Readline Library is free software; you can redistribute it
  11.    and/or modify it under the terms of the GNU General Public License
  12.    as published by the Free Software Foundation; either version 1, or
  13.    (at your option) any later version.
  14.  
  15.    The GNU Readline Library is distributed in the hope that it will be
  16.    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  17.    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.    GNU General Public License for more details.
  19.  
  20.    The GNU General Public License is often shipped with GNU software, and
  21.    is generally kept in a file called COPYING or LICENSE.  If you do not
  22.    have a copy of the license, write to the Free Software Foundation,
  23.    675 Mass Ave, Cambridge, MA 02139, USA. */
  24.  
  25. /* Modified by Klaus Gebhardt, 1998 */
  26.  
  27. #define READLINE_LIBRARY
  28.  
  29. #if defined (HAVE_CONFIG_H)
  30. #  include <config.h>
  31. #endif
  32.  
  33. #include <sys/types.h>
  34. #include <signal.h>
  35. #include <errno.h>
  36. #include <stdio.h>
  37.  
  38. #if defined (__EMX__)
  39. #include <sys/termio.h>
  40. #endif
  41.  
  42. #if defined (HAVE_UNISTD_H)
  43. #  include <unistd.h>
  44. #endif /* HAVE_UNISTD_H */
  45.  
  46. #include "rldefs.h"
  47.  
  48. #if !defined (SHELL) && defined (GWINSZ_IN_SYS_IOCTL)
  49. #  include <sys/ioctl.h>
  50. #endif /* !SHELL && GWINSZ_IN_SYS_IOCTL */
  51.  
  52. #include "rltty.h"
  53. #include "readline.h"
  54.  
  55. #if !defined (errno)
  56. extern int errno;
  57. #endif /* !errno */
  58.  
  59. extern int readline_echoing_p;
  60. extern int _rl_eof_char;
  61.  
  62. extern int _rl_enable_keypad, _rl_enable_meta;
  63.  
  64. extern void _rl_control_keypad ();
  65.  
  66. #if defined (__GO32__)
  67. #  include <pc.h>
  68. #  undef HANDLE_SIGNALS
  69. #endif /* __GO32__ */
  70.  
  71. /* Indirect functions to allow apps control over terminal management. */
  72. extern void rl_prep_terminal (), rl_deprep_terminal ();
  73.  
  74. VFunction *rl_prep_term_function = rl_prep_terminal;
  75. VFunction *rl_deprep_term_function = rl_deprep_terminal;
  76.  
  77. /* **************************************************************** */
  78. /*                                    */
  79. /*               Signal Management                */
  80. /*                                    */
  81. /* **************************************************************** */
  82.  
  83. #if defined (HAVE_POSIX_SIGNALS)
  84. static sigset_t sigint_set, sigint_oset;
  85. #else /* !HAVE_POSIX_SIGNALS */
  86. #  if defined (HAVE_BSD_SIGNALS)
  87. static int sigint_oldmask;
  88. #  endif /* HAVE_BSD_SIGNALS */
  89. #endif /* !HAVE_POSIX_SIGNALS */
  90.  
  91. static int sigint_blocked;
  92.  
  93. /* Cause SIGINT to not be delivered until the corresponding call to
  94.    release_sigint(). */
  95. static void
  96. block_sigint ()
  97. {
  98.   if (sigint_blocked)
  99.     return;
  100.  
  101. #if defined (__EMX__)
  102.   sigemptyset (&sigint_set);
  103.   sigemptyset (&sigint_oset);
  104.   sigaddset (&sigint_set, SIGINT);
  105.   sigaddset (&sigint_set, SIGBREAK);
  106.   sigprocmask (SIG_BLOCK, &sigint_set, &sigint_oset);
  107. #else
  108. #if defined (HAVE_POSIX_SIGNALS)
  109.   sigemptyset (&sigint_set);
  110.   sigemptyset (&sigint_oset);
  111.   sigaddset (&sigint_set, SIGINT);
  112.   sigprocmask (SIG_BLOCK, &sigint_set, &sigint_oset);
  113. #else /* !HAVE_POSIX_SIGNALS */
  114. #  if defined (HAVE_BSD_SIGNALS)
  115.   sigint_oldmask = sigblock (sigmask (SIGINT));
  116. #  else /* !HAVE_BSD_SIGNALS */
  117. #    if defined (HAVE_USG_SIGHOLD)
  118.   sighold (SIGINT);
  119. #    endif /* HAVE_USG_SIGHOLD */
  120. #  endif /* !HAVE_BSD_SIGNALS */
  121. #endif /* !HAVE_POSIX_SIGNALS */
  122. #endif
  123.  
  124.   sigint_blocked = 1;
  125. }
  126.  
  127. /* Allow SIGINT to be delivered. */
  128. static void
  129. release_sigint ()
  130. {
  131.   if (!sigint_blocked)
  132.     return;
  133.  
  134. #if defined (__EMX__)
  135.   sigprocmask (SIG_SETMASK, &sigint_oset, (sigset_t *)NULL);
  136. #else
  137. #if defined (HAVE_POSIX_SIGNALS)
  138.   sigprocmask (SIG_SETMASK, &sigint_oset, (sigset_t *)NULL);
  139. #else
  140. #  if defined (HAVE_BSD_SIGNALS)
  141.   sigsetmask (sigint_oldmask);
  142. #  else /* !HAVE_BSD_SIGNALS */
  143. #    if defined (HAVE_USG_SIGHOLD)
  144.   sigrelse (SIGINT);
  145. #    endif /* HAVE_USG_SIGHOLD */
  146. #  endif /* !HAVE_BSD_SIGNALS */
  147. #endif /* !HAVE_POSIX_SIGNALS */
  148. #endif
  149.  
  150.   sigint_blocked = 0;
  151. }
  152.  
  153. /* **************************************************************** */
  154. /*                                    */
  155. /*              Saving and Restoring the TTY                */
  156. /*                                    */
  157. /* **************************************************************** */
  158.  
  159. /* Non-zero means that the terminal is in a prepped state. */
  160. static int terminal_prepped;
  161.  
  162. /* If non-zero, means that this process has called tcflow(fd, TCOOFF)
  163.    and output is suspended. */
  164. #if defined (__ksr1__)
  165. static int ksrflow;
  166. #endif
  167.  
  168. #if !defined (SHELL) && defined (TIOCGWINSZ)
  169. /* Dummy call to force a backgrounded readline to stop before it tries
  170.    to get the tty settings. */
  171. static void
  172. set_winsize (tty)
  173.      int tty;
  174. {
  175.   struct winsize w;
  176.  
  177.   if (ioctl (tty, TIOCGWINSZ, &w) == 0)
  178.       (void) ioctl (tty, TIOCSWINSZ, &w);
  179. }
  180. #else /* SHELL || !TIOCGWINSZ */
  181. #  define set_winsize(tty)
  182. #endif /* SHELL || !TIOCGWINSZ */
  183.  
  184. #if defined (NEW_TTY_DRIVER)
  185.  
  186. /* Values for the `flags' field of a struct bsdtty.  This tells which
  187.    elements of the struct bsdtty have been fetched from the system and
  188.    are valid. */
  189. #define SGTTY_SET    0x01
  190. #define LFLAG_SET    0x02
  191. #define TCHARS_SET    0x04
  192. #define LTCHARS_SET    0x08
  193.  
  194. struct bsdtty {
  195.   struct sgttyb sgttyb;    /* Basic BSD tty driver information. */
  196.   int lflag;        /* Local mode flags, like LPASS8. */
  197. #if defined (TIOCGETC)
  198.   struct tchars tchars;    /* Terminal special characters, including ^S and ^Q. */
  199. #endif
  200. #if defined (TIOCGLTC)
  201.   struct ltchars ltchars; /* 4.2 BSD editing characters */
  202. #endif
  203.   int flags;        /* Bitmap saying which parts of the struct are valid. */
  204. };
  205.  
  206. #define TIOTYPE struct bsdtty
  207.  
  208. static TIOTYPE otio;
  209.  
  210. static int
  211. get_tty_settings (tty, tiop)
  212.      int tty;
  213.      TIOTYPE *tiop;
  214. {
  215.   set_winsize (tty);
  216.  
  217.   tiop->flags = tiop->lflag = 0;
  218.  
  219.   ioctl (tty, TIOCGETP, &(tiop->sgttyb));
  220.   tiop->flags |= SGTTY_SET;
  221.  
  222. #if defined (TIOCLGET)
  223.   ioctl (tty, TIOCLGET, &(tiop->lflag));
  224.   tiop->flags |= LFLAG_SET;
  225. #endif
  226.  
  227. #if defined (TIOCGETC)
  228.   ioctl (tty, TIOCGETC, &(tiop->tchars));
  229.   tiop->flags |= TCHARS_SET;
  230. #endif
  231.  
  232. #if defined (TIOCGLTC)
  233.   ioctl (tty, TIOCGLTC, &(tiop->ltchars));
  234.   tiop->flags |= LTCHARS_SET;
  235. #endif
  236.  
  237.   return 0;
  238. }
  239.  
  240. static int
  241. set_tty_settings (tty, tiop)
  242.      int tty;
  243.      TIOTYPE *tiop;
  244. {
  245.   if (tiop->flags & SGTTY_SET)
  246.     {
  247.       ioctl (tty, TIOCSETN, &(tiop->sgttyb));
  248.       tiop->flags &= ~SGTTY_SET;
  249.     }
  250.   readline_echoing_p = 1;
  251.  
  252. #if defined (TIOCLSET)
  253.   if (tiop->flags & LFLAG_SET)
  254.     {
  255.       ioctl (tty, TIOCLSET, &(tiop->lflag));
  256.       tiop->flags &= ~LFLAG_SET;
  257.     }
  258. #endif
  259.  
  260. #if defined (TIOCSETC)
  261.   if (tiop->flags & TCHARS_SET)
  262.     {
  263.       ioctl (tty, TIOCSETC, &(tiop->tchars));
  264.       tiop->flags &= ~TCHARS_SET;
  265.     }
  266. #endif
  267.  
  268. #if defined (TIOCSLTC)
  269.   if (tiop->flags & LTCHARS_SET)
  270.     {
  271.       ioctl (tty, TIOCSLTC, &(tiop->ltchars));
  272.       tiop->flags &= ~LTCHARS_SET;
  273.     }
  274. #endif
  275.  
  276.   return 0;
  277. }
  278.  
  279. static void
  280. prepare_terminal_settings (meta_flag, otio, tiop)
  281.      int meta_flag;
  282.      TIOTYPE otio, *tiop;
  283. {
  284. #if !defined (__GO32__)
  285.   readline_echoing_p = (otio.sgttyb.sg_flags & ECHO);
  286.  
  287.   /* Copy the original settings to the structure we're going to use for
  288.      our settings. */
  289.   tiop->sgttyb = otio.sgttyb;
  290.   tiop->lflag = otio.lflag;
  291. #if defined (TIOCGETC)
  292.   tiop->tchars = otio.tchars;
  293. #endif
  294. #if defined (TIOCGLTC)
  295.   tiop->ltchars = otio.ltchars;
  296. #endif
  297.   tiop->flags = otio.flags;
  298.  
  299.   /* First, the basic settings to put us into character-at-a-time, no-echo
  300.      input mode. */
  301.   tiop->sgttyb.sg_flags &= ~(ECHO | CRMOD);
  302.   tiop->sgttyb.sg_flags |= CBREAK;
  303.  
  304.   /* If this terminal doesn't care how the 8th bit is used, then we can
  305.      use it for the meta-key.  If only one of even or odd parity is
  306.      specified, then the terminal is using parity, and we cannot. */
  307. #if !defined (ANYP)
  308. #  define ANYP (EVENP | ODDP)
  309. #endif
  310.   if (((otio.sgttyb.sg_flags & ANYP) == ANYP) ||
  311.       ((otio.sgttyb.sg_flags & ANYP) == 0))
  312.     {
  313.       tiop->sgttyb.sg_flags |= ANYP;
  314.  
  315.       /* Hack on local mode flags if we can. */
  316. #if defined (TIOCLGET)
  317. #  if defined (LPASS8)
  318.       tiop->lflag |= LPASS8;
  319. #  endif /* LPASS8 */
  320. #endif /* TIOCLGET */
  321.     }
  322.  
  323. #if defined (TIOCGETC)
  324. #  if defined (USE_XON_XOFF)
  325.   /* Get rid of terminal output start and stop characters. */
  326.   tiop->tchars.t_stopc = -1; /* C-s */
  327.   tiop->tchars.t_startc = -1; /* C-q */
  328.  
  329.   /* If there is an XON character, bind it to restart the output. */
  330.   if (otio.tchars.t_startc != -1)
  331.     rl_bind_key (otio.tchars.t_startc, rl_restart_output);
  332. #  endif /* USE_XON_XOFF */
  333.  
  334.   /* If there is an EOF char, bind _rl_eof_char to it. */
  335.   if (otio.tchars.t_eofc != -1)
  336.     _rl_eof_char = otio.tchars.t_eofc;
  337.  
  338. #  if defined (NO_KILL_INTR)
  339.   /* Get rid of terminal-generated SIGQUIT and SIGINT. */
  340.   tiop->tchars.t_quitc = -1; /* C-\ */
  341.   tiop->tchars.t_intrc = -1; /* C-c */
  342. #  endif /* NO_KILL_INTR */
  343. #endif /* TIOCGETC */
  344.  
  345. #if defined (TIOCGLTC)
  346.   /* Make the interrupt keys go away.  Just enough to make people happy. */
  347.   tiop->ltchars.t_dsuspc = -1;    /* C-y */
  348.   tiop->ltchars.t_lnextc = -1;    /* C-v */
  349. #endif /* TIOCGLTC */
  350. #endif /* !__GO32__ */
  351. }
  352.  
  353. #else  /* !defined (NEW_TTY_DRIVER) */
  354.  
  355. #if !defined (VMIN)
  356. #  define VMIN VEOF
  357. #endif
  358.  
  359. #if !defined (VTIME)
  360. #  define VTIME VEOL
  361. #endif
  362.  
  363. #if defined (TERMIOS_TTY_DRIVER)
  364. #  define TIOTYPE struct termios
  365. #  define DRAIN_OUTPUT(fd)    tcdrain (fd)
  366. #  define GETATTR(tty, tiop)    (tcgetattr (tty, tiop))
  367. #  ifdef M_UNIX
  368. #    define SETATTR(tty, tiop)    (tcsetattr (tty, TCSANOW, tiop))
  369. #  else
  370. #    define SETATTR(tty, tiop)    (tcsetattr (tty, TCSADRAIN, tiop))
  371. #  endif /* !M_UNIX */
  372. #else
  373. #  define TIOTYPE struct termio
  374. #  define DRAIN_OUTPUT(fd)
  375. #  define GETATTR(tty, tiop)    (ioctl (tty, TCGETA, tiop))
  376. #  define SETATTR(tty, tiop)    (ioctl (tty, TCSETA, tiop))
  377. #endif /* !TERMIOS_TTY_DRIVER */
  378.  
  379. static TIOTYPE otio;
  380.  
  381. #if defined (FLUSHO)
  382. #  define OUTPUT_BEING_FLUSHED(tp)  (tp->c_lflag & FLUSHO)
  383. #else
  384. #  define OUTPUT_BEING_FLUSHED(tp)  0
  385. #endif
  386.  
  387. static void
  388. rltty_warning (msg)
  389.      char *msg;
  390. {
  391.   fprintf (stderr, "readline: warning: %s\n", msg);
  392. }
  393.  
  394. #if defined (_AIX)
  395. void
  396. setopost(tp)
  397. TIOTYPE *tp;
  398. {
  399.   if ((tp->c_oflag & OPOST) == 0)
  400.     {
  401.       rltty_warning ("turning on OPOST for terminal\r");
  402.       tp->c_oflag |= OPOST|ONLCR;
  403.     }
  404. }
  405. #endif
  406.  
  407. static int
  408. get_tty_settings (tty, tiop)
  409.      int tty;
  410.      TIOTYPE *tiop;
  411. {
  412.   int ioctl_ret;
  413.   set_winsize (tty);
  414.  
  415.   while (1)
  416.     {
  417.       ioctl_ret = GETATTR (tty, tiop);
  418.       if (ioctl_ret < 0)
  419.     {
  420.       if (errno != EINTR)
  421.         return -1;
  422.       else
  423.         continue;
  424.     }
  425.       if (OUTPUT_BEING_FLUSHED (tiop))
  426.     {
  427. #if defined (FLUSHO) && defined (_AIX41)
  428.       rltty_warning ("turning off output flushing");
  429.       tiop->c_lflag &= ~FLUSHO;
  430.       break;
  431. #else
  432.       continue;
  433. #endif
  434.     }
  435.       break;
  436.     }
  437.  
  438. #if defined (_AIX)
  439.   setopost(tiop);
  440. #endif
  441.  
  442.   return 0;
  443. }
  444.  
  445. static int
  446. set_tty_settings (tty, tiop)
  447.      int tty;
  448.      TIOTYPE *tiop;
  449. {
  450.   while (SETATTR (tty, tiop) < 0)
  451.     {
  452.       if (errno != EINTR)
  453.     return -1;
  454.       errno = 0;
  455.     }
  456.  
  457. #if 0
  458.  
  459. #if defined (TERMIOS_TTY_DRIVER)
  460. #  if defined (__ksr1__)
  461.   if (ksrflow)
  462.     {
  463.       ksrflow = 0;
  464.       tcflow (tty, TCOON);
  465.     }
  466. #  else /* !ksr1 */
  467.   tcflow (tty, TCOON);        /* Simulate a ^Q. */
  468. #  endif /* !ksr1 */
  469. #else
  470.   ioctl (tty, TCXONC, 1);    /* Simulate a ^Q. */
  471. #endif /* !TERMIOS_TTY_DRIVER */
  472.  
  473. #endif
  474.  
  475.   return 0;
  476. }
  477.  
  478. static void
  479. prepare_terminal_settings (meta_flag, otio, tiop)
  480.      int meta_flag;
  481.      TIOTYPE otio, *tiop;
  482. {
  483.   readline_echoing_p = (otio.c_lflag & ECHO);
  484.  
  485. #if defined (__EMX__)
  486.   tiop->c_lflag &= ~IDEFAULT;
  487. #endif /* __EMX__ */
  488.   tiop->c_lflag &= ~(ICANON | ECHO);
  489.  
  490.   if ((unsigned char) otio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE)
  491.     _rl_eof_char = otio.c_cc[VEOF];
  492.  
  493. #if defined (USE_XON_XOFF)
  494. #if defined (IXANY)
  495.   tiop->c_iflag &= ~(IXON | IXOFF | IXANY);
  496. #else
  497.   /* `strict' Posix systems do not define IXANY. */
  498.   tiop->c_iflag &= ~(IXON | IXOFF);
  499. #endif /* IXANY */
  500. #endif /* USE_XON_XOFF */
  501.  
  502.   /* Only turn this off if we are using all 8 bits. */
  503.   if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag)
  504.     tiop->c_iflag &= ~(ISTRIP | INPCK);
  505.  
  506.   /* Make sure we differentiate between CR and NL on input. */
  507.   tiop->c_iflag &= ~(ICRNL | INLCR);
  508.  
  509. #if !defined (HANDLE_SIGNALS)
  510.   tiop->c_lflag &= ~ISIG;
  511. #else
  512.   tiop->c_lflag |= ISIG;
  513. #endif
  514.  
  515.   tiop->c_cc[VMIN] = 1;
  516.   tiop->c_cc[VTIME] = 0;
  517.  
  518. #if defined (FLUSHO)
  519.   if (OUTPUT_BEING_FLUSHED (tiop))
  520.     {
  521.       tiop->c_lflag &= ~FLUSHO;
  522.       otio.c_lflag &= ~FLUSHO;
  523.     }
  524. #endif
  525.  
  526.   /* Turn off characters that we need on Posix systems with job control,
  527.      just to be sure.  This includes ^Y and ^V.  This should not really
  528.      be necessary.  */
  529. #if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE)
  530.  
  531. #if defined (VLNEXT)
  532.   tiop->c_cc[VLNEXT] = _POSIX_VDISABLE;
  533. #endif
  534.  
  535. #if defined (VDSUSP)
  536.   tiop->c_cc[VDSUSP] = _POSIX_VDISABLE;
  537. #endif
  538.  
  539. #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */
  540. }
  541. #endif  /* NEW_TTY_DRIVER */
  542.  
  543. /* Put the terminal in CBREAK mode so that we can detect key presses. */
  544. void
  545. rl_prep_terminal (meta_flag)
  546.      int meta_flag;
  547. {
  548. #if !defined (__GO32__)
  549.   int tty;
  550.   TIOTYPE tio;
  551.  
  552.   if (terminal_prepped)
  553.     return;
  554.  
  555.   /* Try to keep this function from being INTerrupted. */
  556.   block_sigint ();
  557.  
  558.   tty = fileno (rl_instream);
  559.  
  560.   if (get_tty_settings (tty, &tio) < 0)
  561.     {
  562.       release_sigint ();
  563.       return;
  564.     }
  565.  
  566.   otio = tio;
  567.  
  568.   prepare_terminal_settings (meta_flag, otio, &tio);
  569.  
  570.   if (set_tty_settings (tty, &tio) < 0)
  571.     {
  572.       release_sigint ();
  573.       return;
  574.     }
  575.  
  576.   if (_rl_enable_keypad)
  577.     _rl_control_keypad (1);
  578.  
  579.   fflush (rl_outstream);
  580.   terminal_prepped = 1;
  581.  
  582.   release_sigint ();
  583. #endif /* !__GO32__ */
  584. }
  585.  
  586. /* Restore the terminal's normal settings and modes. */
  587. void
  588. rl_deprep_terminal ()
  589. {
  590. #if !defined (__GO32__)
  591.   int tty;
  592.  
  593.   if (!terminal_prepped)
  594.     return;
  595.  
  596.   /* Try to keep this function from being interrupted. */
  597.   block_sigint ();
  598.  
  599.   tty = fileno (rl_instream);
  600.  
  601.   if (_rl_enable_keypad)
  602.     _rl_control_keypad (0);
  603.  
  604.   fflush (rl_outstream);
  605.  
  606.   if (set_tty_settings (tty, &otio) < 0)
  607.     {
  608.       release_sigint ();
  609.       return;
  610.     }
  611.  
  612.   terminal_prepped = 0;
  613.  
  614.   release_sigint ();
  615. #endif /* !__GO32__ */
  616. }
  617.  
  618. /* **************************************************************** */
  619. /*                                    */
  620. /*            Bogus Flow Control                  */
  621. /*                                    */
  622. /* **************************************************************** */
  623.  
  624. int
  625. rl_restart_output (count, key)
  626.      int count, key;
  627. {
  628.   int fildes = fileno (rl_outstream);
  629. #if defined (TIOCSTART)
  630. #if defined (apollo)
  631.   ioctl (&fildes, TIOCSTART, 0);
  632. #else
  633.   ioctl (fildes, TIOCSTART, 0);
  634. #endif /* apollo */
  635.  
  636. #else /* !TIOCSTART */
  637. #  if defined (TERMIOS_TTY_DRIVER)
  638. #    if defined (__ksr1__)
  639.   if (ksrflow)
  640.     {
  641.       ksrflow = 0;
  642.       tcflow (fildes, TCOON);
  643.     }
  644. #    else /* !ksr1 */
  645.   tcflow (fildes, TCOON);        /* Simulate a ^Q. */
  646. #    endif /* !ksr1 */
  647. #  else /* !TERMIOS_TTY_DRIVER */
  648. #    if defined (TCXONC)
  649.   ioctl (fildes, TCXONC, TCOON);
  650. #    endif /* TCXONC */
  651. #  endif /* !TERMIOS_TTY_DRIVER */
  652. #endif /* !TIOCSTART */
  653.  
  654.   return 0;
  655. }
  656.  
  657. int
  658. rl_stop_output (count, key)
  659.      int count, key;
  660. {
  661.   int fildes = fileno (rl_instream);
  662.  
  663. #if defined (TIOCSTOP)
  664. # if defined (apollo)
  665.   ioctl (&fildes, TIOCSTOP, 0);
  666. # else
  667.   ioctl (fildes, TIOCSTOP, 0);
  668. # endif /* apollo */
  669. #else /* !TIOCSTOP */
  670. # if defined (TERMIOS_TTY_DRIVER)
  671. #  if defined (__ksr1__)
  672.   ksrflow = 1;
  673. #  endif /* ksr1 */
  674.   tcflow (fildes, TCOOFF);
  675. # else
  676. #   if defined (TCXONC)
  677.   ioctl (fildes, TCXONC, TCOON);
  678. #   endif /* TCXONC */
  679. # endif /* !TERMIOS_TTY_DRIVER */
  680. #endif /* !TIOCSTOP */
  681.  
  682.   return 0;
  683. }
  684.  
  685. /* **************************************************************** */
  686. /*                                    */
  687. /*            Default Key Bindings                */
  688. /*                                    */
  689. /* **************************************************************** */
  690. void
  691. rltty_set_default_bindings (kmap)
  692.      Keymap kmap;
  693. {
  694.   TIOTYPE ttybuff;
  695.   int tty = fileno (rl_instream);
  696.  
  697. #if defined (NEW_TTY_DRIVER)
  698.  
  699. #define SET_SPECIAL(sc, func) \
  700.   do \
  701.     { \
  702.       int ic; \
  703.       ic = sc; \
  704.       if (ic != -1 && kmap[ic].type == ISFUNC) \
  705.     kmap[ic].function = func; \
  706.     } \
  707.   while (0)
  708.  
  709.   if (get_tty_settings (tty, &ttybuff) == 0)
  710.     {
  711.       if (ttybuff.flags & SGTTY_SET)
  712.     {
  713.       SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout);
  714.       SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard);
  715.     }
  716.  
  717. #  if defined (TIOCGLTC)
  718.       if (ttybuff.flags & LTCHARS_SET)
  719.     {
  720.       SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout);
  721.       SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert);
  722.     }
  723. #  endif /* TIOCGLTC */
  724.     }
  725.  
  726. #else /* !NEW_TTY_DRIVER */
  727.  
  728. #define SET_SPECIAL(sc, func) \
  729.   do \
  730.     { \
  731.       unsigned char uc; \
  732.       uc = ttybuff.c_cc[sc]; \
  733.       if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \
  734.     kmap[uc].function = func; \
  735.     } \
  736.   while (0)
  737.  
  738.   if (get_tty_settings (tty, &ttybuff) == 0)
  739.     {
  740.       SET_SPECIAL (VERASE, rl_rubout);
  741.       SET_SPECIAL (VKILL, rl_unix_line_discard);
  742.  
  743. #  if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)
  744.       SET_SPECIAL (VLNEXT, rl_quoted_insert);
  745. #  endif /* VLNEXT && TERMIOS_TTY_DRIVER */
  746.  
  747. #  if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
  748.       SET_SPECIAL (VWERASE, rl_unix_word_rubout);
  749. #  endif /* VWERASE && TERMIOS_TTY_DRIVER */
  750.     }
  751. #endif /* !NEW_TTY_DRIVER */
  752. }
  753.