]> git.saurik.com Git - apt-legacy.git/blob - test/scratch.cc
Added some initial debtags data.
[apt-legacy.git] / test / scratch.cc
1 #include <apt-pkg/dpkgdb.h>
2 #include <apt-pkg/debfile.h>
3 #include <apt-pkg/error.h>
4 #include <apt-pkg/configuration.h>
5 #include <apt-pkg/progress.h>
6 #include <apt-pkg/extract.h>
7 #include <apt-pkg/init.h>
8 #include <apt-pkg/fileutl.h>
9
10 using namespace std;
11
12 int main(int argc,char *argv[])
13 {
14 pkgInitConfig(*_config);
15 pkgInitSystem(*_config,_system);
16
17 // cout << flNoLink(argv[1]) << endl;
18
19 // #if 0
20 /* DynamicMMap *FileMap = new DynamicMMap(MMap::Public);
21 pkgFLCache *FList = new pkgFLCache(*FileMap);
22
23 char *Name = "/tmp/test";
24 pkgFLCache::PkgIterator Pkg(*FList,0);
25 pkgFLCache::NodeIterator Node = FList->GetNode(Name,Name+strlen(Name),Pkg.Offset(),true,false);
26 cout << (pkgFLCache::Node *)Node << endl;
27 Node = FList->GetNode(Name,Name+strlen(Name),Pkg.Offset(),true,false);
28 cout << (pkgFLCache::Node *)Node << endl;
29 */
30 // #if 0
31 _config->Set("Dir::State::status","/tmp/testing/status");
32
33 debDpkgDB Db;
34
35 {
36 OpTextProgress Prog;
37
38 if (Db.ReadyPkgCache(Prog) == false)
39 cerr << "Error!" << endl;
40 Prog.Done();
41
42 if (Db.ReadyFileList(Prog) == false)
43 cerr << "Error!" << endl;
44 }
45
46 if (_error->PendingError() == true)
47 {
48 _error->DumpErrors();
49 return 0;
50 }
51
52 /* Db.GetFLCache().BeginDiverLoad();
53 pkgFLCache::PkgIterator Pkg(Db.GetFLCache(),0);
54 if (Db.GetFLCache().AddDiversion(Pkg,"/usr/include/linux/kerneld.h","/usr/bin/nslookup") == false)
55 cerr << "Error!" << endl;
56
57 const char *Tmp = "/usr/include/linux/kerneld.h";
58 pkgFLCache::NodeIterator Nde = Db.GetFLCache().GetNode(Tmp,Tmp+strlen(Tmp),0,false,false);
59 map_ptrloc Loc = Nde->File;
60
61 for (; Nde.end() == false && Nde->File == Loc; Nde++)
62 cout << Nde->Flags << ',' << Nde->Pointer << ',' << Nde.File() << endl;
63 Db.GetFLCache().FinishDiverLoad();*/
64
65 /* unsigned int I = 0;
66 pkgFLCache &Fl = Db.GetFLCache();
67 while (I < Fl.HeaderP->HashSize)
68 {
69 cout << I << endl;
70 pkgFLCache::NodeIterator Node(Fl,Fl.NodeP + Fl.HeaderP->FileHash + I++);
71 if (Node->Pointer == 0)
72 continue;
73 for (; Node.end() == false; Node++)
74 {
75 cout << Node.DirN() << '/' << Node.File();
76 if (Node->Flags == pkgFLCache::Node::Diversion)
77 cout << " (div)";
78 if (Node->Flags == pkgFLCache::Node::ConfFile)
79 cout << " (conf)";
80 cout << endl;
81 }
82 }*/
83
84 for (int I = 1; I < argc; I++)
85 {
86 FileFd F(argv[I],FileFd::ReadOnly);
87 debDebFile Deb(F);
88
89 if (Deb.ExtractControl(Db) == false)
90 cerr << "Error!" << endl;
91 cout << argv[I] << endl;
92
93 pkgCache::VerIterator Ver = Deb.MergeControl(Db);
94 if (Ver.end() == true)
95 cerr << "Failed" << endl;
96 else
97 cout << Ver.ParentPkg().Name() << ' ' << Ver.VerStr() << endl;
98
99 pkgExtract Extract(Db.GetFLCache(),Ver);
100 Deb.ExtractArchive(Extract);
101 }
102 // #endif
103 //#endif
104 _error->DumpErrors();
105 }