]> git.saurik.com Git - apt.git/commitdiff
add a GroupedFromCommandLine method to the PackageSet to split the
authorDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 6 Jun 2010 19:41:27 +0000 (21:41 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 6 Jun 2010 19:41:27 +0000 (21:41 +0200)
packages on the commandline into groups based on modifiers

apt-pkg/cacheset.cc
apt-pkg/cacheset.h

index c0b06ba323c58b17d5dde95c9bcdf1c7b704c53d..43ade4b4e7eb2cd27f8e5d0210e72c597572d0b7 100644 (file)
@@ -76,6 +76,39 @@ PackageSet PackageSet::FromRegEx(pkgCacheFile &Cache, std::string pattern, std::
        return pkgset;
 }
                                                                        /*}}}*/
+// GroupedFromCommandLine - Return all versions specified on commandline/*{{{*/
+std::map<unsigned short, PackageSet> PackageSet::GroupedFromCommandLine(
+               pkgCacheFile &Cache, const char **cmdline,
+               std::list<PackageSet::Modifier> const &mods,
+               unsigned short const &fallback, std::ostream &out) {
+       std::map<unsigned short, PackageSet> pkgsets;
+       for (const char **I = cmdline; *I != 0; ++I) {
+               unsigned short modID = fallback;
+               std::string str = *I;
+               for (std::list<PackageSet::Modifier>::const_iterator mod = mods.begin();
+                    mod != mods.end(); ++mod) {
+                       size_t const alength = strlen(mod->Alias);
+                       switch(mod->Pos) {
+                       case PackageSet::Modifier::POSTFIX:
+                               if (str.compare(str.length() - alength, alength,
+                                   mod->Alias, 0, alength) != 0)
+                                       continue;
+                               str.erase(str.length() - alength);
+                               modID = mod->ID;
+                               break;
+                       case PackageSet::Modifier::PREFIX:
+                               continue;
+                       case PackageSet::Modifier::NONE:
+                               continue;
+                       }
+                       break;
+               }
+               PackageSet pset = PackageSet::FromString(Cache, str, out);
+               pkgsets[modID].insert(pset.begin(), pset.end());
+       }
+       return pkgsets;
+}
+                                                                       /*}}}*/
 // FromCommandLine - Return all packages specified on commandline      /*{{{*/
 PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out) {
        PackageSet pkgset;
index 0f3a87a3d8b3d03dc619242c05ef653766d922f0..c9d1210835da75abd2eec36e6d8cda3808cb0bd6 100644 (file)
@@ -11,6 +11,8 @@
 // Include Files                                                       /*{{{*/
 #include <iostream>
 #include <fstream>
+#include <list>
+#include <map>
 #include <set>
 #include <string>
 
@@ -101,6 +103,27 @@ public:                                                                    /*{{{*/
                std::ostream out (std::ofstream("/dev/null").rdbuf());
                return APT::PackageSet::FromCommandLine(Cache, cmdline, out);
        }
+
+       struct Modifier {
+               enum Position { NONE, PREFIX, POSTFIX };
+               unsigned short ID;
+               const char * const Alias;
+               Position Pos;
+               Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {};
+       };
+
+       static std::map<unsigned short, PackageSet> GroupedFromCommandLine(
+               pkgCacheFile &Cache, const char **cmdline,
+               std::list<PackageSet::Modifier> const &mods,
+               unsigned short const &fallback, std::ostream &out);
+       static std::map<unsigned short, PackageSet> GroupedFromCommandLine(
+               pkgCacheFile &Cache, const char **cmdline,
+               std::list<PackageSet::Modifier> const &mods,
+               unsigned short const &fallback) {
+               std::ostream out (std::ofstream("/dev/null").rdbuf());
+               return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline,
+                               mods, fallback, out);
+       }
                                                                        /*}}}*/
 };                                                                     /*}}}*/
 class VersionSet : public std::set<pkgCache::VerIterator> {            /*{{{*/