* Enable apt-ftparchive to generate Release files
[ntk/apt.git] / ftparchive / writer.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: writer.h,v 1.5 2003/12/26 20:08:56 mdz Exp $
4 /* ######################################################################
5
6 Writer
7
8 The file writer classes. These write various types of output, sources,
9 packages and contents.
10
11 ##################################################################### */
12 /*}}}*/
13 #ifndef WRITER_H
14 #define WRITER_H
15
16 #ifdef __GNUG__
17 #pragma interface "writer.h"
18 #endif
19
20 #include <string>
21 #include <stdio.h>
22 #include <iostream>
23 #include <vector>
24
25 #include "cachedb.h"
26 #include "override.h"
27 #include "apt-ftparchive.h"
28
29 using std::string;
30 using std::cout;
31 using std::endl;
32 using std::vector;
33
34 class FTWScanner
35 {
36 protected:
37 vector<string> Patterns;
38 const char *OriginalPath;
39 char *RealPath;
40 bool ErrorPrinted;
41
42 // Stuff for the delinker
43 bool NoLinkAct;
44
45 static FTWScanner *Owner;
46 static int Scanner(const char *File,const struct stat *sb,int Flag);
47
48 bool Delink(string &FileName,const char *OriginalPath,
49 unsigned long &Bytes,struct stat &St);
50
51 inline void NewLine(unsigned Priority)
52 {
53 if (ErrorPrinted == false && Quiet <= Priority)
54 {
55 cout << endl;
56 ErrorPrinted = true;
57 }
58 }
59
60 public:
61
62 unsigned long DeLinkLimit;
63 string InternalPrefix;
64
65 virtual bool DoPackage(string FileName) = 0;
66 bool RecursiveScan(string Dir);
67 bool LoadFileList(string BaseDir,string File);
68 bool ClearPatterns() { Patterns.clear(); };
69 bool AddPattern(string Pattern) { Patterns.push_back(Pattern); };
70 bool SetExts(string Vals);
71
72 FTWScanner();
73 virtual ~FTWScanner() {delete [] RealPath;};
74 };
75
76 class PackagesWriter : public FTWScanner
77 {
78 Override Over;
79 CacheDB Db;
80
81 public:
82
83 // Some flags
84 bool DoMD5;
85 bool NoOverride;
86 bool DoContents;
87
88 // General options
89 string PathPrefix;
90 string DirStrip;
91 FILE *Output;
92 struct CacheDB::Stats &Stats;
93
94 inline bool ReadOverride(string File) {return Over.ReadOverride(File);};
95 inline bool ReadExtraOverride(string File)
96 {return Over.ReadExtraOverride(File);};
97 virtual bool DoPackage(string FileName);
98
99 PackagesWriter(string DB,string Overrides,string ExtOverrides=string());
100 virtual ~PackagesWriter() {};
101 };
102
103 class ContentsWriter : public FTWScanner
104 {
105 CacheDB Db;
106
107 GenContents Gen;
108
109 public:
110
111 // General options
112 FILE *Output;
113 struct CacheDB::Stats &Stats;
114 string Prefix;
115
116 bool DoPackage(string FileName,string Package);
117 virtual bool DoPackage(string FileName)
118 {return DoPackage(FileName,string());};
119 bool ReadFromPkgs(string PkgFile,string PkgCompress);
120
121 void Finish() {Gen.Print(Output);};
122 inline bool ReadyDB(string DB) {return Db.ReadyDB(DB);};
123
124 ContentsWriter(string DB);
125 virtual ~ContentsWriter() {};
126 };
127
128 class SourcesWriter : public FTWScanner
129 {
130 Override BOver;
131 Override SOver;
132 char *Buffer;
133 unsigned long BufSize;
134
135 public:
136
137 bool NoOverride;
138
139 // General options
140 string PathPrefix;
141 string DirStrip;
142 FILE *Output;
143 struct CacheDB::Stats Stats;
144
145 virtual bool DoPackage(string FileName);
146
147 SourcesWriter(string BOverrides,string SOverrides,
148 string ExtOverrides=string());
149 virtual ~SourcesWriter() {free(Buffer);};
150 };
151
152 class ReleaseWriter : public FTWScanner
153 {
154 public:
155 ReleaseWriter(string DB);
156 virtual bool DoPackage(string FileName);
157 protected:
158 // General options
159 string PathPrefix;
160 string DirStrip;
161 FILE *Output;
162 };
163
164 #endif