tweaks: elide a parameter that is relevant for only one menu (Goto Dir)

Instead of burdening seven other calls of do_prompt() with a useless
parameter, just check for MGOTODIR in the appropriate place.  It also
saves having to pass the parameter down through three more functions.
master
Benno Schulenberg 2020-06-19 10:46:45 +02:00
parent 61dda8ff62
commit 499b926b74
6 changed files with 25 additions and 33 deletions

View File

@ -233,7 +233,7 @@ char *do_browser(char *path)
selected = filelist_len - 1; selected = filelist_len - 1;
} else if (func == goto_dir) { } else if (func == goto_dir) {
/* Ask for the directory to go to. */ /* Ask for the directory to go to. */
if (do_prompt(TRUE, FALSE, MGOTODIR, "", NULL, if (do_prompt(TRUE, MGOTODIR, "", NULL,
/* TRANSLATORS: This is a prompt. */ /* TRANSLATORS: This is a prompt. */
browser_refresh, _("Go To Directory")) < 0) { browser_refresh, _("Go To Directory")) < 0) {
statusbar(_("Cancelled")); statusbar(_("Cancelled"));
@ -639,7 +639,7 @@ int filesearch_init(bool forwards)
thedefault = copy_of(""); thedefault = copy_of("");
/* Now ask what to search for. */ /* Now ask what to search for. */
response = do_prompt(FALSE, FALSE, MWHEREISFILE, "", &search_history, response = do_prompt(FALSE, MWHEREISFILE, "", &search_history,
browser_refresh, "%s%s%s", _("Search"), browser_refresh, "%s%s%s", _("Search"),
/* TRANSLATORS: A modifier of the Search prompt. */ /* TRANSLATORS: A modifier of the Search prompt. */
!forwards ? _(" [Backwards]") : "", thedefault); !forwards ? _(" [Backwards]") : "", thedefault);

View File

@ -1135,7 +1135,7 @@ void do_insertfile(bool execute)
present_path = mallocstrcpy(present_path, "./"); present_path = mallocstrcpy(present_path, "./");
response = do_prompt(TRUE, TRUE, response = do_prompt(TRUE,
#ifndef NANO_TINY #ifndef NANO_TINY
execute ? MEXECUTE : execute ? MEXECUTE :
#endif #endif
@ -2078,7 +2078,7 @@ int do_writeout(bool exiting, bool withprompt)
/* Ask for (confirmation of) the filename. Disable tab completion /* Ask for (confirmation of) the filename. Disable tab completion
* when using restricted mode and the filename isn't blank. */ * when using restricted mode and the filename isn't blank. */
response = do_prompt(!ISSET(RESTRICTED) || openfile->filename[0] == '\0', response = do_prompt(!ISSET(RESTRICTED) || openfile->filename[0] == '\0',
TRUE, MWRITEFILE, given, NULL, MWRITEFILE, given, NULL,
edit_refresh, "%s%s%s", msg, edit_refresh, "%s%s%s", msg,
#ifndef NANO_TINY #ifndef NANO_TINY
formatstr, backupstr formatstr, backupstr
@ -2406,8 +2406,7 @@ char **username_completion(const char *buf, size_t length, size_t *num_matches)
* This code may safely be consumed by a BSD or GPL license. */ * This code may safely be consumed by a BSD or GPL license. */
/* Try to complete the given fragment in 'buf' to a filename. */ /* Try to complete the given fragment in 'buf' to a filename. */
char **filename_completion(const char *buf, size_t length, char **filename_completion(const char *buf, size_t length, size_t *num_matches)
bool only_folders, size_t *num_matches)
{ {
char *dirname = copy_of(buf); char *dirname = copy_of(buf);
char *slash, *filename; char *slash, *filename;
@ -2463,7 +2462,7 @@ char **filename_completion(const char *buf, size_t length,
continue; continue;
} }
#endif #endif
if (only_folders && !is_dir(fullname)) { if (currmenu == MGOTODIR && !is_dir(fullname)) {
free(fullname); free(fullname);
continue; continue;
} }
@ -2483,8 +2482,8 @@ char **filename_completion(const char *buf, size_t length,
/* Do tab completion. 'place' is the position of the status-bar cursor, and /* Do tab completion. 'place' is the position of the status-bar cursor, and
* 'refresh_func' is the function to be called to refresh the edit window. */ * 'refresh_func' is the function to be called to refresh the edit window. */
char *input_tab(char *buf, size_t *place, bool only_folders, char *input_tab(char *buf, size_t *place, bool *lastwastab,
bool *lastwastab, void (*refresh_func)(void), bool *listed) void (*refresh_func)(void), bool *listed)
{ {
size_t num_matches = 0; size_t num_matches = 0;
char **matches = NULL; char **matches = NULL;
@ -2505,7 +2504,7 @@ char *input_tab(char *buf, size_t *place, bool only_folders,
/* If there are no matches yet, try matching against filenames /* If there are no matches yet, try matching against filenames
* in the current directory. */ * in the current directory. */
if (matches == NULL) if (matches == NULL)
matches = filename_completion(buf, *place, only_folders, &num_matches); matches = filename_completion(buf, *place, &num_matches);
if (num_matches == 0) if (num_matches == 0)
beep(); beep();

View File

@ -404,8 +404,7 @@ void add_or_remove_pipe_symbol_from_answer(void)
/* Get a string of input at the status-bar prompt. */ /* Get a string of input at the status-bar prompt. */
functionptrtype acquire_an_answer(int *actual, bool allow_tabbing, functionptrtype acquire_an_answer(int *actual, bool allow_tabbing,
bool allow_files, bool *listed, linestruct **history_list, bool *listed, linestruct **history_list, void (*refresh_func)(void))
void (*refresh_func)(void))
{ {
int kbinput = ERR; int kbinput = ERR;
bool finished; bool finished;
@ -471,8 +470,7 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabbing,
} else } else
#endif #endif
if (allow_tabbing) if (allow_tabbing)
answer = input_tab(answer, &typing_x, !allow_files, answer = input_tab(answer, &typing_x, &tabbed, refresh_func, listed);
&tabbed, refresh_func, listed);
} else } else
#endif /* ENABLE_TABCOMP */ #endif /* ENABLE_TABCOMP */
#ifdef ENABLE_HISTORIES #ifdef ENABLE_HISTORIES
@ -550,15 +548,11 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabbing,
/* Ask a question on the status bar. Return 0 when text was entered, /* Ask a question on the status bar. Return 0 when text was entered,
* -1 for a cancelled entry, -2 for a blank string, and the relevant * -1 for a cancelled entry, -2 for a blank string, and the relevant
* keycode when a valid shortcut key was pressed. * keycode when a valid shortcut key was pressed. The allow_tabbing
* * parameter indicates whether tab completion is allowed; 'provided'
* The allow_tabbing parameter indicates whether tab completion is allowed, * is the default answer for when simply Enter is typed. */
* and allow_files indicates whether all files (and not just directories) int do_prompt(bool allow_tabbing, int menu, const char *provided,
* can be tab completed. The 'provided' parameter is the default answer linestruct **history_list, void (*refresh_func)(void), const char *msg, ...)
* for when simply Enter is typed. */
int do_prompt(bool allow_tabbing, bool allow_files,
int menu, const char *provided, linestruct **history_list,
void (*refresh_func)(void), const char *msg, ...)
{ {
va_list ap; va_list ap;
int retval; int retval;
@ -585,7 +579,7 @@ int do_prompt(bool allow_tabbing, bool allow_files,
lastmessage = VACUUM; lastmessage = VACUUM;
func = acquire_an_answer(&retval, allow_tabbing, allow_files, &listed, func = acquire_an_answer(&retval, allow_tabbing, &listed,
history_list, refresh_func); history_list, refresh_func);
free(prompt); free(prompt);
prompt = saved_prompt; prompt = saved_prompt;

View File

@ -323,8 +323,8 @@ char *real_dir_from_tilde(const char *buf);
int diralphasort(const void *va, const void *vb); int diralphasort(const void *va, const void *vb);
#endif #endif
#ifdef ENABLE_TABCOMP #ifdef ENABLE_TABCOMP
char *input_tab(char *buf, size_t *place, bool only_folders, char *input_tab(char *buf, size_t *place, bool *lastwastab,
bool *lastwastab, void (*refresh_func)(void), bool *listed); void (*refresh_func)(void), bool *listed);
#endif #endif
/* Some functions in global.c. */ /* Some functions in global.c. */
@ -447,9 +447,8 @@ void inject(char *burst, size_t count);
size_t get_statusbar_page_start(size_t start_col, size_t column); size_t get_statusbar_page_start(size_t start_col, size_t column);
void put_cursor_at_end_of_answer(void); void put_cursor_at_end_of_answer(void);
void add_or_remove_pipe_symbol_from_answer(void); void add_or_remove_pipe_symbol_from_answer(void);
int do_prompt(bool allow_tabs, bool allow_files, int do_prompt(bool allow_tabbing, int menu, const char *curranswer,
int menu, const char *curranswer, linestruct **history_list, linestruct **history_list, void (*refresh_func)(void), const char *msg, ...);
void (*refresh_func)(void), const char *msg, ...);
int do_yesno_prompt(bool all, const char *msg); int do_yesno_prompt(bool all, const char *msg);
/* Most functions in rcfile.c. */ /* Most functions in rcfile.c. */

View File

@ -93,7 +93,7 @@ void search_init(bool replacing, bool keep_the_answer)
while (TRUE) { while (TRUE) {
functionptrtype func; functionptrtype func;
/* Ask the user what to search for (or replace). */ /* Ask the user what to search for (or replace). */
int response = do_prompt(FALSE, FALSE, int response = do_prompt(FALSE,
inhelp ? MFINDINHELP : (replacing ? MREPLACE : MWHEREIS), inhelp ? MFINDINHELP : (replacing ? MREPLACE : MWHEREIS),
answer, &search_history, edit_refresh, answer, &search_history, edit_refresh,
/* TRANSLATORS: This is the main search prompt. */ /* TRANSLATORS: This is the main search prompt. */
@ -710,7 +710,7 @@ void ask_for_and_do_replacements(void)
linestruct *beginline = openfile->current; linestruct *beginline = openfile->current;
size_t begin_x = openfile->current_x; size_t begin_x = openfile->current_x;
ssize_t numreplaced; ssize_t numreplaced;
int response = do_prompt(FALSE, FALSE, MREPLACEWITH, "", int response = do_prompt(FALSE, MREPLACEWITH, "",
/* TRANSLATORS: This is a prompt. */ /* TRANSLATORS: This is a prompt. */
&replace_history, edit_refresh, _("Replace with")); &replace_history, edit_refresh, _("Replace with"));
@ -762,7 +762,7 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
{ {
if (interactive) { if (interactive) {
/* Ask for the line and column. */ /* Ask for the line and column. */
int response = do_prompt(FALSE, FALSE, MGOTOLINE, int response = do_prompt(FALSE, MGOTOLINE,
use_answer ? answer : "", NULL, edit_refresh, use_answer ? answer : "", NULL, edit_refresh,
/* TRANSLATORS: This is a prompt. */ /* TRANSLATORS: This is a prompt. */
_("Enter line number, column number")); _("Enter line number, column number"));

View File

@ -2110,7 +2110,7 @@ bool fix_spello(const char *word)
put_cursor_at_end_of_answer(); put_cursor_at_end_of_answer();
/* Let the user supply a correctly spelled alternative. */ /* Let the user supply a correctly spelled alternative. */
proceed = (do_prompt(FALSE, FALSE, MSPELL, word, NULL, proceed = (do_prompt(FALSE, MSPELL, word, NULL,
edit_refresh, _("Edit a replacement")) != -1); edit_refresh, _("Edit a replacement")) != -1);
spotlighted = FALSE; spotlighted = FALSE;