]> git.saurik.com Git - apt.git/blob - apt-pkg/tagfile.h
* merged from main
[apt.git] / apt-pkg / tagfile.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: tagfile.h,v 1.20 2003/05/19 17:13:57 doogie Exp $
4 /* ######################################################################
5
6 Fast scanner for RFC-822 type header information
7
8 This parser handles Debian package files (and others). Their form is
9 RFC-822 type header fields in groups separated by a blank line.
10
11 The parser reads the file and provides methods to step linearly
12 over it or to jump to a pre-recorded start point and read that record.
13
14 A second class is used to perform pre-parsing of the record. It works
15 by indexing the start of each header field and providing lookup
16 functions for header fields.
17
18 ##################################################################### */
19 /*}}}*/
20 #ifndef PKGLIB_TAGFILE_H
21 #define PKGLIB_TAGFILE_H
22
23
24 #include <apt-pkg/fileutl.h>
25 #include <stdio.h>
26
27 class pkgTagSection
28 {
29 const char *Section;
30 const char *Stop;
31
32 // We have a limit of 256 tags per section.
33 unsigned short Indexes[256];
34 unsigned short AlphaIndexes[0x100];
35
36 unsigned int TagCount;
37
38 public:
39
40 inline bool operator ==(const pkgTagSection &rhs) {return Section == rhs.Section;};
41 inline bool operator !=(const pkgTagSection &rhs) {return Section != rhs.Section;};
42
43 bool Find(const char *Tag,const char *&Start, const char *&End) const;
44 bool Find(const char *Tag,unsigned &Pos) const;
45 string FindS(const char *Tag) const;
46 signed int FindI(const char *Tag,signed long Default = 0) const ;
47 bool FindFlag(const char *Tag,unsigned long &Flags,
48 unsigned long Flag) const;
49 bool Scan(const char *Start,unsigned long MaxLength);
50 inline unsigned long size() const {return Stop - Section;};
51 void Trim();
52
53 inline unsigned int Count() const {return TagCount;};
54 inline void Get(const char *&Start,const char *&Stop,unsigned int I) const
55 {Start = Section + Indexes[I]; Stop = Section + Indexes[I+1];}
56
57 inline void GetSection(const char *&Start,const char *&Stop) const
58 {
59 Start = Section;
60 Stop = this->Stop;
61 };
62
63 pkgTagSection() : Section(0), Stop(0) {};
64 };
65
66 class pkgTagFile
67 {
68 FileFd &Fd;
69 char *Buffer;
70 char *Start;
71 char *End;
72 bool Done;
73 unsigned long iOffset;
74 unsigned long Size;
75
76 bool Fill();
77 bool Resize();
78
79 public:
80
81 bool Step(pkgTagSection &Section);
82 inline unsigned long Offset() {return iOffset;};
83 bool Jump(pkgTagSection &Tag,unsigned long Offset);
84
85 pkgTagFile(FileFd *F,unsigned long Size = 32*1024);
86 ~pkgTagFile();
87 };
88
89 /* This is the list of things to rewrite. The rewriter
90 goes through and changes or adds each of these headers
91 to suit. A zero forces the header to be erased, an empty string
92 causes the old value to be used. (rewrite rule ignored) */
93 struct TFRewriteData
94 {
95 const char *Tag;
96 const char *Rewrite;
97 const char *NewTag;
98 };
99 extern const char **TFRewritePackageOrder;
100 extern const char **TFRewriteSourceOrder;
101
102 bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[],
103 TFRewriteData *Rewrite);
104
105 #endif