contents.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: contents.h,v 1.2 2001/02/20 07:03:18 jgg Exp $
  4. /* ######################################################################
  5. contents - Contents of archive things.
  6. ##################################################################### */
  7. /*}}}*/
  8. #ifndef CONTENTS_H
  9. #define CONTENTS_H
  10. #include <apt-pkg/dirstream.h>
  11. #include <stddef.h>
  12. #include <stdio.h>
  13. #include <string>
  14. class debDebFile;
  15. class FileFd;
  16. class GenContents
  17. {
  18. struct Node
  19. {
  20. // Binary Tree links
  21. Node *BTreeLeft;
  22. Node *BTreeRight;
  23. Node *DirDown;
  24. Node *Dups;
  25. const char *Path;
  26. const char *Package;
  27. void *operator new(size_t Amount,GenContents *Owner);
  28. void operator delete(void *) {};
  29. Node() : BTreeLeft(0), BTreeRight(0), DirDown(0), Dups(0),
  30. Path(0), Package(0) {};
  31. };
  32. friend struct Node;
  33. struct BigBlock
  34. {
  35. void *Block;
  36. BigBlock *Next;
  37. };
  38. Node Root;
  39. // Big block allocation pools
  40. BigBlock *BlockList;
  41. char *StrPool;
  42. unsigned long StrLeft;
  43. Node *NodePool;
  44. unsigned long NodeLeft;
  45. Node *Grab(Node *Top,const char *Name,const char *Package);
  46. void WriteSpace(std::string &out, size_t Current, size_t Target);
  47. void DoPrint(FileFd &Out,Node *Top, char *Buf);
  48. public:
  49. char *Mystrdup(const char *From);
  50. void Add(const char *Dir,const char *Package);
  51. void Print(FileFd &Out);
  52. GenContents() : BlockList(0), StrPool(0), StrLeft(0),
  53. NodePool(0), NodeLeft(0) {};
  54. ~GenContents();
  55. };
  56. class ContentsExtract : public pkgDirStream
  57. {
  58. public:
  59. // The Data Block
  60. char *Data;
  61. unsigned long long MaxSize;
  62. unsigned long long CurSize;
  63. void AddData(const char *Text);
  64. bool Read(debDebFile &Deb);
  65. virtual bool DoItem(Item &Itm,int &Fd) APT_OVERRIDE;
  66. void Reset() {CurSize = 0;};
  67. bool TakeContents(const void *Data,unsigned long long Length);
  68. void Add(GenContents &Contents,std::string const &Package);
  69. ContentsExtract();
  70. virtual ~ContentsExtract();
  71. };
  72. #endif