tagfile.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: tagfile.h,v 1.2 1998/07/05 05:33:59 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 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. #include <pkglib/fileutl.h>
  19. class pkgTagSection
  20. {
  21. const char *Section;
  22. const char *Stop;
  23. // We have a limit of 256 tags per section.
  24. unsigned short Indexes[256];
  25. unsigned int TagCount;
  26. public:
  27. inline bool operator ==(const pkgTagSection &rhs) {return Section == rhs.Section;};
  28. inline bool operator !=(const pkgTagSection &rhs) {return Section != rhs.Section;};
  29. bool Find(const char *Tag,const char *&Start, const char *&End);
  30. bool Scan(const char *Start,unsigned long MaxLength);
  31. inline unsigned long size() {return Stop - Section;};
  32. pkgTagSection() : Section(0), Stop(0) {};
  33. };
  34. class pkgTagFile
  35. {
  36. File Fd;
  37. char *Buffer;
  38. char *Start;
  39. char *End;
  40. unsigned long Left;
  41. unsigned long iOffset;
  42. bool Fill();
  43. public:
  44. bool Step(pkgTagSection &Section);
  45. inline unsigned long Offset() {return iOffset;};
  46. pkgTagFile(File &F);
  47. };
  48. #endif