summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 17:02:47 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 17:02:47 +0000
commit10cda9fe466c0c0631fb56adb04e54329594d8af (patch)
tree6346a5b860171b5b168c0740c58be03720172fba
parent2519f2ecacdb7e9dac9875649cda3b8cc448fdce (diff)
Switch to using nl_langinfo(YESEXPR) for yes/no prompting
Author: mdz Date: 2003-08-09 03:07:03 GMT Switch to using nl_langinfo(YESEXPR) for yes/no prompting
-rw-r--r--cmdline/apt-get.cc41
-rw-r--r--debian/changelog10
2 files changed, 30 insertions, 21 deletions
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index f744177e3..53c4f166a 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -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. /*{{{*/
diff --git a/debian/changelog b/debian/changelog
index c114c2abd..c2af56097 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -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