]>
git.saurik.com Git - apt.git/blob - apt-pkg/versionmatch.cc
8e8e2d2d175d20343ae8dc08aff6ebfb22a1c918
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: versionmatch.cc,v 1.5 2001/05/29 03:07:12 jgg Exp $
4 /* ######################################################################
8 This module takes a matching string and a type and locates the version
9 record that satisfies the constraint described by the matching string.
11 ##################################################################### */
13 // Include Files /*{{{*/
15 #pragma implementation "apt-pkg/versionmatch.h"
17 #include <apt-pkg/versionmatch.h>
19 #include <apt-pkg/strutl.h>
20 #include <apt-pkg/error.h>
26 // VersionMatch::pkgVersionMatch - Constructor /*{{{*/
27 // ---------------------------------------------------------------------
28 /* Break up the data string according to the selected type */
29 pkgVersionMatch::pkgVersionMatch(string Data
,MatchType Type
) : Type(Type
)
31 if (Type
== None
|| Data
.length() < 1)
34 // Cut up the version representation
37 if (Data
.end()[-1] == '*')
39 VerPrefixMatch
= true;
40 VerStr
= string(Data
,0,Data
.length()-1);
49 // All empty = match all
58 // Are we a simple specification?
59 string::const_iterator I
= Data
.begin();
60 for (; I
!= Data
.end() && *I
!= '='; I
++);
69 if (RelVerStr
.end()[-1] == '*')
71 RelVerPrefixMatch
= true;
72 RelVerStr
= string(RelVerStr
.begin(),RelVerStr
.end()-1);
79 snprintf(Spec
,sizeof(Spec
),"%s",Data
.c_str());
80 if (TokSplitString(',',Spec
,Fragments
,
81 sizeof(Fragments
)/sizeof(Fragments
[0])) == false)
87 for (unsigned J
= 0; Fragments
[J
] != 0; J
++)
89 if (strlen(Fragments
[J
]) < 3)
92 if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"v=") == 0)
93 RelVerStr
= Fragments
[J
]+2;
94 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"o=") == 0)
95 RelOrigin
= Fragments
[J
]+2;
96 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"a=") == 0)
97 RelArchive
= Fragments
[J
]+2;
98 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"l=") == 0)
99 RelLabel
= Fragments
[J
]+2;
100 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"c=") == 0)
101 RelComponent
= Fragments
[J
]+2;
104 if (RelVerStr
.end()[-1] == '*')
106 RelVerPrefixMatch
= true;
107 RelVerStr
= string(RelVerStr
.begin(),RelVerStr
.end()-1);
119 // VersionMatch::MatchVer - Match a version string with prefixing /*{{{*/
120 // ---------------------------------------------------------------------
122 bool pkgVersionMatch::MatchVer(const char *A
,string B
,bool Prefix
)
125 const char *Ae
= Ab
+ strlen(A
);
127 // Strings are not a compatible size.
128 if ((unsigned)(Ae
- Ab
) != B
.length() && Prefix
== false ||
129 (unsigned)(Ae
- Ab
) < B
.length())
133 if (stringcasecmp(B
,Ab
,Ab
+ B
.length()) == 0)
139 // VersionMatch::Find - Locate the best match for the select type /*{{{*/
140 // ---------------------------------------------------------------------
142 pkgCache::VerIterator
pkgVersionMatch::Find(pkgCache::PkgIterator Pkg
)
144 pkgCache::VerIterator Ver
= Pkg
.VersionList();
145 for (; Ver
.end() == false; Ver
++)
149 if (MatchVer(Ver
.VerStr(),VerStr
,VerPrefixMatch
) == true)
154 for (pkgCache::VerFileIterator VF
= Ver
.FileList(); VF
.end() == false; VF
++)
155 if (FileMatch(VF
.File()) == true)
159 // This will be Ended by now.
163 // VersionMatch::FileMatch - Match against an index file /*{{{*/
164 // ---------------------------------------------------------------------
165 /* This matcher checks against the release file and the origin location
166 to see if the constraints are met. */
167 bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File
)
171 if (MatchAll
== true)
174 /* cout << RelVerStr << ',' << RelOrigin << ',' << RelArchive << ',' << RelLabel << endl;
175 cout << File.Version() << ',' << File.Origin() << ',' << File.Archive() << ',' << File.Label() << endl;*/
177 if (RelVerStr
.empty() == true && RelOrigin
.empty() == true &&
178 RelArchive
.empty() == true && RelLabel
.empty() == true &&
179 RelComponent
.empty() == true)
182 if (RelVerStr
.empty() == false)
183 if (File
->Version
== 0 ||
184 MatchVer(File
.Version(),RelVerStr
,RelVerPrefixMatch
) == false)
186 if (RelOrigin
.empty() == false)
187 if (File
->Origin
== 0 ||
188 stringcasecmp(RelOrigin
,File
.Origin()) != 0)
190 if (RelArchive
.empty() == false)
192 if (File
->Archive
== 0 ||
193 stringcasecmp(RelArchive
,File
.Archive()) != 0)
196 if (RelLabel
.empty() == false)
197 if (File
->Label
== 0 ||
198 stringcasecmp(RelLabel
,File
.Label()) != 0)
200 if (RelComponent
.empty() == false)
201 if (File
->Component
== 0 ||
202 stringcasecmp(RelComponent
,File
.Component()) != 0)
209 if (OrSite
.empty() == false)
210 if (File
->Site
== 0 ||
211 OrSite
!= File
.Site())