writer.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: writer.h,v 1.4 2001/06/26 02:50:27 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 <iostream>
  18. #include <vector>
  19. #include "cachedb.h"
  20. #include "override.h"
  21. #include "apt-ftparchive.h"
  22. using std::string;
  23. using std::cout;
  24. using std::endl;
  25. class FTWScanner
  26. {
  27. protected:
  28. char *TmpExt;
  29. const char *Ext[10];
  30. const char *OriginalPath;
  31. char *RealPath;
  32. bool ErrorPrinted;
  33. // Stuff for the delinker
  34. bool NoLinkAct;
  35. static FTWScanner *Owner;
  36. static int Scanner(const char *File,const struct stat *sb,int Flag);
  37. bool Delink(string &FileName,const char *OriginalPath,
  38. unsigned long &Bytes,struct stat &St);
  39. inline void NewLine(unsigned Priority)
  40. {
  41. if (ErrorPrinted == false && Quiet <= Priority)
  42. {
  43. cout << endl;
  44. ErrorPrinted = true;
  45. }
  46. }
  47. public:
  48. unsigned long DeLinkLimit;
  49. string InternalPrefix;
  50. virtual bool DoPackage(string FileName) = 0;
  51. bool RecursiveScan(string Dir);
  52. bool LoadFileList(string BaseDir,string File);
  53. bool SetExts(string Vals);
  54. FTWScanner();
  55. virtual ~FTWScanner() {delete [] RealPath; delete [] TmpExt;};
  56. };
  57. class PackagesWriter : public FTWScanner
  58. {
  59. Override Over;
  60. CacheDB Db;
  61. public:
  62. // Some flags
  63. bool DoMD5;
  64. bool NoOverride;
  65. bool DoContents;
  66. // General options
  67. string PathPrefix;
  68. string DirStrip;
  69. FILE *Output;
  70. struct CacheDB::Stats &Stats;
  71. inline bool ReadOverride(string File) {return Over.ReadOverride(File);};
  72. inline bool ReadExtraOverride(string File)
  73. {return Over.ReadExtraOverride(File);};
  74. virtual bool DoPackage(string FileName);
  75. PackagesWriter(string DB,string Overrides,string ExtOverrides=string());
  76. virtual ~PackagesWriter() {};
  77. };
  78. class ContentsWriter : public FTWScanner
  79. {
  80. CacheDB Db;
  81. GenContents Gen;
  82. public:
  83. // General options
  84. FILE *Output;
  85. struct CacheDB::Stats &Stats;
  86. string Prefix;
  87. bool DoPackage(string FileName,string Package);
  88. virtual bool DoPackage(string FileName)
  89. {return DoPackage(FileName,string());};
  90. bool ReadFromPkgs(string PkgFile,string PkgCompress);
  91. void Finish() {Gen.Print(Output);};
  92. inline bool ReadyDB(string DB) {return Db.ReadyDB(DB);};
  93. ContentsWriter(string DB);
  94. virtual ~ContentsWriter() {};
  95. };
  96. class SourcesWriter : public FTWScanner
  97. {
  98. Override BOver;
  99. Override SOver;
  100. char *Buffer;
  101. unsigned long BufSize;
  102. public:
  103. bool NoOverride;
  104. // General options
  105. string PathPrefix;
  106. string DirStrip;
  107. FILE *Output;
  108. struct CacheDB::Stats Stats;
  109. virtual bool DoPackage(string FileName);
  110. SourcesWriter(string BOverrides,string SOverrides,
  111. string ExtOverrides=string());
  112. virtual ~SourcesWriter() {free(Buffer);};
  113. };
  114. #endif