+ return true;
+}
+
+const char *debListParser::ConvertRelation(const char *I,unsigned int &Op)
+{
+ // Determine the operator
+ switch (*I)
+ {
+ case '<':
+ I++;
+ if (*I == '=')
+ {
+ I++;
+ Op = pkgCache::Dep::LessEq;
+ break;
+ }
+
+ if (*I == '<')
+ {
+ I++;
+ Op = pkgCache::Dep::Less;
+ break;
+ }
+
+ // < is the same as <= and << is really Cs < for some reason
+ Op = pkgCache::Dep::LessEq;
+ break;
+
+ case '>':
+ I++;
+ if (*I == '=')
+ {
+ I++;
+ Op = pkgCache::Dep::GreaterEq;
+ break;
+ }
+
+ if (*I == '>')
+ {
+ I++;
+ Op = pkgCache::Dep::Greater;
+ break;
+ }
+
+ // > is the same as >= and >> is really Cs > for some reason
+ Op = pkgCache::Dep::GreaterEq;
+ break;
+
+ case '=':
+ Op = pkgCache::Dep::Equals;
+ I++;
+ break;
+
+ // HACK around bad package definitions
+ default:
+ Op = pkgCache::Dep::Equals;
+ break;
+ }
+ return I;
+}
+
+ /*}}}*/
+// ListParser::ParseDepends - Parse a dependency element /*{{{*/
+// ---------------------------------------------------------------------
+/* This parses the dependency elements out of a standard string in place,
+ bit by bit. */
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+ string &Package,string &Ver,
+ unsigned int &Op, bool const &ParseArchFlags,
+ bool const &StripMultiArch)
+{
+ // Strip off leading space
+ for (;Start != Stop && isspace(*Start) != 0; Start++);
+
+ // Parse off the package name
+ const char *I = Start;
+ for (;I != Stop && isspace(*I) == 0 && *I != '(' && *I != ')' &&
+ *I != ',' && *I != '|'; I++);
+
+ // Malformed, no '('
+ if (I != Stop && *I == ')')
+ return 0;
+
+ if (I == Start)
+ return 0;
+
+ // Stash the package name
+ Package.assign(Start,I - Start);
+
+ // We don't want to confuse library users which can't handle MultiArch
+ if (StripMultiArch == true) {
+ size_t const found = Package.rfind(':');
+ if (found != string::npos)
+ Package = Package.substr(0,found);
+ }
+
+ // Skip white space to the '('
+ for (;I != Stop && isspace(*I) != 0 ; I++);
+
+ // Parse a version
+ if (I != Stop && *I == '(')
+ {
+ // Skip the '('
+ for (I++; I != Stop && isspace(*I) != 0 ; I++);
+ if (I + 3 >= Stop)
+ return 0;
+ I = ConvertRelation(I,Op);
+
+ // Skip whitespace
+ for (;I != Stop && isspace(*I) != 0; I++);
+ Start = I;
+ for (;I != Stop && *I != ')'; I++);
+ if (I == Stop || Start == I)
+ return 0;
+
+ // Skip trailing whitespace
+ const char *End = I;
+ for (; End > Start && isspace(End[-1]); End--);
+
+ Ver.assign(Start,End-Start);
+ I++;
+ }
+ else
+ {
+ Ver.clear();
+ Op = pkgCache::Dep::NoOp;
+ }
+
+ // Skip whitespace
+ for (;I != Stop && isspace(*I) != 0; I++);
+
+ if (ParseArchFlags == true)
+ {
+ string arch = _config->Find("APT::Architecture");
+
+ // Parse an architecture
+ if (I != Stop && *I == '[')
+ {
+ // malformed
+ I++;
+ if (I == Stop)
+ return 0;
+
+ const char *End = I;
+ bool Found = false;
+ bool NegArch = false;
+ while (I != Stop)
+ {
+ // look for whitespace or ending ']'
+ while (End != Stop && !isspace(*End) && *End != ']')
+ End++;
+
+ if (End == Stop)
+ return 0;
+
+ if (*I == '!')
+ {
+ NegArch = true;
+ I++;
+ }
+
+ if (stringcmp(arch,I,End) == 0)
+ Found = true;
+
+ if (*End++ == ']') {
+ I = End;
+ break;
+ }
+
+ I = End;
+ for (;I != Stop && isspace(*I) != 0; I++);
+ }
+
+ if (NegArch)
+ Found = !Found;
+
+ if (Found == false)
+ Package = ""; /* not for this arch */
+ }
+
+ // Skip whitespace
+ for (;I != Stop && isspace(*I) != 0; I++);
+ }
+
+ if (I != Stop && *I == '|')
+ Op |= pkgCache::Dep::Or;
+
+ if (I == Stop || *I == ',' || *I == '|')
+ {
+ if (I != Stop)
+ for (I++; I != Stop && isspace(*I) != 0; I++);
+ return I;
+ }
+
+ return 0;
+}
+ /*}}}*/
+// ListParser::ParseDepends - Parse a dependency list /*{{{*/
+// ---------------------------------------------------------------------
+/* This is the higher level depends parser. It takes a tag and generates
+ a complete depends tree for the given version. */
+bool debListParser::ParseDepends(pkgCache::VerIterator Ver,
+ const char *Tag,unsigned int Type)
+{
+ const char *Start;
+ const char *Stop;
+ if (Section.Find(Tag,Start,Stop) == false)
+ return true;
+
+ string Package;
+ string Version;
+ unsigned int Op;
+
+ while (1)
+ {
+ Start = ParseDepends(Start,Stop,Package,Version,Op);
+ if (Start == 0)
+ return _error->Error("Problem parsing dependency %s",Tag);
+
+ if (NewDepends(Ver,Package,Version,Op,Type) == false)
+ return false;
+ if (Start == Stop)
+ break;
+ }
+ return true;
+}
+ /*}}}*/
+// ListParser::ParseProvides - Parse the provides list /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool debListParser::ParseProvides(pkgCache::VerIterator Ver)
+{
+ const char *Start;
+ const char *Stop;
+ if (Section.Find("Provides",Start,Stop) == false)
+ return true;
+
+ string Package;
+ string Version;
+ unsigned int Op;
+
+ while (1)
+ {
+ Start = ParseDepends(Start,Stop,Package,Version,Op);
+ if (Start == 0)
+ return _error->Error("Problem parsing Provides line");
+ if (Op != pkgCache::Dep::NoOp) {
+ _error->Warning("Ignoring Provides line with DepCompareOp for package %s", Package.c_str());
+ } else {
+ if (NewProvides(Ver,Package,Version) == false)
+ return false;
+ }
+
+ if (Start == Stop)
+ break;
+ }
+