00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PKGLIB_TAGFILE_H
00021 #define PKGLIB_TAGFILE_H
00022
00023
00024 #include <apt-pkg/fileutl.h>
00025 #include <stdio.h>
00026
00027 class pkgTagSection
00028 {
00029 const char *Section;
00030
00031
00032 unsigned int Indexes[256];
00033 unsigned int AlphaIndexes[0x100];
00034
00035 unsigned int TagCount;
00036
00037
00038
00039 inline static unsigned long AlphaHash(const char *Text, const char *End = 0)
00040 {
00041 unsigned long Res = 0;
00042 for (; Text != End && *Text != ':' && *Text != 0; Text++)
00043 Res = ((unsigned long)(*Text) & 0xDF) ^ (Res << 1);
00044 return Res & 0xFF;
00045 }
00046
00047
00048 protected:
00049 const char *Stop;
00050
00051 public:
00052
00053 inline bool operator ==(const pkgTagSection &rhs) {return Section == rhs.Section;};
00054 inline bool operator !=(const pkgTagSection &rhs) {return Section != rhs.Section;};
00055
00056 bool Find(const char *Tag,const char *&Start, const char *&End) const;
00057 bool Find(const char *Tag,unsigned &Pos) const;
00058 string FindS(const char *Tag) const;
00059 signed int FindI(const char *Tag,signed long Default = 0) const ;
00060 unsigned long long FindULL(const char *Tag, unsigned long long const &Default = 0) const;
00061 bool FindFlag(const char *Tag,unsigned long &Flags,
00062 unsigned long Flag) const;
00063 bool Scan(const char *Start,unsigned long MaxLength);
00064 inline unsigned long size() const {return Stop - Section;};
00065 void Trim();
00066 virtual void TrimRecord(bool BeforeRecord, const char* &End);
00067
00068 inline unsigned int Count() const {return TagCount;};
00069 inline bool Exists(const char* const Tag) {return AlphaIndexes[AlphaHash(Tag)] != 0;}
00070
00071 inline void Get(const char *&Start,const char *&Stop,unsigned int I) const
00072 {Start = Section + Indexes[I]; Stop = Section + Indexes[I+1];}
00073
00074 inline void GetSection(const char *&Start,const char *&Stop) const
00075 {
00076 Start = Section;
00077 Stop = this->Stop;
00078 };
00079
00080 pkgTagSection() : Section(0), Stop(0) {};
00081 };
00082
00083 class pkgTagFile
00084 {
00085 FileFd &Fd;
00086 char *Buffer;
00087 char *Start;
00088 char *End;
00089 bool Done;
00090 unsigned long iOffset;
00091 unsigned long Size;
00092
00093 bool Fill();
00094 bool Resize();
00095
00096 public:
00097
00098 bool Step(pkgTagSection &Section);
00099 inline unsigned long Offset() {return iOffset;};
00100 bool Jump(pkgTagSection &Tag,unsigned long Offset);
00101
00102 pkgTagFile(FileFd *F,unsigned long Size = 32*1024);
00103 ~pkgTagFile();
00104 };
00105
00106
00107
00108
00109
00110 struct TFRewriteData
00111 {
00112 const char *Tag;
00113 const char *Rewrite;
00114 const char *NewTag;
00115 };
00116 extern const char **TFRewritePackageOrder;
00117 extern const char **TFRewriteSourceOrder;
00118
00119 bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[],
00120 TFRewriteData *Rewrite);
00121
00122 #endif