]>
git.saurik.com Git - apt.git/blob - apt-pkg/versionmatch.cc
45cdb117e4a63d2fc282e545a002194145671e8a
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: versionmatch.cc,v 1.2 2001/02/20 07:03:17 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>
25 // VersionMatch::pkgVersionMatch - Constructor /*{{{*/
26 // ---------------------------------------------------------------------
27 /* Break up the data string according to the selected type */
28 pkgVersionMatch::pkgVersionMatch(string Data
,MatchType Type
) : Type(Type
)
30 if (Type
== None
|| Data
.length() < 1)
33 // Cut up the version representation
36 if (Data
.end()[-1] == '*')
38 VerPrefixMatch
= true;
39 VerStr
= string(Data
.begin(),Data
.end()-1);
48 // All empty = match all
52 // Are we a simple specification?
53 const char *I
= Data
.begin();
54 for (; I
< Data
.end() && *I
!= '='; I
++);
63 if (RelVerStr
.end()[-1] == '*')
65 RelVerPrefixMatch
= true;
66 RelVerStr
= string(RelVerStr
.begin(),RelVerStr
.end()-1);
73 snprintf(Spec
,sizeof(Spec
),"%s",Data
.c_str());
74 if (TokSplitString(',',Spec
,Fragments
,
75 sizeof(Fragments
)/sizeof(Fragments
[0])) == false)
81 for (unsigned J
= 0; Fragments
[J
] != 0; J
++)
83 if (strlen(Fragments
[J
]) < 3)
86 if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"v=") == 0)
87 RelVerStr
= Fragments
[J
]+2;
88 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"o=") == 0)
89 RelOrigin
= Fragments
[J
]+2;
90 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"a=") == 0)
91 RelArchive
= Fragments
[J
]+2;
92 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"l=") == 0)
93 RelLabel
= Fragments
[J
]+2;
94 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"c=") == 0)
95 RelComponent
= Fragments
[J
]+2;
98 if (RelVerStr
.end()[-1] == '*')
100 RelVerPrefixMatch
= true;
101 RelVerStr
= string(RelVerStr
.begin(),RelVerStr
.end()-1);
113 // VersionMatch::MatchVer - Match a version string with prefixing /*{{{*/
114 // ---------------------------------------------------------------------
116 bool pkgVersionMatch::MatchVer(const char *A
,string B
,bool Prefix
)
119 const char *Ae
= Ab
+ strlen(A
);
121 // Strings are not a compatible size.
122 if ((unsigned)(Ae
- Ab
) != B
.length() && Prefix
== false ||
123 (unsigned)(Ae
- Ab
) < B
.length())
127 if (stringcasecmp(B
.begin(),B
.end(),
128 Ab
,Ab
+ B
.length()) == 0)
134 // VersionMatch::Find - Locate the best match for the select type /*{{{*/
135 // ---------------------------------------------------------------------
137 pkgCache::VerIterator
pkgVersionMatch::Find(pkgCache::PkgIterator Pkg
)
139 pkgCache::VerIterator Ver
= Pkg
.VersionList();
140 for (; Ver
.end() == false; Ver
++)
144 if (MatchVer(Ver
.VerStr(),VerStr
,VerPrefixMatch
) == true)
149 for (pkgCache::VerFileIterator VF
= Ver
.FileList(); VF
.end() == false; VF
++)
150 if (FileMatch(VF
.File()) == true)
154 // This will be Ended by now.
158 // VersionMatch::FileMatch - Match against an index file /*{{{*/
159 // ---------------------------------------------------------------------
160 /* This matcher checks against the release file and the origin location
161 to see if the constraints are met. */
162 bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File
)
166 /* cout << RelVerStr << ',' << RelOrigin << ',' << RelArchive << ',' << RelLabel << endl;
167 cout << File.Version() << ',' << File.Origin() << ',' << File.Archive() << ',' << File.Label() << endl;
169 if (RelVerStr
.empty() == true && RelOrigin
.empty() == true &&
170 RelArchive
.empty() == true && RelLabel
.empty() == true &&
171 RelComponent
.empty() == true)
174 if (RelVerStr
.empty() == false)
175 if (File
->Version
== 0 ||
176 MatchVer(File
.Version(),RelVerStr
,RelVerPrefixMatch
) == false)
178 if (RelOrigin
.empty() == false)
179 if (File
->Origin
== 0 ||
180 stringcasecmp(RelOrigin
,File
.Origin()) != 0)
182 if (RelArchive
.empty() == false)
184 if (File
->Archive
== 0 ||
185 stringcasecmp(RelArchive
,File
.Archive()) != 0)
188 if (RelLabel
.empty() == false)
189 if (File
->Label
== 0 ||
190 stringcasecmp(RelLabel
,File
.Label()) != 0)
192 if (RelComponent
.empty() == false)
193 if (File
->Component
== 0 ||
194 stringcasecmp(RelLabel
,File
.Component()) != 0)
201 if (OrSite
.empty() == false)
202 if (File
->Site
== 0 ||
203 OrSite
!= File
.Site())