[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#264716: aptitude: install ~p... won't work with some languages



  The attached patch should fix this problem.  It adds one more string
to the pofile, but I don't think it's critical for this to be
translated (since it's an obscure error message; the only alternative is
to not present an error in that case at all).

  With this patch, aptitude will accept either the English name for the
priority or the localized name.  It won't accept a regular expression
any more, so the documentation needs to be updated (included in the
patch for English).

  Daniel

-- 
/-------------------- Daniel Burrows <dburrows@debian.org> -------------------\
|                If we do not change our direction                            |
|                we are likely to end up where we are headed.                 |
\------- (if (not (understand-this)) (go-to http://www.schemers.org)) --------/
Index: src/generic/matchers.cc
===================================================================
--- src/generic/matchers.cc	(revision 2679)
+++ src/generic/matchers.cc	(working copy)
@@ -37,6 +37,7 @@
 #include "../aptitude.h"
 
 #include <apt-pkg/error.h>
+#include <apt-pkg/pkgcache.h>
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/version.h>
 
@@ -136,13 +137,6 @@
 }
 typedef pkg_string_matcher<maintainer_matches> pkg_maintainer_matcher;
 
-bool priority_matches(regex_t *pattern, pkgCache::PkgIterator pkg, pkgCache::VerIterator ver)
-{
-  return !ver.end() && ver.PriorityType() &&
-    string_matches(pattern, ver.PriorityType());
-}
-typedef pkg_string_matcher<priority_matches> pkg_priority_matcher;
-
 bool section_matches(regex_t *pattern, pkgCache::PkgIterator pkg, pkgCache::VerIterator ver)
 {
   return !ver.end() && ver.Section() && string_matches(pattern, ver.Section());
@@ -241,6 +235,22 @@
   }
 };
 
+class pkg_priority_matcher:public pkg_matcher
+{
+  pkgCache::State::VerPriority type;
+public:
+  pkg_priority_matcher(pkgCache::State::VerPriority _type)
+    :type(_type) {}
+
+  bool matches(pkgCache::PkgIterator pkg, pkgCache::VerIterator ver)
+  {
+    if(ver.end())
+      return false;
+    else
+      return ver->Priority == type;
+  }
+};
+
 // Matches packages with unmet dependencies of a particular type.
 class pkg_broken_type_matcher:public pkg_matcher
 {
@@ -953,7 +963,48 @@
 		    case 'O':
 		      return pkg_origin_matcher::init(substr, flag_errors);
 		    case 'p':
-		      return pkg_priority_matcher::init(substr, flag_errors);
+		      {
+			pkgCache::State::VerPriority type;
+
+			const char *s=substr.c_str();
+
+			if(strcasecmp(s, "important") == 0 ||
+			   (apt_cache_file &&
+			    strcasecmp(s, (*apt_cache_file)->GetCache().Priority(pkgCache::State::Important)) == 0))
+			  type=pkgCache::State::Important;
+			else if(strcasecmp(s, "required") == 0 ||
+				(apt_cache_file &&
+				 strcasecmp(s, (*apt_cache_file)->GetCache().Priority(pkgCache::State::Required)) == 0))
+			  type=pkgCache::State::Required;
+			else if(strcasecmp(s, "standard") == 0 ||
+				(apt_cache_file &&
+				 strcasecmp(s, (*apt_cache_file)->GetCache().Priority(pkgCache::State::Standard)) == 0))
+			  type=pkgCache::State::Standard;
+			else if(strcasecmp(s, "optional") == 0 ||
+				(apt_cache_file &&
+				 strcasecmp(s, (*apt_cache_file)->GetCache().Priority(pkgCache::State::Optional)) == 0))
+			  type=pkgCache::State::Optional;
+			else if(strcasecmp(s, "extra") == 0 ||
+				(apt_cache_file &&
+				 strcasecmp(s, (*apt_cache_file)->GetCache().Priority(pkgCache::State::Extra)) == 0))
+			  type=pkgCache::State::Extra;
+			else
+			  {
+			    if(flag_errors)
+			      {
+				char buf[512];
+
+				snprintf(buf, 512, _("Unknown priority %s"),
+					 substr.c_str());
+
+				_error->Error("%s", buf);
+			      }
+
+			    return NULL;
+			  }
+
+			return new pkg_priority_matcher(type);
+		      }
 		    case 's':
 		      return pkg_section_matcher::init(substr, flag_errors);
 		    case 't':
Index: doc/en/aptitude.xml
===================================================================
--- doc/en/aptitude.xml	(revision 2689)
+++ doc/en/aptitude.xml	(working copy)
@@ -3264,9 +3264,14 @@
 
 	  <listitem>
 	    <para>
-	      Matches packages whose priority matches the regular
-	      expression <replaceable>priority</replaceable>.  For
-	      instance, <quote><literal>~prequired</literal></quote> matches
+	      Matches packages whose priority is
+	      <replaceable>priority</replaceable>;
+	      <replaceable>priority</replaceable> must be
+	      <literal>extra</literal>, <literal>important</literal>,
+	      <literal>optional</literal>,
+	      <literal>required</literal>, or
+	      <literal>standard</literal>.  For instance,
+	      <quote><literal>~prequired</literal></quote> matches
 	      packages whose priority is
 	      <quote><literal>required</literal></quote>.
 	    </para>
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2693)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2004-08-10  Daniel Burrows  <dburrows@debian.org>
+
+	* src/generic/matchers.cc, doc/en/aptitude.xml:
+	  Do priority matching by priority type (based on the input string)
+	  rather than by string.  This will make searches by priority
+	  somewhat faster, as well as making them reliable regardless of
+	  locale.
+
 2004-08-09  Daniel Burrows  <dburrows@debian.org>
 
 	* src/cmdline/cmdline_action.cc (cmdline_applyaction):

Reply to: