From 10cda9fe466c0c0631fb56adb04e54329594d8af Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Mon, 20 Sep 2004 17:02:47 +0000 Subject: 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 --- cmdline/apt-get.cc | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'cmdline') 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. /*{{{*/ -- cgit v1.2.3