tagfile.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: tagfile.h,v 1.14 1999/07/03 06:45:40 jgg Exp $
  4. /* ######################################################################
  5. Fast scanner for RFC-822 type header information
  6. This parser handles Debian package files (and others). Their form is
  7. RFC-822 type header fields in groups seperated by a blank line.
  8. The parser reads the file and provides methods to step linearly
  9. over it or to jump to a pre-recorded start point and read that record.
  10. A second class is used to perform pre-parsing of the record. It works
  11. by indexing the start of each header field and providing lookup
  12. functions for header fields.
  13. ##################################################################### */
  14. /*}}}*/
  15. // Header section: pkglib
  16. #ifndef PKGLIB_TAGFILE_H
  17. #define PKGLIB_TAGFILE_H
  18. #ifdef __GNUG__
  19. #pragma interface "apt-pkg/tagfile.h"
  20. #endif
  21. #include <apt-pkg/fileutl.h>
  22. class pkgTagSection
  23. {
  24. const char *Section;
  25. const char *Stop;
  26. // We have a limit of 256 tags per section.
  27. unsigned short Indexes[256];
  28. unsigned short AlphaIndexes[26 + 26*26];
  29. unsigned int TagCount;
  30. public:
  31. inline bool operator ==(const pkgTagSection &rhs) {return Section == rhs.Section;};
  32. inline bool operator !=(const pkgTagSection &rhs) {return Section != rhs.Section;};
  33. bool Find(const char *Tag,const char *&Start, const char *&End);
  34. string FindS(const char *Tag);
  35. signed int FindI(const char *Tag,signed long Default = 0);
  36. bool pkgTagSection::FindFlag(const char *Tag,unsigned long &Flags,
  37. unsigned long Flag);
  38. bool Scan(const char *Start,unsigned long MaxLength);
  39. inline unsigned long size() {return Stop - Section;};
  40. inline unsigned int Count() {return TagCount;};
  41. inline void Get(const char *&Start,const char *&Stop,unsigned int I)
  42. {Start = Section + Indexes[I]; Stop = Section + Indexes[I+1];}
  43. inline void GetSection(const char *&Start,const char *&Stop)
  44. {
  45. Start = Section;
  46. Stop = this->Stop;
  47. };
  48. pkgTagSection() : Section(0), Stop(0) {};
  49. };
  50. class pkgTagFile
  51. {
  52. FileFd &Fd;
  53. char *Buffer;
  54. char *Start;
  55. char *End;
  56. unsigned long Left;
  57. unsigned long iOffset;
  58. unsigned long Size;
  59. bool Fill();
  60. public:
  61. bool Step(pkgTagSection &Section);
  62. inline unsigned long Offset() {return iOffset;};
  63. bool Jump(pkgTagSection &Tag,unsigned long Offset);
  64. pkgTagFile(FileFd &F,unsigned long Size = 32*1024);
  65. ~pkgTagFile();
  66. };
  67. #endif