Document "apt-ftparchive release"
[ntk/apt.git] / ftparchive / writer.h
CommitLineData
b2e465d6
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
98953965 3// $Id: writer.h,v 1.5 2003/12/26 20:08:56 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
16#ifdef __GNUG__
17#pragma interface "writer.h"
18#endif
19
20#include <string>
21#include <stdio.h>
8c58f506 22#include <iostream>
64177f17 23#include <vector>
b2e465d6
AL
24
25#include "cachedb.h"
26#include "override.h"
27#include "apt-ftparchive.h"
8c58f506
AL
28
29using std::string;
30using std::cout;
31using std::endl;
98953965 32using std::vector;
b2e465d6
AL
33
34class FTWScanner
35{
36 protected:
98953965 37 vector<string> Patterns;
b2e465d6
AL
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);
98953965
AL
68 bool ClearPatterns() { Patterns.clear(); };
69 bool AddPattern(string Pattern) { Patterns.push_back(Pattern); };
b2e465d6
AL
70 bool SetExts(string Vals);
71
72 FTWScanner();
98953965 73 virtual ~FTWScanner() {delete [] RealPath;};
b2e465d6
AL
74};
75
76class 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);};
64177f17
AL
95 inline bool ReadExtraOverride(string File)
96 {return Over.ReadExtraOverride(File);};
b2e465d6
AL
97 virtual bool DoPackage(string FileName);
98
64177f17 99 PackagesWriter(string DB,string Overrides,string ExtOverrides=string());
b2e465d6
AL
100 virtual ~PackagesWriter() {};
101};
102
103class 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
128class 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
b2e465d6
AL
145 virtual bool DoPackage(string FileName);
146
64177f17
AL
147 SourcesWriter(string BOverrides,string SOverrides,
148 string ExtOverrides=string());
b2e465d6
AL
149 virtual ~SourcesWriter() {free(Buffer);};
150};
151
98953965
AL
152class ReleaseWriter : public FTWScanner
153{
154public:
155 ReleaseWriter(string DB);
156 virtual bool DoPackage(string FileName);
157protected:
158 // General options
159 string PathPrefix;
160 string DirStrip;
161 FILE *Output;
162};
b2e465d6
AL
163
164#endif