]> granicus.if.org Git - mutt/commitdiff
Use locale for yes/no expressions.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 29 Aug 2000 10:22:29 +0000 (10:22 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 29 Aug 2000 10:22:29 +0000 (10:22 +0000)
acconfig.h
configure.in
curs_lib.c
main.c

index 21747e6b649d5dd5b8a6a52df230ac99a903da7a..1f50cc6fc69e14a0447d9b8eb386d88a9ec875b7 100644 (file)
 /* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
 #undef HAVE_LANGINFO_CODESET
 
+/* Define if you have <langinfo.h> and nl_langinfo(YESEXPR). */
+#undef HAVE_LANGINFO_YESEXPR
+
 /* Define if you have iconv(). */
 #undef HAVE_ICONV
 
index 1b5781286269da4f48d353b8ef88849bda4a51a8..9bd00533da21ee5e1e5add78db4e28f33dd790bc 100644 (file)
@@ -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 <langinfo.h>],
+    [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
index 7947653d9b31bf271650668d6f7b2fa7d0ae68c4..68db3d12924bee3c2642580f4bda8aa461cdd33b 100644 (file)
 #include <errno.h>
 #include <ctype.h>
 
+#ifdef HAVE_LANGINFO_YESEXPR
+#include <langinfo.h>
+#include <regex.h>
+#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 b59dd11ed90551ff72d67021a2972e90932fa09d..1f02af9c4c21a020dfdb7561ed16ef75b8c97b67 100644 (file)
--- 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