tweaks: rename a variable, to be easier to read and to make more sense
Also update and improve five comments.master
parent
77457fa6e9
commit
9a9714fe0c
30
src/prompt.c
30
src/prompt.c
|
@ -446,8 +446,8 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
|
||||||
bool finished;
|
bool finished;
|
||||||
functionptrtype func;
|
functionptrtype func;
|
||||||
#ifdef ENABLE_HISTORIES
|
#ifdef ENABLE_HISTORIES
|
||||||
char *magichistory = NULL;
|
char *stored_string = NULL;
|
||||||
/* The (partial) answer that was typed at the prompt, if any. */
|
/* Whatever the answer was before the user foraged into history. */
|
||||||
#ifdef ENABLE_TABCOMP
|
#ifdef ENABLE_TABCOMP
|
||||||
bool previous_was_tab = FALSE;
|
bool previous_was_tab = FALSE;
|
||||||
/* Whether the previous keystroke was an attempt at tab completion. */
|
/* Whether the previous keystroke was an attempt at tab completion. */
|
||||||
|
@ -470,7 +470,7 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
|
||||||
refresh_func();
|
refresh_func();
|
||||||
*actual = KEY_WINCH;
|
*actual = KEY_WINCH;
|
||||||
#ifdef ENABLE_HISTORIES
|
#ifdef ENABLE_HISTORIES
|
||||||
free(magichistory);
|
free(stored_string);
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -504,16 +504,14 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
|
||||||
if (func == get_older_item) {
|
if (func == get_older_item) {
|
||||||
if (history_list != NULL) {
|
if (history_list != NULL) {
|
||||||
/* If this is the first step into history, start at the bottom. */
|
/* If this is the first step into history, start at the bottom. */
|
||||||
if (magichistory == NULL)
|
if (stored_string == NULL)
|
||||||
reset_history_pointer_for(*history_list);
|
reset_history_pointer_for(*history_list);
|
||||||
|
|
||||||
/* If we're scrolling up at the bottom of the history list
|
/* When moving up from the bottom, remember the current answer. */
|
||||||
* and answer isn't blank, save answer in magichistory. */
|
|
||||||
if ((*history_list)->next == NULL)
|
if ((*history_list)->next == NULL)
|
||||||
magichistory = mallocstrcpy(magichistory, answer);
|
stored_string = mallocstrcpy(stored_string, answer);
|
||||||
|
|
||||||
/* Get the older search from the history list and save it in
|
/* If there is an older item, move to it and copy its string. */
|
||||||
* answer. If there is no older search, don't do anything. */
|
|
||||||
if ((*history_list)->prev != NULL) {
|
if ((*history_list)->prev != NULL) {
|
||||||
*history_list = (*history_list)->prev;
|
*history_list = (*history_list)->prev;
|
||||||
answer = mallocstrcpy(answer, (*history_list)->data);
|
answer = mallocstrcpy(answer, (*history_list)->data);
|
||||||
|
@ -522,19 +520,17 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
|
||||||
}
|
}
|
||||||
} else if (func == get_newer_item) {
|
} else if (func == get_newer_item) {
|
||||||
if (history_list != NULL) {
|
if (history_list != NULL) {
|
||||||
/* Get the newer search from the history list and save it in
|
/* If there is a newer item, move to it and copy its string. */
|
||||||
* answer. If there is no newer search, don't do anything. */
|
|
||||||
if ((*history_list)->next != NULL) {
|
if ((*history_list)->next != NULL) {
|
||||||
*history_list = (*history_list)->next;
|
*history_list = (*history_list)->next;
|
||||||
answer = mallocstrcpy(answer, (*history_list)->data);
|
answer = mallocstrcpy(answer, (*history_list)->data);
|
||||||
typing_x = strlen(answer);
|
typing_x = strlen(answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we've reached the bottom of the history list, and answer
|
/* When at the bottom of the history list, restore the old answer. */
|
||||||
* is blank, and magichistory is set, restore the old answer. */
|
|
||||||
if ((*history_list)->next == NULL &&
|
if ((*history_list)->next == NULL &&
|
||||||
*answer == '\0' && magichistory != NULL) {
|
*answer == '\0' && stored_string != NULL) {
|
||||||
answer = mallocstrcpy(answer, magichistory);
|
answer = mallocstrcpy(answer, stored_string);
|
||||||
typing_x = strlen(answer);
|
typing_x = strlen(answer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -568,9 +564,9 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
|
||||||
|
|
||||||
#ifdef ENABLE_HISTORIES
|
#ifdef ENABLE_HISTORIES
|
||||||
/* If the history pointer was moved, point it at the bottom again. */
|
/* If the history pointer was moved, point it at the bottom again. */
|
||||||
if (magichistory != NULL) {
|
if (stored_string != NULL) {
|
||||||
reset_history_pointer_for(*history_list);
|
reset_history_pointer_for(*history_list);
|
||||||
free(magichistory);
|
free(stored_string);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue