[Aptitude-svn-commit] r3851 - in branches/aptitude-0.3/aptitude: . src/generic/problemresolver

Daniel Burrows dburrows at costa.debian.org
Mon Aug 15 21:48:02 UTC 2005


Author: dburrows
Date: Mon Aug 15 21:47:58 2005
New Revision: 3851

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/dummy_universe.cc
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/dummy_universe.h
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/test.cc
Log:
Split out some of the universe parsing code.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Mon Aug 15 21:47:58 2005
@@ -1,5 +1,10 @@
 2005-08-15  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/problemresolver/dummy_universe.cc, src/generic/problemresolver/dummy_universe.h, src/generic/problemresolver/test.cc:
+
+	  Move some of the universe parsing code to the dummy_universe
+	  interface file.  More to be done here.
+
 	* src/generic/problemresolver/dummy_universe.h:
 
 	  Add an interface for changing the current version of a package

Modified: branches/aptitude-0.3/aptitude/src/generic/problemresolver/dummy_universe.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/problemresolver/dummy_universe.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/dummy_universe.cc	Mon Aug 15 21:47:58 2005
@@ -150,3 +150,170 @@
 
   return out;
 }
+
+pair<string, string> read_pkgverpair(istream &in)
+{
+  in >> ws;
+
+  string pkgname,vername;
+
+  in >> pkgname >> ws;
+
+  if(in.eof())
+    throw ParseError("Expected version name after package name "+pkgname+", got EOF");
+
+  in >> vername >> ws;
+
+  return pair<string, string>(pkgname, vername);
+}
+
+dummy_universe_ref parse_universe(istream &in)
+{
+  string s;
+
+  in >> ws;
+  if(in.eof())
+    throw ParseError("Expected \"UNIVERSE\"; got EOF");
+
+  in >> s >> ws;
+
+  if(s != "UNIVERSE")
+    throw ParseError("Expected \"UNIVERSE\"; got \"" + s + "\"");
+
+  if(in.eof())
+    throw ParseError("Expected \"[\"; got EOF");
+
+  in >> s >> ws;
+
+  if(s != "[")
+    throw ParseError("Expected \"[\" following UNIVERSE; got \"" + s + "\"");
+
+  if(in.eof())
+    throw ParseError("Unexpected EOF after \"UNIVERSE [\"");
+
+  return parse_universe_tail(in);
+}
+
+dummy_universe_ref parse_universe_tail(istream &in)
+{
+  dummy_universe_ref rval=new dummy_universe;
+
+  in >> ws;
+  while(in)
+    {
+      string s;
+
+      if(in.eof())
+	throw ParseError("Expected ']', 'PACKAGE', or 'DEP'; got EOF");
+
+      in >> s >> ws;
+
+      if(s == "]")
+	break;
+      else if(s == "PACKAGE")
+	{
+	  string pkgname;
+
+	  in >> pkgname >> ws;
+
+	  if(in.eof())
+	    throw ParseError("Unexpected EOF after PACKAGE "+pkgname);
+
+	  in >> s >> ws;
+
+	  if(s != "<")
+	    throw ParseError("Expected '<', got "+s);
+
+	  if(in.eof())
+	    throw ParseError("Unexpected EOF after PACKAGE "+pkgname+" <");
+
+	  vector<string> vernames;
+
+	  while(in)
+	    {
+	      string vername;
+
+	      if(in.eof())
+		throw ParseError("Expected version name or '>', got EOF");
+
+	      in >> vername >> ws;
+
+	      if(vername == ">")
+		break;
+
+	      vernames.push_back(vername);
+	    }
+
+	  if(in.eof())
+	    throw ParseError("Expected a definition of the current version of "+pkgname+", got EOF");
+
+	  string curname;
+
+	  in >> curname >> ws;
+
+	  if(vernames.empty())
+	    throw ParseError("Package "+pkgname+" has no versions");
+
+	  rval.add_package(pkgname, vernames, curname);
+	}
+      else if(s == "DEP" || s == "SOFTDEP")
+	{
+	  pair<string, string> source=read_pkgverpair(in);
+	  bool is_conflict=false;
+	  bool is_soft = (s == "SOFTDEP");
+
+	  in >> s >> ws;
+
+	  if(s == "!!")
+	    is_conflict=true;
+	  else if(s != "->")
+	    throw ParseError("Expected '->' or '!!', got "+s);
+
+	  if(in.eof())
+	    throw ParseError("Expected '<', got EOF");
+
+	  in >> s >> ws;
+
+	  if(s != "<")
+	    throw ParseError("Expected '<', got "+s);
+
+	  if(in.eof())
+	    throw ParseError("Expected package-version pair, got EOF");
+
+	  vector<pair<string, string> > targets;
+
+	  while(in)
+	    {
+	      string pkgname,vername;
+
+	      in >> pkgname >> ws;
+
+	      if(pkgname == ">")
+		break;
+
+	      if(in.eof())
+		throw ParseError("Expected version name after package name "+pkgname+", got EOF");
+
+	      in >> vername >> ws;
+
+	      if(vername == ">")
+		throw ParseError("Expected version name after package name "+pkgname+", got end-of-list instead");
+
+	      targets.push_back(pair<string,string>(pkgname,vername));
+
+	      if(in.eof())
+		throw ParseError("Unexpected EOF in dependency target list following package "+pkgname+" version "+vername);
+	    }
+
+	  rval.add_dep(source.first, source.second, targets,
+		       is_conflict, is_soft);
+	}
+      else
+	throw ParseError("Expected PACKAGE, DEP, or SOFTDEP, got "+s);
+
+      if(in.eof())
+	throw ParseError("Expected ']' following universe declaration, got EOF.");
+    }
+
+  return rval;
+}

Modified: branches/aptitude-0.3/aptitude/src/generic/problemresolver/dummy_universe.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/problemresolver/dummy_universe.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/dummy_universe.h	Mon Aug 15 21:47:58 2005
@@ -741,4 +741,30 @@
 
 std::ostream &operator<<(std::ostream &out, const dummy_universe::dep &d);
 
+class ParseError : public Exception
+{
+  std::string msg;
+public:
+  ParseError(const std::string &_msg):msg(_msg) {}
+
+  std::string errmsg() const {return msg;}
+};
+
+/** Read a (package, version) pair of strings from the given stream.
+ *
+ *  \throws ParseError
+ */
+std::pair<std::string, std::string> read_pkgverpair(std::istream &in);
+
+
+/** Parses a universe from the given stream. \throws ParseError */
+dummy_universe_ref parse_universe(std::istream &in);
+
+/** Parses a universe to the closing ']'.  Meant for use as a subroutine
+ *  to be called after the opening "UNIVERSE [" has been stripped.
+ *
+ *  \throws ParseError
+ */
+dummy_universe_ref parse_universe_tail(std::istream &in);
+
 #endif // DUMMY_UNIVERSE_H

Modified: branches/aptitude-0.3/aptitude/src/generic/problemresolver/test.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/problemresolver/test.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/test.cc	Mon Aug 15 21:47:58 2005
@@ -53,156 +53,6 @@
 // The second DEP form is a Conflicts, and is implicitly converted to
 // dependency form internally.
 
-class ParseError:public Exception
-{
-  string msg;
-public:
-  ParseError(const string &_msg):msg(_msg) {}
-
-  string errmsg() const {return msg;}
-};
-
-pair<string, string> read_pkgverpair(istream &in)
-{
-  in >> ws;
-
-  string pkgname,vername;
-
-  in >> pkgname >> ws;
-
-  if(in.eof())
-    throw ParseError("Expected version name after package name "+pkgname+", got EOF");
-
-  in >> vername >> ws;
-
-  return pair<string, string>(pkgname, vername);
-}
-
-/** Parses a universe to the closing ']'. */
-dummy_universe_ref parse_universe(istream &in)
-{
-  dummy_universe_ref rval=new dummy_universe;
-
-  in >> ws;
-  while(in)
-    {
-      string s;
-
-      if(in.eof())
-	throw ParseError("Expected ']', 'PACKAGE', or 'DEP'; got EOF");
-
-      in >> s >> ws;
-
-      if(s == "]")
-	break;
-      else if(s == "PACKAGE")
-	{
-	  string pkgname;
-
-	  in >> pkgname >> ws;
-
-	  if(in.eof())
-	    throw ParseError("Unexpected EOF after PACKAGE "+pkgname);
-
-	  in >> s >> ws;
-
-	  if(s != "<")
-	    throw ParseError("Expected '<', got "+s);
-
-	  if(in.eof())
-	    throw ParseError("Unexpected EOF after PACKAGE "+pkgname+" <");
-
-	  vector<string> vernames;
-
-	  while(in)
-	    {
-	      string vername;
-
-	      if(in.eof())
-		throw ParseError("Expected version name or '>', got EOF");
-
-	      in >> vername >> ws;
-
-	      if(vername == ">")
-		break;
-
-	      vernames.push_back(vername);
-	    }
-
-	  if(in.eof())
-	    throw ParseError("Expected a definition of the current version of "+pkgname+", got EOF");
-
-	  string curname;
-
-	  in >> curname >> ws;
-
-	  if(vernames.empty())
-	    throw ParseError("Package "+pkgname+" has no versions");
-
-	  rval.add_package(pkgname, vernames, curname);
-	}
-      else if(s == "DEP" || s == "SOFTDEP")
-	{
-	  pair<string, string> source=read_pkgverpair(in);
-	  bool is_conflict=false;
-	  bool is_soft = (s == "SOFTDEP");
-
-	  in >> s >> ws;
-
-	  if(s == "!!")
-	    is_conflict=true;
-	  else if(s != "->")
-	    throw ParseError("Expected '->' or '!!', got "+s);
-
-	  if(in.eof())
-	    throw ParseError("Expected '<', got EOF");
-
-	  in >> s >> ws;
-
-	  if(s != "<")
-	    throw ParseError("Expected '<', got "+s);
-
-	  if(in.eof())
-	    throw ParseError("Expected package-version pair, got EOF");
-
-	  vector<pair<string, string> > targets;
-
-	  while(in)
-	    {
-	      string pkgname,vername;
-
-	      in >> pkgname >> ws;
-
-	      if(pkgname == ">")
-		break;
-
-	      if(in.eof())
-		throw ParseError("Expected version name after package name "+pkgname+", got EOF");
-
-	      in >> vername >> ws;
-
-	      if(vername == ">")
-		throw ParseError("Expected version name after package name "+pkgname+", got end-of-list instead");
-
-	      targets.push_back(pair<string,string>(pkgname,vername));
-
-	      if(in.eof())
-		throw ParseError("Unexpected EOF in dependency target list following package "+pkgname+" version "+vername);
-	    }
-
-	  rval.add_dep(source.first, source.second, targets,
-		       is_conflict, is_soft);
-	}
-      else
-	throw ParseError("Expected PACKAGE, DEP, or SOFTDEP, got "+s);
-
-      if(in.eof())
-	throw ParseError("Expected ']' following universe declaration, got EOF.");
-    }
-
-  return rval;
-}
-
 /** Reads the list of scores into the resolver. */
 void read_scores(istream &f,
 		 dummy_universe_ref universe, dummy_resolver &resolver)
@@ -352,7 +202,7 @@
 	  if(s != "[")
 	    throw ParseError("Expected '[' following UNIVERSE, got " + s);
 
-	  universe=parse_universe(f);
+	  universe=parse_universe_tail(f);
 
 	  if(show_world)
 	    {



More information about the Aptitude-svn-commit mailing list