scratch.cc 2.8 KB

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