G++3 fixes from Randolph
[ntk/apt.git] / ftparchive / writer.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: writer.h,v 1.3 2001/05/29 04:08:09 jgg 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
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
32 class FTWScanner
33 {
34 protected:
35
36 char *TmpExt;
37 const char *Ext[10];
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 SetExts(string Vals);
69
70 FTWScanner();
71 virtual ~FTWScanner() {delete [] RealPath; delete [] TmpExt;};
72 };
73
74 class PackagesWriter : public FTWScanner
75 {
76 Override Over;
77 CacheDB Db;
78
79 public:
80
81 // Some flags
82 bool DoMD5;
83 bool NoOverride;
84 bool DoContents;
85
86 // General options
87 string PathPrefix;
88 string DirStrip;
89 FILE *Output;
90 struct CacheDB::Stats &Stats;
91
92 inline bool ReadOverride(string File) {return Over.ReadOverride(File);};
93 virtual bool DoPackage(string FileName);
94
95 PackagesWriter(string DB,string Overrides);
96 virtual ~PackagesWriter() {};
97 };
98
99 class ContentsWriter : public FTWScanner
100 {
101 CacheDB Db;
102
103 GenContents Gen;
104
105 public:
106
107 // General options
108 FILE *Output;
109 struct CacheDB::Stats &Stats;
110 string Prefix;
111
112 bool DoPackage(string FileName,string Package);
113 virtual bool DoPackage(string FileName)
114 {return DoPackage(FileName,string());};
115 bool ReadFromPkgs(string PkgFile,string PkgCompress);
116
117 void Finish() {Gen.Print(Output);};
118 inline bool ReadyDB(string DB) {return Db.ReadyDB(DB);};
119
120 ContentsWriter(string DB);
121 virtual ~ContentsWriter() {};
122 };
123
124 class SourcesWriter : public FTWScanner
125 {
126 Override BOver;
127 Override SOver;
128 char *Buffer;
129 unsigned long BufSize;
130
131 public:
132
133 bool NoOverride;
134
135 // General options
136 string PathPrefix;
137 string DirStrip;
138 FILE *Output;
139 struct CacheDB::Stats Stats;
140
141 /* inline bool ReadBinOverride(string File) {return BOver.ReadOverride(File);};
142 bool ReadSrcOverride(string File); // {return BOver.ReadOverride(File);};*/
143 virtual bool DoPackage(string FileName);
144
145 SourcesWriter(string BOverrides,string SOverrides);
146 virtual ~SourcesWriter() {free(Buffer);};
147 };
148
149
150 #endif