Switch to using nl_langinfo(YESEXPR) for yes/no prompting
authorArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 17:02:47 +0000 (17:02 +0000)
committerArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 17:02:47 +0000 (17:02 +0000)
Author: mdz
Date: 2003-08-09 03:07:03 GMT
Switch to using nl_langinfo(YESEXPR) for yes/no prompting

cmdline/apt-get.cc
debian/changelog

index f744177..53c4f16 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: apt-get.cc,v 1.137 2003/08/09 00:26:30 mdz Exp $
+// $Id: apt-get.cc,v 1.138 2003/08/09 03:07:03 mdz Exp $
 /* ######################################################################
    
    apt-get - Cover for dpkg
@@ -112,26 +112,37 @@ class CacheFile : public pkgCacheFile
 /* Returns true on a Yes.*/
 bool YnPrompt()
 {
-   // This needs to be a capital
-   const char *Yes = _("Y");
-                          
    if (_config->FindB("APT::Get::Assume-Yes",false) == true)
    {
-      c1out << Yes << endl;
+      c1out << _("Y") << endl;
       return true;
    }
-   
-   unsigned char C = 0;
-   unsigned char Jnk = 0;
-   if (read(STDIN_FILENO,&C,1) != 1)
+
+   char response[1024] = "";
+   cin.getline(response, sizeof(response));
+
+   if (!cin)
       return false;
-   while (C != '\n' && Jnk != '\n') 
-      if (read(STDIN_FILENO,&Jnk,1) != 1)
-        return false;
+
+   if (strlen(response) == 0)
+      return true;
+
+   regex_t Pattern;
+   int Res;
+
+   Res = regcomp(&Pattern, nl_langinfo(YESEXPR),
+                 REG_EXTENDED|REG_ICASE|REG_NOSUB);
+
+   if (Res != 0) {
+      char Error[300];        
+      regerror(Res,&Pattern,Error,sizeof(Error));
+      return _error->Error(_("Regex compilation error - %s"),Error);
+   }
    
-   if (!(toupper(C) == toupper((unsigned char)(*Yes)) || C == '\n' || C == '\r'))
-      return false;
-   return true;
+   Res = regexec(&Pattern, response, 0, NULL, 0);
+   if (Res == 0)
+      return true;
+   return false;
 }
                                                                        /*}}}*/
 // AnalPrompt - Annoying Yes No Prompt.                                        /*{{{*/
index c114c2a..c2af560 100644 (file)
@@ -25,12 +25,10 @@ apt (0.5.9) unstable; urgency=low
     are Provided by a package which is already installed (Closes: #200395)
   * Patch to update pt_BR man page for apt_preferences(5) from Andre Luis
     Lopes <andrelop@debian.org> (Closes: #202245)
-  * Ensure that the comparison of the "yes" character in YnPrompt is done
-    with unsigned values, so that 8-bit characters work correctly.  This
-    should probably all use nl_langinfo(YESEXPR) at some point instead.
-    (Closes: #200953)
-  * Pass the translated character through toupper(3), so that it doesn't
-    really matter anymore whether the translated string is uppercase
+  * Use nl_langinfo(YESEXPR) rather than comparing to the translated
+    string "Y".  Closes: #200953 and should make the prompting generally
+    more robust in the face of i18n.  In the particular case of #200953,
+    it was being fooled because of signedness issues with toupper(3)
 
  -- Matt Zimmerman <mdz@debian.org>  Fri,  8 Aug 2003 20:25:40 -0400