nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 2fd30ee0954ad5c4e9cc3df40fb1fe09d3e46a92
parent 9bc6f1797e02070f3d32881981720f5d8a740a51
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 25 Jan 2022 12:22:41 +0100

tweaks: rename a function and its two parameters, for clarity

Diffstat:
Msrc/definitions.h | 5++++-
Msrc/files.c | 10+++++-----
Msrc/nano.c | 2+-
Msrc/prompt.c | 21++++++++++-----------
Msrc/prototypes.h | 2+-
Msrc/search.c | 2+-
Msrc/text.c | 4++--
7 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/src/definitions.h b/src/definitions.h @@ -108,9 +108,12 @@ #define BACKWARD FALSE #define FORWARD TRUE +#define YESORNO FALSE +#define YESORALLORNO TRUE + #define YES 1 -#define NO 0 #define ALL 2 +#define NO 0 #define CANCEL -1 #define BLIND FALSE diff --git a/src/files.c b/src/files.c @@ -303,7 +303,7 @@ char *do_lockfile(const char *filename, bool ask_the_user) free(postedname); free(pidstring); - choice = do_yesno_prompt(FALSE, promptstr); + choice = ask_user(YESORNO, promptstr); free(promptstr); /* When the user cancelled while we're still starting up, quit. */ @@ -1732,7 +1732,7 @@ bool make_backup_of(char *realname) * ask the user what to do, because if something goes wrong during the * save of the file itself, its contents may be lost. */ /* TRANSLATORS: Try to keep this message at most 76 characters. */ - if (errno != ENOSPC && do_yesno_prompt(FALSE, _("Cannot make backup; " + if (errno != ENOSPC && ask_user(YESORNO, _("Cannot make backup; " "continue and save actual file? ")) == YES) return TRUE; @@ -2256,7 +2256,7 @@ int write_it_out(bool exiting, bool withprompt) if (exiting || !openfile->mark) #endif { - if (do_yesno_prompt(FALSE, _("Save file under " + if (ask_user(YESORNO, _("Save file under " "DIFFERENT NAME? ")) != YES) continue; maychange = TRUE; @@ -2270,7 +2270,7 @@ int write_it_out(bool exiting, bool withprompt) sprintf(message, question, name); - choice = do_yesno_prompt(FALSE, message); + choice = ask_user(YESORNO, message); free(message); free(name); @@ -2291,7 +2291,7 @@ int write_it_out(bool exiting, bool withprompt) warn_and_briefly_pause(_("File on disk has changed")); /* TRANSLATORS: Try to keep this at most 76 characters. */ - choice = do_yesno_prompt(FALSE, _("File was modified " + choice = ask_user(YESORNO, _("File was modified " "since you opened it; continue saving? ")); wipe_statusbar(); diff --git a/src/nano.c b/src/nano.c @@ -311,7 +311,7 @@ void do_exit(void) if (ISSET(SAVE_ON_EXIT)) warn_and_briefly_pause(_("No file name")); - choice = do_yesno_prompt(FALSE, _("Save modified buffer? ")); + choice = ask_user(YESORNO, _("Save modified buffer? ")); } /* When not saving, or the save succeeds, close the buffer. */ diff --git a/src/prompt.c b/src/prompt.c @@ -637,10 +637,9 @@ int do_prompt(int menu, const char *provided, linestruct **history_list, #define UNDECIDED -2 -/* Ask a simple Yes/No (and optionally All) question, specified in msg, - * on the status bar. Return 1 for Yes, 0 for No, 2 for All (if all is - * TRUE when passed in), and -1 for Cancel. */ -int do_yesno_prompt(bool all, const char *msg) +/* Ask a simple Yes/No (and optionally All) question on the status bar + * and return the choice -- either YES or NO or ALL or CANCEL. */ +int ask_user(bool withall, const char *question) { int choice = UNDECIDED; int width = 16; @@ -679,7 +678,7 @@ int do_yesno_prompt(bool all, const char *msg) wmove(bottomwin, 2, 0); post_one_key(shortstr, _("No"), width); - if (all) { + if (withall) { shortstr[1] = allstr[0]; wmove(bottomwin, 1, width); post_one_key(shortstr, _("All"), width); @@ -692,14 +691,14 @@ int do_yesno_prompt(bool all, const char *msg) /* Color the prompt bar over its full width and display the question. */ wattron(bottomwin, interface_color_pair[PROMPT_BAR]); mvwprintw(bottomwin, 0, 0, "%*s", COLS, " "); - mvwaddnstr(bottomwin, 0, 0, msg, actual_x(msg, COLS - 1)); + mvwaddnstr(bottomwin, 0, 0, question, actual_x(question, COLS - 1)); wattroff(bottomwin, interface_color_pair[PROMPT_BAR]); wnoutrefresh(bottomwin); currmenu = MYESNO; /* When not replacing, show the cursor while waiting for a key. */ - kbinput = get_kbinput(bottomwin, !all); + kbinput = get_kbinput(bottomwin, !withall); #ifndef NANO_TINY if (kbinput == KEY_WINCH) @@ -719,7 +718,7 @@ int do_yesno_prompt(bool all, const char *msg) int extras = (kbinput / 16) % 4 + (kbinput <= 0xCF ? 1 : 0); while (extras <= get_key_buffer_len() && extras-- > 0) - letter[index++] = (unsigned char)get_kbinput(bottomwin, !all); + letter[index++] = (unsigned char)get_kbinput(bottomwin, !withall); } #endif letter[index] = '\0'; @@ -729,7 +728,7 @@ int do_yesno_prompt(bool all, const char *msg) choice = YES; else if (strstr(nostr, letter) != NULL) choice = NO; - else if (all && strstr(allstr, letter) != NULL) + else if (withall && strstr(allstr, letter) != NULL) choice = ALL; else #endif /* ENABLE_NLS */ @@ -737,7 +736,7 @@ int do_yesno_prompt(bool all, const char *msg) choice = YES; else if (strchr("Nn", kbinput) != NULL) choice = NO; - else if (all && strchr("Aa", kbinput) != NULL) + else if (withall && strchr("Aa", kbinput) != NULL) choice = ALL; else if (func_from_key(&kbinput) == do_cancel) choice = CANCEL; @@ -760,7 +759,7 @@ int do_yesno_prompt(bool all, const char *msg) /* x == 0 means Yes or No, y == 0 means Yes or All. */ choice = -2 * x * y + x - y + 1; - if (choice == ALL && !all) + if (choice == ALL && !withall) choice = UNDECIDED; } } diff --git a/src/prototypes.h b/src/prototypes.h @@ -430,7 +430,7 @@ void put_cursor_at_end_of_answer(void); void add_or_remove_pipe_symbol_from_answer(void); int do_prompt(int menu, const char *provided, linestruct **history_list, void (*refresh_func)(void), const char *msg, ...); -int do_yesno_prompt(bool all, const char *msg); +int ask_user(bool withall, const char *question); /* Most functions in rcfile.c. */ #if defined(ENABLE_NANORC) || defined(ENABLE_HISTORIES) diff --git a/src/search.c b/src/search.c @@ -589,7 +589,7 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only, edit_refresh(); /* TRANSLATORS: This is a prompt. */ - choice = do_yesno_prompt(TRUE, _("Replace this instance?")); + choice = ask_user(YESORALLORNO, _("Replace this instance?")); spotlighted = FALSE; diff --git a/src/text.c b/src/text.c @@ -2558,7 +2558,7 @@ void do_linter(void) edit_refresh(); if (openfile->modified) { - int choice = do_yesno_prompt(FALSE, _("Save modified buffer before linting?")); + int choice = ask_user(YESORNO, _("Save modified buffer before linting?")); if (choice == CANCEL) { statusbar(_("Cancelled")); @@ -2752,7 +2752,7 @@ void do_linter(void) sprintf(msg, _("This message is for unopened file %s," " open it in a new buffer?"), curlint->filename); - choice = do_yesno_prompt(FALSE, msg); + choice = ask_user(YESORNO, msg); currmenu = MLINTER; free(msg);