tweaks: elide two functions that each were called just once
This also gets rid of an assignment in an 'if' clause (twice), elides a local variable, and makes it clearer that a pointer gets moved to the previous or next item (instead of hiding it as a side effect of the function call).master
parent
65d81c60cd
commit
87cde1590d
|
@ -145,30 +145,6 @@ void update_history(linestruct **item, const char *text)
|
||||||
*item = *hbot;
|
*item = *hbot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move h to the string in the history list just before it, and return
|
|
||||||
* that string. If there isn't one, don't move h and return NULL. */
|
|
||||||
char *get_history_older(linestruct **h)
|
|
||||||
{
|
|
||||||
if ((*h)->prev == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
*h = (*h)->prev;
|
|
||||||
|
|
||||||
return (*h)->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move h to the string in the history list just after it, and return
|
|
||||||
* that string. If there isn't one, don't move h and return NULL. */
|
|
||||||
char *get_history_newer(linestruct **h)
|
|
||||||
{
|
|
||||||
if ((*h)->next == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
*h = (*h)->next;
|
|
||||||
|
|
||||||
return (*h)->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Two empty placeholder functions. */
|
/* Two empty placeholder functions. */
|
||||||
void get_history_older_void(void)
|
void get_history_older_void(void)
|
||||||
{
|
{
|
||||||
|
|
12
src/prompt.c
12
src/prompt.c
|
@ -446,8 +446,6 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
|
||||||
bool finished;
|
bool finished;
|
||||||
functionptrtype func;
|
functionptrtype func;
|
||||||
#ifdef ENABLE_HISTORIES
|
#ifdef ENABLE_HISTORIES
|
||||||
char *history = NULL;
|
|
||||||
/* The current history string. */
|
|
||||||
char *magichistory = NULL;
|
char *magichistory = NULL;
|
||||||
/* The (partial) answer that was typed at the prompt, if any. */
|
/* The (partial) answer that was typed at the prompt, if any. */
|
||||||
#ifdef ENABLE_TABCOMP
|
#ifdef ENABLE_TABCOMP
|
||||||
|
@ -515,8 +513,9 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
|
||||||
|
|
||||||
/* Get the older search from the history list and save it in
|
/* Get the older search from the history list and save it in
|
||||||
* answer. If there is no older search, don't do anything. */
|
* answer. If there is no older search, don't do anything. */
|
||||||
if ((history = get_history_older(history_list)) != NULL) {
|
if ((*history_list)->prev != NULL) {
|
||||||
answer = mallocstrcpy(answer, history);
|
*history_list = (*history_list)->prev;
|
||||||
|
answer = mallocstrcpy(answer, (*history_list)->data);
|
||||||
typing_x = strlen(answer);
|
typing_x = strlen(answer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,8 +523,9 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
|
||||||
if (history_list != NULL) {
|
if (history_list != NULL) {
|
||||||
/* Get the newer search from the history list and save it in
|
/* Get the newer search from the history list and save it in
|
||||||
* answer. If there is no newer search, don't do anything. */
|
* answer. If there is no newer search, don't do anything. */
|
||||||
if ((history = get_history_newer(history_list)) != NULL) {
|
if ((*history_list)->next != NULL) {
|
||||||
answer = mallocstrcpy(answer, history);
|
*history_list = (*history_list)->next;
|
||||||
|
answer = mallocstrcpy(answer, (*history_list)->data);
|
||||||
typing_x = strlen(answer);
|
typing_x = strlen(answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -336,8 +336,6 @@ void do_help(void);
|
||||||
void history_init(void);
|
void history_init(void);
|
||||||
void history_reset(const linestruct *list);
|
void history_reset(const linestruct *list);
|
||||||
void update_history(linestruct **item, const char *text);
|
void update_history(linestruct **item, const char *text);
|
||||||
char *get_history_older(linestruct **h);
|
|
||||||
char *get_history_newer(linestruct **h);
|
|
||||||
void get_history_older_void(void);
|
void get_history_older_void(void);
|
||||||
void get_history_newer_void(void);
|
void get_history_newer_void(void);
|
||||||
#ifdef ENABLE_TABCOMP
|
#ifdef ENABLE_TABCOMP
|
||||||
|
|
Loading…
Reference in New Issue