]>
Commit | Line | Data |
---|---|---|
b2e465d6 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
64177f17 | 3 | // $Id: writer.h,v 1.4 2001/06/26 02:50:27 jgg 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 | |
29 | using std::string; | |
30 | using std::cout; | |
31 | using std::endl; | |
b2e465d6 AL |
32 | |
33 | class FTWScanner | |
34 | { | |
35 | protected: | |
36 | ||
37 | char *TmpExt; | |
38 | const char *Ext[10]; | |
39 | const char *OriginalPath; | |
40 | char *RealPath; | |
41 | bool ErrorPrinted; | |
42 | ||
43 | // Stuff for the delinker | |
44 | bool NoLinkAct; | |
45 | ||
46 | static FTWScanner *Owner; | |
47 | static int Scanner(const char *File,const struct stat *sb,int Flag); | |
48 | ||
49 | bool Delink(string &FileName,const char *OriginalPath, | |
50 | unsigned long &Bytes,struct stat &St); | |
51 | ||
52 | inline void NewLine(unsigned Priority) | |
53 | { | |
54 | if (ErrorPrinted == false && Quiet <= Priority) | |
55 | { | |
56 | cout << endl; | |
57 | ErrorPrinted = true; | |
58 | } | |
59 | } | |
60 | ||
61 | public: | |
62 | ||
63 | unsigned long DeLinkLimit; | |
64 | string InternalPrefix; | |
65 | ||
66 | virtual bool DoPackage(string FileName) = 0; | |
67 | bool RecursiveScan(string Dir); | |
68 | bool LoadFileList(string BaseDir,string File); | |
69 | bool SetExts(string Vals); | |
70 | ||
71 | FTWScanner(); | |
72 | virtual ~FTWScanner() {delete [] RealPath; delete [] TmpExt;}; | |
73 | }; | |
74 | ||
75 | class PackagesWriter : public FTWScanner | |
76 | { | |
77 | Override Over; | |
78 | CacheDB Db; | |
79 | ||
80 | public: | |
81 | ||
82 | // Some flags | |
83 | bool DoMD5; | |
84 | bool NoOverride; | |
85 | bool DoContents; | |
86 | ||
87 | // General options | |
88 | string PathPrefix; | |
89 | string DirStrip; | |
90 | FILE *Output; | |
91 | struct CacheDB::Stats &Stats; | |
92 | ||
93 | inline bool ReadOverride(string File) {return Over.ReadOverride(File);}; | |
64177f17 AL |
94 | inline bool ReadExtraOverride(string File) |
95 | {return Over.ReadExtraOverride(File);}; | |
b2e465d6 AL |
96 | virtual bool DoPackage(string FileName); |
97 | ||
64177f17 | 98 | PackagesWriter(string DB,string Overrides,string ExtOverrides=string()); |
b2e465d6 AL |
99 | virtual ~PackagesWriter() {}; |
100 | }; | |
101 | ||
102 | class ContentsWriter : public FTWScanner | |
103 | { | |
104 | CacheDB Db; | |
105 | ||
106 | GenContents Gen; | |
107 | ||
108 | public: | |
109 | ||
110 | // General options | |
111 | FILE *Output; | |
112 | struct CacheDB::Stats &Stats; | |
113 | string Prefix; | |
114 | ||
115 | bool DoPackage(string FileName,string Package); | |
116 | virtual bool DoPackage(string FileName) | |
117 | {return DoPackage(FileName,string());}; | |
118 | bool ReadFromPkgs(string PkgFile,string PkgCompress); | |
119 | ||
120 | void Finish() {Gen.Print(Output);}; | |
121 | inline bool ReadyDB(string DB) {return Db.ReadyDB(DB);}; | |
122 | ||
123 | ContentsWriter(string DB); | |
124 | virtual ~ContentsWriter() {}; | |
125 | }; | |
126 | ||
127 | class SourcesWriter : public FTWScanner | |
128 | { | |
129 | Override BOver; | |
130 | Override SOver; | |
131 | char *Buffer; | |
132 | unsigned long BufSize; | |
133 | ||
134 | public: | |
135 | ||
136 | bool NoOverride; | |
137 | ||
138 | // General options | |
139 | string PathPrefix; | |
140 | string DirStrip; | |
141 | FILE *Output; | |
142 | struct CacheDB::Stats Stats; | |
143 | ||
b2e465d6 AL |
144 | virtual bool DoPackage(string FileName); |
145 | ||
64177f17 AL |
146 | SourcesWriter(string BOverrides,string SOverrides, |
147 | string ExtOverrides=string()); | |
b2e465d6 AL |
148 | virtual ~SourcesWriter() {free(Buffer);}; |
149 | }; | |
150 | ||
151 | ||
152 | #endif |