--- embedaddon/readline/misc.c 2016/11/03 13:35:37 1.1.1.2 +++ embedaddon/readline/misc.c 2021/03/17 01:01:01 1.1.1.3 @@ -1,6 +1,6 @@ /* misc.c -- miscellaneous bindable readline functions. */ -/* Copyright (C) 1987-2012 Free Software Foundation, Inc. +/* Copyright (C) 1987-2019 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. @@ -56,8 +56,6 @@ static int rl_digit_loop PARAMS((void)); static void _rl_history_set_point PARAMS((void)); -extern int history_offset; - /* Forward declarations used in this file */ void _rl_free_history_entry PARAMS((HIST_ENTRY *)); @@ -78,7 +76,7 @@ int _rl_history_saved_point = -1; /* **************************************************************** */ int -_rl_arg_overflow () +_rl_arg_overflow (void) { if (rl_numeric_arg > 1000000) { @@ -94,7 +92,7 @@ _rl_arg_overflow () } void -_rl_arg_init () +_rl_arg_init (void) { rl_save_prompt (); _rl_argcxt = 0; @@ -102,7 +100,7 @@ _rl_arg_init () } int -_rl_arg_getchar () +_rl_arg_getchar (void) { int c; @@ -118,9 +116,7 @@ _rl_arg_getchar () argument should be aborted, 0 if we should not read any more chars, and 1 if we should continue to read chars. */ int -_rl_arg_dispatch (cxt, c) - _rl_arg_cxt cxt; - int c; +_rl_arg_dispatch (_rl_arg_cxt cxt, int c) { int key, r; @@ -128,7 +124,7 @@ _rl_arg_dispatch (cxt, c) /* If we see a key bound to `universal-argument' after seeing digits, it ends the argument but is otherwise ignored. */ - if (_rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument) + if (c >= 0 && _rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument) { if ((cxt & NUM_SAWDIGITS) == 0) { @@ -142,9 +138,7 @@ _rl_arg_dispatch (cxt, c) } else { - RL_SETSTATE(RL_STATE_MOREINPUT); - key = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); + key = _rl_bracketed_read_key (); rl_restore_prompt (); rl_clear_message (); RL_UNSETSTATE(RL_STATE_NUMERICARG); @@ -195,7 +189,7 @@ _rl_arg_dispatch (cxt, c) /* Handle C-u style numeric args, as well as M--, and M-digits. */ static int -rl_digit_loop () +rl_digit_loop (void) { int c, r; @@ -222,7 +216,7 @@ rl_digit_loop () /* Create a default argument. */ void -_rl_reset_argument () +_rl_reset_argument (void) { rl_numeric_arg = rl_arg_sign = 1; rl_explicit_arg = 0; @@ -231,8 +225,7 @@ _rl_reset_argument () /* Start a numeric argument with initial value KEY */ int -rl_digit_argument (ignore, key) - int ignore, key; +rl_digit_argument (int ignore, int key) { _rl_arg_init (); if (RL_ISSTATE (RL_STATE_CALLBACK)) @@ -252,8 +245,7 @@ rl_digit_argument (ignore, key) Read a key. If the key has nothing to do with arguments, then dispatch on it. If the key is the abort character then abort. */ int -rl_universal_argument (count, key) - int count, key; +rl_universal_argument (int count, int key) { _rl_arg_init (); rl_numeric_arg *= 4; @@ -262,12 +254,13 @@ rl_universal_argument (count, key) } int -_rl_arg_callback (cxt) - _rl_arg_cxt cxt; +_rl_arg_callback (_rl_arg_cxt cxt) { int c, r; c = _rl_arg_getchar (); + if (c < 0) + return (1); /* EOF */ if (_rl_argcxt & NUM_READONE) { @@ -280,12 +273,14 @@ _rl_arg_callback (cxt) } r = _rl_arg_dispatch (cxt, c); + if (r > 0) + rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); return (r != 1); } /* What to do when you abort reading an argument. */ int -rl_discard_argument () +rl_discard_argument (void) { rl_ding (); rl_clear_message (); @@ -310,7 +305,7 @@ HIST_ENTRY *_rl_saved_line_for_history = (HIST_ENTRY * /* Set the history pointer back to the last entry in the history. */ void -_rl_start_using_history () +_rl_start_using_history (void) { using_history (); if (_rl_saved_line_for_history) @@ -321,8 +316,7 @@ _rl_start_using_history () /* Free the contents (and containing structure) of a HIST_ENTRY. */ void -_rl_free_history_entry (entry) - HIST_ENTRY *entry; +_rl_free_history_entry (HIST_ENTRY *entry) { if (entry == 0) return; @@ -335,7 +329,7 @@ _rl_free_history_entry (entry) /* Perhaps put back the current line if it has changed. */ int -rl_maybe_replace_line () +rl_maybe_replace_line (void) { HIST_ENTRY *temp; @@ -353,7 +347,7 @@ rl_maybe_replace_line () /* Restore the _rl_saved_line_for_history if there is one. */ int -rl_maybe_unsave_line () +rl_maybe_unsave_line (void) { if (_rl_saved_line_for_history) { @@ -372,7 +366,7 @@ rl_maybe_unsave_line () /* Save the current line in _rl_saved_line_for_history. */ int -rl_maybe_save_line () +rl_maybe_save_line (void) { if (_rl_saved_line_for_history == 0) { @@ -386,7 +380,7 @@ rl_maybe_save_line () } int -_rl_free_saved_history_line () +_rl_free_saved_history_line (void) { if (_rl_saved_line_for_history) { @@ -397,7 +391,7 @@ _rl_free_saved_history_line () } static void -_rl_history_set_point () +_rl_history_set_point (void) { rl_point = (_rl_history_preserve_point && _rl_history_saved_point != -1) ? _rl_history_saved_point @@ -415,9 +409,7 @@ _rl_history_set_point () } void -rl_replace_from_history (entry, flags) - HIST_ENTRY *entry; - int flags; /* currently unused */ +rl_replace_from_history (HIST_ENTRY *entry, int flags) { /* Can't call with `1' because rl_undo_list might point to an undo list from a history entry, just like we're setting up here. */ @@ -441,7 +433,7 @@ rl_replace_from_history (entry, flags) intended to be called while actively editing, and the current line is not assumed to have been added to the history list. */ void -_rl_revert_all_lines () +_rl_revert_previous_lines (void) { int hpos; HIST_ENTRY *entry; @@ -485,12 +477,25 @@ _rl_revert_all_lines () xfree (lbuf); } +/* Revert all lines in the history by making sure we are at the end of the + history before calling _rl_revert_previous_lines() */ +void +_rl_revert_all_lines (void) +{ + int pos; + + pos = where_history (); + using_history (); + _rl_revert_previous_lines (); + history_set_pos (pos); +} + /* Free the history list, including private readline data and take care of pointer aliases to history data. Resets rl_undo_list if it points to an UNDO_LIST * saved as some history entry's data member. This should not be called while editing is active. */ void -rl_clear_history () +rl_clear_history (void) { HIST_ENTRY **hlist, *hent; register int i; @@ -524,16 +529,14 @@ rl_clear_history () /* Meta-< goes to the start of the history. */ int -rl_beginning_of_history (count, key) - int count, key; +rl_beginning_of_history (int count, int key) { return (rl_get_previous_history (1 + where_history (), key)); } /* Meta-> goes to the end of the history. (The current line). */ int -rl_end_of_history (count, key) - int count, key; +rl_end_of_history (int count, int key) { rl_maybe_replace_line (); using_history (); @@ -543,8 +546,7 @@ rl_end_of_history (count, key) /* Move down to the next history line. */ int -rl_get_next_history (count, key) - int count, key; +rl_get_next_history (int count, int key) { HIST_ENTRY *temp; @@ -582,15 +584,15 @@ rl_get_next_history (count, key) /* Get the previous item out of our interactive history, making it the current line. If there is no previous history, just ding. */ int -rl_get_previous_history (count, key) - int count, key; +rl_get_previous_history (int count, int key) { HIST_ENTRY *old_temp, *temp; + int had_saved_line; if (count < 0) return (rl_get_next_history (-count, key)); - if (count == 0) + if (count == 0 || history_list () == 0) return 0; /* either not saved by rl_newline or at end of line, so set appropriately. */ @@ -598,6 +600,7 @@ rl_get_previous_history (count, key) _rl_history_saved_point = (rl_point == rl_end) ? -1 : rl_point; /* If we don't have a line saved, then save this one. */ + had_saved_line = _rl_saved_line_for_history != 0; rl_maybe_save_line (); /* If the current line has changed, save the changes. */ @@ -620,7 +623,11 @@ rl_get_previous_history (count, key) temp = old_temp; if (temp == 0) - rl_ding (); + { + if (had_saved_line == 0) + _rl_free_saved_history_line (); + rl_ding (); + } else { rl_replace_from_history (temp, 0); @@ -630,6 +637,48 @@ rl_get_previous_history (count, key) return 0; } +/* The equivalent of the Korn shell C-o operate-and-get-next-history-line + editing command. */ + +/* This could stand to be global to the readline library */ +static rl_hook_func_t *_rl_saved_internal_startup_hook = 0; +static int saved_history_logical_offset = -1; + +#define HISTORY_FULL() (history_is_stifled () && history_length >= history_max_entries) + +static int +set_saved_history () +{ + int absolute_offset, count; + + if (saved_history_logical_offset >= 0) + { + absolute_offset = saved_history_logical_offset - history_base; + count = where_history () - absolute_offset; + rl_get_previous_history (count, 0); + } + saved_history_logical_offset = -1; + _rl_internal_startup_hook = _rl_saved_internal_startup_hook; + + return (0); +} + +int +rl_operate_and_get_next (count, c) + int count, c; +{ + /* Accept the current line. */ + rl_newline (1, c); + + saved_history_logical_offset = rl_explicit_arg ? count : where_history () + history_base + 1; + + + _rl_saved_internal_startup_hook = _rl_internal_startup_hook; + _rl_internal_startup_hook = set_saved_history; + + return 0; +} + /* **************************************************************** */ /* */ /* Editing Modes */ @@ -637,8 +686,7 @@ rl_get_previous_history (count, key) /* **************************************************************** */ /* How to toggle back and forth between editing modes. */ int -rl_vi_editing_mode (count, key) - int count, key; +rl_vi_editing_mode (int count, int key) { #if defined (VI_MODE) _rl_set_insert_mode (RL_IM_INSERT, 1); /* vi mode ignores insert mode */ @@ -650,8 +698,7 @@ rl_vi_editing_mode (count, key) } int -rl_emacs_editing_mode (count, key) - int count, key; +rl_emacs_editing_mode (int count, int key) { rl_editing_mode = emacs_mode; _rl_set_insert_mode (RL_IM_INSERT, 1); /* emacs mode default is insert mode */ @@ -665,8 +712,7 @@ rl_emacs_editing_mode (count, key) /* Function for the rest of the library to use to set insert/overwrite mode. */ void -_rl_set_insert_mode (im, force) - int im, force; +_rl_set_insert_mode (int im, int force) { #ifdef CURSOR_MODE _rl_set_cursor (im, force); @@ -678,8 +724,7 @@ _rl_set_insert_mode (im, force) /* Toggle overwrite mode. A positive explicit argument selects overwrite mode. A negative or zero explicit argument selects insert mode. */ int -rl_overwrite_mode (count, key) - int count, key; +rl_overwrite_mode (int count, int key) { if (rl_explicit_arg == 0) _rl_set_insert_mode (rl_insert_mode ^ 1, 0);