[Aptitude-svn-commit] r3389 - in branches/aptitude-0.3/aptitude: . src/generic
Daniel Burrows
dburrows@costa.debian.org
Tue, 07 Jun 2005 20:08:44 +0000
Author: dburrows
Date: Tue Jun 7 20:08:41 2005
New Revision: 3389
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/generic/matchers.cc
branches/aptitude-0.3/aptitude/src/generic/matchers.h
Log:
Add futureproofing for easily matching both names and descriptions.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Tue Jun 7 20:08:41 2005
@@ -1,5 +1,10 @@
2005-06-07 Daniel Burrows <dburrows@debian.org>
+ * src/generic/matchers.cc, src/generic/matchers.h:
+
+ Add an option to parse_matcher that causes the matchers generated
+ for plain strings to match both names and descriptions.
+
* src/vscreen/fragment.cc:
Take the style of an indentbox's formatting from the surrounding
Modified: branches/aptitude-0.3/aptitude/src/generic/matchers.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/matchers.cc (original)
+++ branches/aptitude-0.3/aptitude/src/generic/matchers.cc Tue Jun 7 20:08:41 2005
@@ -722,7 +722,7 @@
}
pkg_matcher *parse_condition_list(string s, unsigned int &loc,
- bool flag_errors);
+ bool match_descriptions, bool flag_errors);
// Returns a substring up to the first metacharacter, including escaped
// metacharacters (parentheses, ~, |, and !)
@@ -765,7 +765,7 @@
}
pkg_matcher *parse_atom(string s, unsigned int &loc,
- bool flag_errors)
+ bool search_descriptions, bool flag_errors)
{
std::string substr;
@@ -777,16 +777,17 @@
if(s[loc]=='!')
{
loc++;
- pkg_matcher *atom=parse_atom(s, loc, flag_errors);
+ pkg_matcher *atom=parse_atom(s, loc, search_descriptions, flag_errors);
if(!atom)
return NULL;
return new pkg_not_matcher(atom);
}
else if(s[loc]=='(')
- // Recurse into the list
+ // Recur into the list
{
loc++;
pkg_matcher *lst=parse_condition_list(s, loc,
+ search_descriptions,
flag_errors);
if(!lst)
return NULL;
@@ -846,7 +847,7 @@
case 'P':
case 'C':
{
- pkg_matcher *m=parse_atom(s, loc, flag_errors);
+ pkg_matcher *m=parse_atom(s, loc, search_descriptions, flag_errors);
if(!m)
return NULL;
@@ -893,7 +894,7 @@
}
}
- pkg_matcher *m=parse_atom(s, loc, flag_errors);
+ pkg_matcher *m=parse_atom(s, loc, search_descriptions, flag_errors);
if(!m)
return NULL;
@@ -1047,8 +1048,26 @@
}
else
{
- return pkg_name_matcher::init(parse_substr(s, loc),
- flag_errors);
+ if(!search_descriptions)
+ return pkg_name_matcher::init(parse_substr(s, loc),
+ flag_errors);
+ else
+ {
+ substr=parse_substr(s, loc);
+ pkg_matcher *name=pkg_name_matcher::init(substr,
+ flag_errors);
+ pkg_matcher *desc=pkg_description_matcher::init(substr,
+ flag_errors);
+
+ if(!name || !desc)
+ {
+ delete name;
+ delete desc;
+ return NULL;
+ }
+ else
+ return new pkg_or_matcher(name, desc);
+ }
}
}
@@ -1057,6 +1076,7 @@
}
pkg_matcher *parse_and_group(string s, unsigned int &loc,
+ bool search_descriptions,
bool flag_errors)
{
pkg_matcher *rval=NULL;
@@ -1065,7 +1085,8 @@
while(loc<s.size() && s[loc]!='|' && s[loc]!=')')
{
- pkg_matcher *atom=parse_atom(s, loc, flag_errors);
+ pkg_matcher *atom=parse_atom(s, loc,
+ search_descriptions, flag_errors);
if(!atom)
{
delete rval;
@@ -1086,11 +1107,13 @@
}
pkg_matcher *parse_condition_list(string s, unsigned int &loc,
+ bool search_descriptions,
bool flag_errors)
// This (and the grammer) should be optimized to avoid deep recursion
// what does the above line mean? -- DNB 11/21/01
{
- pkg_matcher *grp=parse_and_group(s, loc, flag_errors);
+ pkg_matcher *grp=parse_and_group(s, loc, search_descriptions,
+ flag_errors);
if(!grp)
return NULL;
@@ -1103,6 +1126,7 @@
{
loc++;
pkg_matcher *grp2=parse_condition_list(s, loc,
+ search_descriptions,
flag_errors);
if(!grp2)
{
@@ -1127,7 +1151,8 @@
return grp;
}
-pkg_matcher *parse_pattern(string s, bool flag_errors)
+pkg_matcher *parse_pattern(string s,
+ bool search_descriptions, bool flag_errors)
{
unsigned int loc=0;
@@ -1138,7 +1163,9 @@
if(loc==s.size())
return NULL;
- pkg_matcher *rval=parse_condition_list(s, loc, flag_errors);
+ pkg_matcher *rval=parse_condition_list(s, loc,
+ search_descriptions,
+ flag_errors);
if(rval==NULL)
return NULL;
Modified: branches/aptitude-0.3/aptitude/src/generic/matchers.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/matchers.h (original)
+++ branches/aptitude-0.3/aptitude/src/generic/matchers.h Tue Jun 7 20:08:41 2005
@@ -1,6 +1,6 @@
// matchers.h -*-c++-*-
//
-// Copyright 2000 Daniel Burrows
+// Copyright 2000-2001, 2005 Daniel Burrows
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -35,7 +35,20 @@
virtual ~pkg_matcher() {}
};
-pkg_matcher *parse_pattern(string s, bool flag_errors=true);
+/** Parse the given pattern, returning a matcher.
+ *
+ * \param s the pattern to parse
+ * \param search_descriptions if \b true, then strings without an
+ * explicit pattern escape will be used to search
+ * both names and descriptions rather than
+ * names alone
+ * \param flag_errors if \b true, then error messages will be generated
+ * for incorrect patterns.
+ *
+ * \return the new matcher or \b NULL if an error occurs.
+ */
+pkg_matcher *parse_pattern(string s, bool search_descriptions=false,
+ bool flag_errors=true);
inline bool pkg_matches(string s, pkgCache::PkgIterator pkg, pkgCache::VerIterator ver)
{
pkg_matcher *m=parse_pattern(s);