/* 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 (void) { HIST_ENTRY **hlist, *hent; register int i; UNDO_LIST *ul, *saved_undo_list; saved_undo_list = rl_undo_list; hlist = history_list (); /* direct pointer, not copy */ for (i = 0; i < history_length; i++) { hent = hlist[i]; if (ul = (UNDO_LIST *)hent->data) { if (ul == saved_undo_list) saved_undo_list = 0; _rl_free_undo_list (ul); hent->data = 0; } _rl_free_history_entry (hent); } history_offset = history_length = 0; rl_undo_list = saved_undo_list; /* should be NULL */ }
/* Set the history pointer back to the last entry in the history. */ void _rl_start_using_history (void) { using_history (); if (_rl_saved_line_for_history) _rl_free_history_entry (_rl_saved_line_for_history); _rl_saved_line_for_history = (HIST_ENTRY *)NULL; }
int _rl_free_saved_history_line (void) { if (_rl_saved_line_for_history) { _rl_free_history_entry (_rl_saved_line_for_history); _rl_saved_line_for_history = (HIST_ENTRY *)NULL; } return 0; }
/* Search for a line in the history containing STRING. If DIR is < 0, the search is backwards through previous entries, else through subsequent entries. */ static void noninc_dosearch (char *string, int dir) { int oldpos, pos; HIST_ENTRY *entry; if (string == 0 || *string == '\0' || noninc_history_pos < 0) { DING (); return; } pos = noninc_search_from_pos (string, noninc_history_pos + dir, dir); if (pos == -1) { /* Search failed, current history position unchanged. */ maybe_unsave_line (); rl_clear_message (); rl_point = 0; DING (); return; } noninc_history_pos = pos; oldpos = where_history (); history_set_pos (noninc_history_pos); entry = current_history (); #if defined (VI_MODE) if (rl_editing_mode != vi_mode) #endif history_set_pos (oldpos); { int line_len; line_len = strlen (entry->line); if (line_len >= rl_line_buffer_len) rl_extend_line_buffer (line_len); strcpy (rl_line_buffer, entry->line); } rl_undo_list = (UNDO_LIST *)entry->data; rl_end = strlen (rl_line_buffer); rl_point = 0; rl_clear_message (); if (saved_line_for_history) _rl_free_history_entry (saved_line_for_history); saved_line_for_history = (HIST_ENTRY *)NULL; }
/* Restore the _rl_saved_line_for_history if there is one. */ int rl_maybe_unsave_line (void) { if (_rl_saved_line_for_history) { /* Can't call with `1' because rl_undo_list might point to an undo list from a history entry, as in rl_replace_from_history() below. */ rl_replace_line (_rl_saved_line_for_history->line, 0); rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data; _rl_free_history_entry (_rl_saved_line_for_history); _rl_saved_line_for_history = (HIST_ENTRY *)NULL; rl_point = rl_end; /* rl_replace_line sets rl_end */ } else rl_ding (); return 0; }