summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cachefilter-patterns.cc57
-rw-r--r--apt-pkg/cachefilter-patterns.h1
-rw-r--r--apt-pkg/cacheset.cc2
3 files changed, 59 insertions, 1 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index 7abc4536d..11ad5d723 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -17,6 +17,32 @@ namespace APT
namespace Internal
{
+static const constexpr struct
+{
+ APT::StringView shortName;
+ APT::StringView longName;
+ bool takesArgument;
+} shortPatterns[] = {
+ {"r"_sv, "?architecture"_sv, true},
+ {"A"_sv, "?archive"_sv, true},
+ {"M"_sv, "?automatic"_sv, false},
+ {"b"_sv, "?broken"_sv, false},
+ {"c"_sv, "?config-files"_sv, false},
+ {"E"_sv, "?essential"_sv, false},
+ {"F"_sv, "?false"_sv, false},
+ {"g"_sv, "?garbage"_sv, false},
+ {"i"_sv, "?installed"_sv, false},
+ {"n"_sv, "?name"_sv, true},
+ {"o"_sv, "?obsolete"_sv, false},
+ {"O"_sv, "?origin"_sv, true},
+ {"s"_sv, "?section"_sv, true},
+ {"e"_sv, "?source-package"_sv, true},
+ {"T"_sv, "?true"_sv, false},
+ {"U"_sv, "?upgradable"_sv, false},
+ {"V"_sv, "?version"_sv, true},
+ {"v"_sv, "?virtual"_sv, false},
+};
+
template <class... Args>
std::string rstrprintf(Args... args)
{
@@ -42,6 +68,8 @@ std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parseTop()
std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parse()
{
std::unique_ptr<Node> node;
+ if ((node = parseShortPattern()) != nullptr)
+ return node;
if ((node = parsePattern()) != nullptr)
return node;
if ((node = parseQuotedWord()) != nullptr)
@@ -53,6 +81,35 @@ std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parse()
"Expected pattern, quoted word, or word"};
}
+// Parse a short pattern
+std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parseShortPattern()
+{
+ if (sentence[state.offset] != '~')
+ return nullptr;
+
+ for (auto &sp : shortPatterns)
+ {
+ if (sentence.substr(state.offset + 1, sp.shortName.size()) != sp.shortName)
+ continue;
+
+ auto node = std::make_unique<PatternNode>();
+ node->end = node->start = state.offset;
+ node->term = sp.longName;
+
+ state.offset += sp.shortName.size() + 1;
+ if (sp.takesArgument)
+ {
+ node->arguments.push_back(parse());
+ node->haveArgumentList = true;
+ }
+ node->end = state.offset;
+
+ return node;
+ }
+
+ throw Error{Node{state.offset, sentence.size()}, "Unknown short pattern"};
+}
+
// Parse a list pattern (or function call pattern)
std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parsePattern()
{
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h
index 8317665bc..0d6e9d99e 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -96,6 +96,7 @@ struct PatternTreeParser
private:
std::unique_ptr<Node> parse();
std::unique_ptr<Node> parsePattern();
+ std::unique_ptr<Node> parseShortPattern();
std::unique_ptr<Node> parseWord();
std::unique_ptr<Node> parseQuotedWord();
};
diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc
index f5251eda8..ae1d5ee3e 100644
--- a/apt-pkg/cacheset.cc
+++ b/apt-pkg/cacheset.cc
@@ -295,7 +295,7 @@ bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface * const pc
bool CacheSetHelper::PackageFromPattern(PackageContainerInterface *const pci, pkgCacheFile &Cache, std::string const &pattern)
{
- if (pattern.size() < 1 || pattern[0] != '?')
+ if (pattern.size() < 1 || (pattern[0] != '?' && pattern[0] != '~'))
return false;
auto compiledPattern = APT::CacheFilter::ParsePattern(pattern, &Cache);