]>
git.saurik.com Git - apt.git/blob - apt-pkg/tagfile.cc
aaef3da8b329d493f15eca8e5df03a3f6f3be959
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: tagfile.cc,v 1.6 1998/07/09 05:12:32 jgg Exp $
4 /* ######################################################################
6 Fast scanner for RFC-822 type header information
8 This uses a rotating 64K buffer to load the package information into.
9 The scanner runs over it and isolates and indexes a single section.
11 ##################################################################### */
13 // Include Files /*{{{*/
15 #pragma implementation "pkglib/tagfile.h"
18 #include <pkglib/tagfile.h>
19 #include <pkglib/error.h>
20 #include <pkglib/init.h>
26 // TagFile::pkgTagFile - Constructor /*{{{*/
27 // ---------------------------------------------------------------------
29 pkgTagFile::pkgTagFile(File
&Fd
) : Fd(Fd
)
31 Buffer
= new char[64*1024];
32 Start
= End
= Buffer
+ 64*1024;
38 // TagFile::Step - Advance to the next section /*{{{*/
39 // ---------------------------------------------------------------------
40 /* If the Section Scanner fails we refill the buffer and try again. */
41 bool pkgTagFile::Step(pkgTagSection
&Tag
)
43 if (Tag
.Scan(Start
,End
- Start
) == false)
48 if (Tag
.Scan(Start
,End
- Start
) == false)
49 return _error
->Error("Unable to parse package file");
52 iOffset
+= Tag
.size();
57 // TagFile::Fill - Top up the buffer /*{{{*/
58 // ---------------------------------------------------------------------
59 /* This takes the bit at the end of the buffer and puts it at the start
60 then fills the rest from the file */
61 bool pkgTagFile::Fill()
63 unsigned long Size
= End
- Start
;
72 memmove(Buffer
,Start
,Size
);
75 // See if only a bit of the file is left or if
76 if (Left
< End
- Buffer
- Size
)
78 if (Fd
.Read(Buffer
+ Size
,Left
) == false)
80 End
= Buffer
+ Size
+ Left
;
85 if (Fd
.Read(Buffer
+ Size
, End
- Buffer
- Size
) == false)
87 Left
-= End
- Buffer
- Size
;
92 // TagSection::Scan - Scan for the end of the header information /*{{{*/
93 // ---------------------------------------------------------------------
94 /* This looks for the first double new line in the data stream. It also
95 indexes the tags in the section. */
96 bool pkgTagSection::Scan(const char *Start
,unsigned long MaxLength
)
98 const char *End
= Start
+ MaxLength
;
99 Stop
= Section
= Start
;
102 Indexes
[TagCount
++] = Stop
- Section
;
104 for (; Stop
< End
; Stop
++)
106 if (Stop
[-1] != '\n')
110 // Extra one at the end to simplify find
111 Indexes
[TagCount
] = Stop
- Section
;
112 for (; Stop
[0] == '\n' && Stop
< End
; Stop
++);
117 if (isspace(Stop
[0]) == 0)
118 Indexes
[TagCount
++] = Stop
- Section
;
121 if (TagCount
> sizeof(Indexes
)/sizeof(Indexes
[0]))
122 TagCount
= sizeof(Indexes
)/sizeof(Indexes
[0]);
127 // TagSection::Find - Locate a tag /*{{{*/
128 // ---------------------------------------------------------------------
129 /* This searches the section for a tag that matches the given string. */
130 bool pkgTagSection::Find(const char *Tag
,const char *&Start
,
133 unsigned int Length
= strlen(Tag
);
134 for (unsigned int I
= 0; I
!= TagCount
; I
++)
136 if (strncasecmp(Tag
,Section
+ Indexes
[I
],Length
) != 0)
139 // Make sure the colon is in the right place
140 const char *C
= Section
+ Length
+ Indexes
[I
];
141 for (; isspace(*C
) != 0; C
++);
145 // Strip off the gunk from the start end
147 End
= Section
+ Indexes
[I
+1];
148 for (; (isspace(*Start
) != 0 || *Start
== ':') && Start
< End
; Start
++);
149 for (; isspace(End
[-1]) != 0 && End
> Start
; End
--);
157 #include <pkglib/pkgcachegen.h>
158 #include <pkglib/deblistparser.h>
160 int main(int argc
,char *argv
[])
162 pkglibInitialize(*_config
);
163 cout
<< _config
->Find("APT::arch") << endl
;
164 cout
<< _config
->FindDir("DIR::Etc::sourcelist") << endl
;
167 File
CacheF("./cache",File::WriteEmpty
);
168 DynamicMMap
Map(CacheF
,MMap::Public
);
169 pkgCacheGenerator
Gen(Map
);
171 for (int I
= 1; I
!= argc
; I
++)
173 cout
<< "Merging in " << argv
[I
] << endl
;
174 File
F(argv
[I
],File::ReadOnly
);
175 Gen
.SelectFile(argv
[I
]);
176 debListParser
Parser(F
);
177 Gen
.MergeList(Parser
);
182 File CacheF("./cache",File::WriteExists);
183 MMap Map(CacheF,MMap::Public | MMap::ReadOnly);
185 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
187 cout << "Package: " << I.Name() << endl;
188 for (pkgCache::VerIterator V = I.VersionList(); V.end() == false; V++)
190 cout << "Version: " << V.VerStr() << endl;
191 cout << "Size: " << V->Size << endl;
192 cout << "Installed-Size: " << V->InstalledSize << endl;
193 cout << "Section: " << V.Section() << endl;
194 cout << "Priority: " << Cache.Priority(V->Priority) << endl;
196 pkgCache::PrvIterator P = V.ProvidesList();
197 if (P.end() == false)
199 cout << "Provides: ";
200 for (; P.end() == false; P++)
201 cout << P.Name() << ", ";
211 while (Test
.Step(I
) == true)
215 if (I
.Find("Package",Start
,End
) == false)
217 cout
<< "Failed" << endl
;
221 cout
<< "Package: " << string(Start
,End
- Start
) << endl
;
223 /* for (const char *I = Start; I < End; I++)
225 const char *Begin = I;
227 while (isspace(*I) == 0 && ispunct(*I) == 0 && I < End)
229 if (isalpha(*I) != 0)
234 cout << string(Begin,I-Begin) << endl;
235 while ((isspace(*I) != 0 || ispunct(*I) != 0) && I < End)
241 _error
->DumpErrors();