Ubuntu Pastebin

Paste from egon at Fri, 8 Apr 2016 14:24:03 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// 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);
}
Download as text