// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: versionmatch.cc,v 1.3 2001/04/29 05:13:51 jgg Exp $
+// $Id: versionmatch.cc,v 1.9 2003/05/19 17:58:26 doogie Exp $
/* ######################################################################
Version Matching
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/versionmatch.h"
-#endif
#include <apt-pkg/versionmatch.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
#include <stdio.h>
+#include <ctype.h>
/*}}}*/
// VersionMatch::pkgVersionMatch - Constructor /*{{{*/
/* Break up the data string according to the selected type */
pkgVersionMatch::pkgVersionMatch(string Data,MatchType Type) : Type(Type)
{
+ MatchAll = false;
+ VerPrefixMatch = false;
+ RelVerPrefixMatch = false;
+
if (Type == None || Data.length() < 1)
return;
if (Data.end()[-1] == '*')
{
VerPrefixMatch = true;
- VerStr = string(Data.begin(),Data.end()-1);
+ VerStr = string(Data,0,Data.length()-1);
}
else
VerStr = Data;
{
// All empty = match all
if (Data == "*")
+ {
+ MatchAll = true;
return;
+ }
// Are we a simple specification?
- const char *I = Data.begin();
- for (; I < Data.end() && *I != '='; I++);
+ string::const_iterator I = Data.begin();
+ for (; I != Data.end() && *I != '='; I++);
if (I == Data.end())
{
// Temporary
if (isdigit(Data[0]))
RelVerStr = Data;
else
- RelArchive = Data;
-
- if (RelVerStr.end()[-1] == '*')
+ RelRelease = Data;
+
+ if (RelVerStr.length() > 0 && RelVerStr.end()[-1] == '*')
{
RelVerPrefixMatch = true;
RelVerStr = string(RelVerStr.begin(),RelVerStr.end()-1);
{
if (strlen(Fragments[J]) < 3)
continue;
-
+
if (stringcasecmp(Fragments[J],Fragments[J]+2,"v=") == 0)
RelVerStr = Fragments[J]+2;
else if (stringcasecmp(Fragments[J],Fragments[J]+2,"o=") == 0)
RelOrigin = Fragments[J]+2;
else if (stringcasecmp(Fragments[J],Fragments[J]+2,"a=") == 0)
RelArchive = Fragments[J]+2;
+ else if (stringcasecmp(Fragments[J],Fragments[J]+2,"n=") == 0)
+ RelCodename = Fragments[J]+2;
else if (stringcasecmp(Fragments[J],Fragments[J]+2,"l=") == 0)
RelLabel = Fragments[J]+2;
else if (stringcasecmp(Fragments[J],Fragments[J]+2,"c=") == 0)
RelComponent = Fragments[J]+2;
}
-
+
if (RelVerStr.end()[-1] == '*')
{
RelVerPrefixMatch = true;
const char *Ae = Ab + strlen(A);
// Strings are not a compatible size.
- if ((unsigned)(Ae - Ab) != B.length() && Prefix == false ||
+ if (((unsigned)(Ae - Ab) != B.length() && Prefix == false) ||
(unsigned)(Ae - Ab) < B.length())
return false;
// Match (leading?)
- if (stringcasecmp(B.begin(),B.end(),
- Ab,Ab + B.length()) == 0)
+ if (stringcasecmp(B,Ab,Ab + B.length()) == 0)
return true;
return false;
{
if (Type == Release)
{
+ if (MatchAll == true)
+ return true;
+
/* cout << RelVerStr << ',' << RelOrigin << ',' << RelArchive << ',' << RelLabel << endl;
cout << File.Version() << ',' << File.Origin() << ',' << File.Archive() << ',' << File.Label() << endl;*/
-
+
if (RelVerStr.empty() == true && RelOrigin.empty() == true &&
RelArchive.empty() == true && RelLabel.empty() == true &&
+ RelRelease.empty() == true && RelCodename.empty() == true &&
RelComponent.empty() == true)
return false;
-
+
if (RelVerStr.empty() == false)
if (File->Version == 0 ||
MatchVer(File.Version(),RelVerStr,RelVerPrefixMatch) == false)
stringcasecmp(RelOrigin,File.Origin()) != 0)
return false;
if (RelArchive.empty() == false)
- {
- if (File->Archive == 0 ||
+ if (File->Archive == 0 ||
stringcasecmp(RelArchive,File.Archive()) != 0)
- return false;
- }
+ return false;
+ if (RelCodename.empty() == false)
+ if (File->Codename == 0 ||
+ stringcasecmp(RelCodename,File.Codename()) != 0)
+ return false;
+ if (RelRelease.empty() == false)
+ if ((File->Archive == 0 ||
+ stringcasecmp(RelRelease,File.Archive()) != 0) &&
+ (File->Codename == 0 ||
+ stringcasecmp(RelRelease,File.Codename()) != 0))
+ return false;
if (RelLabel.empty() == false)
if (File->Label == 0 ||
stringcasecmp(RelLabel,File.Label()) != 0)
return false;
return true;
}
-
+
if (Type == Origin)
{
- if (OrSite.empty() == false)
- if (File->Site == 0 ||
- OrSite != File.Site())
+ if (OrSite.empty() == false) {
+ if (File->Site == 0 || OrSite != File.Site())
return false;
- return true;
+ } else // so we are talking about file:// or status file
+ if (strcmp(File.Site(),"") == 0 && File->Archive != 0) // skip the status file
+ return false;
+ return (OrSite == File.Site()); /* both strings match */
}
-
+
return false;
}
/*}}}*/