tagfile.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: tagfile.h,v 1.9 1998/08/26 04:52:24 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. bool Scan(const char *Start,unsigned long MaxLength);
  34. inline unsigned long size() {return Stop - Section;};
  35. pkgTagSection() : Section(0), Stop(0) {};
  36. };
  37. class pkgTagFile
  38. {
  39. FileFd &Fd;
  40. char *Buffer;
  41. char *Start;
  42. char *End;
  43. unsigned long Left;
  44. unsigned long iOffset;
  45. unsigned long Size;
  46. bool Fill();
  47. public:
  48. bool Step(pkgTagSection &Section);
  49. inline unsigned long Offset() {return iOffset;};
  50. bool Jump(pkgTagSection &Tag,unsigned long Offset);
  51. pkgTagFile(FileFd &F,unsigned long Size = 32*1024);
  52. };
  53. #endif