writer.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: writer.h,v 1.2 2001/02/20 07:03:18 jgg Exp $
  4. /* ######################################################################
  5. Writer
  6. The file writer classes. These write various types of output, sources,
  7. packages and contents.
  8. ##################################################################### */
  9. /*}}}*/
  10. #ifndef WRITER_H
  11. #define WRITER_H
  12. #ifdef __GNUG__
  13. #pragma interface "writer.h"
  14. #endif
  15. #include <string>
  16. #include <stdio.h>
  17. #include "cachedb.h"
  18. #include "override.h"
  19. #include "apt-ftparchive.h"
  20. class FTWScanner
  21. {
  22. protected:
  23. char *TmpExt;
  24. const char *Ext[10];
  25. const char *OriginalPath;
  26. char *RealPath;
  27. bool ErrorPrinted;
  28. // Stuff for the delinker
  29. bool NoLinkAct;
  30. static FTWScanner *Owner;
  31. static int Scanner(const char *File,const struct stat *sb,int Flag);
  32. bool Delink(string &FileName,const char *OriginalPath,
  33. unsigned long &Bytes,struct stat &St);
  34. inline void NewLine(unsigned Priority)
  35. {
  36. if (ErrorPrinted == false && Quiet <= Priority)
  37. {
  38. cout << endl;
  39. ErrorPrinted = true;
  40. }
  41. }
  42. public:
  43. unsigned long DeLinkLimit;
  44. string InternalPrefix;
  45. virtual bool DoPackage(string FileName) = 0;
  46. bool RecursiveScan(string Dir);
  47. bool LoadFileList(string BaseDir,string File);
  48. bool SetExts(string Vals);
  49. FTWScanner();
  50. virtual ~FTWScanner() {delete [] RealPath; delete [] TmpExt;};
  51. };
  52. class PackagesWriter : public FTWScanner
  53. {
  54. Override Over;
  55. CacheDB Db;
  56. public:
  57. // Some flags
  58. bool DoMD5;
  59. bool NoOverride;
  60. bool DoContents;
  61. // General options
  62. string PathPrefix;
  63. string DirStrip;
  64. FILE *Output;
  65. struct CacheDB::Stats &Stats;
  66. inline bool ReadOverride(string File) {return Over.ReadOverride(File);};
  67. virtual bool DoPackage(string FileName);
  68. PackagesWriter(string DB,string Overrides);
  69. virtual ~PackagesWriter() {};
  70. };
  71. class ContentsWriter : public FTWScanner
  72. {
  73. CacheDB Db;
  74. GenContents Gen;
  75. public:
  76. // General options
  77. FILE *Output;
  78. struct CacheDB::Stats &Stats;
  79. string Prefix;
  80. bool DoPackage(string FileName,string Package);
  81. virtual bool DoPackage(string FileName)
  82. {return DoPackage(FileName,string());};
  83. bool ReadFromPkgs(string PkgFile,string PkgCompress);
  84. void Finish() {Gen.Print(Output);};
  85. inline bool ReadyDB(string DB) {return Db.ReadyDB(DB);};
  86. ContentsWriter(string DB);
  87. virtual ~ContentsWriter() {};
  88. };
  89. class SourcesWriter : public FTWScanner
  90. {
  91. Override BOver;
  92. Override SOver;
  93. char *Buffer;
  94. unsigned long BufSize;
  95. public:
  96. bool NoOverride;
  97. // General options
  98. string PathPrefix;
  99. string DirStrip;
  100. FILE *Output;
  101. struct CacheDB::Stats Stats;
  102. /* inline bool ReadBinOverride(string File) {return BOver.ReadOverride(File);};
  103. bool ReadSrcOverride(string File); // {return BOver.ReadOverride(File);};*/
  104. virtual bool DoPackage(string FileName);
  105. SourcesWriter(string BOverrides,string SOverrides);
  106. virtual ~SourcesWriter() {free(Buffer);};
  107. };
  108. #endif