diff options
author | Chet Ramey <chet.ramey@case.edu> | 2011-11-23 18:44:58 -0500 |
---|---|---|
committer | Chet Ramey <chet.ramey@case.edu> | 2011-11-23 18:44:58 -0500 |
commit | fe34a312c8be645944828402351bd1192972586b (patch) | |
tree | ca2a8dae3e43cc5d8ee1d96b6252255eecd866ff /rltty.c | |
parent | 06cd36cdc90634c88636a6d09230c573078ead0e (diff) | |
download | readline-fe34a312c8be645944828402351bd1192972586b.tar.gz |
Readline-2.1 import
Diffstat (limited to 'rltty.c')
-rw-r--r-- | rltty.c | 195 |
1 files changed, 113 insertions, 82 deletions
@@ -22,6 +22,10 @@ 675 Mass Ave, Cambridge, MA 02139, USA. */ #define READLINE_LIBRARY +#if defined (HAVE_CONFIG_H) +# include <config.h> +#endif + #include <sys/types.h> #include <signal.h> #include <errno.h> @@ -32,6 +36,12 @@ #endif /* HAVE_UNISTD_H */ #include "rldefs.h" + +#if !defined (SHELL) && defined (GWINSZ_IN_SYS_IOCTL) +# include <sys/ioctl.h> +#endif /* !SHELL && GWINSZ_IN_SYS_IOCTL */ + +#include "rltty.h" #include "readline.h" #if !defined (errno) @@ -41,12 +51,20 @@ extern int errno; extern int readline_echoing_p; extern int _rl_eof_char; +extern int _rl_enable_keypad, _rl_enable_meta; + +extern void _rl_control_keypad (); + #if defined (__GO32__) -# include <sys/pc.h> +# include <pc.h> # undef HANDLE_SIGNALS #endif /* __GO32__ */ -static int output_was_flushed; +/* Indirect functions to allow apps control over terminal management. */ +extern void rl_prep_terminal (), rl_deprep_terminal (); + +VFunction *rl_prep_term_function = rl_prep_terminal; +VFunction *rl_deprep_term_function = rl_deprep_terminal; /* **************************************************************** */ /* */ @@ -62,7 +80,7 @@ static int sigint_oldmask; # endif /* HAVE_BSD_SIGNALS */ #endif /* !HAVE_POSIX_SIGNALS */ -static int sigint_blocked = 0; +static int sigint_blocked; /* Cause SIGINT to not be delivered until the corresponding call to release_sigint(). */ @@ -113,62 +131,35 @@ release_sigint () /* **************************************************************** */ /* */ -/* Controlling the Meta Key and Keypad */ -/* */ -/* **************************************************************** */ - -extern int term_has_meta; -extern char *term_mm; -extern char *term_mo; - -extern char *term_ks; -extern char *term_ke; - -static int -outchar (c) - int c; -{ - return putc (c, rl_outstream); -} - -/* Turn on/off the meta key depending on ON. */ -static void -control_meta_key (on) - int on; -{ - if (term_has_meta) - { - if (on && term_mm) - tputs (term_mm, 1, outchar); - else if (!on && term_mo) - tputs (term_mo, 1, outchar); - } -} - -static void -control_keypad (on) - int on; -{ - if (on && term_ks) - tputs (term_ks, 1, outchar); - else if (!on && term_ke) - tputs (term_ke, 1, outchar); -} - -/* **************************************************************** */ -/* */ /* Saving and Restoring the TTY */ /* */ /* **************************************************************** */ /* Non-zero means that the terminal is in a prepped state. */ -static int terminal_prepped = 0; +static int terminal_prepped; /* If non-zero, means that this process has called tcflow(fd, TCOOFF) and output is suspended. */ #if defined (__ksr1__) -static int ksrflow = 0; +static int ksrflow; #endif + +#if !defined (SHELL) && defined (TIOCGWINSZ) +/* Dummy call to force a backgrounded readline to stop before it tries + to get the tty settings. */ +static void +set_winsize (tty) + int tty; +{ + struct winsize w; + + if (ioctl (tty, TIOCGWINSZ, &w) == 0) + (void) ioctl (tty, TIOCSWINSZ, &w); +} +#else /* SHELL || !TIOCGWINSZ */ +# define set_winsize(tty) +#endif /* SHELL || !TIOCGWINSZ */ + #if defined (NEW_TTY_DRIVER) /* Values for the `flags' field of a struct bsdtty. This tells which @@ -200,12 +191,7 @@ get_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { -#if !defined (SHELL) && defined (TIOCGWINSZ) - struct winsize w; - - if (ioctl (tty, TIOCGWINSZ, &w) == 0) - (void) ioctl (tty, TIOCSWINSZ, &w); -#endif + set_winsize (tty); tiop->flags = tiop->lflag = 0; @@ -230,6 +216,7 @@ get_tty_settings (tty, tiop) return 0; } +static int set_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; @@ -356,7 +343,11 @@ prepare_terminal_settings (meta_flag, otio, tiop) # define TIOTYPE struct termios # define DRAIN_OUTPUT(fd) tcdrain (fd) # define GETATTR(tty, tiop) (tcgetattr (tty, tiop)) -# define SETATTR(tty, tiop) (tcsetattr (tty, TCSANOW, tiop)) +# ifdef M_UNIX +# define SETATTR(tty, tiop) (tcsetattr (tty, TCSANOW, tiop)) +# else +# define SETATTR(tty, tiop) (tcsetattr (tty, TCSADRAIN, tiop)) +# endif /* !M_UNIX */ #else # define TIOTYPE struct termio # define DRAIN_OUTPUT(fd) @@ -372,28 +363,61 @@ static TIOTYPE otio; # define OUTPUT_BEING_FLUSHED(tp) 0 #endif +static void +rltty_warning (msg) + char *msg; +{ + fprintf (stderr, "readline: warning: %s\n", msg); +} + +#if defined (_AIX) +void +setopost(tp) +TIOTYPE *tp; +{ + if ((tp->c_oflag & OPOST) == 0) + { + rltty_warning ("turning on OPOST for terminal\r"); + tp->c_oflag |= OPOST|ONLCR; + } +} +#endif + static int get_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { -#if !defined (SHELL) && defined (TIOCGWINSZ) - struct winsize w; + int ioctl_ret; + set_winsize (tty); - if (ioctl (tty, TIOCGWINSZ, &w) == 0) - (void) ioctl (tty, TIOCSWINSZ, &w); -#endif - - /* Keep looping if output is being flushed after a ^O (or whatever - the flush character is). */ - while (GETATTR (tty, tiop) < 0 || OUTPUT_BEING_FLUSHED (tiop)) + while (1) { + ioctl_ret = GETATTR (tty, tiop); + if (ioctl_ret < 0) + { + if (errno != EINTR) + return -1; + else + continue; + } if (OUTPUT_BEING_FLUSHED (tiop)) - continue; - if (errno != EINTR) - return -1; - errno = 0; + { +#if defined (FLUSHO) && defined (_AIX41) + rltty_warning ("turning off output flushing"); + tiop->c_lflag &= ~FLUSHO; + break; +#else + continue; +#endif + } + break; } + +#if defined (_AIX) + setopost(tiop); +#endif + return 0; } @@ -467,12 +491,13 @@ prepare_terminal_settings (meta_flag, otio, tiop) tiop->c_cc[VMIN] = 1; tiop->c_cc[VTIME] = 0; - if (tiop->c_lflag & FLUSHO) +#if defined (FLUSHO) + if (OUTPUT_BEING_FLUSHED (tiop)) { - output_was_flushed = 1; tiop->c_lflag &= ~FLUSHO; otio.c_lflag &= ~FLUSHO; } +#endif /* Turn off characters that we need on Posix systems with job control, just to be sure. This includes ^Y and ^V. This should not really @@ -497,7 +522,7 @@ rl_prep_terminal (meta_flag) int meta_flag; { #if !defined (__GO32__) - int tty = fileno (rl_instream); + int tty; TIOTYPE tio; if (terminal_prepped) @@ -506,6 +531,8 @@ rl_prep_terminal (meta_flag) /* Try to keep this function from being INTerrupted. */ block_sigint (); + tty = fileno (rl_instream); + if (get_tty_settings (tty, &tio) < 0) { release_sigint (); @@ -522,11 +549,9 @@ rl_prep_terminal (meta_flag) return; } - if (output_was_flushed) - output_was_flushed = 0; + if (_rl_enable_keypad) + _rl_control_keypad (1); - control_meta_key (1); - control_keypad (1); fflush (rl_outstream); terminal_prepped = 1; @@ -539,23 +564,27 @@ void rl_deprep_terminal () { #if !defined (__GO32__) - int tty = fileno (rl_instream); + int tty; if (!terminal_prepped) return; - /* Try to keep this function from being INTerrupted. */ + /* Try to keep this function from being interrupted. */ block_sigint (); + tty = fileno (rl_instream); + + if (_rl_enable_keypad) + _rl_control_keypad (0); + + fflush (rl_outstream); + if (set_tty_settings (tty, &otio) < 0) { release_sigint (); return; } - control_meta_key (0); - control_keypad (0); - fflush (rl_outstream); terminal_prepped = 0; release_sigint (); @@ -568,6 +597,7 @@ rl_deprep_terminal () /* */ /* **************************************************************** */ +int rl_restart_output (count, key) int count, key; { @@ -600,6 +630,7 @@ rl_restart_output (count, key) return 0; } +int rl_stop_output (count, key) int count, key; { @@ -626,7 +657,7 @@ rl_stop_output (count, key) return 0; } - + /* **************************************************************** */ /* */ /* Default Key Bindings */ |