]>
git.saurik.com Git - apt.git/blob - apt-pkg/tagfile.cc
9710b76159c51cb6f76f706ef77b2fb183befa98
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: tagfile.cc,v 1.4 1998/07/05 05:33:58 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 /*{{{*/
14 #include <pkglib/tagfile.h>
15 #include <pkglib/error.h>
21 // TagFile::pkgTagFile - Constructor /*{{{*/
22 // ---------------------------------------------------------------------
24 pkgTagFile::pkgTagFile(File
&Fd
) : Fd(Fd
)
26 Buffer
= new char[64*1024];
27 Start
= End
= Buffer
+ 64*1024;
33 // TagFile::Step - Advance to the next section /*{{{*/
34 // ---------------------------------------------------------------------
35 /* If the Section Scanner fails we refill the buffer and try again. */
36 bool pkgTagFile::Step(pkgTagSection
&Tag
)
38 if (Tag
.Scan(Start
,End
- Start
) == false)
43 if (Tag
.Scan(Start
,End
- Start
) == false)
44 return _error
->Error("Unable to parse package file");
47 iOffset
+= Tag
.size();
52 // TagFile::Fill - Top up the buffer /*{{{*/
53 // ---------------------------------------------------------------------
54 /* This takes the bit at the end of the buffer and puts it at the start
55 then fills the rest from the file */
56 bool pkgTagFile::Fill()
58 unsigned long Size
= End
- Start
;
67 memmove(Buffer
,Start
,Size
);
70 // See if only a bit of the file is left or if
71 if (Left
< End
- Buffer
- Size
)
73 if (Fd
.Read(Buffer
+ Size
,Left
) == false)
75 End
= Buffer
+ Size
+ Left
;
80 if (Fd
.Read(Buffer
+ Size
, End
- Buffer
- Size
) == false)
82 Left
-= End
- Buffer
- Size
;
87 // TagSection::Scan - Scan for the end of the header information /*{{{*/
88 // ---------------------------------------------------------------------
89 /* This looks for the first double new line in the data stream. It also
90 indexes the tags in the section. */
91 bool pkgTagSection::Scan(const char *Start
,unsigned long MaxLength
)
93 const char *End
= Start
+ MaxLength
;
94 Stop
= Section
= Start
;
97 Indexes
[TagCount
++] = Stop
- Section
;
99 for (; Stop
< End
; Stop
++)
101 if (Stop
[-1] != '\n')
105 // Extra one at the end to simplify find
106 Indexes
[TagCount
] = Stop
- Section
;
107 for (; Stop
[0] == '\n' && Stop
< End
; Stop
++);
112 if (isspace(Stop
[0]) == 0)
113 Indexes
[TagCount
++] = Stop
- Section
;
116 if (TagCount
> sizeof(Indexes
)/sizeof(Indexes
[0]))
117 TagCount
= sizeof(Indexes
)/sizeof(Indexes
[0]);
122 // TagSection::Find - Locate a tag /*{{{*/
123 // ---------------------------------------------------------------------
124 /* This searches the section for a tag that matches the given string. */
125 bool pkgTagSection::Find(const char *Tag
,const char *&Start
,
128 unsigned int Length
= strlen(Tag
);
129 for (unsigned int I
= 0; I
!= TagCount
; I
++)
131 if (strncasecmp(Tag
,Section
+ Indexes
[I
],Length
) != 0)
134 // Make sure the colon is in the right place
135 const char *C
= Section
+ Length
+ Indexes
[I
];
136 for (; isspace(*C
) != 0; C
++);
140 // Strip off the gunk from the start end
142 End
= Section
+ Indexes
[I
+1];
143 for (; (isspace(*Start
) != 0 || *Start
== ':') && Start
< End
; Start
++);
144 for (; isspace(End
[-1]) != 0 && End
> Start
; End
--);
152 #include <pkglib/pkgcachegen.h>
153 #include <pkglib/deblistparser.h>
155 int main(int argc
,char *argv
[])
158 File
CacheF("./cache",File::WriteEmpty
);
159 DynamicMMap
Map(CacheF
,MMap::Public
);
160 pkgCacheGenerator
Gen(Map
);
162 for (int I
= 1; I
!= argc
; I
++)
164 cout
<< "Merging in " << argv
[I
] << endl
;
165 File
F(argv
[I
],File::ReadOnly
);
166 Gen
.SelectFile(argv
[I
]);
167 debListParser
Parser(F
);
168 Gen
.MergeList(Parser
);
173 File CacheF("./cache",File::WriteExists);
174 MMap Map(CacheF,MMap::Public | MMap::ReadOnly);
176 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
178 cout << "Package: " << I.Name() << endl;
179 for (pkgCache::VerIterator V = I.VersionList(); V.end() == false; V++)
181 cout << "Version: " << V.VerStr() << endl;
182 cout << "Size: " << V->Size << endl;
183 cout << "Installed-Size: " << V->InstalledSize << endl;
184 cout << "Section: " << V.Section() << endl;
185 cout << "Priority: " << Cache.Priority(V->Priority) << endl;
187 pkgCache::PrvIterator P = V.ProvidesList();
188 if (P.end() == false)
190 cout << "Provides: ";
191 for (; P.end() == false; P++)
192 cout << P.Name() << ", ";
202 while (Test
.Step(I
) == true)
206 if (I
.Find("Package",Start
,End
) == false)
208 cout
<< "Failed" << endl
;
212 cout
<< "Package: " << string(Start
,End
- Start
) << endl
;
214 /* for (const char *I = Start; I < End; I++)
216 const char *Begin = I;
218 while (isspace(*I) == 0 && ispunct(*I) == 0 && I < End)
220 if (isalpha(*I) != 0)
225 cout << string(Begin,I-Begin) << endl;
226 while ((isspace(*I) != 0 || ispunct(*I) != 0) && I < End)
232 _error
->DumpErrors();