From: Thomas Roessler Date: Tue, 29 Aug 2000 10:22:29 +0000 (+0000) Subject: Use locale for yes/no expressions. X-Git-Tag: mutt-1-3-8-rel~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ce482cd6bc9d26c0b48f07cdcb08017c0694d73;p=mutt Use locale for yes/no expressions. --- diff --git a/acconfig.h b/acconfig.h index 21747e6b..1f50cc6f 100644 --- a/acconfig.h +++ b/acconfig.h @@ -200,6 +200,9 @@ /* Define if you have and nl_langinfo(CODESET). */ #undef HAVE_LANGINFO_CODESET +/* Define if you have and nl_langinfo(YESEXPR). */ +#undef HAVE_LANGINFO_YESEXPR + /* Define if you have iconv(). */ #undef HAVE_ICONV diff --git a/configure.in b/configure.in index 1b578128..9bd00533 100644 --- a/configure.in +++ b/configure.in @@ -849,6 +849,15 @@ if test $mutt_cv_langinfo_codeset = yes; then AC_DEFINE(HAVE_LANGINFO_CODESET) fi +AC_CACHE_CHECK([for nl_langinfo and YESEXPR], mutt_cv_langinfo_yesexpr, + [AC_TRY_LINK([#include ], + [char* cs = nl_langinfo(YESEXPR);], + mutt_cv_langinfo_yesexpr=yes, + mutt_cv_langinfo_yesexpr=no)]) +if test $mutt_cv_langinfo_yesexpr = yes; then + AC_DEFINE(HAVE_LANGINFO_YESEXPR) +fi + AC_OUTPUT(Makefile intl/Makefile m4/Makefile dnl po/Makefile.in doc/Makefile contrib/Makefile dnl muttbug.sh dnl diff --git a/curs_lib.c b/curs_lib.c index 7947653d..68db3d12 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -31,6 +31,11 @@ #include #include +#ifdef HAVE_LANGINFO_YESEXPR +#include +#include +#endif + /* not possible to unget more than one char under some curses libs, and it * is impossible to unget function keys in SLang, so roll our own input * buffering routines. @@ -144,36 +149,46 @@ int mutt_yesorno (const char *msg, int def) event_t ch; unsigned char *yes = (unsigned char *) _("yes"); unsigned char *no = (unsigned char *) _("no"); - char yes1 = 'y'; - char no1 = 'n'; - /* - * The keys are not localised, because none of the other - * keys in mutt are localised. Also, non-ASCII characters - * are unlikely to work at present ... - */ +#ifdef HAVE_LANGINFO_YESEXPR + regex_t reyes; + regex_t reno; + int reyes_ok = ! regcomp (& reyes, nl_langinfo (YESEXPR), REG_NOSUB); + int reno_ok = ! regcomp (& reno, nl_langinfo (NOEXPR), REG_NOSUB); + char answer[2]; + + answer[1] = 0; +#endif CLEARLINE(LINES-1); - if (*yes == yes1 && *no == no1) /* English, or not localised */ - printw ("%s ([%c]/%c): ", msg, def ? yes1 : no1, - def ? no1 : yes1); - else - printw ("%s ([%c=%s]/%c=%s): ", msg, - def ? yes1 : no1, def ? yes : no, - def ? no1 : yes1, def ? no : yes); + printw ("%s ([%s]/%s): ", msg, def ? yes : no, def ? no : yes); FOREVER { mutt_refresh (); ch = mutt_getch (); - if (ch.ch == -1) return(-1); + if (ch.ch == -1) + return (-1); if (CI_is_return (ch.ch)) break; - else if (tolower (ch.ch) == tolower (yes1)) + +#ifdef HAVE_LANGINFO_YESEXPR + answer[0] = ch.ch; + if (reyes_ok ? + (regexec (& reyes, answer, 0, 0, 0) == 0) : +#else + if ( +#endif + (tolower (ch.ch) == 'y')) { def = 1; break; } - else if (tolower (ch.ch) == tolower (no1)) + else if ( +#ifdef HAVE_LANGINFO_YESEXPR + reno_ok ? + (regexec (& reno, answer, 0, 0, 0) == 0) : +#endif + (tolower (ch.ch) == 'n')) { def = 0; break; @@ -183,8 +198,16 @@ int mutt_yesorno (const char *msg, int def) BEEP(); } } + addstr ((char *) (def ? yes : no)); mutt_refresh (); +#ifdef HAVE_LANGINFO_YESEXPR + if (reyes_ok) + regfree (& reyes); + if (reno_ok) + regfree (& reno); +#endif + return (def); } diff --git a/main.c b/main.c index b59dd11e..1f02af9c 100644 --- a/main.c +++ b/main.c @@ -358,6 +358,13 @@ static void show_version (void) "-HAVE_LANGINFO_CODESET " #endif + +#ifdef HAVE_LANGINFO_YESEXPR + "+HAVE_LANGINFO_YESEXPR " +#else + "-HAVE_LANGINFO_YESEXPR " +#endif + "\n" #if HAVE_ICONV