tagfile.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: tagfile.h,v 1.12 1998/12/07 07:26:23 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. unsigned int FindI(const char *Tag);
  36. bool Scan(const char *Start,unsigned long MaxLength);
  37. inline unsigned long size() {return Stop - Section;};
  38. inline unsigned int Count() {return TagCount;};
  39. inline void Get(const char *&Start,const char *&Stop,unsigned int I)
  40. {Start = Section + Indexes[I]; Stop = Section + Indexes[I+1];}
  41. inline void GetSection(const char *&Start,const char *&Stop)
  42. {
  43. Start = Section;
  44. Stop = this->Stop;
  45. };
  46. pkgTagSection() : Section(0), Stop(0) {};
  47. };
  48. class pkgTagFile
  49. {
  50. FileFd &Fd;
  51. char *Buffer;
  52. char *Start;
  53. char *End;
  54. unsigned long Left;
  55. unsigned long iOffset;
  56. unsigned long Size;
  57. bool Fill();
  58. public:
  59. bool Step(pkgTagSection &Section);
  60. inline unsigned long Offset() {return iOffset;};
  61. bool Jump(pkgTagSection &Tag,unsigned long Offset);
  62. pkgTagFile(FileFd &F,unsigned long Size = 32*1024);
  63. };
  64. #endif