summaryrefslogtreecommitdiff
path: root/apt-pkg/tagfile.h
blob: 661ac4f23fa2adeacca5ea75043b391425bb500c (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
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
// $Id: tagfile.h,v 1.2 1998/07/05 05:33:59 jgg Exp $
/* ######################################################################

   Fast scanner for RFC-822 type header information
   
   This parser handles Debian package files (and others). Their form is
   RFC-822 type header fields in groups seperated by a blank line.
   
   The parser reads the and provides methods to step linearly
   over it or to jump to a pre-recorded start point and read that record.
   
   A second class is used to perform pre-parsing of the record. It works
   by indexing the start of each header field and providing lookup 
   functions for header fields.
   
   ##################################################################### */
									/*}}}*/
// Header section: pkglib
#ifndef PKGLIB_TAGFILE_H
#define PKGLIB_TAGFILE_H

#include <pkglib/fileutl.h>

class pkgTagSection
{
   const char *Section;
   const char *Stop;
   
   // We have a limit of 256 tags per section.
   unsigned short Indexes[256];
   unsigned int TagCount;
     
   public:
   
   inline bool operator ==(const pkgTagSection &rhs) {return Section == rhs.Section;};
   inline bool operator !=(const pkgTagSection &rhs) {return Section != rhs.Section;};
   
   bool Find(const char *Tag,const char *&Start, const char *&End);
   bool Scan(const char *Start,unsigned long MaxLength);
   inline unsigned long size() {return Stop - Section;};

   pkgTagSection() : Section(0), Stop(0) {};
};

class pkgTagFile
{
   File Fd;
   char *Buffer;
   char *Start;
   char *End;
   unsigned long Left;
   unsigned long iOffset;
   
   bool Fill();
   
   public:

   bool Step(pkgTagSection &Section);
   inline unsigned long Offset() {return iOffset;};
   
   pkgTagFile(File &F);
};

#endif