//
// build with:
// g++ -o miniapt miniapt.cc -lapt-pkg
//
#include <apt-pkg/init.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/cmndline.h>
#include <apt-pkg/version.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <set>
#include <vector>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <stdexcept>
static pkgSourceList *list;
static pkgPolicy *policy;
static void look_at_pkg(const pkgCache::PkgIterator &P)
{
pkgCache::VerIterator current = P.CurrentVer();
pkgCache::VerIterator candidate = policy->GetCandidateVer(P);
std::string archive, origin;
for (pkgCache::VerIterator V = P.VersionList(); V.IsGood(); V++) {
for (pkgCache::VerFileIterator VF = V.FileList(); VF.IsGood(); VF++) {
// see InRelease for the fields
archive = VF.File().Archive();
origin = VF.File().Origin();
// also available: Codename, Label
break;
}
}
if (candidate) {
std::cout << P.FullName() << " "
<< candidate.VerStr() << " "
<< archive << " "
<< origin << " "
<< std::endl;
}
}
int main(int argc,const char **argv)
{
pkgInitConfig(*_config);
pkgInitSystem(*_config, _system);
pkgCacheFile cachefile;
pkgCache *cache = cachefile.GetPkgCache();
list = cachefile.GetSourceList();
policy = cachefile.GetPolicy();
if (cache == NULL || _error->PendingError()) {
_error->DumpErrors();
return 1;
}
for (pkgCache::GrpIterator grp = cache->GrpBegin(); grp != cache->GrpEnd(); grp++)
for (pkgCache::PkgIterator p = grp.PackageList(); !p.end(); p = grp.NextPkg(p))
look_at_pkg(p);
}