home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / TERMNET / READLINE.0 / RLTTY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-20  |  16.0 KB  |  698 lines

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