]> git.saurik.com Git - apt.git/blob - ftparchive/writer.h
merged from David, uncommited the previous i18n commit first as its part of the merge...
[apt.git] / ftparchive / writer.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: writer.h,v 1.4.2.2 2003/12/26 22:55:43 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
17 #include <string>
18 #include <stdio.h>
19 #include <iostream>
20 #include <vector>
21 #include <map>
22 #include <set>
23
24 #include "cachedb.h"
25 #include "override.h"
26 #include "apt-ftparchive.h"
27
28 using std::string;
29 using std::cout;
30 using std::endl;
31 using std::vector;
32 using std::map;
33
34 class FTWScanner
35 {
36 protected:
37 vector<string> Patterns;
38 string Arch;
39 const char *OriginalPath;
40 bool ErrorPrinted;
41
42 // Stuff for the delinker
43 bool NoLinkAct;
44
45 static FTWScanner *Owner;
46 static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
47 static int ScannerFile(const char *File, bool const &ReadLink);
48
49 bool Delink(string &FileName,const char *OriginalPath,
50 unsigned long long &Bytes,unsigned long long const &FileSize);
51
52 inline void NewLine(unsigned const &Priority)
53 {
54 if (ErrorPrinted == false && Quiet <= Priority)
55 {
56 c1out << endl;
57 ErrorPrinted = true;
58 }
59 }
60
61 public:
62 bool DoMD5;
63 bool DoSHA1;
64 bool DoSHA256;
65 bool DoSHA512;
66
67 unsigned long DeLinkLimit;
68 string InternalPrefix;
69
70 virtual bool DoPackage(string FileName) = 0;
71 bool RecursiveScan(string const &Dir);
72 bool LoadFileList(string const &BaseDir,string const &File);
73 void ClearPatterns() { Patterns.clear(); };
74 void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
75 void AddPattern(char const *Pattern) { Patterns.push_back(Pattern); };
76 void AddPatterns(std::vector<std::string> const &patterns) { Patterns.insert(Patterns.end(), patterns.begin(), patterns.end()); };
77 bool SetExts(string const &Vals);
78
79 FTWScanner(string const &Arch = string());
80 virtual ~FTWScanner() {};
81 };
82
83 class MultiCompress;
84
85 class TranslationWriter
86 {
87 MultiCompress *Comp;
88 FILE *Output;
89 std::set<string> Included;
90 unsigned short RefCounter;
91
92 public:
93 void IncreaseRefCounter() { ++RefCounter; };
94 unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; };
95 unsigned short GetRefCounter() const { return RefCounter; };
96 bool DoPackage(string const &Pkg, string const &Desc, string const &MD5);
97
98 TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions);
99 TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {};
100 ~TranslationWriter();
101 };
102
103 class PackagesWriter : public FTWScanner
104 {
105 Override Over;
106 CacheDB Db;
107
108 public:
109
110 // Some flags
111 bool DoAlwaysStat;
112 bool NoOverride;
113 bool DoContents;
114 bool LongDescription;
115
116 // General options
117 string PathPrefix;
118 string DirStrip;
119 FILE *Output;
120 struct CacheDB::Stats &Stats;
121 TranslationWriter *TransWriter;
122
123 inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
124 inline bool ReadExtraOverride(string const &File)
125 {return Over.ReadExtraOverride(File);};
126 virtual bool DoPackage(string FileName);
127
128 PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
129 string const &Arch=string());
130 virtual ~PackagesWriter() {};
131 };
132
133 class ContentsWriter : public FTWScanner
134 {
135 CacheDB Db;
136
137 GenContents Gen;
138
139 public:
140
141 // General options
142 FILE *Output;
143 struct CacheDB::Stats &Stats;
144 string Prefix;
145
146 bool DoPackage(string FileName,string Package);
147 virtual bool DoPackage(string FileName)
148 {return DoPackage(FileName,string());};
149 bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);
150
151 void Finish() {Gen.Print(Output);};
152 inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
153
154 ContentsWriter(string const &DB, string const &Arch = string());
155 virtual ~ContentsWriter() {};
156 };
157
158 class SourcesWriter : public FTWScanner
159 {
160 Override BOver;
161 Override SOver;
162 char *Buffer;
163 unsigned long long BufSize;
164
165 public:
166
167 bool NoOverride;
168
169 // General options
170 string PathPrefix;
171 string DirStrip;
172 FILE *Output;
173 struct CacheDB::Stats Stats;
174
175 virtual bool DoPackage(string FileName);
176
177 SourcesWriter(string const &BOverrides,string const &SOverrides,
178 string const &ExtOverrides=string());
179 virtual ~SourcesWriter() {free(Buffer);};
180 };
181
182 class ReleaseWriter : public FTWScanner
183 {
184 public:
185 ReleaseWriter(string const &DB);
186 virtual bool DoPackage(string FileName);
187 void Finish();
188
189 FILE *Output;
190 // General options
191 string PathPrefix;
192 string DirStrip;
193
194 protected:
195 struct CheckSum
196 {
197 string MD5;
198 string SHA1;
199 string SHA256;
200 string SHA512;
201 // Limited by FileFd::Size()
202 unsigned long long size;
203 ~CheckSum() {};
204 };
205 map<string,struct CheckSum> CheckSums;
206 };
207
208 #endif