contents.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <stdlib.h>
  11. #include <stdio.h>
  12. #include <apt-pkg/debfile.h>
  13. #include <apt-pkg/dirstream.h>
  14. class GenContents
  15. {
  16. struct Node
  17. {
  18. // Binary Tree links
  19. Node *BTreeLeft;
  20. Node *BTreeRight;
  21. Node *DirDown;
  22. Node *Dups;
  23. const char *Path;
  24. const char *Package;
  25. void *operator new(size_t Amount,GenContents *Owner);
  26. void operator delete(void *) {};
  27. Node() : BTreeLeft(0), BTreeRight(0), DirDown(0), Dups(0),
  28. Path(0), Package(0) {};
  29. };
  30. friend struct Node;
  31. struct BigBlock
  32. {
  33. void *Block;
  34. BigBlock *Next;
  35. };
  36. Node Root;
  37. // Big block allocation pools
  38. BigBlock *BlockList;
  39. char *StrPool;
  40. unsigned long StrLeft;
  41. Node *NodePool;
  42. unsigned long NodeLeft;
  43. Node *Grab(Node *Top,const char *Name,const char *Package);
  44. void WriteSpace(FILE *Out,unsigned int Current,unsigned int Target);
  45. void DoPrint(FILE *Out,Node *Top, char *Buf);
  46. public:
  47. char *Mystrdup(const char *From);
  48. void Add(const char *Dir,const char *Package);
  49. void Print(FILE *Out);
  50. GenContents() : BlockList(0), StrPool(0), StrLeft(0),
  51. NodePool(0), NodeLeft(0) {};
  52. ~GenContents();
  53. };
  54. class ContentsExtract : public pkgDirStream
  55. {
  56. public:
  57. // The Data Block
  58. char *Data;
  59. unsigned long MaxSize;
  60. unsigned long CurSize;
  61. void AddData(const char *Text);
  62. bool Read(debDebFile &Deb);
  63. virtual bool DoItem(Item &Itm,int &Fd);
  64. void Reset() {CurSize = 0;};
  65. bool TakeContents(const void *Data,unsigned long Length);
  66. void Add(GenContents &Contents,string const &Package);
  67. ContentsExtract() : Data(0), MaxSize(0), CurSize(0) {};
  68. virtual ~ContentsExtract() {delete [] Data;};
  69. };
  70. #endif