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 BACKWARD FALSE
|
||||||
#define FORWARD TRUE
|
#define FORWARD TRUE
|
||||||
|
|
||||||
|
#define YES 1
|
||||||
|
#define NO 0
|
||||||
|
#define ALL 2
|
||||||
|
#define CANCEL -1
|
||||||
|
|
||||||
#define BLIND FALSE
|
#define BLIND FALSE
|
||||||
#define VISIBLE TRUE
|
#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);
|
free(promptstr);
|
||||||
|
|
||||||
/* When the user cancelled while we're still starting up, quit. */
|
/* When the user cancelled while we're still starting up, quit. */
|
||||||
if (choice < 0 && !we_are_running)
|
if (choice == CANCEL && !we_are_running)
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
if (choice < 1) {
|
if (choice != YES) {
|
||||||
free(lockfilename);
|
free(lockfilename);
|
||||||
wipe_statusbar();
|
wipe_statusbar();
|
||||||
return SKIPTHISFILE;
|
return SKIPTHISFILE;
|
||||||
|
@ -1733,7 +1733,7 @@ bool make_backup_of(char *realname)
|
||||||
* save of the file itself, its contents may be lost. */
|
* save of the file itself, its contents may be lost. */
|
||||||
/* TRANSLATORS: Try to keep this message at most 76 characters. */
|
/* TRANSLATORS: Try to keep this message at most 76 characters. */
|
||||||
if (errno != ENOSPC && do_yesno_prompt(FALSE, _("Cannot make backup; "
|
if (errno != ENOSPC && do_yesno_prompt(FALSE, _("Cannot make backup; "
|
||||||
"continue and save actual file? ")) == 1)
|
"continue and save actual file? ")) == YES)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
/* TRANSLATORS: The %s is the reason of failure. */
|
/* TRANSLATORS: The %s is the reason of failure. */
|
||||||
|
@ -2115,7 +2115,7 @@ int write_it_out(bool exiting, bool withprompt)
|
||||||
functionptrtype func;
|
functionptrtype func;
|
||||||
const char *msg;
|
const char *msg;
|
||||||
int response = 0;
|
int response = 0;
|
||||||
int choice = 0;
|
int choice = NO;
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
const char *formatstr = (openfile->fmt == DOS_FILE) ? _(" [DOS Format]") :
|
const char *formatstr = (openfile->fmt == DOS_FILE) ? _(" [DOS Format]") :
|
||||||
(openfile->fmt == MAC_FILE) ? _(" [Mac Format]") : "";
|
(openfile->fmt == MAC_FILE) ? _(" [Mac Format]") : "";
|
||||||
|
@ -2257,7 +2257,7 @@ int write_it_out(bool exiting, bool withprompt)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (do_yesno_prompt(FALSE, _("Save file under "
|
if (do_yesno_prompt(FALSE, _("Save file under "
|
||||||
"DIFFERENT NAME? ")) < 1)
|
"DIFFERENT NAME? ")) != YES)
|
||||||
continue;
|
continue;
|
||||||
maychange = TRUE;
|
maychange = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -2275,7 +2275,7 @@ int write_it_out(bool exiting, bool withprompt)
|
||||||
free(message);
|
free(message);
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
if (choice < 1)
|
if (choice != YES)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2299,16 +2299,16 @@ int write_it_out(bool exiting, bool withprompt)
|
||||||
* overwrite the file right here when requested. */
|
* overwrite the file right here when requested. */
|
||||||
if (ISSET(SAVE_ON_EXIT) && withprompt) {
|
if (ISSET(SAVE_ON_EXIT) && withprompt) {
|
||||||
free(given);
|
free(given);
|
||||||
if (choice == 1) /* Yes */
|
if (choice == YES)
|
||||||
return write_file(openfile->filename, NULL,
|
return write_file(openfile->filename, NULL,
|
||||||
NORMAL, OVERWRITE, NONOTES);
|
NORMAL, OVERWRITE, NONOTES);
|
||||||
else if (choice == 0) /* No -- discard buffer */
|
else if (choice == NO) /* Discard buffer */
|
||||||
return 2;
|
return 2;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
} else if (choice < 0 && exiting) { /* Cancel of ^X */
|
} else if (choice == CANCEL && exiting) {
|
||||||
continue;
|
continue;
|
||||||
} else if (choice < 1) { /* No or Cancel */
|
} else if (choice != YES) {
|
||||||
free(given);
|
free(given);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,9 +304,9 @@ void do_exit(void)
|
||||||
/* When unmodified, simply close. Else, when doing automatic saving
|
/* When unmodified, simply close. Else, when doing automatic saving
|
||||||
* and the file has a name, simply save. Otherwise, ask the user. */
|
* and the file has a name, simply save. Otherwise, ask the user. */
|
||||||
if (!openfile->modified)
|
if (!openfile->modified)
|
||||||
choice = 0;
|
choice = NO;
|
||||||
else if (ISSET(SAVE_ON_EXIT) && openfile->filename[0] != '\0')
|
else if (ISSET(SAVE_ON_EXIT) && openfile->filename[0] != '\0')
|
||||||
choice = 1;
|
choice = YES;
|
||||||
else {
|
else {
|
||||||
if (ISSET(SAVE_ON_EXIT))
|
if (ISSET(SAVE_ON_EXIT))
|
||||||
warn_and_briefly_pause(_("No file name"));
|
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. */
|
/* 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();
|
close_and_go();
|
||||||
else if (choice != 1)
|
else if (choice != YES)
|
||||||
statusbar(_("Cancelled"));
|
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;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define UNDECIDED -2
|
||||||
|
|
||||||
/* Ask a simple Yes/No (and optionally All) question, specified in msg,
|
/* 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
|
* 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. */
|
* TRUE when passed in), and -1 for Cancel. */
|
||||||
int do_yesno_prompt(bool all, const char *msg)
|
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
|
/* TRANSLATORS: For the next three strings, specify the starting letters
|
||||||
* of the translations for "Yes"/"No"/"All". The first letter of each of
|
* 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. */
|
* 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 *nostr = _("Nn");
|
||||||
const char *allstr = _("Aa");
|
const char *allstr = _("Aa");
|
||||||
|
|
||||||
while (choice == -2) {
|
while (choice == UNDECIDED) {
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
char letter[MAXCHARLEN + 1];
|
char letter[MAXCHARLEN + 1];
|
||||||
int index = 0;
|
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. */
|
/* See if the typed letter is in the Yes, No, or All strings. */
|
||||||
if (strstr(yesstr, letter) != NULL)
|
if (strstr(yesstr, letter) != NULL)
|
||||||
choice = 1;
|
choice = YES;
|
||||||
else if (strstr(nostr, letter) != NULL)
|
else if (strstr(nostr, letter) != NULL)
|
||||||
choice = 0;
|
choice = NO;
|
||||||
else if (all && strstr(allstr, letter) != NULL)
|
else if (all && strstr(allstr, letter) != NULL)
|
||||||
choice = 2;
|
choice = ALL;
|
||||||
else
|
else
|
||||||
#endif /* ENABLE_NLS */
|
#endif /* ENABLE_NLS */
|
||||||
if (strchr("Yy", kbinput) != NULL)
|
if (strchr("Yy", kbinput) != NULL)
|
||||||
choice = 1;
|
choice = YES;
|
||||||
else if (strchr("Nn", kbinput) != NULL)
|
else if (strchr("Nn", kbinput) != NULL)
|
||||||
choice = 0;
|
choice = NO;
|
||||||
else if (all && strchr("Aa", kbinput) != NULL)
|
else if (all && strchr("Aa", kbinput) != NULL)
|
||||||
choice = 2;
|
choice = ALL;
|
||||||
else if (func_from_key(&kbinput) == do_cancel)
|
else if (func_from_key(&kbinput) == do_cancel)
|
||||||
choice = -1;
|
choice = CANCEL;
|
||||||
/* Interpret ^N and ^Q as "No", to allow exiting in anger. */
|
/* Interpret ^N and ^Q as "No", to allow exiting in anger. */
|
||||||
else if (kbinput == '\x0E' || kbinput == '\x11')
|
else if (kbinput == '\x0E' || kbinput == '\x11')
|
||||||
choice = 0;
|
choice = NO;
|
||||||
/* And interpret ^Y as "Yes". */
|
/* And interpret ^Y as "Yes". */
|
||||||
else if (kbinput == '\x19')
|
else if (kbinput == '\x19')
|
||||||
choice = 1;
|
choice = YES;
|
||||||
#ifdef ENABLE_MOUSE
|
#ifdef ENABLE_MOUSE
|
||||||
else if (kbinput == KEY_MOUSE) {
|
else if (kbinput == KEY_MOUSE) {
|
||||||
int mouse_x, mouse_y;
|
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. */
|
/* x == 0 means Yes or No, y == 0 means Yes or All. */
|
||||||
choice = -2 * x * y + x - y + 1;
|
choice = -2 * x * y + x - y + 1;
|
||||||
|
|
||||||
if (choice == 2 && !all)
|
if (choice == ALL && !all)
|
||||||
choice = -2;
|
choice = UNDECIDED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
came_full_circle = FALSE;
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
int choice = 0;
|
int choice = NO;
|
||||||
int result = findnextstr(needle, whole_word_only, modus,
|
int result = findnextstr(needle, whole_word_only, modus,
|
||||||
&match_len, skipone, real_current, *real_current_x);
|
&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;
|
spotlighted = FALSE;
|
||||||
|
|
||||||
if (choice == -1) /* The replacing was cancelled. */
|
if (choice == CANCEL)
|
||||||
break;
|
break;
|
||||||
else if (choice == 2)
|
|
||||||
replaceall = TRUE;
|
replaceall = (choice == ALL);
|
||||||
|
|
||||||
/* When "No" or moving backwards, the search routine should
|
/* When "No" or moving backwards, the search routine should
|
||||||
* first move one character further before continuing. */
|
* first move one character further before continuing. */
|
||||||
skipone = (choice == 0 || ISSET(BACKWARDS_SEARCH));
|
skipone = (choice == 0 || ISSET(BACKWARDS_SEARCH));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (choice == 1 || replaceall) { /* Yes, replace it. */
|
if (choice == YES || replaceall) {
|
||||||
size_t length_change;
|
size_t length_change;
|
||||||
char *altered;
|
char *altered;
|
||||||
|
|
||||||
|
|
|
@ -2560,10 +2560,10 @@ void do_linter(void)
|
||||||
if (openfile->modified) {
|
if (openfile->modified) {
|
||||||
int choice = do_yesno_prompt(FALSE, _("Save modified buffer before linting?"));
|
int choice = do_yesno_prompt(FALSE, _("Save modified buffer before linting?"));
|
||||||
|
|
||||||
if (choice == -1) {
|
if (choice == CANCEL) {
|
||||||
statusbar(_("Cancelled"));
|
statusbar(_("Cancelled"));
|
||||||
return;
|
return;
|
||||||
} else if (choice == 1 && (write_it_out(FALSE, FALSE) != 1))
|
} else if (choice == YES && (write_it_out(FALSE, FALSE) != 1))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2756,10 +2756,10 @@ void do_linter(void)
|
||||||
currmenu = MLINTER;
|
currmenu = MLINTER;
|
||||||
free(msg);
|
free(msg);
|
||||||
|
|
||||||
if (choice == -1) {
|
if (choice == CANCEL) {
|
||||||
statusbar(_("Cancelled"));
|
statusbar(_("Cancelled"));
|
||||||
break;
|
break;
|
||||||
} else if (choice == 1) {
|
} else if (choice == YES) {
|
||||||
open_buffer(curlint->filename, TRUE);
|
open_buffer(curlint->filename, TRUE);
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue