tagfile.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: tagfile.h,v 1.5 1998/07/16 06:08: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 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. File &Fd;
  40. char *Buffer;
  41. char *Start;
  42. char *End;
  43. unsigned long Left;
  44. unsigned long iOffset;
  45. bool Fill();
  46. public:
  47. bool Step(pkgTagSection &Section);
  48. inline unsigned long Offset() {return iOffset;};
  49. pkgTagFile(File &F);
  50. };
  51. #endif