--- embedaddon/readline/terminal.c 2014/07/30 08:16:45 1.1.1.1 +++ embedaddon/readline/terminal.c 2021/03/17 01:01:01 1.1.1.2 @@ -1,6 +1,6 @@ /* terminal.c -- controlling the terminal with termcap. */ -/* Copyright (C) 1996-2009 Free Software Foundation, Inc. +/* Copyright (C) 1996-2017 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -51,15 +51,14 @@ /* System-specific feature definitions and include files. */ #include "rldefs.h" -#if defined (GWINSZ_IN_SYS_IOCTL) && !defined (TIOCGWINSZ) -# include -#endif /* GWINSZ_IN_SYS_IOCTL && !TIOCGWINSZ */ - #ifdef __MSDOS__ # include #endif #include "rltty.h" +#if defined (HAVE_SYS_IOCTL_H) +# include /* include for declaration of ioctl */ +#endif #include "tcap.h" /* Some standard library routines. */ @@ -113,6 +112,7 @@ char PC, *BC, *UP; /* Some strings to control terminal actions. These are output by tputs (). */ char *_rl_term_clreol; char *_rl_term_clrpag; +char *_rl_term_clrscroll; char *_rl_term_cr; char *_rl_term_backspace; char *_rl_term_goto; @@ -132,6 +132,7 @@ char *_rl_term_IC; char *_rl_term_dc; char *_rl_term_DC; +/* How to move forward a char, non-destructively */ char *_rl_term_forward_char; /* How to go up a line. */ @@ -151,6 +152,10 @@ static int term_has_meta; static char *_rl_term_mm; static char *_rl_term_mo; +/* The sequences to enter and exit standout mode. */ +static char *_rl_term_so; +static char *_rl_term_se; + /* The key sequences output by the arrow keys, if this terminal has any. */ static char *_rl_term_ku; static char *_rl_term_kd; @@ -176,6 +181,19 @@ static char *_rl_term_kI; static char *_rl_term_vs; /* very visible */ static char *_rl_term_ve; /* normal */ +/* It's not clear how HPUX is so broken here. */ +#ifdef TGETENT_BROKEN +# define TGETENT_SUCCESS 0 +#else +# define TGETENT_SUCCESS 1 +#endif +#ifdef TGETFLAG_BROKEN +# define TGETFLAG_SUCCESS 0 +#else +# define TGETFLAG_SUCCESS 1 +#endif +#define TGETFLAG(cap) (tgetflag (cap) == TGETFLAG_SUCCESS) + static void bind_termcap_arrow_keys PARAMS((Keymap)); /* Variables that hold the screen dimensions, used by the display code. */ @@ -189,8 +207,7 @@ int _rl_enable_meta = 1; #if defined (__EMX__) static void -_emx_get_screensize (swp, shp) - int *swp, *shp; +_emx_get_screensize (int *swp, int *shp) { int sz[2]; @@ -205,8 +222,7 @@ _emx_get_screensize (swp, shp) #if defined (__MINGW32__) static void -_win_get_screensize (swp, shp) - int *swp, *shp; +_win_get_screensize (int *swp, int *shp) { HANDLE hConOut; CONSOLE_SCREEN_BUFFER_INFO scr; @@ -228,8 +244,7 @@ _win_get_screensize (swp, shp) values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being non-null serve to check whether or not we have initialized termcap. */ void -_rl_get_screen_size (tty, ignore_env) - int tty, ignore_env; +_rl_get_screen_size (int tty, int ignore_env) { char *ss; #if defined (TIOCGWINSZ) @@ -319,8 +334,7 @@ _rl_get_screen_size (tty, ignore_env) } void -_rl_set_screen_size (rows, cols) - int rows, cols; +_rl_set_screen_size (int rows, int cols) { if (_rl_term_autowrap == -1) _rl_init_terminal_io (rl_terminal_name); @@ -339,15 +353,13 @@ _rl_set_screen_size (rows, cols) } void -rl_set_screen_size (rows, cols) - int rows, cols; +rl_set_screen_size (int rows, int cols) { _rl_set_screen_size (rows, cols); } void -rl_get_screen_size (rows, cols) - int *rows, *cols; +rl_get_screen_size (int *rows, int *cols) { if (rows) *rows = _rl_screenheight; @@ -356,19 +368,19 @@ rl_get_screen_size (rows, cols) } void -rl_reset_screen_size () +rl_reset_screen_size (void) { _rl_get_screen_size (fileno (rl_instream), 0); } void -_rl_sigwinch_resize_terminal () +_rl_sigwinch_resize_terminal (void) { _rl_get_screen_size (fileno (rl_instream), 1); } void -rl_resize_terminal () +rl_resize_terminal (void) { _rl_get_screen_size (fileno (rl_instream), 1); if (_rl_echoing_p) @@ -391,6 +403,7 @@ static const struct _tc_string tc_strings[] = { { "@7", &_rl_term_at7 }, { "DC", &_rl_term_DC }, + { "E3", &_rl_term_clrscroll }, { "IC", &_rl_term_IC }, { "ce", &_rl_term_clreol }, { "cl", &_rl_term_clrpag }, @@ -414,6 +427,8 @@ static const struct _tc_string tc_strings[] = { "mo", &_rl_term_mo }, { "nd", &_rl_term_forward_char }, { "pc", &_rl_term_pc }, + { "se", &_rl_term_se }, + { "so", &_rl_term_so }, { "up", &_rl_term_up }, { "vb", &_rl_visible_bell }, { "vs", &_rl_term_vs }, @@ -425,8 +440,7 @@ static const struct _tc_string tc_strings[] = /* Read the desired terminal capability strings into BP. The capabilities are described in the TC_STRINGS table. */ static void -get_term_capabilities (bp) - char **bp; +get_term_capabilities (char **bp) { #if !defined (__DJGPP__) /* XXX - doesn't DJGPP have a termcap library? */ register int i; @@ -438,20 +452,21 @@ get_term_capabilities (bp) } int -_rl_init_terminal_io (terminal_name) - const char *terminal_name; +_rl_init_terminal_io (const char *terminal_name) { const char *term; char *buffer; - int tty, tgetent_ret; + int tty, tgetent_ret, dumbterm; term = terminal_name ? terminal_name : sh_get_env_value ("TERM"); - _rl_term_clrpag = _rl_term_cr = _rl_term_clreol = (char *)NULL; + _rl_term_clrpag = _rl_term_cr = _rl_term_clreol = _rl_term_clrscroll = (char *)NULL; tty = rl_instream ? fileno (rl_instream) : 0; if (term == 0) term = "dumb"; + dumbterm = STREQ (term, "dumb"); + #ifdef __MSDOS__ _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL; _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL; @@ -459,10 +474,11 @@ _rl_init_terminal_io (terminal_name) _rl_term_mm = _rl_term_mo = (char *)NULL; _rl_terminal_can_insert = term_has_meta = _rl_term_autowrap = 0; _rl_term_cr = "\r"; - _rl_term_clreol = _rl_term_clrpag = _rl_term_backspace = (char *)NULL; + _rl_term_backspace = (char *)NULL; _rl_term_goto = _rl_term_pc = _rl_term_ip = (char *)NULL; _rl_term_ks = _rl_term_ke =_rl_term_vs = _rl_term_ve = (char *)NULL; _rl_term_kh = _rl_term_kH = _rl_term_at7 = _rl_term_kI = (char *)NULL; + _rl_term_so = _rl_term_se = (char *)NULL; #if defined(HACK_TERMCAP_MOTION) _rl_term_forward_char = (char *)NULL; #endif @@ -489,7 +505,7 @@ _rl_init_terminal_io (terminal_name) tgetent_ret = tgetent (term_buffer, term); } - if (tgetent_ret <= 0) + if (tgetent_ret != TGETENT_SUCCESS) { FREE (term_string_buffer); FREE (term_buffer); @@ -527,8 +543,13 @@ _rl_init_terminal_io (terminal_name) _rl_term_mm = _rl_term_mo = (char *)NULL; _rl_term_ve = _rl_term_vs = (char *)NULL; _rl_term_forward_char = (char *)NULL; + _rl_term_so = _rl_term_se = (char *)NULL; _rl_terminal_can_insert = term_has_meta = 0; + /* Assume generic unknown terminal can't handle the enable/disable + escape sequences */ + _rl_enable_bracketed_paste = 0; + /* Reasonable defaults for tgoto(). Readline currently only uses tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we change that later... */ @@ -547,10 +568,10 @@ _rl_init_terminal_io (terminal_name) BC = _rl_term_backspace; UP = _rl_term_up; - if (!_rl_term_cr) + if (_rl_term_cr == 0) _rl_term_cr = "\r"; - _rl_term_autowrap = tgetflag ("am") && tgetflag ("xn"); + _rl_term_autowrap = TGETFLAG ("am") && TGETFLAG ("xn"); /* Allow calling application to set default height and width, using rl_set_screen_size */ @@ -565,7 +586,7 @@ _rl_init_terminal_io (terminal_name) /* Check to see if this terminal has a meta key and clear the capability variables if there is none. */ - term_has_meta = tgetflag ("km") != 0; + term_has_meta = TGETFLAG ("km"); if (term_has_meta == 0) _rl_term_mm = _rl_term_mo = (char *)NULL; #endif /* !__MSDOS__ */ @@ -580,13 +601,17 @@ _rl_init_terminal_io (terminal_name) bind_termcap_arrow_keys (vi_insertion_keymap); #endif /* VI_MODE */ + /* There's no way to determine whether or not a given terminal supports + bracketed paste mode, so we assume a terminal named "dumb" does not. */ + if (dumbterm) + _rl_enable_bracketed_paste = 0; + return 0; } /* Bind the arrow key sequences from the termcap description in MAP. */ static void -bind_termcap_arrow_keys (map) - Keymap map; +bind_termcap_arrow_keys (Keymap map) { Keymap xkeymap; @@ -602,13 +627,13 @@ bind_termcap_arrow_keys (map) rl_bind_keyseq_if_unbound (_rl_term_at7, rl_end_of_line); /* End */ rl_bind_keyseq_if_unbound (_rl_term_kD, rl_delete); + rl_bind_keyseq_if_unbound (_rl_term_kI, rl_overwrite_mode); /* Insert */ _rl_keymap = xkeymap; } char * -rl_get_termcap (cap) - const char *cap; +rl_get_termcap (const char *cap) { register int i; @@ -625,8 +650,7 @@ rl_get_termcap (cap) /* Re-initialize the terminal considering that the TERM/TERMCAP variable has changed. */ int -rl_reset_terminal (terminal_name) - const char *terminal_name; +rl_reset_terminal (const char *terminal_name) { _rl_screenwidth = _rl_screenheight = 0; _rl_init_terminal_io (terminal_name); @@ -636,15 +660,13 @@ rl_reset_terminal (terminal_name) /* A function for the use of tputs () */ #ifdef _MINIX void -_rl_output_character_function (c) - int c; +_rl_output_character_function (int c) { putc (c, _rl_out_stream); } #else /* !_MINIX */ int -_rl_output_character_function (c) - int c; +_rl_output_character_function (int c) { return putc (c, _rl_out_stream); } @@ -652,17 +674,14 @@ _rl_output_character_function (c) /* Write COUNT characters from STRING to the output stream. */ void -_rl_output_some_chars (string, count) - const char *string; - int count; +_rl_output_some_chars (const char *string, int count) { fwrite (string, 1, count, _rl_out_stream); } /* Move the cursor back. */ int -_rl_backspace (count) - int count; +_rl_backspace (int count) { register int i; @@ -679,7 +698,7 @@ _rl_backspace (count) /* Move to the start of the next line. */ int -rl_crlf () +rl_crlf (void) { #if defined (NEW_TTY_DRIVER) || defined (__MINT__) if (_rl_term_cr) @@ -689,9 +708,19 @@ rl_crlf () return 0; } +void +_rl_cr (void) +{ +#if defined (__MSDOS__) + putc ('\r', rl_outstream); +#else + tputs (_rl_term_cr, 1, _rl_output_character_function); +#endif +} + /* Ring the terminal bell. */ int -rl_ding () +rl_ding (void) { if (_rl_echoing_p) { @@ -723,6 +752,30 @@ rl_ding () /* **************************************************************** */ /* */ +/* Entering and leaving terminal standout mode */ +/* */ +/* **************************************************************** */ + +void +_rl_standout_on (void) +{ +#ifndef __MSDOS__ + if (_rl_term_so && _rl_term_se) + tputs (_rl_term_so, 1, _rl_output_character_function); +#endif +} + +void +_rl_standout_off (void) +{ +#ifndef __MSDOS__ + if (_rl_term_so && _rl_term_se) + tputs (_rl_term_se, 1, _rl_output_character_function); +#endif +} + +/* **************************************************************** */ +/* */ /* Controlling the Meta Key and Keypad */ /* */ /* **************************************************************** */ @@ -730,7 +783,7 @@ rl_ding () static int enabled_meta = 0; /* flag indicating we enabled meta mode */ void -_rl_enable_meta_key () +_rl_enable_meta_key (void) { #if !defined (__DJGPP__) if (term_has_meta && _rl_term_mm) @@ -742,7 +795,7 @@ _rl_enable_meta_key () } void -_rl_disable_meta_key () +_rl_disable_meta_key (void) { #if !defined (__DJGPP__) if (term_has_meta && _rl_term_mo && enabled_meta) @@ -754,8 +807,7 @@ _rl_disable_meta_key () } void -_rl_control_keypad (on) - int on; +_rl_control_keypad (int on) { #if !defined (__DJGPP__) if (on && _rl_term_ks) @@ -776,8 +828,7 @@ _rl_control_keypad (on) cursor. Overwrite mode gets a very visible cursor. Only does anything if we have both capabilities. */ void -_rl_set_cursor (im, force) - int im, force; +_rl_set_cursor (int im, int force) { #ifndef __MSDOS__ if (_rl_term_ve && _rl_term_vs)