mirror of git://git.sv.gnu.org/nano.git
tweaks: use some symbolic names instead of unclear numeric values
This commit is contained in:
parent
32e63fe1b8
commit
9bc6f1797e
|
@ -108,6 +108,11 @@
|
|||
#define BACKWARD FALSE
|
||||
#define FORWARD TRUE
|
||||
|
||||
#define YES 1
|
||||
#define NO 0
|
||||
#define ALL 2
|
||||
#define CANCEL -1
|
||||
|
||||
#define BLIND FALSE
|
||||
#define VISIBLE TRUE
|
||||
|
||||
|
|
20
src/files.c
20
src/files.c
|
@ -307,10 +307,10 @@ char *do_lockfile(const char *filename, bool ask_the_user)
|
|||
free(promptstr);
|
||||
|
||||
/* When the user cancelled while we're still starting up, quit. */
|
||||
if (choice < 0 && !we_are_running)
|
||||
if (choice == CANCEL && !we_are_running)
|
||||
finish();
|
||||
|
||||
if (choice < 1) {
|
||||
if (choice != YES) {
|
||||
free(lockfilename);
|
||||
wipe_statusbar();
|
||||
return SKIPTHISFILE;
|
||||
|
@ -1733,7 +1733,7 @@ bool make_backup_of(char *realname)
|
|||
* 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; "
|
||||
"continue and save actual file? ")) == 1)
|
||||
"continue and save actual file? ")) == YES)
|
||||
return TRUE;
|
||||
|
||||
/* TRANSLATORS: The %s is the reason of failure. */
|
||||
|
@ -2115,7 +2115,7 @@ int write_it_out(bool exiting, bool withprompt)
|
|||
functionptrtype func;
|
||||
const char *msg;
|
||||
int response = 0;
|
||||
int choice = 0;
|
||||
int choice = NO;
|
||||
#ifndef NANO_TINY
|
||||
const char *formatstr = (openfile->fmt == DOS_FILE) ? _(" [DOS Format]") :
|
||||
(openfile->fmt == MAC_FILE) ? _(" [Mac Format]") : "";
|
||||
|
@ -2257,7 +2257,7 @@ int write_it_out(bool exiting, bool withprompt)
|
|||
#endif
|
||||
{
|
||||
if (do_yesno_prompt(FALSE, _("Save file under "
|
||||
"DIFFERENT NAME? ")) < 1)
|
||||
"DIFFERENT NAME? ")) != YES)
|
||||
continue;
|
||||
maychange = TRUE;
|
||||
}
|
||||
|
@ -2275,7 +2275,7 @@ int write_it_out(bool exiting, bool withprompt)
|
|||
free(message);
|
||||
free(name);
|
||||
|
||||
if (choice < 1)
|
||||
if (choice != YES)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -2299,16 +2299,16 @@ int write_it_out(bool exiting, bool withprompt)
|
|||
* overwrite the file right here when requested. */
|
||||
if (ISSET(SAVE_ON_EXIT) && withprompt) {
|
||||
free(given);
|
||||
if (choice == 1) /* Yes */
|
||||
if (choice == YES)
|
||||
return write_file(openfile->filename, NULL,
|
||||
NORMAL, OVERWRITE, NONOTES);
|
||||
else if (choice == 0) /* No -- discard buffer */
|
||||
else if (choice == NO) /* Discard buffer */
|
||||
return 2;
|
||||
else
|
||||
return 0;
|
||||
} else if (choice < 0 && exiting) { /* Cancel of ^X */
|
||||
} else if (choice == CANCEL && exiting) {
|
||||
continue;
|
||||
} else if (choice < 1) { /* No or Cancel */
|
||||
} else if (choice != YES) {
|
||||
free(given);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -304,9 +304,9 @@ void do_exit(void)
|
|||
/* When unmodified, simply close. Else, when doing automatic saving
|
||||
* and the file has a name, simply save. Otherwise, ask the user. */
|
||||
if (!openfile->modified)
|
||||
choice = 0;
|
||||
choice = NO;
|
||||
else if (ISSET(SAVE_ON_EXIT) && openfile->filename[0] != '\0')
|
||||
choice = 1;
|
||||
choice = YES;
|
||||
else {
|
||||
if (ISSET(SAVE_ON_EXIT))
|
||||
warn_and_briefly_pause(_("No file name"));
|
||||
|
@ -315,9 +315,9 @@ void do_exit(void)
|
|||
}
|
||||
|
||||
/* When not saving, or the save succeeds, close the buffer. */
|
||||
if (choice == 0 || (choice == 1 && write_it_out(TRUE, TRUE) > 0))
|
||||
if (choice == NO || (choice == YES && write_it_out(TRUE, TRUE) > 0))
|
||||
close_and_go();
|
||||
else if (choice != 1)
|
||||
else if (choice != YES)
|
||||
statusbar(_("Cancelled"));
|
||||
}
|
||||
|
||||
|
|
29
src/prompt.c
29
src/prompt.c
|
@ -635,12 +635,15 @@ int do_prompt(int menu, const char *provided, linestruct **history_list,
|
|||
return retval;
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
int choice = -2, width = 16;
|
||||
int choice = UNDECIDED;
|
||||
int width = 16;
|
||||
/* TRANSLATORS: For the next three strings, specify the starting letters
|
||||
* of the translations for "Yes"/"No"/"All". The first letter of each of
|
||||
* these strings MUST be a single-byte letter; others may be multi-byte. */
|
||||
|
@ -648,7 +651,7 @@ int do_yesno_prompt(bool all, const char *msg)
|
|||
const char *nostr = _("Nn");
|
||||
const char *allstr = _("Aa");
|
||||
|
||||
while (choice == -2) {
|
||||
while (choice == UNDECIDED) {
|
||||
#ifdef ENABLE_NLS
|
||||
char letter[MAXCHARLEN + 1];
|
||||
int index = 0;
|
||||
|
@ -723,27 +726,27 @@ int do_yesno_prompt(bool all, const char *msg)
|
|||
|
||||
/* See if the typed letter is in the Yes, No, or All strings. */
|
||||
if (strstr(yesstr, letter) != NULL)
|
||||
choice = 1;
|
||||
choice = YES;
|
||||
else if (strstr(nostr, letter) != NULL)
|
||||
choice = 0;
|
||||
choice = NO;
|
||||
else if (all && strstr(allstr, letter) != NULL)
|
||||
choice = 2;
|
||||
choice = ALL;
|
||||
else
|
||||
#endif /* ENABLE_NLS */
|
||||
if (strchr("Yy", kbinput) != NULL)
|
||||
choice = 1;
|
||||
choice = YES;
|
||||
else if (strchr("Nn", kbinput) != NULL)
|
||||
choice = 0;
|
||||
choice = NO;
|
||||
else if (all && strchr("Aa", kbinput) != NULL)
|
||||
choice = 2;
|
||||
choice = ALL;
|
||||
else if (func_from_key(&kbinput) == do_cancel)
|
||||
choice = -1;
|
||||
choice = CANCEL;
|
||||
/* Interpret ^N and ^Q as "No", to allow exiting in anger. */
|
||||
else if (kbinput == '\x0E' || kbinput == '\x11')
|
||||
choice = 0;
|
||||
choice = NO;
|
||||
/* And interpret ^Y as "Yes". */
|
||||
else if (kbinput == '\x19')
|
||||
choice = 1;
|
||||
choice = YES;
|
||||
#ifdef ENABLE_MOUSE
|
||||
else if (kbinput == KEY_MOUSE) {
|
||||
int mouse_x, mouse_y;
|
||||
|
@ -757,8 +760,8 @@ 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 == 2 && !all)
|
||||
choice = -2;
|
||||
if (choice == ALL && !all)
|
||||
choice = UNDECIDED;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
10
src/search.c
10
src/search.c
|
@ -553,7 +553,7 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
|
|||
came_full_circle = FALSE;
|
||||
|
||||
while (TRUE) {
|
||||
int choice = 0;
|
||||
int choice = NO;
|
||||
int result = findnextstr(needle, whole_word_only, modus,
|
||||
&match_len, skipone, real_current, *real_current_x);
|
||||
|
||||
|
@ -593,17 +593,17 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
|
|||
|
||||
spotlighted = FALSE;
|
||||
|
||||
if (choice == -1) /* The replacing was cancelled. */
|
||||
if (choice == CANCEL)
|
||||
break;
|
||||
else if (choice == 2)
|
||||
replaceall = TRUE;
|
||||
|
||||
replaceall = (choice == ALL);
|
||||
|
||||
/* When "No" or moving backwards, the search routine should
|
||||
* first move one character further before continuing. */
|
||||
skipone = (choice == 0 || ISSET(BACKWARDS_SEARCH));
|
||||
}
|
||||
|
||||
if (choice == 1 || replaceall) { /* Yes, replace it. */
|
||||
if (choice == YES || replaceall) {
|
||||
size_t length_change;
|
||||
char *altered;
|
||||
|
||||
|
|
|
@ -2560,10 +2560,10 @@ void do_linter(void)
|
|||
if (openfile->modified) {
|
||||
int choice = do_yesno_prompt(FALSE, _("Save modified buffer before linting?"));
|
||||
|
||||
if (choice == -1) {
|
||||
if (choice == CANCEL) {
|
||||
statusbar(_("Cancelled"));
|
||||
return;
|
||||
} else if (choice == 1 && (write_it_out(FALSE, FALSE) != 1))
|
||||
} else if (choice == YES && (write_it_out(FALSE, FALSE) != 1))
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2756,10 +2756,10 @@ void do_linter(void)
|
|||
currmenu = MLINTER;
|
||||
free(msg);
|
||||
|
||||
if (choice == -1) {
|
||||
if (choice == CANCEL) {
|
||||
statusbar(_("Cancelled"));
|
||||
break;
|
||||
} else if (choice == 1) {
|
||||
} else if (choice == YES) {
|
||||
open_buffer(curlint->filename, TRUE);
|
||||
} else {
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue