summaryrefslogtreecommitdiff
path: root/ftparchive/contents.h
blob: dbbb83350c8aa7913174f6d4691e0aa7e1138204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
// $Id: contents.h,v 1.2 2001/02/20 07:03:18 jgg Exp $
/* ######################################################################
   
   contents - Contents of archive things.
   
   ##################################################################### */
									/*}}}*/
#ifndef CONTENTS_H
#define CONTENTS_H

#include <apt-pkg/dirstream.h>

#include <stddef.h>
#include <stdio.h>
#include <string>

class debDebFile;

class GenContents
{
   struct Node
   {
      // Binary Tree links
      Node *BTreeLeft;
      Node *BTreeRight;
      Node *DirDown;
      Node *Dups;
      const char *Path;
      const char *Package;
      
      void *operator new(size_t Amount,GenContents *Owner);
      void operator delete(void *) {};
      
      Node() : BTreeLeft(0), BTreeRight(0), DirDown(0), Dups(0), 
               Path(0), Package(0) {};
   };
   friend struct Node;
   
   struct BigBlock
   {
      void *Block;
      BigBlock *Next;
   };
   
   Node Root;
   
   // Big block allocation pools
   BigBlock *BlockList;   
   char *StrPool;
   unsigned long StrLeft;
   Node *NodePool;
   unsigned long NodeLeft;
   
   Node *Grab(Node *Top,const char *Name,const char *Package);
   void WriteSpace(FILE *Out,unsigned int Current,unsigned int Target);
   void DoPrint(FILE *Out,Node *Top, char *Buf);
   
   public:
   
   char *Mystrdup(const char *From);
   void Add(const char *Dir,const char *Package);   
   void Print(FILE *Out);

   GenContents() : BlockList(0), StrPool(0), StrLeft(0), 
                   NodePool(0), NodeLeft(0) {};
   ~GenContents();
};

class ContentsExtract : public pkgDirStream      
{
   public:

   // The Data Block
   char *Data;
   unsigned long long MaxSize;
   unsigned long long CurSize;
   void AddData(const char *Text);
   
   bool Read(debDebFile &Deb);
   
   virtual bool DoItem(Item &Itm,int &Fd);      
   void Reset() {CurSize = 0;};
   bool TakeContents(const void *Data,unsigned long long Length);
   void Add(GenContents &Contents,std::string const &Package);
   
   ContentsExtract() : Data(0), MaxSize(0), CurSize(0) {};
   virtual ~ContentsExtract() {delete [] Data;};
};

#endif