]> git.saurik.com Git - apt.git/blame - ftparchive/writer.h
dd support for the LANGUAGE environment variable
[apt.git] / ftparchive / writer.h
CommitLineData
b2e465d6
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
b3d44315 3// $Id: writer.h,v 1.4.2.2 2003/12/26 22:55:43 mdz Exp $
b2e465d6
AL
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
b2e465d6
AL
16
17#include <string>
18#include <stdio.h>
8c58f506 19#include <iostream>
64177f17 20#include <vector>
f7291f62 21#include <map>
b2e465d6
AL
22
23#include "cachedb.h"
24#include "override.h"
25#include "apt-ftparchive.h"
8c58f506
AL
26
27using std::string;
28using std::cout;
29using std::endl;
98953965 30using std::vector;
f7291f62 31using std::map;
b2e465d6
AL
32
33class FTWScanner
34{
35 protected:
98953965 36 vector<string> Patterns;
31981076 37 string Arch;
b2e465d6 38 const char *OriginalPath;
b2e465d6
AL
39 bool ErrorPrinted;
40
41 // Stuff for the delinker
42 bool NoLinkAct;
43
44 static FTWScanner *Owner;
cde41ae8 45 static int ScannerFTW(const char *File,const struct stat *sb,int Flag);
9209ec47 46 static int ScannerFile(const char *File, bool const &ReadLink);
b2e465d6
AL
47
48 bool Delink(string &FileName,const char *OriginalPath,
9209ec47 49 unsigned long &Bytes,off_t const &FileSize);
b2e465d6 50
9209ec47 51 inline void NewLine(unsigned const &Priority)
b2e465d6
AL
52 {
53 if (ErrorPrinted == false && Quiet <= Priority)
54 {
db40f8e0 55 c1out << endl;
b2e465d6
AL
56 ErrorPrinted = true;
57 }
58 }
59
60 public:
61
62 unsigned long DeLinkLimit;
63 string InternalPrefix;
64
65 virtual bool DoPackage(string FileName) = 0;
9209ec47
DK
66 bool RecursiveScan(string const &Dir);
67 bool LoadFileList(string const &BaseDir,string const &File);
af6fa0b8 68 void ClearPatterns() { Patterns.clear(); };
9209ec47
DK
69 void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
70 bool SetExts(string const &Vals);
b2e465d6 71
31981076 72 FTWScanner(string const &Arch = string());
b2e465d6
AL
73};
74
75class PackagesWriter : public FTWScanner
76{
77 Override Over;
78 CacheDB Db;
79
80 public:
81
82 // Some flags
83 bool DoMD5;
cde41ae8
MV
84 bool DoSHA1;
85 bool DoSHA256;
ff574e76 86 bool DoAlwaysStat;
b2e465d6
AL
87 bool NoOverride;
88 bool DoContents;
9c24493f 89 bool LongDescription;
b2e465d6
AL
90
91 // General options
92 string PathPrefix;
93 string DirStrip;
94 FILE *Output;
95 struct CacheDB::Stats &Stats;
0b41e0e7 96
9209ec47
DK
97 inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);};
98 inline bool ReadExtraOverride(string const &File)
64177f17 99 {return Over.ReadExtraOverride(File);};
b2e465d6
AL
100 virtual bool DoPackage(string FileName);
101
9209ec47
DK
102 PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
103 string const &Arch=string());
b2e465d6
AL
104 virtual ~PackagesWriter() {};
105};
106
107class ContentsWriter : public FTWScanner
108{
109 CacheDB Db;
110
111 GenContents Gen;
112
113 public:
114
115 // General options
116 FILE *Output;
117 struct CacheDB::Stats &Stats;
118 string Prefix;
119
120 bool DoPackage(string FileName,string Package);
121 virtual bool DoPackage(string FileName)
122 {return DoPackage(FileName,string());};
9209ec47 123 bool ReadFromPkgs(string const &PkgFile,string const &PkgCompress);
b2e465d6
AL
124
125 void Finish() {Gen.Print(Output);};
9209ec47 126 inline bool ReadyDB(string const &DB) {return Db.ReadyDB(DB);};
b2e465d6 127
31981076 128 ContentsWriter(string const &DB, string const &Arch = string());
b2e465d6
AL
129 virtual ~ContentsWriter() {};
130};
131
132class SourcesWriter : public FTWScanner
133{
134 Override BOver;
135 Override SOver;
136 char *Buffer;
137 unsigned long BufSize;
138
139 public:
140
141 bool NoOverride;
142
143 // General options
144 string PathPrefix;
145 string DirStrip;
146 FILE *Output;
147 struct CacheDB::Stats Stats;
148
b2e465d6
AL
149 virtual bool DoPackage(string FileName);
150
9209ec47
DK
151 SourcesWriter(string const &BOverrides,string const &SOverrides,
152 string const &ExtOverrides=string());
b2e465d6
AL
153 virtual ~SourcesWriter() {free(Buffer);};
154};
155
98953965
AL
156class ReleaseWriter : public FTWScanner
157{
158public:
9209ec47 159 ReleaseWriter(string const &DB);
98953965 160 virtual bool DoPackage(string FileName);
f7291f62
AL
161 void Finish();
162
163 FILE *Output;
98953965
AL
164 // General options
165 string PathPrefix;
166 string DirStrip;
f7291f62
AL
167
168protected:
169 struct CheckSum
170 {
171 string MD5;
172 string SHA1;
cde41ae8 173 string SHA256;
f7291f62
AL
174 // Limited by FileFd::Size()
175 unsigned long size;
0b41e0e7 176 ~CheckSum() {};
f7291f62
AL
177 };
178 map<string,struct CheckSum> CheckSums;
98953965 179};
b2e465d6
AL
180
181#endif