scratch.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. using namespace std;
  10. int main(int argc,char *argv[])
  11. {
  12. pkgInitConfig(*_config);
  13. pkgInitSystem(*_config,_system);
  14. // cout << flNoLink(argv[1]) << endl;
  15. // #if 0
  16. /* DynamicMMap *FileMap = new DynamicMMap(MMap::Public);
  17. pkgFLCache *FList = new pkgFLCache(*FileMap);
  18. char *Name = "/tmp/test";
  19. pkgFLCache::PkgIterator Pkg(*FList,0);
  20. pkgFLCache::NodeIterator Node = FList->GetNode(Name,Name+strlen(Name),Pkg.Offset(),true,false);
  21. cout << (pkgFLCache::Node *)Node << endl;
  22. Node = FList->GetNode(Name,Name+strlen(Name),Pkg.Offset(),true,false);
  23. cout << (pkgFLCache::Node *)Node << endl;
  24. */
  25. // #if 0
  26. _config->Set("Dir::State::status","/tmp/testing/status");
  27. debDpkgDB Db;
  28. {
  29. OpTextProgress Prog;
  30. if (Db.ReadyPkgCache(Prog) == false)
  31. cerr << "Error!" << endl;
  32. Prog.Done();
  33. if (Db.ReadyFileList(Prog) == false)
  34. cerr << "Error!" << endl;
  35. }
  36. if (_error->PendingError() == true)
  37. {
  38. _error->DumpErrors();
  39. return 0;
  40. }
  41. /* Db.GetFLCache().BeginDiverLoad();
  42. pkgFLCache::PkgIterator Pkg(Db.GetFLCache(),0);
  43. if (Db.GetFLCache().AddDiversion(Pkg,"/usr/include/linux/kerneld.h","/usr/bin/nslookup") == false)
  44. cerr << "Error!" << endl;
  45. const char *Tmp = "/usr/include/linux/kerneld.h";
  46. pkgFLCache::NodeIterator Nde = Db.GetFLCache().GetNode(Tmp,Tmp+strlen(Tmp),0,false,false);
  47. map_ptrloc Loc = Nde->File;
  48. for (; Nde.end() == false && Nde->File == Loc; Nde++)
  49. cout << Nde->Flags << ',' << Nde->Pointer << ',' << Nde.File() << endl;
  50. Db.GetFLCache().FinishDiverLoad();*/
  51. /* unsigned int I = 0;
  52. pkgFLCache &Fl = Db.GetFLCache();
  53. while (I < Fl.HeaderP->HashSize)
  54. {
  55. cout << I << endl;
  56. pkgFLCache::NodeIterator Node(Fl,Fl.NodeP + Fl.HeaderP->FileHash + I++);
  57. if (Node->Pointer == 0)
  58. continue;
  59. for (; Node.end() == false; Node++)
  60. {
  61. cout << Node.DirN() << '/' << Node.File();
  62. if (Node->Flags == pkgFLCache::Node::Diversion)
  63. cout << " (div)";
  64. if (Node->Flags == pkgFLCache::Node::ConfFile)
  65. cout << " (conf)";
  66. cout << endl;
  67. }
  68. }*/
  69. for (int I = 1; I < argc; I++)
  70. {
  71. FileFd F(argv[I],FileFd::ReadOnly);
  72. debDebFile Deb(F);
  73. if (Deb.ExtractControl(Db) == false)
  74. cerr << "Error!" << endl;
  75. cout << argv[I] << endl;
  76. pkgCache::VerIterator Ver = Deb.MergeControl(Db);
  77. if (Ver.end() == true)
  78. cerr << "Failed" << endl;
  79. else
  80. cout << Ver.ParentPkg().Name() << ' ' << Ver.VerStr() << endl;
  81. pkgExtract Extract(Db.GetFLCache(),Ver);
  82. Deb.ExtractArchive(Extract);
  83. }
  84. // #endif
  85. //#endif
  86. _error->DumpErrors();
  87. }