commit ac4c56f6369a7e3ac7e5d389022b571cbc9f2eb8
parent 1db7d57a248c158a05ff1695aae921ced882522a
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Wed, 2 Sep 2020 09:55:08 +0200
tweaks: fold one function into another, to elide an unneeded return value
Diffstat:
2 files changed, 18 insertions(+), 31 deletions(-)
diff --git a/src/browser.c b/src/browser.c
@@ -604,11 +604,9 @@ void browser_select_dirname(const char *needle)
}
}
-/* Prepare the prompt and ask the user what to search for. If forwards is
- * TRUE, search forward in the list; otherwise, search backward. Return -2
- * for a blank answer, -1 for Cancel, 0 when we have a string, and a
- * positive value when some function was run. */
-int filesearch_init(bool forwards)
+/* Prepare the prompt and ask the user what to search for; then search for it.
+ * If forwards is TRUE, search forward in the list; otherwise, search backward. */
+void do_filesearch(bool forwards)
{
char *thedefault;
int response;
@@ -632,15 +630,22 @@ int filesearch_init(bool forwards)
!forwards ? _(" [Backwards]") : "", thedefault);
free(thedefault);
- /* If only Enter was pressed but we have a previous string, it's okay. */
- if (response == -2 && *last_search != '\0')
- return 0;
-
- /* Otherwise negative responses are a bailout. */
- if (response < 0)
+ /* If the user cancelled, or typed <Enter> on a blank answer and
+ * nothing was searched for yet during this session, get out. */
+ if (response == -1 || (response == -2 && *last_search == '\0')) {
statusbar(_("Cancelled"));
+ return;
+ }
+
+ /* If the user typed an answer, remember it. */
+ if (*answer != '\0') {
+ last_search = mallocstrcpy(last_search, answer);
+#ifdef ENABLE_HISTORIES
+ update_history(&search_history, answer);
+#endif
+ }
- return response;
+ findfile(last_search, forwards);
}
/* Look for the given needle in the list of files. If forwards is TRUE,
@@ -702,25 +707,6 @@ void findfile(const char *needle, bool forwards)
selected = looking_at;
}
-/* Search for a filename. If forwards is TRUE, search forward in the list;
- * otherwise, search backward.*/
-void do_filesearch(bool forwards)
-{
- /* If the user cancelled or jumped to first or last file, don't search. */
- if (filesearch_init(forwards) != 0)
- return;
-
- /* If the user typed an answer, remember it. */
- if (*answer != '\0') {
- last_search = mallocstrcpy(last_search, answer);
-#ifdef ENABLE_HISTORIES
- update_history(&search_history, answer);
-#endif
- }
-
- findfile(last_search, forwards);
-}
-
/* Search again without prompting for the last given search string,
* either forwards or backwards. */
void do_fileresearch(bool forwards)
diff --git a/src/prototypes.h b/src/prototypes.h
@@ -193,6 +193,7 @@ void read_the_list(const char *path, DIR *dir);
void browser_refresh(void);
void browser_select_dirname(const char *needle);
void do_filesearch(bool forwards);
+void findfile(const char *needle, bool forwards);
void do_fileresearch(bool forwards);
char *strip_last_component(const char *path);
#endif