tagfile.h 2.3 KB

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