tweaks: improve some comments, and rename a variable for symmetry

This commit is contained in:
Benno Schulenberg 2017-09-17 17:16:36 +02:00
parent 36e88032cb
commit 067a920517
2 changed files with 25 additions and 26 deletions

View File

@ -205,25 +205,24 @@ subnfunc *uncutfunc;
#ifndef DISABLE_HISTORIES #ifndef DISABLE_HISTORIES
filestruct *search_history = NULL; filestruct *search_history = NULL;
/* The search string history list. */ /* The current item in the list of strings that were searched for. */
filestruct *searchtop = NULL; filestruct *searchtop = NULL;
/* The top of the search string history list. */ /* The oldest item in the list of search strings. */
filestruct *searchbot = NULL; filestruct *searchbot = NULL;
/* The bottom of the search string history list. */ /* The newest item in the list of search strings. */
filestruct *replace_history = NULL; filestruct *replace_history = NULL;
/* The replace string history list. */ /* The current item in the list of replace strings. */
filestruct *replacetop = NULL; filestruct *replacetop = NULL;
/* The top of the replace string history list. */
filestruct *replacebot = NULL; filestruct *replacebot = NULL;
/* The bottom of the replace string history list. */
filestruct *execute_history = NULL; filestruct *execute_history = NULL;
/* The list of commands that have been run with ^R ^X. */ /* The current item in the list of commands that were run with ^R ^X. */
filestruct *executetop = NULL; filestruct *executetop = NULL;
/* The top of the execute history list. */
filestruct *executebot = NULL; filestruct *executebot = NULL;
/* The bottom of the execute history list. */
poshiststruct *position_history = NULL; poshiststruct *position_history = NULL;
/* The cursor position history list. */ /* The list of filenames with their last cursor positions. */
#endif #endif
regex_t search_regexp; regex_t search_regexp;

View File

@ -78,29 +78,29 @@ filestruct *find_history(const filestruct *h_start, const filestruct
* with a fresh string s. That is: add s, or move it to the end. */ * with a fresh string s. That is: add s, or move it to the end. */
void update_history(filestruct **h, const char *s) void update_history(filestruct **h, const char *s)
{ {
filestruct **hage = NULL, **hbot = NULL, *thesame; filestruct **htop = NULL, **hbot = NULL, *thesame;
if (*h == search_history) { if (*h == search_history) {
hage = &searchtop; htop = &searchtop;
hbot = &searchbot; hbot = &searchbot;
} else if (*h == replace_history) { } else if (*h == replace_history) {
hage = &replacetop; htop = &replacetop;
hbot = &replacebot; hbot = &replacebot;
} else if (*h == execute_history) { } else if (*h == execute_history) {
hage = &executetop; htop = &executetop;
hbot = &executebot; hbot = &executebot;
} }
/* See if the string is already in the history. */ /* See if the string is already in the history. */
thesame = find_history(*hbot, *hage, s, HIGHEST_POSITIVE); thesame = find_history(*hbot, *htop, s, HIGHEST_POSITIVE);
/* If an identical string was found, delete that item. */ /* If an identical string was found, delete that item. */
if (thesame != NULL) { if (thesame != NULL) {
filestruct *after = thesame->next; filestruct *after = thesame->next;
/* If the string is at the head of the list, move the head. */ /* If the string is at the head of the list, move the head. */
if (thesame == *hage) if (thesame == *htop)
*hage = after; *htop = after;
unlink_node(thesame); unlink_node(thesame);
renumber(after); renumber(after);
@ -109,11 +109,11 @@ void update_history(filestruct **h, const char *s)
/* If the history is full, delete the oldest item (the one at the /* If the history is full, delete the oldest item (the one at the
* head of the list), to make room for a new item at the end. */ * head of the list), to make room for a new item at the end. */
if ((*hbot)->lineno == MAX_SEARCH_HISTORY + 1) { if ((*hbot)->lineno == MAX_SEARCH_HISTORY + 1) {
filestruct *oldest = *hage; filestruct *oldest = *htop;
*hage = (*hage)->next; *htop = (*htop)->next;
unlink_node(oldest); unlink_node(oldest);
renumber(*hage); renumber(*htop);
} }
/* Store the fresh string in the last item, then create a new item. */ /* Store the fresh string in the last item, then create a new item. */
@ -171,25 +171,25 @@ void get_history_older_void(void)
char *get_history_completion(filestruct **h, char *s, size_t len) char *get_history_completion(filestruct **h, char *s, size_t len)
{ {
if (len > 0) { if (len > 0) {
filestruct *hage = NULL, *hbot = NULL, *p; filestruct *htop = NULL, *hbot = NULL, *p;
if (*h == search_history) { if (*h == search_history) {
hage = searchtop; htop = searchtop;
hbot = searchbot; hbot = searchbot;
} else if (*h == replace_history) { } else if (*h == replace_history) {
hage = replacetop; htop = replacetop;
hbot = replacebot; hbot = replacebot;
} else if (*h == execute_history) { } else if (*h == execute_history) {
hage = executetop; htop = executetop;
hbot = executebot; hbot = executebot;
} }
/* Search the history list from the current position to the top /* Search the history list from the current position to the top
* for a match of len characters. Skip over an exact match. */ * for a match of len characters. Skip over an exact match. */
p = find_history((*h)->prev, hage, s, len); p = find_history((*h)->prev, htop, s, len);
while (p != NULL && strcmp(p->data, s) == 0) while (p != NULL && strcmp(p->data, s) == 0)
p = find_history(p->prev, hage, s, len); p = find_history(p->prev, htop, s, len);
if (p != NULL) { if (p != NULL) {
*h = p; *h = p;