Index: /CMT/HEAD/ChangeLog
===================================================================
--- /CMT/HEAD/ChangeLog	(revision 534)
+++ /CMT/HEAD/ChangeLog	(revision 535)
@@ -1,2 +1,74 @@
+2010-03-26    <rybkin@lal.in2p3.fr> 422
+
+	* source/cmt_system.cxx: In function CMTPathManager::do_add_cmt_path,
+	ensure that projects created from CMTPATH environment variable entries do
+	not become each others children-parents automatically (that will be
+	based on use statements in project.cmt files). Ensure that command exit
+	status is returned by CmtSystem::execute (const cmt_string&, cmt_string&)
+	* source/cmt_database.h: Introduce member m_ordered_projects to keep vector
+	of pointers to the ordered projects and function ordered_projects to return
+	that
+	* source/cmt_database.cxx: Implement function ordered_projects
+	* source/cmt_project.h: Introduce functions order_all, set_is_current,
+	is_current, erase_child, and member m_is_current
+	* source/cmt_project.cxx: Implement introduced functions. In function
+	ProjectFactory::create_project, call Project::order_all () if projects
+	dependencies are updated or new project is created, call
+	Cmt::get_current_dir_real to determine (and set the project member
+	accordingly) whether project is current or not, do NOT make project that
+	has no parent the top project. In function get_current, make use of
+	is_current rather than pwd. Function Project::ordered_projects now only
+	returns ordered projects pointers vector, projects ordering is done in
+	Project::order_all. Ordering starts with current project, if exists, and
+	projects without parents, if current project does not exist or has no
+	parents and no children (the case for projects created from CMTPATH
+	environment variable entries), and aims to put parents before children
+	in projects order. If current project exists, only ordered projects are
+	present in ordered projects vector. For projects without parents and
+	without children, strategies are updated from the project next after
+	them in the ordered projects vector. In function Project::show_all, always
+	show all projects (rather than children of current or first project only),
+	first show ordered projects, then show the rest. In function Project::visit,
+	do not reorder current project if exists. Implement functions is_current,
+	set_is_current, erase_child. In function container_action, start search
+	from project m_cmtpath_pwd, if container is found, ensure its real_path is
+	absolute path
+	* source/cmt_use.h: Add helper function get_info to return use info as
+	string
+	* source/cmt_use.cxx: In function show_all, for home_package and
+	user_context_package use version assigned when they are created rather
+	than hard-wire version here, set error package_not_found if there are uses
+	that are not located. In function reach_package, consider case of empty
+	version. Implement get_info and make use of it in function Use::add
+	* source/cmt_pattern.cxx: In function ApplyPattern::action, always print
+	warning pattern_not_found, if appropriate, but do not set error (for now)
+	* source/cmt_syntax.cxx: In functions do_parse_requirements, do_parse_words,
+	clear syntax_error only, and print error messages in case of syntax_error
+	only
+	* source/cmt_log.h: Add CmtMessage::verbose function
+	* source/cmt.h: Introduce functions get_current_dir_real, get_current_path,
+	set_recursive
+	* source/cmt_parser.cxx: Implement introduced functions, in function
+	use_special_requirements, set use m_located member value to true, if
+	requirements file exists
+	* source/cmt_vcs.h: In class Vcs, introduce functions checkout_context,
+	parse_arguments, resolve_uses, introduce class IUseVisitor
+	* source/cmt_vcs.cxx: Introduce and implement class GlobalProjectAction,
+	class Packages, in order to generate uses available via current context
+	and search for specific packages among them. Rewrite class Walkthru to
+	accept an implementation of IUseVisitor interface, replace parse_checkout
+	with parse_arguments with new options -C, -i, and implement new
+	parse_checkout, in particular, in order to implement new options -C, -i.
+	Introduce helper classes VisitorForInfo, VisitorForCheckout implementing
+	IUseVisitor interface, enhance Vcs::checkout_module to allow for HEAD,
+	head, TRUNK, trunk to be used as arguments of option -r. Implement
+	functions visit, Vcs::checkout_context, Vcs::resolve_uses in order to
+	implement option -C, enhance Vcs::checkout_from_requirements in order to
+	implement option -i
+	* src/Makefile.header: Improve a diagnostic message
+	* src/Makefile.core: Do not ignore errors in command lines beginning with
+	macro echo
+	* mgr/cmt_dependencies.make: Update
+	
 2010-02-25    <rybkin@lal.in2p3.fr> 421
 
Index: /CMT/HEAD/mgr/cmt_dependencies.make
===================================================================
--- /CMT/HEAD/mgr/cmt_dependencies.make	(revision 534)
+++ /CMT/HEAD/mgr/cmt_dependencies.make	(revision 535)
@@ -17,5 +17,5 @@
 cmt_pattern_cxx_dependencies =  ../source/cmt_pattern.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h   ../source/cmt_error.h   ../source/cmt_syntax.h   ../source/cmt_log.h 
 cmt_language_cxx_dependencies =  ../source/cmt_language.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_language.h   ../source/cmt_branch.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h   ../source/cmt_error.h 
-cmt_vcs_cxx_dependencies =  ../source/cmt_vcs.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_cvs.h   ../source/cmt_vcs.h   ../source/cmt_awk.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_project.h   ../source/cmt_log.h   ../source/cmt_error.h 
+cmt_vcs_cxx_dependencies =  ../source/cmt_vcs.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_cvs.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_vcs.h   ../source/cmt_awk.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_project.h   ../source/cmt_log.h   ../source/cmt_error.h   ../source/cmt_syntax.h 
 cmt_group_cxx_dependencies =  ../source/cmt_group.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_group.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h 
 cmt_database_cxx_dependencies =  ../source/cmt_database.cxx   ../source/cmt_vector.h   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h 
Index: /CMT/HEAD/source/cmt.h
===================================================================
--- /CMT/HEAD/source/cmt.h	(revision 534)
+++ /CMT/HEAD/source/cmt.h	(revision 535)
@@ -210,5 +210,7 @@
   static const cmt_string& get_cmt_version ();
   static const cmt_string& get_current_dir ();
+  static const cmt_string get_current_dir_real ();
   static const cmt_string& get_current_package ();
+  static const cmt_string& get_current_path ();
   static const cmt_string& get_current_cmtpath ();
   static const cmt_string& get_current_offset ();
@@ -258,4 +260,5 @@
   static void restore_all_tags (Use* use);
   static void set_current_access (AccessMode mode);
+  static void set_recursive (bool mode);
   static void set_scope_filtering_mode (CmtScopeFilteringMode mode);
   static void set_standard_macros ();
Index: /CMT/HEAD/source/cmt_database.cxx
===================================================================
--- /CMT/HEAD/source/cmt_database.cxx	(revision 534)
+++ /CMT/HEAD/source/cmt_database.cxx	(revision 535)
@@ -158,4 +158,11 @@
 }
 
+Project::ProjectPtrVector& Database::ordered_projects ()
+{
+  static Database& db = instance ();
+
+  return (db.m_ordered_projects);
+}
+
 CmtPathPattern::CmtPathPatternVector& Database::cmtpath_patterns ()
 {
Index: /CMT/HEAD/source/cmt_database.h
===================================================================
--- /CMT/HEAD/source/cmt_database.h	(revision 534)
+++ /CMT/HEAD/source/cmt_database.h	(revision 535)
@@ -54,4 +54,5 @@
 
   static Project::ProjectVector& projects ();
+  static Project::ProjectPtrVector& ordered_projects ();
 
   static CmtPathPattern::CmtPathPatternVector& cmtpath_patterns ();
@@ -83,4 +84,5 @@
   Tag::TagMap m_tag_map;
   Project::ProjectVector m_projects;
+  Project::ProjectPtrVector m_ordered_projects;
 
   CmtPathPattern::CmtPathPatternVector m_cmtpath_patterns;
Index: /CMT/HEAD/source/cmt_log.h
===================================================================
--- /CMT/HEAD/source/cmt_log.h	(revision 534)
+++ /CMT/HEAD/source/cmt_log.h	(revision 535)
@@ -64,4 +64,5 @@
   static void set_level (const CmtMsgLevel& level);
   static bool active (const CmtMsgLevel& level);
+  static void verbose (const cmt_string& message);
   static void info (const cmt_string& message);
   static void warning (const cmt_string& message);
@@ -118,4 +119,10 @@
 }
 
+inline void CmtMessage::verbose (const cmt_string& message)
+{
+  if (active (Verbose))
+    cerr << prefix () << " Verbose: " << message << endl;
+}
+
 inline void CmtMessage::info (const cmt_string& message)
 {
Index: /CMT/HEAD/source/cmt_parser.cxx
===================================================================
--- /CMT/HEAD/source/cmt_parser.cxx	(revision 534)
+++ /CMT/HEAD/source/cmt_parser.cxx	(revision 535)
@@ -532,8 +532,10 @@
   log << "configure_site_tag" << log_endl;
   configure_site_tag (0);
+  log << "configure_current_dir" << log_endl;
+  configure_current_dir ();
   log << "configure_home" << log_endl;
   // CMTHOME, CMTUSERCONTEXT and CMTPATH
   configure_home (0);
-  log << "configure_current_dir" << log_endl;
+  //  log << "configure_current_dir" << log_endl;
 
 
@@ -547,5 +549,5 @@
   Me.m_quiet = save_quiet;
 
-  configure_current_dir ();
+  //  configure_current_dir ();
 
   guess_current_project ();
@@ -4289,4 +4291,8 @@
   cout << "----------> uses" << endl;
   do_show_uses (ap);
+  // This is temporary to ensure that Make - which runs "cmt show setup" -
+  // does not fail for packages with unresolved uses
+  if (CmtError::get_last_error_code () == CmtError::package_not_found)
+    CmtError::clear ();
 
   cout << "----------> tags" << endl;
@@ -4571,7 +4577,20 @@
 }
 
+const cmt_string Cmt::get_current_dir_real ()
+{
+  cmt_string current_dir_real;
+  if (CmtSystem::realpath_ (Me.m_current_dir, current_dir_real))
+    return current_dir_real;
+  return (Me.m_current_dir);
+}
+
 const cmt_string& Cmt::get_current_package ()
 {
   return (Me.m_current_package);
+}
+
+const cmt_string& Cmt::get_current_path ()
+{
+  return (Me.m_current_path);
 }
 
@@ -8562,4 +8581,10 @@
 
 //----------------------------------------------------------
+void Cmt::set_recursive (bool mode)
+{
+  Me.m_recursive = mode;
+}
+
+//----------------------------------------------------------
 void Cmt::set_scope_filtering_mode (CmtScopeFilteringMode mode)
 {
@@ -8778,4 +8803,8 @@
   f += CmtSystem::file_separator ();
   f += file_name;
+  if (CmtSystem::test_file (f))
+    {
+      use->m_located = true;
+    }
   SyntaxParser::parse_requirements (f, use);
 
Index: /CMT/HEAD/source/cmt_pattern.cxx
===================================================================
--- /CMT/HEAD/source/cmt_pattern.cxx	(revision 534)
+++ /CMT/HEAD/source/cmt_pattern.cxx	(revision 535)
@@ -844,14 +844,29 @@
   if (p == 0) 
     {
-      CmtError::set (CmtError::pattern_not_found, name);
+      if (use->get_current_scope () != ScopeUnspecified &&
+	  use->get_current_scope () != ScopePublic)
+	return;
+      /*
+      cmt_string use_info (use->get_package_name () +
+			   " " + use->version +
+			   (use->path != "" ? " " + use->path : "") +
+			   " " + use->real_path
+			   );
+      */
+      CmtMessage::warning (CmtError::get_error_name (CmtError::pattern_not_found) +
+			   ": " + name +
+			   " (applied by " + use->get_package_name () + ")"
+			   );
+      /*
+	CmtError::set (CmtError::pattern_not_found, name +
+	" (applied by " + use->get_package_name () + ")"
+	);
+      */
+      /*
       if (CmtMessage::active (Verbose))
 	{
-	  cmt_string cmtpath, offset;
-	  use->get_cmtpath_and_offset (cmtpath, offset);
-	  CmtMessage::warning ((offset != "" ? offset + "/" : "")
-			       + use->get_package_name ()
-			       + ": " + CmtError::get_last_error ());
-	  //CmtMessage::warning (CmtError::get_last_error ());
+	  CmtMessage::warning (CmtError::get_last_error ());
 	}
+      */
       return;
     }
Index: /CMT/HEAD/source/cmt_project.cxx
===================================================================
--- /CMT/HEAD/source/cmt_project.cxx	(revision 534)
+++ /CMT/HEAD/source/cmt_project.cxx	(revision 535)
@@ -247,6 +247,9 @@
 	    }
   
+	  bool updated (false);
 	  if (parent != 0)
 	    {
+	      if (!p.has_parent (parent) || !parent->has_child (&p))
+		{
 	      p.add_parent (parent);
 	      parent->add_child (&p);
@@ -255,7 +258,11 @@
 
 	      parent->update_strategies_from_children ();
+	      updated = true;
+		}
+
 	    }
 
 	  CmtSystem::cd (here);
+	  if (updated) Project::order_all ();
 	  return (&p);
 	}
@@ -278,9 +285,17 @@
 
   // In case there are symlinks
-  cmt_string here_real, pwd_real;
+
+  //  cmt_string here_real, pwd_real;
   //cerr << "realpath_: create_project" << endl;
+  /*
   if (CmtSystem::realpath_ (here, here_real) && CmtSystem::realpath_ (pwd, pwd_real))
     {
       if (here_real.find (pwd_real) == 0) is_current = true;
+    }
+  */
+  cmt_string pwd_real;
+  if (CmtSystem::realpath_ (pwd, pwd_real))
+    {
+      if (Cmt::get_current_dir_real ().find (pwd_real) == 0) is_current = true;
     }
 
@@ -544,4 +559,5 @@
       parent->update_strategies_from_children ();
     }
+  /*
   else if ((name != "CMTUSERCONTEXT") && (name != "CMTHOME"))
     //  else
@@ -569,5 +585,5 @@
       project->update_strategies_from_children ();
     }
-
+  */
   if (source == "default path")
     {
@@ -581,6 +597,9 @@
   project->set_cmtpath_source (source);
 
+  project->set_is_current (is_current);
+
   if (is_current)
     {
+      //      cerr << "current: " << project->get_name () << endl;
       //
       // The current project defines a tag with its name
@@ -594,4 +613,5 @@
 
 
+  //  Project::order_all ();
 
   if (text != "")
@@ -649,4 +669,5 @@
 
   CmtSystem::cd (here);
+  Project::order_all ();
 
   return (project);
@@ -820,4 +841,5 @@
 Project* Project::get_current ()
 {
+  /*
   cmt_string here = CmtSystem::pwd ();
 
@@ -825,5 +847,5 @@
   cmt_string here_real;
   CmtSystem::realpath_ (here, here_real);
-
+  */
   static ProjectVector& Projects = projects ();
 
@@ -840,5 +862,6 @@
 
 //      if (here.find (p.m_cmtpath) == 0) 
-      if (here_real.find (p.m_cmtpath_real) == 0) 
+      if (p.is_current ()) 
+	//      if (here_real.find (p.m_cmtpath_real) == 0) 
 	{
 	  result = &p;
@@ -907,7 +930,19 @@
 
 //----------------------------------------------------------
-Project::ProjectPtrVector Project::ordered_projects ()
-{
-  static ProjectPtrVector OrderedProjects;
+Project::ProjectPtrVector& Project::ordered_projects ()
+{
+  static Database& db = Database::instance ();
+  static ProjectPtrVector& Projects = db.ordered_projects ();
+
+  return (Projects);
+}
+
+//----------------------------------------------------------
+void Project::order_all ()
+//Project::ProjectPtrVector Project::ordered_projects ()
+{
+  ProjectPtrVector OrderedProjects;
+  //  static ProjectPtrVector OrderedProjects;
+  static Project::ProjectPtrVector& orderedProjects = Project::ordered_projects ();
 
   static Project::ProjectVector& Projects = Project::projects ();
@@ -956,4 +991,5 @@
 	  OrderedProjects[i] = p;
 	}
+      /*
       if (2 == offset)
 	{
@@ -962,5 +998,19 @@
 	  OrderedProjects[0]->update_strategies_from_children ();
 	}
-      return OrderedProjects;
+      */
+      for (int i = OrderedProjects.size () - 2; i >= 0; i--)
+	{
+	  if (!OrderedProjects[i]->has_parents () &&
+	      OrderedProjects[i]->get_children_size () == 0)
+	    {
+	      OrderedProjects[i]->add_child (OrderedProjects[i + 1]);
+	      OrderedProjects[i]->update_strategies_from_children ();
+	      OrderedProjects[i]->erase_child (OrderedProjects[i + 1]);
+	    }
+	}
+
+      orderedProjects = OrderedProjects;
+      //      return OrderedProjects;
+      return;
     }
 
@@ -968,4 +1018,5 @@
 
   //  cerr << "get_current: " << p << " offset: " << offset << endl;
+  /*
   if (p == 0)
     {
@@ -973,8 +1024,9 @@
       //      p = &(Projects[0]);
     }
+  */
   //  cerr << "p: " << p << " offset: " << offset << " name: " << p->get_name () << endl;
 
   int order (-1);
-
+  /*
   if ((p->get_name () != "CMTUSERCONTEXT") && (p->get_name () != "CMTHOME"))
     {
@@ -989,4 +1041,30 @@
   //  cerr << "order: " << order << endl;
   //  int unordered = size - offset - (order + 1);
+  */
+  ProjectPtrVector projs;
+
+  if (p != 0 && (p->get_name () != "CMTUSERCONTEXT") && (p->get_name () != "CMTHOME"))
+    {
+      p->m_order = ++order;
+      projs.push_back (p);
+    }
+
+  if (p == 0 ||
+      (!p->has_parents () && p->get_children_size () == 0)
+      // comes from CMTPATH entry
+      )
+    {
+      for (int i = offset; i < size; i++)
+	{
+	  Project* q = &(Projects[i]);
+	  if (q != p && !q->has_parents ())
+	    {
+	      q->m_order = ++order;
+	      projs.push_back (q);
+	    }
+	}
+    }
+
+  visit (offset, order, projs);
 
   int beg (0);
@@ -1017,4 +1095,9 @@
 	  */
 	}
+      else if (-2 != j)
+	{
+	  OrderedProjects[beg + j] = p;
+	}
+      /*
       else if  (-2 == j)
 	{
@@ -1026,11 +1109,35 @@
 	  //	  cerr << "OrderedProjects[" << beg + j << "]: " << (OrderedProjects[beg + j])->get_name () << endl;
 	}
-    }
-
+      */
+    }
+
+  if (p != 0)
+    {
+      for (int i = 0; i < noorder; i++)
+	OrderedProjects.pop_back ();
+    }
   if  (-1 != ihome)
     {
-      OrderedProjects[size - 1] = &(Projects[ihome]);
-    }
-
+      OrderedProjects[OrderedProjects.size () - 1] = &(Projects[ihome]);
+    }
+  /*
+  if (p)
+    {
+      if  (-1 != ihome)
+	{
+	  OrderedProjects[beg + order + 1] = &(Projects[ihome]);
+	}
+      for (int i = 0; i < noorder; i++)
+	OrderedProjects.pop_back ();
+    }
+  else
+    {
+      if  (-1 != ihome)
+	{
+	  OrderedProjects[size - 1] = &(Projects[ihome]);
+	}
+    }
+  */
+      /*
   if  (-1 != iuser)
     {
@@ -1039,11 +1146,13 @@
       OrderedProjects[0]->update_strategies_from_children ();
     }
-
-  if  (-1 != ihome)
-    {
+      */
+
+//   if  (-1 != ihome)
+//     {
       /*
       cerr << "beg: " << beg << " order: " << order << endl;
       cerr << "noorder: " << noorder << " size - offset: " << size - offset << endl;
       */
+      /*
       if (noorder != size - offset)
 	{  // the last ordered project
@@ -1058,7 +1167,21 @@
 	  OrderedProjects[size - 2]->update_strategies_from_children ();
 	}
-    }
-
-  return OrderedProjects;
+      */
+//     }
+
+  for (int i = OrderedProjects.size () - 2; i >= 0; i--)
+    {
+      if (!OrderedProjects[i]->has_parents () &&
+	  OrderedProjects[i]->get_children_size () == 0)
+	{
+	  OrderedProjects[i]->add_child (OrderedProjects[i + 1]);
+	  OrderedProjects[i]->update_strategies_from_children ();
+	  OrderedProjects[i]->erase_child (OrderedProjects[i + 1]);
+	}
+    }
+
+  orderedProjects = OrderedProjects;
+  //  return OrderedProjects;
+  return;
 }
 
@@ -1080,22 +1203,5 @@
 void Project::show_all ()
 {
-  const Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
-  //  static const Project::ProjectPtrVector Ordered = Project::ordered_projects ();
-  
-  for (int i = 0; i < Ordered.size (); i++)
-    {
-      Project* p = Ordered[i];
-      p->m_visited = false;
-    }
-
-  Project* p = get_current ();
-
-  if (p == 0)
-    {
-      if (Ordered.size () == 0) return;
-
-      p = Ordered[0];
-    }
-  /*
+  static const Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
   static Project::ProjectVector& Projects = Project::projects ();
   
@@ -1106,15 +1212,21 @@
     }
 
+  for (int i = 0; i < Ordered.size (); i++)
+    Ordered[i]->show ();
+
+  for (int i = 0; i < Projects.size (); i++)
+    Projects[i].show ();
+
+  /*
   Project* p = get_current ();
 
   if (p == 0)
     {
-      if (Projects.size () == 0) return;
-
-      p = &(Projects[0]);
+      if (Ordered.size () == 0) return;
+
+      p = Ordered[0];
     }
   */
-
-  p->show ();
+  //  p->show ();
 }
 
@@ -1303,5 +1415,5 @@
 void Project::fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections)
 {
-  static ProjectPtrVector Ordered = Project::ordered_projects ();
+  static ProjectPtrVector& Ordered = Project::ordered_projects ();
   for (int i = 0; i < Ordered.size (); i++)
     {
@@ -1352,5 +1464,6 @@
 void Project::broadcast (IProjectAction& action)
 {
-  static ProjectPtrVector Projects = Project::ordered_projects ();
+  //  const ProjectPtrVector Projects = Project::ordered_projects ();
+  static ProjectPtrVector& Projects = Project::ordered_projects ();
 
   for (int i = 0; i < Projects.size (); i++)
@@ -1375,5 +1488,6 @@
 void Project::reverse_broadcast (IProjectAction& action)
 {
-  static ProjectPtrVector Projects = Project::ordered_projects ();
+  //  const ProjectPtrVector Projects = Project::ordered_projects ();
+  static ProjectPtrVector& Projects = Project::ordered_projects ();
 
   for (int i = (Projects.size () - 1); i >= 0; i--)
@@ -1556,4 +1670,5 @@
 {
   int size = projs.size ();
+  //  cerr << "visit: " << offset << " " << order << " " << size << endl;
   if (0 == size) return;
   static ProjectVector& all = Project::projects ();
@@ -1591,5 +1706,6 @@
 	      child->m_order = ++order;
 	    }
-	  else if (0 == chorder)
+	  else if (child->is_current ())
+	    //	  else if (0 == chorder)
 	    { // the project we started with, i. e. the current project:
 	      //     o circular dependency
@@ -1601,5 +1717,6 @@
 				     + " " + child->get_cmtpath ());
 	    }
-	  else if ((0 < chorder) && (chorder < porder))
+	  else if ((0 <= chorder) && (chorder < porder))
+	    //	  else if ((0 < chorder) && (chorder < porder))
 	    { // ordered already, want to put it after the parent in the order
 	      for (int k = offset; k < all.size (); k++)
@@ -1609,5 +1726,5 @@
 		    {// the child we are putting after the parent in the order
 		      q.m_order = porder;
-		      //     cerr << "Moved back: " << q.get_name () << " order: " << q.m_order << endl;
+		      //	      cerr << "Moved back: " << q.get_name () << " order: " << q.m_order << endl;
 		    }
 		  else if ((chorder < q.m_order) && (q.m_order <= porder))
@@ -1615,5 +1732,5 @@
 		}
 	    }
-	  //	  cerr << child->get_name () << " out: " << child->m_order << endl;
+	  //  cerr << child->get_name () << " out: " << child->m_order << endl;
 	  //	  child->m_visits++;
 	  bool unknown (true);
@@ -1748,5 +1865,5 @@
   start_visit (visitor);
   */
-  const ProjectPtrVector Ordered = Project::ordered_projects ();
+  const ProjectPtrVector& Ordered = Project::ordered_projects ();
 
   buffer = "path CMTPATH \"\" \n";
@@ -1909,4 +2026,16 @@
 
 //----------------------------------------------------------
+void Project::set_is_current (bool is_current)
+{
+  m_is_current = is_current;
+}
+
+//----------------------------------------------------------
+bool Project::is_current () const
+{
+  return m_is_current;
+}
+
+//----------------------------------------------------------
 void Project::clear ()
 {
@@ -1925,4 +2054,5 @@
 
   m_strategies.clear ();
+  m_is_current = false;
 }
 
@@ -2019,4 +2149,28 @@
 
   m_children.push_back (p);
+}
+
+//----------------------------------------------------------
+void Project::erase_child (Project* p)
+{
+  if (p == 0) return;
+  if (p == this) return;
+
+  if (!has_child (p)) return;
+
+  const cmt_string& name = p->get_name ();
+
+  for (int i = 0; i < m_children.size (); i++)
+    {
+      const Project* child = m_children[i];
+      if (child == 0) continue;
+
+      if (child->get_name () == name)
+	{
+	  // registered as a child
+	  m_children.erase (i);
+	  break;
+	}
+    }
 }
 
@@ -2088,4 +2242,5 @@
       use->set (name, version, path);
       use->get_package ()->remove_use (use);
+      CmtSystem::cd (m_cmtpath_pwd);
       if (use->move_to ())
 	{
@@ -2103,4 +2258,8 @@
 	    {
 	      use->~Use ();
+	    }
+	  else if (!CmtSystem::absolute_path (use->real_path))
+	    {
+	      use->change_path (m_cmtpath_pwd);
 	    }
 	}
@@ -2382,8 +2541,9 @@
   static int level = 0;
 
-  bool is_current = false;
+  //  bool is_current = false;
 
   //  cmt_string here = CmtSystem::pwd ();
   // In case there are symlinks
+  /*
   cmt_string here_real;
   CmtSystem::realpath_ (CmtSystem::pwd (), here_real);
@@ -2397,10 +2557,11 @@
 	}
     }
-
+  */
   for (int tab = 0; tab < level; tab++) cout << "  ";
   cout << m_name << " " << (m_name != "CMTUSERCONTEXT" && m_name != "CMTHOME" ? m_release : "v0") << " (in " << m_cmtpath << ")";
   //  cout << m_name << " " << m_release << " (in " << m_cmtpath << ")";
 
-  if (is_current) cout << " (current)";
+  if (m_is_current) cout << " (current)";
+  //  if (is_current) cout << " (current)";
 
   int i;
Index: /CMT/HEAD/source/cmt_project.h
===================================================================
--- /CMT/HEAD/source/cmt_project.h	(revision 534)
+++ /CMT/HEAD/source/cmt_project.h	(revision 535)
@@ -109,5 +109,6 @@
 
   static ProjectVector& projects ();
-  static ProjectPtrVector ordered_projects ();
+  static ProjectPtrVector& ordered_projects ();
+  static void order_all ();
   static void clear_all ();
   static void show_all ();
@@ -163,4 +164,6 @@
   void set_cmtpath_pwd (const cmt_string& path);
   void set_cmtpath_source (const cmt_string& source);
+  void set_is_current (bool is_current);
+  bool is_current () const;
   void clear ();
   void configure ();
@@ -170,4 +173,5 @@
   void add_parent (Project* p);
   void add_child (Project* p);
+  void erase_child (Project* p);
 
   void container_action (const CmtSystem::cmt_string_vector& words);
@@ -225,4 +229,5 @@
   int m_visits;
   int m_order;
+  bool m_is_current;
 
   cmt_string m_cmtpath;
Index: /CMT/HEAD/source/cmt_syntax.cxx
===================================================================
--- /CMT/HEAD/source/cmt_syntax.cxx	(revision 534)
+++ /CMT/HEAD/source/cmt_syntax.cxx	(revision 535)
@@ -1656,5 +1656,6 @@
   cmt_string text;
 
-  CmtError::clear ();
+  if (CmtError::get_last_error_code () == CmtError::syntax_error)
+    CmtError::clear ();
 
   if (!CmtSystem::test_file (actual_file_name))
@@ -1888,5 +1889,6 @@
 				   Use* use)
 {
-  CmtError::clear ();
+  if (CmtError::get_last_error_code () == CmtError::syntax_error)
+        CmtError::clear ();
 
   if (words.size () == 0) return;
@@ -1921,6 +1923,9 @@
     }
 
-  if (CmtError::has_pending_error ())
+  if (CmtError::get_last_error_code () == CmtError::syntax_error)
+    //  if (CmtError::has_pending_error ())
     {
+      CmtError::print ();
+
       char num[32]; sprintf (num, "%d", line_number);
       CmtMessage::error ("bad syntax in requirements of " + use->get_package_name ()
@@ -1955,5 +1960,6 @@
 				   Project* project)
 {
-  CmtError::clear ();
+  if (CmtError::get_last_error_code () == CmtError::syntax_error)
+    CmtError::clear ();
 
   if (words.size () == 0) return;
@@ -1973,6 +1979,9 @@
     }
 
-  if (CmtError::has_pending_error ())
+  if (CmtError::get_last_error_code () == CmtError::syntax_error)
+    //  if (CmtError::has_pending_error ())
     {
+      CmtError::print ();
+
       char num[32]; sprintf (num, "%d", line_number);
       CmtMessage::error ("bad syntax in project file of " + project->get_name ()
Index: /CMT/HEAD/source/cmt_system.cxx
===================================================================
--- /CMT/HEAD/source/cmt_system.cxx	(revision 534)
+++ /CMT/HEAD/source/cmt_system.cxx	(revision 535)
@@ -1413,5 +1413,7 @@
 	  }
 
-	m_project = factory.create_project (project_name, npath, path_source, m_project);
+	m_project = factory.create_project (project_name, npath, path_source, 0);
+	//	m_project = factory.create_project (project_name, npath, path_source, m_project);
+	/*
 	if ((path_source == "CMTUSERCONTEXT") ||
 	    (path_source == "CMTHOME"))
@@ -1419,4 +1421,5 @@
 	    m_project = 0;
 	  }
+	*/
       }
   }
@@ -1646,5 +1649,5 @@
   output = "";
 
-  //cerr << "CmtSystem::execute2> [" << command << "]" << endl;
+  //  cerr << "CmtSystem::execute2> [" << command << "]" << endl;
 
   FILE* f = popen (command.c_str (), "r"); 
@@ -1661,17 +1664,22 @@
         } 
 
-      if (pclose (f) == -1)
+      int status = pclose (f);
+      if (status == -1) // error reported by pclose ()
 	{
+	  perror ("pclose");
 	  if (errno == ECHILD)
 	    {
 	      return (0);
 	    }
-	  return (1);
+	  return (-1);
 	}
-
-      return (0);
-    }
-
-  return (1);
+      else
+	{
+	  return WEXITSTATUS(status); // return status of the command
+	  //return (0);
+	}
+    }
+
+  return (-2);
 }
 
Index: /CMT/HEAD/source/cmt_use.cxx
===================================================================
--- /CMT/HEAD/source/cmt_use.cxx	(revision 534)
+++ /CMT/HEAD/source/cmt_use.cxx	(revision 535)
@@ -574,4 +574,27 @@
         }
 
+      Use* suse = Use::find (CmtSystem::get_home_package ());
+      if (suse != 0 && !suse->discarded && !suse->m_hidden && suse->located ())
+	{
+	  cout << prefix << suse->get_package_name ()
+	       << " " << suse->version;
+	  if (!Cmt::get_quiet ()) 
+	    {
+	      cout << " (" << suse->path << ")";
+	    }
+	  cout << endl;
+	}
+      suse = Use::find (CmtSystem::get_user_context_package ());
+      if (suse != 0 && !suse->discarded && !suse->m_hidden && suse->located ())
+	{
+	  cout << prefix << suse->get_package_name ()
+	       << " " << suse->version;
+	  if (!Cmt::get_quiet ()) 
+	    {
+	      cout << " (" << suse->path << ")";
+	    }
+	  cout << endl;
+	}
+      /*
       if (Cmt::get_cmt_home () != "")
         {
@@ -593,4 +616,30 @@
 	  cout << endl;
         }
+      */
+    }
+ 
+  const UseVector& instances = get_instances ();
+  for (int use_index = 0; use_index < instances.size (); use_index++)
+    {
+      Use* use = &(instances[use_index]);
+      //Use* use = uses[j];
+      
+      if (use->discarded) continue;
+      if (use->m_hidden) continue;
+      
+      if (!use->located ())
+	{
+	  CmtError::set (CmtError::package_not_found, use->get_info ());
+	}
+      else
+	{
+	  /*
+	    CmtMessage::info ("package " +
+	    use->get_package_name () +
+	    " " + use->version +
+	    (use->path != "" ? " " + use->path : "") +
+	    " found");
+	  */
+	}
     }
 }
@@ -854,4 +903,13 @@
               }
           }
+	/*
+        else // new_use == 0
+          {
+	    cerr << "action: " << action << " new_use: " <<  new_use
+		 << " package: " <<  package << endl;
+
+	    CmtError::set (CmtError::package_not_found, package);
+	  }
+	*/
 
         return (new_use);
@@ -1604,5 +1662,6 @@
       return (1);
     }
-  else if (!CmtSystem::cd (version))
+  else if (!CmtSystem::cd (version) || (version == ""))
+    //  else if (!CmtSystem::cd (version))
     {
       //
@@ -1610,6 +1669,7 @@
       // There are alternate possibilities when it contains wild cards
       //
+      if ((version.find ("*") != cmt_string::npos) || (version == ""))
       //      if ((version == "") || (version.find ("*") != cmt_string::npos))
-      if (version.find ("*") != cmt_string::npos)
+      //      if (version.find ("*") != cmt_string::npos)
         {
           static CmtSystem::cmt_string_vector versions;
@@ -1618,10 +1678,11 @@
           name = ".";
           name += CmtSystem::file_separator ();
-          name += version;
+          if (version != "") name += version;
+          else name += "*";
 	  /*
           if (version == "") name += "*";
           else name += version;
 	  */
-
+	  //          name += version;
           CmtSystem::scan_dir (name, versions);
           if (n_version != "")
@@ -2506,4 +2567,11 @@
   if (!found)
     {
+      CmtMessage::warning (CmtError::get_error_name (CmtError::package_not_found)
+			   + ": " + use->get_info ()
+			   + ( (context_use != 0) ?
+			       " (requested by " + context_use->get_package_name () + ")" :
+			       "" )
+			   );
+      /*
       CmtMessage::warning ("package " + use->get_package_name ()
 			   + " " + use->version + " " + use->path
@@ -2513,4 +2581,5 @@
 			       "" )
 			   );
+      */
       /*
       if (!Cmt::get_quiet ())
@@ -2530,4 +2599,5 @@
 
       //CmtError::set (CmtError::package_not_found, use->get_package_name ());
+      //use->m_located = false;
       use = 0;
     }
@@ -4670,2 +4740,10 @@
   return p;   
 }
+
+//----------------------------------------------------------
+cmt_string Use::get_info () const
+{    
+  return get_package_name () + " " + (version != "" ? version : "*") +
+    (path != "" ? " " + path : "") ;
+  //  return get_package_name () + " " + version + (path != "" ? " " + path : "") ;
+}
Index: /CMT/HEAD/source/cmt_use.h
===================================================================
--- /CMT/HEAD/source/cmt_use.h	(revision 534)
+++ /CMT/HEAD/source/cmt_use.h	(revision 535)
@@ -134,4 +134,5 @@
 
   Project* get_project ();
+  cmt_string get_info () const;
 // Public attributes
 public:
Index: /CMT/HEAD/source/cmt_vcs.cxx
===================================================================
--- /CMT/HEAD/source/cmt_vcs.cxx	(revision 534)
+++ /CMT/HEAD/source/cmt_vcs.cxx	(revision 535)
@@ -18,4 +18,6 @@
 #include "cmt_error.h"
 
+#include "cmt_syntax.h"
+
 /**
 
@@ -92,4 +94,345 @@
 };
 
+//--------------------------------------------------------------------
+static void show_packages ()
+{
+  Package::PackageVector& vector = Package::packages ();
+
+  int i;
+  int j;
+
+  cout << "### Packages: ";
+  for (i = 0; i < vector.size (); i++)
+    {
+      Package& p = vector[i];
+      cout << p.get_name () << "[";
+      Use::UsePtrVector& uses = p.get_uses ();
+      for (j = 0; j < uses.size (); j++)
+	{
+	  Use* u = uses[j];
+	  cout << u << ",";
+	}
+
+      cout << "] ";
+    }
+  cout << endl;
+
+  {
+    Use::UsePtrVector& uses = Use::get_ordered_uses ();
+    //    static Use::UsePtrVector& uses = Use::get_ordered_uses ();
+
+    cout << "### Uses: ";
+    for (i = 0; i < uses.size (); i++)
+      {
+	Use* u = uses[i];
+	cout << "[" << u << "]" << u->get_package_name () << " ";
+      }
+  }
+
+  cout << endl;
+}
+
+//--------------------------------------------------------------------
+
+class GlobalProjectAction : public IProjectAction
+{
+public:
+  GlobalProjectAction (const cmt_string& package,
+		       const cmt_string& version = "",
+			const cmt_string& path = "")
+    : m_package (package), m_version (version), m_path (path)
+  {
+    m_home_dir = CmtSystem::pwd ();
+    m_current = Use::current();
+    m_current_name = m_current.get_package_name ();
+    m_current.set_package_name ("m_current");
+  }
+
+  bool run (const Project& project)
+  {
+    if (project.is_current ()) return true;
+    CmtMessage::verbose ("run: " + project.get_cmtpath ());
+    const Use* use = &(project.get_container ());
+    if (use->get_package_name () != "" && use->located ())
+      {
+	CmtMessage::verbose ("container " + use->get_info () +
+			     " (" + use->real_path + ")");
+	Use* cuse = Use::add (use->real_path,
+			      use->get_package_name (),
+			      use->version,
+			      "", "", "", 0); // 0 == NOT used by current
+	if (cuse)
+	  {
+	    cmt_string cmt (use->get_full_path ());
+	    cmt += CmtSystem::file_separator ();
+	    cmt += "cmt";
+	    if (!CmtSystem::cd (cmt))
+	      {
+		CmtMessage::error ("Cannot move to directory " + cmt);
+		CmtError::set (CmtError::file_access_error, cmt);
+		if (!CmtSystem::cd (m_home_dir))
+		  {
+		    CmtMessage::error ("Cannot move to directory " + m_home_dir);
+		    CmtError::set (CmtError::file_access_error, m_home_dir);
+		  }
+		return true;
+	      }
+	    //cerr << "parsing: " << "requirements" << endl; 
+	    SyntaxParser::parse_requirements ("requirements", cuse);
+	    //cerr << "parsed: " << "requirements" << endl; 
+	    //show_packages ();
+	  }
+	else
+	  {
+	    CmtMessage::error ("Cannot add container " + use->get_package_name () +
+			       " " + use->version + " " + use->real_path);
+	  }
+	if (!CmtSystem::cd (m_home_dir))
+	  {
+	    CmtMessage::error ("Cannot move to directory " + m_home_dir);
+	    CmtError::set (CmtError::file_access_error, m_home_dir);
+	  }
+      }
+    return true;
+  }
+
+private:
+  cmt_string m_home_dir;
+  cmt_string m_package;
+  cmt_string m_version;
+  cmt_string m_path;
+  cmt_string m_cmtpath;
+  Use m_current;
+  cmt_string m_current_name;
+};
+
+//--------------------------------------------------------------------
+/**
+ *
+ *   Packages: keep info on all packages that can be found
+ *   in current context - CMTPATHs.
+ *
+ */
+
+class Packages
+{
+public:
+  static Packages& instance ();
+  //  void clear ();
+  //  void install (const cmt_string& line);
+  //  bool is_installed (const cmt_string& line);
+
+  Use* find (const cmt_string& name,
+	     const cmt_string& version = "",
+	     const cmt_string& path = "");
+
+private:
+  Packages ();
+  void exclude_current_project ();
+  void restore_current_project ();
+
+  int m_i;
+  Project* m_cur;
+  Project m_null;
+  bool m_initialized;
+};
+
+//--------------------------------------------------------------------
+Packages::Packages ()
+  : m_i (-1), m_cur (0), m_initialized (false)
+{
+  m_null.set_cmtpath (CmtSystem::get_temporary_name ());
+}
+
+//--------------------------------------------------------------------
+Packages& Packages::instance ()
+{
+  static Packages pkgs;
+  return (pkgs);
+}
+
+//--------------------------------------------------------------------
+Use* Packages::find (const cmt_string& name,
+		     const cmt_string& version,
+		     const cmt_string& path)
+{
+  if (name == "") return 0;
+  //  cerr << "find: " << name << " " << version << " " << path << endl;
+  exclude_current_project ();
+  if (path != "")
+    {
+      //cerr << "find: No need to find path: " << name << " " << path << endl;
+      //      Use use_obj (name, "", path);
+      Use use_obj (name, version, path);
+      Use* use = &use_obj;
+      //use->set (name, version, path);
+      use->get_package ()->remove_use (use);
+      if (use->move_to ())
+	{
+	  CmtSystem::cd (Cmt::get_current_dir ());
+	  /*
+	  cerr << "real_path: " << use->real_path
+	       << " style: " << use->style
+	       << " structuring_style: " << use->structuring_style
+	       << " full_path: " << use->get_full_path () << endl;
+	  */
+	  Use::UseVector& instances = Use::get_instances ();
+	  Use& use_object = instances.add ();
+	  use_object = *use;
+	  /*
+	  use_object.set (use->get_package_name (), use->version, use->path,
+			  use->version_alias, use->path_alias);
+	  use_object.get_package ()->remove_use (&use_object);
+	  */
+	  restore_current_project ();
+	  return (&use_object);
+	}
+      else
+	{
+	  CmtSystem::cd (Cmt::get_current_dir ());
+	  CmtMessage::warning (CmtError::get_error_name (CmtError::package_not_found)
+			       + ": " + use->get_info ());
+	}
+    }
+  //
+  // Second try is among the CMTPATHs
+  //
+  if (!m_initialized)
+    {
+      m_initialized = true;
+
+      GlobalProjectAction pa (name, version, path);
+      
+      Project::reverse_broadcast (pa);
+  //  Project::broadcast (pa);
+    }
+  //  cerr << "find: " << name << " " << version << " " << path << " Done." << endl;
+  //show_packages ();
+
+  Package* p = Package::find (name);
+  if (p == 0)
+    {
+      restore_current_project ();
+      return 0;
+    }
+    //return PackageInfo (name, version, path, "");
+  Use::UsePtrVector& uses = p->get_uses ();
+  Use* p_use (0);
+  //  cerr << "find for: " << name << endl;
+  for (int use_index = 0; use_index < uses.size (); use_index++)
+    {
+      Use* use = uses[use_index];
+      char index[8];
+      sprintf (index, "%d", use->m_index);
+      CmtMessage::verbose ("find: " + use->get_info () +
+			   " (" + use->real_path + ")" + 
+			   " m_index: " + index + 
+			   " located: " + (use->located () ? "1" : "0"));
+      if (use->located ()) p_use = use;
+      //      if (use->m_index >= 0) return use;
+      if (use->m_index >= 0) break;
+    }
+  if (p_use)
+    {
+//       cerr << "find: Try to validate: " << p_use->get_info ()
+// 	   << ": " << p_use->real_path << endl;
+      //      Use use_obj (name, "", path);
+      Use use_obj (name, version, p_use->path);
+      Use* use = &use_obj;
+      use->get_package ()->remove_use (use);
+      if (use->move_to ())
+	{
+	  CmtSystem::cd (Cmt::get_current_dir ());
+	  if (use->version == p_use->version)
+	    {
+	      CmtMessage::verbose ("Validated: " + p_use->get_info () +
+				   " (" + p_use->real_path + ")");
+	      restore_current_project ();
+	      return p_use;
+	    }
+	  Use* n_use = Use::add (use->real_path,
+				 use->get_package_name (),
+				 use->version,
+				 use->version_alias,
+				 use->path_alias,
+				 use->native_version,
+				 0); // 0 == NOT used by current
+	  CmtSystem::cd (Cmt::get_current_dir ());
+	  restore_current_project ();
+	  return n_use;
+	}
+      else
+	{
+	  CmtSystem::cd (Cmt::get_current_dir ());
+	  CmtMessage::verbose (CmtError::get_error_name (CmtError::package_not_found)
+			       + ": " + use->get_info ());
+	  restore_current_project ();
+	  return 0;
+	}
+    }
+
+  restore_current_project ();
+  return p_use;
+  //  return PackageInfo (name, version, path, "");
+  //  return pa.info ();
+}
+
+//--------------------------------------------------------------------
+void Packages::exclude_current_project ()
+{
+  if (m_i != -1 || m_cur != 0) return;
+  //  cerr << "exclude_current_project: " << m_i << ": " << m_cur << endl;
+  Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
+  int i = -1;
+  //  m_cur = 0;
+  //  Project null;
+  for (i = 0; i < Ordered.size (); i++)
+    if (Ordered[i]->is_current ()) break;
+  if (i >= 0 && i < Ordered.size ())
+    {
+      m_i = i;
+      m_cur = Ordered[i];
+      Ordered[i] = &m_null;
+    }
+}
+
+//--------------------------------------------------------------------
+void Packages::restore_current_project ()
+{
+  Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
+  if (m_i >= 0 && m_i < Ordered.size ())
+    {
+      Ordered[m_i] = m_cur;
+      m_i = -1;
+      m_cur = 0;
+    }
+}
+
+//--------------------------------------------------------------------
+/*
+void Packages::clear ()
+{
+  m_installed = "";
+}
+
+void Packages::install (const cmt_string& line)
+{
+  m_installed += "|";
+  m_installed += line;
+  m_installed += "|";
+}
+
+bool Packages::is_installed (const cmt_string& line)
+{
+  if (m_installed.find (line) != cmt_string::npos)
+    {
+      return (true);
+    }
+  
+  return (false);
+}
+*/
+
+//--------------------------------------------------------------------
 /**
 
@@ -129,43 +472,35 @@
 };
 
-class Walkthru : public Awk
+//--------------------------------------------------------------------
+/**
+ *
+ * Helper classes
+ *
+ */
+
+/*
+class SelectSubUses : public Awk
 {
 public:
-  Walkthru (const Vcs::Checkout& checkout,
-	    bool config, bool with_version_directory,
-	    Vcs::VcsType type);
-  //  RecursivePass2 (CvsImplementation& cvs);
+
   void begin ();
   void filter (const cmt_string& line);
+  //  const cmt_string& result () const;
+  bool has (const cmt_string& package) const;
 
 private:
-  const Vcs::Checkout& m_checkout;
-  bool m_config;
-  bool m_with_version_directory;
-  Vcs::VcsType m_type;
-  //  CvsImplementation& m_cvs;
+  void append (const cmt_string& package);
+  cmt_string m_result;
+  bool m_first;
 };
 
-Walkthru::Walkthru (const Vcs::Checkout& checkout,
-		    bool config, bool with_version_directory,
-		    Vcs::VcsType type)
-  : m_checkout (checkout),
-    m_config (config), m_with_version_directory (with_version_directory),
-    m_type (type)
-{
-}
-
-void Walkthru::begin ()
-{
-}
-
-void Walkthru::filter (const cmt_string& line)
-{
-//   History& h = History::instance ();
-  
-//   if (h.is_installed (line)) return;
-  
-//   h.install (line);
-  
+void SelectSubUses::begin ()
+{
+  m_first = true;
+  m_result = "";
+}
+
+void SelectSubUses::filter (const cmt_string& line)
+{
   CmtSystem::cmt_string_vector words;
   
@@ -183,9 +518,9 @@
   cmt_string version;
   cmt_string path;
-
-  for (int i = 1; i < words.size (); i++)
+  cerr << line;
+  for (int i = 2; i < words.size (); i++)
     {
       const cmt_string& s = words[i];
-
+      cerr << " `" + s + "'"; 
       if (s[0] == '-') continue;
 
@@ -201,38 +536,150 @@
 	  break;
 	case need_path:
-	  path = s;
+	  if (s.find ("(") != 0)
+	    path = s;
 	  state = no_need;
 	  break;
         }
     }
-
+  cerr << endl;
+
+  if (package == "" ||
+      package == "CMT" ||
+      package == "cmt")
+    return;
+  append (package);
+}
+
+void SelectSubUses::append (const cmt_string& package)
+{
+  if (m_first)
+    {
+      m_first = false;
+      m_result = "|" + package + "|";
+    }
+  else
+    {
+      if (!has (package))
+	m_result += package + "|";
+    }
+  cerr << "m_result: " << m_result << endl;
+}
+
+bool SelectSubUses::has (const cmt_string& package) const
+{
+  return (m_result.find ("|" + package + "|") != cmt_string::npos);
+}
+*/
+
+//--------------------------------------------------------------------
+class Walkthru : public Awk
+{
+public:
+  Walkthru (IUseVisitor& visitor);
+  //  RecursivePass2 (CvsImplementation& cvs);
+  void begin ();
+  void filter (const cmt_string& line);
+
+private:
+  //  CvsImplementation& m_cvs;
+  IUseVisitor& m_visitor;
+};
+
+//--------------------------------------------------------------------
+Walkthru::Walkthru (IUseVisitor& visitor)
+  : m_visitor (visitor)
+{
+}
+
+//--------------------------------------------------------------------
+void Walkthru::begin ()
+{
+}
+
+//--------------------------------------------------------------------
+void Walkthru::filter (const cmt_string& line)
+{
+  CmtSystem::cmt_string_vector words;
+  
+  CmtSystem::split (line, " \t", words);
+
+  enum
+    {
+      need_package,
+      need_version,
+      need_path,
+      no_need
+    } state = need_package;
+
+  cmt_string package;
+  cmt_string version;
+  cmt_string path;
+  //  cerr << line;
+  for (int i = 1; i < words.size (); i++)
+    {
+      const cmt_string& s = words[i];
+      //      cerr << " `" + s + "'"; 
+      if (s[0] == '-') continue;
+
+      switch (state)
+        {
+	case need_package:
+	  package = s;
+	  state = need_version;
+	  break;
+	case need_version:
+	  version = s;
+	  state = need_path;
+	  break;
+	case need_path:
+	  if (s.find ("(") != 0 && s.find ("#") != 0)
+	    path = s;
+	  state = no_need;
+	  break;
+        }
+    }
+  //  cerr << endl;
+  
+  if (package == "" ||
+      package == "CMT" ||
+      package == "cmt" ||
+      package == CmtSystem::get_home_package () ||
+      package == CmtSystem::get_user_context_package ()
+      )
+    return;
+  /*
   if (version == "")
-    {
-      version = "*";
-    }
-
-  if (version.find ("*") != cmt_string::npos &&
-      !m_checkout.m_context)
-    {
-      /*
-	cerr << "# ================= Package " << package 
-	<< " version " << version << " " << path 
-	<< " has wild cards and will not be considered." << endl;
-      */
+    version = "*";
+  */
+
+  if (version.find ("*") != cmt_string::npos)
+    {
+// 	cerr << "# ================= Package " << package 
+// 	<< " version " << version << " " << path 
+// 	<< " has wild cards and will not be considered." << endl;
       CmtMessage::warning (package + " " + version +
 			   (path != "" ? " " + path : "") +
-			   " has wildcards in version and will not be considered.");
+			   ": Skipped due to wildcards in version."
+			   " Consider using -C option.");
     }
   else
     {
+      Use use_obj (package, version, path);
+      Use* use = &use_obj;
+      //use->set (name, version, path);
+      use->get_package ()->remove_use (use);
+      m_visitor.in (use);
       //      static const cmt_string empty;
       //      m_cvs.do_checkout_phase2 (path, package, version, empty);
-      cmt_string module ((path != "") ? path + "/" + package : package);
-      Vcs::checkout_module (m_checkout,
-			    m_config, m_with_version_directory,
-			    module, version,
-			    m_type);
-    }
-}
+//       cmt_string module ((path != "") ? path + "/" + package : package);
+//       Vcs::checkout_module (m_checkout,
+// 			    m_config, m_with_version_directory,
+// 			    module, version,
+// 			    m_type);
+    }
+
+}
+
+//--------------------------------------------------------------------
 
 /**
@@ -1180,4 +1627,5 @@
   void add_cmtpath (const cmt_string& dir)
   {
+    return;
     static cmt_string CMTPATH;
 
@@ -3228,4 +3676,5 @@
 }
 
+//--------------------------------------------------------------------
 void Vcs::help ()
 {
@@ -3238,4 +3687,6 @@
   cerr << "   -R          Process used products recursively." << endl;
   cerr << "   -r rev      Check out version tag. (is sticky)" << endl;
+  cerr << "   -C          Determine version tag and/or package container from context." << endl;
+  cerr << "   -i          Do not check out, show package(s) information only." << endl;
   cerr << "   -vd dir     Use this version directory instead of version tag." << endl;
   cerr << "   -d dir      Check out into dir instead of module name." << endl;
@@ -3257,4 +3708,5 @@
 }
 
+//--------------------------------------------------------------------
 /**
  * When running cmt cvs commands, we stand by definition outside of any existing 
@@ -3262,4 +3714,5 @@
  * This function manually prepends CMTPATH entries to the environment variable.
  */
+//--------------------------------------------------------------------
 void Vcs::add_cmtpath (const cmt_string& dir)
 {
@@ -3293,4 +3746,5 @@
 }
 
+//--------------------------------------------------------------------
 bool Vcs::need_version_directory ()
 {
@@ -3312,6 +3766,7 @@
 }
 
-int Vcs::parse_checkout (const CmtSystem::cmt_string_vector& arguments,
-			 Checkout& checkout, bool& config)
+//--------------------------------------------------------------------
+int Vcs::parse_arguments (const CmtSystem::cmt_string_vector& arguments,
+			  Checkout& checkout, bool& config)
 {
   if (arguments.size () < 1)
@@ -3420,4 +3875,12 @@
 	      //m_head = false;
 	    }
+	  else if (option == "-C")
+	    {
+	      checkout.m_context = true;
+	    }
+	  else if (option == "-i")
+	    {
+	      checkout.m_info = true;
+	    }
 	  else if (option == "-d")
 	    {
@@ -3470,4 +3933,10 @@
 	  else
 	    {
+	      if (option.size () == 0)
+		{
+		  CmtMessage::warning ("Skipping bad module `" +
+				       option + "'");
+		  continue;
+		}
 	      checkout.m_modules.push_back (option);
 	    }
@@ -3497,4 +3966,139 @@
 }
 
+//--------------------------------------------------------------------
+class Modules
+{
+public:
+  //  Use::UsePtrVector m_packages;
+  //  cmt_vector<PackageInfo> m_packages;
+  Use::UseVector m_packages;
+  cmt_string m_uses;
+};
+
+//--------------------------------------------------------------------
+int Vcs::parse_checkout (Checkout& checkout,
+			 Modules& modules)
+  //			 cmt_string& uses)
+{
+  int retval (0);
+
+  if (checkout.m_requirements != "")
+    {
+      if (!CmtSystem::test_file (checkout.m_requirements))
+	{
+	  CmtError::set (CmtError::path_not_found, checkout.m_requirements);
+	  ++retval;
+	}
+      else
+	{
+	  cmt_string text;
+	  if (!text.read (checkout.m_requirements))
+	    {
+	      CmtError::set (CmtError::file_access_error, checkout.m_requirements);
+	      ++retval;
+	    }
+	  else
+	    {
+	      modules.m_uses = text;
+	    }
+	}
+    }
+
+  const cmt_string& version_tag = checkout.m_version_tag;
+  if (version_tag == "HEAD" || version_tag == "head" ||
+      version_tag == "TRUNK" || version_tag == "trunk")
+    checkout.m_head = true;
+  
+  cmt_string uses;
+  for (int arg = 0; arg < checkout.m_modules.size (); arg++)
+    {
+      cmt_string use ("use");
+      cmt_string name = checkout.m_modules[arg];
+      cmt_string package;
+      cmt_string version;
+      cmt_string path;
+      /*
+	if (checkout.m_context)
+	{
+	name.replace_all ("//", "/");
+	}
+      */
+      while (name.size () > 0 && name[name.size () - 1] == '/')
+	name.erase (name.size () - 1);
+      if (name.size () == 0)
+	{
+	  CmtError::set (CmtError::syntax_error, "Bad module name `" +
+			 checkout.m_modules[arg] + "'");
+	  CmtError::print ();
+	  continue;
+	}
+      
+      int pos = name.find_last_of ('/');
+      if (pos != cmt_string::npos)
+	{
+	  package = name.substr (pos + 1);
+	  path = name.substr (0, pos);
+	}
+      else
+	{
+	  package = name;
+	}
+      if (checkout.m_context)
+	{
+	  if (version_tag == "" || path == "")
+	    {
+	      Packages& pkgs = Packages::instance ();
+	      //if (version_tag == "") - want to find 1) version
+	      //                                      2) path, if (path == "")
+	      // args: package, version_tag, path
+	      //if (path == "") - want to find 1) path
+	      //                               2) version, if (version_tag == "")
+	      // args: package, "", path
+	      // package, "", path
+	      Use* p_use = pkgs.find (package, "", path);
+	      if (p_use == 0)
+		{
+		  CmtError::set (CmtError::package_not_found, package +
+				 ": Context");
+		  CmtError::print ();
+		  ++retval;
+		  continue;
+		}
+// 	      cerr << "Obtained: " << p_use->get_info ()
+// 		   << " " << p_use->real_path << endl;
+	      if (version_tag == "" )
+		version = p_use->version;
+	      else
+		version = version_tag;
+
+	      path = p_use->path;
+	    }
+	  if (!checkout.m_head)
+	    {
+	      use += " " + package + " " + version + " " + path + "\n";
+	      CmtMessage::verbose (use);
+	      uses += use;
+	    }
+	} // end of checkout.m_context
+      else
+	{
+	  version = version_tag;
+	}
+      {
+	Use use_obj (package, version, path);
+	Use* use = &use_obj;
+	use->get_package ()->remove_use (use);
+	modules.m_packages.push_back (use_obj);
+      }
+    } // end of for-loop over checkout.m_modules
+  if (checkout.m_context)
+    {
+      resolve_uses (checkout, uses + modules.m_uses);
+    }
+
+  return retval;
+}
+
+//--------------------------------------------------------------------
 void Vcs::checkout (const CmtSystem::cmt_string_vector& arguments)
 {
@@ -3524,9 +4128,13 @@
   bool config (true);
   Checkout checkout;
-  parse_checkout (arguments, checkout, config);
+  parse_arguments (arguments, checkout, config);
 
   if (CmtError::has_pending_error ()) return;
 
-  add_cmtpath (CmtSystem::pwd ());
+  //  cmt_string uses;
+  //  parse_checkout (checkout, uses);
+  Modules modules;
+  parse_checkout (checkout, modules);
+  //  add_cmtpath (CmtSystem::pwd ());
   bool with_version_directory (need_version_directory ());
       /*
@@ -3537,10 +4145,87 @@
   if (svnroot != "")
     {
-      Svn::checkout (checkout, config, with_version_directory);
+      Svn::checkout (checkout, modules, config, with_version_directory);
       return;
     }
 }
 
-void Svn::checkout (Vcs::Checkout checkout,
+//--------------------------------------------------------------------
+class VisitorForInfo : public IUseVisitor
+{
+public:
+  VisitorForInfo ()
+  {
+  }
+
+  void in (Use* use)
+  {
+    cmt_string p = use->real_path;
+    if (use->path != "")
+      {
+	int pos = p.find_last_of (use->path);
+	if (pos != cmt_string::npos)
+	  {
+	    p.erase (pos);
+	  }
+      }
+
+    cout << use->get_package_name ()
+	 << " " << use->version;
+    
+    if (CmtSystem::absolute_path (use->path))
+      {
+	if (!Cmt::get_quiet ()) 
+	  {
+	    cout << " (" << use->path << ")";
+	  }
+      }
+    else
+      {
+	if (use->path != "") cout << " " << use->path;
+      }
+    
+    if (!Cmt::get_quiet ()) 
+      {
+	if (p != "") cout << " (" << p << ")";
+      }
+    
+    cout << endl;
+  }
+};
+
+//--------------------------------------------------------------------
+class VisitorForCheckout : public IUseVisitor
+{
+public:
+  VisitorForCheckout (const Vcs::Checkout& checkout,
+		      bool config, bool with_version_directory,
+		      Vcs::VcsType type)
+    : m_checkout (checkout),
+      m_config (config), m_with_version_directory (with_version_directory),
+      m_type (type)
+  {
+  }
+  
+  void in (Use* use)
+  {
+    cmt_string module ((use->path != "") ? use->path + "/" + use->get_package_name () :
+		       use->get_package_name ());
+    Vcs::checkout_module (m_checkout,
+			  m_config, m_with_version_directory,
+			  //			  module, version,
+			  module,
+			  use->version,
+			  m_type);
+  }
+
+private:
+  const Vcs::Checkout& m_checkout;
+  bool m_config;
+  bool m_with_version_directory;
+  Vcs::VcsType m_type;
+};
+
+//--------------------------------------------------------------------
+void Svn::checkout (Vcs::Checkout checkout, Modules modules,
 		   bool config, bool with_version_directory)
 {
@@ -3560,6 +4245,30 @@
 
   /**
+   * Checkout packages found in context
+   */
+  if (checkout.m_context)
+    {
+      Vcs::checkout_context (checkout, modules,
+			     config, with_version_directory,
+			     Vcs::Svn);
+      if (!checkout.m_head) return;
+    }
+
+  /**
    * Call checkout for each command line argument
    */
+  VisitorForInfo visitor_i;
+  VisitorForCheckout visitor_co (checkout,
+				 config, with_version_directory,
+				 Vcs::Svn);
+  for (int i = 0; i < modules.m_packages.size (); i++)
+    {
+      Use* use = &(modules.m_packages[i]);
+      if (checkout.m_info)
+	visitor_i.in (use);
+      else
+	visitor_co.in (use);
+    }
+  /*
   for (int arg = 0; arg < checkout.m_modules.size (); arg++)
     {
@@ -3572,9 +4281,13 @@
       //      do_checkout_phase1 (modules[arg], m_version_dir, version_tag);
     }
+  */
+
+  if (checkout.m_context) return;
 
   /**
    * Call checkout for used package in requirements file
    */
-  if (checkout.m_requirements != "")
+  if (checkout.m_requirements != "" &&
+      modules.m_uses != "")
     Vcs::checkout_from_requirements (checkout,
 				     config, with_version_directory,
@@ -3583,34 +4296,10 @@
 }
 
+//--------------------------------------------------------------------
 void Vcs::checkout_module (const Vcs::Checkout& checkout,
 			   bool config, bool with_version_directory,
-			   const cmt_string& module, cmt_string version_tag,
+			   cmt_string module, cmt_string version_tag,
 			   Vcs::VcsType type)
 {
-//   cmt_string checkout_command;
-//   Symbol* checkout_command_macro = Symbol::find ("svn_checkout_command");
-//   if (checkout_command_macro != 0)
-//     {
-//       checkout_command = checkout_command_macro->resolve_macro_value ();
-//     }
-//   if (checkout_command == "")
-//     {
-//       CmtError::set (CmtError::symbol_not_found,
-// 		     "Macro svn_checkout_command not defined");
-//       return;
-//     }
-  if (checkout.m_context)
-    {
-      int i;
-      if (version_tag == "")
-	// version tag not specified on the command line
-	{
-	}
-      else if ((i = version_tag.find ("*")) != cmt_string::npos)
-	// version has wildcards (or not specified) in requirements
-	{
-	}
-    }
-
   History& h = History::instance ();
   cmt_string line (module + " " + version_tag);
@@ -3631,12 +4320,16 @@
     cmd += " --without_version_directory";
 
-  if (version_tag != "")
+  if (version_tag == "" ||
+      version_tag == "HEAD" || version_tag == "head" ||
+      version_tag == "TRUNK" || version_tag == "trunk"
+      )
+    {
+      msg += (version_tag == "" ? " (HEAD)" : " (" + version_tag + ")");
+      version_tag = "";
+    }
+  else
     {
       cmd += " -r " + version_tag;
       msg += " (" + version_tag + ")";
-    }
-  else
-    {
-      msg += " (HEAD)";
     }
   if (checkout.m_offset != "")
@@ -3656,7 +4349,4 @@
    * Then call checkout for the module
    */
-  //   for (int arg = 0; arg < checkout.m_modules.size (); arg++)
-  //     {
-  //       const cmt_string& module = checkout.m_modules[arg];
   CmtMessage::info ("Working on " + module + msg);
   //      cerr << cmd + " " + module << endl;
@@ -3665,5 +4355,6 @@
     {
       CmtMessage::info (module + " done.");
-      if (checkout.m_recursive)
+      if (checkout.m_recursive && !checkout.m_context)
+	//      if (checkout.m_recursive)
 	{
 	  cmt_string requirements;
@@ -3694,6 +4385,6 @@
 		    { // checkout of trunk
 		      //
-		      static CmtSystem::cmt_string_vector versions;
-		      static cmt_string name;
+		      CmtSystem::cmt_string_vector versions;
+		      cmt_string name;
 		      
 		      name = requirements;
@@ -3750,7 +4441,6 @@
 		      if (n < 1)
 			{
-			  CmtMessage::error ("Cannot find package in " +
-					     requirements +
-					     " for recursion");
+			  CmtMessage::error ("Cannot find package for recursion"
+					     " in " + requirements);
 			  CmtError::set (CmtError::package_not_found,
 					 "in " + requirements);
@@ -3760,10 +4450,12 @@
 		}
 	    } // end of with_version_directory
-	  cmt_string cmt_req = requirements +
+	  cmt_string
+	    cmt_req = requirements +
 	    CmtSystem::file_separator () +
 	    "cmt" +
 	    CmtSystem::file_separator () +
 	    "requirements";
-	  cmt_string mgr_req = requirements +
+	  cmt_string
+	    mgr_req = requirements +
 	    CmtSystem::file_separator () +
 	    "mgr" +
@@ -3797,4 +4489,277 @@
 }
 
+//--------------------------------------------------------------------
+static void visit (const Use::UsePtrVector& uses, IUseVisitor& visitor)
+{
+  for (int i = 0; i < uses.size (); i++)
+    {
+      Use* use = uses[i];
+      if (use == 0) continue;
+      if (use->selected) continue;
+      use->selected = true;
+      if (use->discarded) continue;
+      if (use->m_hidden) continue;
+      if (!use->located ()) continue;
+      if (use->get_package_name () == "CMT") continue;
+      if (use->get_package_name () == "cmt_standalone") continue;
+      if (use->get_package_name () == CmtSystem::get_home_package ()) continue;
+      if (use->get_package_name () == CmtSystem::get_user_context_package ()) continue;
+
+      //      visitor.in (use);
+      visit (use->sub_uses, visitor);
+      visitor.in (use);
+    }
+}
+
+//--------------------------------------------------------------------
+void Vcs::checkout_context (const Vcs::Checkout& checkout, Modules modules,
+			    bool config, bool with_version_directory,
+			    Vcs::VcsType type)
+{
+  VisitorForInfo visitor_i;
+  VisitorForCheckout visitor_co (checkout,
+				 config, with_version_directory,
+				 type);
+  
+  Use* current = &(Use::current ());
+  if (checkout.m_info)
+    visit (current->sub_uses, visitor_i);
+  else
+    visit (current->sub_uses, visitor_co);
+
+}
+
+//--------------------------------------------------------------------
+int Vcs::resolve_uses (const cmt_string& text, cmt_string& uses)
+{
+  cerr << "Vcs::resolve_uses" << endl;
+  cmt_string home_dir = CmtSystem::pwd ();
+  //
+  // Resolve uses by creating a package in a temporary directory
+  //
+  cmt_string tmp_dir = CmtSystem::getenv ("TMPDIR");
+  if (tmp_dir == "")
+    {
+      tmp_dir = CmtSystem::file_separator ();
+      tmp_dir += "tmp";
+    }
+  
+  if (!CmtSystem::test_directory (tmp_dir))
+    //if (!CmtSystem::cd (tmp_dir))
+    {
+      tmp_dir = home_dir;
+    }
+  
+  tmp_dir += CmtSystem::file_separator ();
+  tmp_dir += "cmtvcs";
+  cmt_string temp = CmtSystem::get_temporary_name ();
+  CmtSystem::basename (temp, temp);
+  // Suppress dots for Windows
+  temp.replace_all (".", "");
+  tmp_dir += temp;
+
+  cerr << "tmp_dir: " << tmp_dir << endl;
+  //  tmp_dir = "/tmp/cmtvcsfileEvmagO";
+
+  if (CmtSystem::test_directory (tmp_dir))
+    {
+      if (!CmtSystem::remove_directory (tmp_dir))
+	{
+	  // CmtMessage::error ("Cannot remove temporary directory " + tmp_dir);
+	  // error message printed by CmtSystem::remove_directory
+	  return 1;
+	}
+    }
+  if (!CmtSystem::mkdir (tmp_dir))
+    {
+      CmtMessage::error ("Cannot create temporary directory " + tmp_dir);
+      return 1;
+    }
+
+  cmt_string pkgspec (temp + " v1 " + tmp_dir);
+  if (0 != CmtSystem::execute ("cmt -without_version_directory create " + pkgspec))
+    //  if (0 != CmtSystem::execute ("cmt -with_version_directory create " + pkg))
+    {
+      CmtMessage::error ("Cannot create package " + pkgspec);
+      CmtSystem::remove_directory (tmp_dir);
+      return 1;
+    }
+
+  cmt_string cmt_dir (tmp_dir +
+		      CmtSystem::file_separator () + temp +
+		      //		      CmtSystem::file_separator () + "v1" + 
+		      CmtSystem::file_separator () + "cmt");
+  
+  cmt_string reqtext;
+  cmt_string requirements (cmt_dir +
+			   CmtSystem::file_separator () + "requirements");
+  if (!reqtext.read (requirements))
+    {
+      CmtError::set (CmtError::file_access_error, requirements);
+      CmtSystem::remove_directory (tmp_dir);
+      return 1;
+    }
+
+  FILE* file = fopen (requirements, "wb");
+  if (file != NULL)
+    {
+      (reqtext + text).write (file);
+      CmtSystem::close_ostream (file, requirements);
+      //      fclose (file);
+    }
+  else
+    {
+      CmtError::set (CmtError::file_access_error, requirements);
+      CmtSystem::remove_directory (tmp_dir);
+      return 1;
+    }
+
+  if (!CmtSystem::cd (cmt_dir))
+    {
+      CmtMessage::error ("Cannot move to temporary package directory " + cmt_dir);
+      CmtSystem::remove_directory (tmp_dir);
+      return 1;
+    }
+
+  int status = CmtSystem::execute ("cmt show uses", uses);
+  //  cerr << "status: " << status << endl;
+  if (status != 0)
+    {
+      CmtMessage::error ("Cannot show uses for package " + pkgspec);
+    }
+  //  cerr << "uses:\n" + uses << endl;
+  CmtSystem::cd (home_dir);
+  CmtSystem::remove_directory (tmp_dir);
+  return  status == 0 ? 0 : -1;
+}
+
+//--------------------------------------------------------------------
+int Vcs::resolve_uses (const cmt_string& text, Use::UsePtrVector& uses)
+{
+  cerr << "Vcs::resolve_uses NEW" << endl;
+  cmt_string home_dir = CmtSystem::pwd ();
+
+  Use* current = &(Use::current());
+
+  SyntaxParser::parse_requirements_text (text, "", current);
+
+  cerr <<  "recursive: " <<  Cmt::get_recursive () << endl;
+
+  Use::show_all ();
+
+  if (CmtError::get_last_error_code () == CmtError::package_not_found)
+    CmtError::print ();
+
+  return -1;
+}
+
+//--------------------------------------------------------------------
+int Vcs::resolve_uses (const Checkout& checkout, const cmt_string& uses)
+  //int Vcs::resolve_uses (const Checkout& checkout, const Modules& modules)
+{
+  if (!checkout.m_context) return 0;
+
+  //  cerr << "Vcs::resolve_uses NEW+" << endl;
+  cmt_string home_dir = CmtSystem::pwd ();
+  //
+  // Resolve uses by creating a package in a temporary directory
+  //
+  cmt_string tmp_dir = CmtSystem::getenv ("TMPDIR");
+  if (tmp_dir == "")
+    {
+      tmp_dir = CmtSystem::file_separator ();
+      tmp_dir += "tmp";
+    }
+  
+  if (!CmtSystem::test_directory (tmp_dir))
+    //if (!CmtSystem::cd (tmp_dir))
+    {
+      tmp_dir = home_dir;
+    }
+  
+  tmp_dir += CmtSystem::file_separator ();
+  tmp_dir += "cmtvcs";
+  cmt_string temp = CmtSystem::get_temporary_name ();
+  CmtSystem::basename (temp, temp);
+  // Suppress dots for Windows
+  temp.replace_all (".", "");
+  tmp_dir += temp;
+
+  if (CmtSystem::test_directory (tmp_dir))
+    {
+      if (!CmtSystem::remove_directory (tmp_dir))
+	{
+	  CmtError::set (CmtError::file_access_error, tmp_dir);
+	  // CmtMessage::error ("Cannot remove temporary directory " + tmp_dir);
+	  // error message printed by CmtSystem::remove_directory
+	  return 1;
+	}
+    }
+  if (!CmtSystem::mkdir (tmp_dir))
+    {
+      CmtError::set (CmtError::file_access_error,
+		     "Cannot create temporary directory " + tmp_dir);
+      CmtError::print ();
+      //CmtMessage::error ("Cannot create temporary directory " + tmp_dir);
+      return 1;
+    }
+
+    if (!CmtSystem::cd (tmp_dir))
+    {
+      CmtError::set (CmtError::file_access_error,
+		     "Cannot move to temporary package directory " + tmp_dir);
+      CmtError::print ();
+     //CmtMessage::error ("Cannot move to temporary package directory " + tmp_dir);
+      CmtSystem::remove_directory (tmp_dir);
+      return 1;
+    }
+
+  Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
+  int i (-1);
+  Project* cur (0);
+  Project null;
+  for (i = 0; i < Ordered.size (); i++)
+    if (Ordered[i]->is_current ()) break;
+  if (i >= 0 && i < Ordered.size ())
+    {
+      cur = Ordered[i];
+      Ordered[i] = &null;
+    }
+
+  bool cur_recursive (Cmt::get_recursive ());
+  CmtScopeFilteringMode
+    cur_scope_filtering_mode (Cmt::get_scope_filtering_mode ());
+  if (checkout.m_recursive)
+    {
+      Cmt::set_recursive (true);
+      Cmt::set_scope_filtering_mode (reach_private_uses);
+    }
+
+  SyntaxParser::parse_requirements_text (uses, "", &(Use::current()));
+
+  if (checkout.m_recursive)
+    {
+      Cmt::set_recursive (cur_recursive);
+      Cmt::set_scope_filtering_mode (cur_scope_filtering_mode);
+    }
+
+  if (i >= 0 && i < Ordered.size ())
+    {
+      Ordered[i] = cur;
+    }
+
+  CmtSystem::cd (home_dir);
+  CmtSystem::remove_directory (tmp_dir);
+
+  if (CmtError::get_last_error_code () == CmtError::package_not_found)
+    {
+      CmtError::print ();
+      return -1;
+    }
+
+  return 0;
+}
+
+//--------------------------------------------------------------------
 void Vcs::checkout_from_requirements (const Vcs::Checkout& checkout,
 				      bool config,
@@ -3808,18 +4773,23 @@
   if (!text.read (requirements))
     {
-      CmtError::set (CmtError::path_not_found, requirements);
+      CmtError::set (CmtError::file_access_error, requirements);
       return;
     }
+
   static cmt_regexp expression ("^[ \t]*use[ \t]");
-
-//   RecursivePass1 p1;
-//   p1.run (text, expression);
-//   bool result = (p1.result () != "");
-//   if (result)
-//     cerr << p1.result () << endl;
-  Walkthru wth (checkout,
-		config,
-		with_version_directory,
-		type);
-  wth.run (text, expression);
-}
+  if (checkout.m_info)
+    {
+      VisitorForInfo visitor_i;
+      Walkthru wth (visitor_i);
+      wth.run (text, expression);
+    }
+  else
+    {
+      VisitorForCheckout visitor_co (checkout,
+				     config, with_version_directory,
+				     type);
+      Walkthru wth (visitor_co);
+      wth.run (text, expression);
+    }
+}
+//--------------------------------------------------------------------
Index: /CMT/HEAD/source/cmt_vcs.h
===================================================================
--- /CMT/HEAD/source/cmt_vcs.h	(revision 534)
+++ /CMT/HEAD/source/cmt_vcs.h	(revision 535)
@@ -9,5 +9,7 @@
 
 #include "cmt_system.h"
+#include "cmt_use.h"
 
+class Modules;
 class Vcs
 {
@@ -32,7 +34,8 @@
   public:
     Checkout ()
-      : m_recursive (false), m_context (false)
+      : m_head (false), m_recursive (false), m_context (false), m_info (false)
       { }
     cmt_string m_version_tag;
+    bool m_head;
     cmt_string m_checkout_dir;
     cmt_string m_version_dir;
@@ -43,7 +46,9 @@
     bool m_recursive;
     bool m_context;
+    bool m_info;
     void print ()
       {
 	cerr << "m_version_tag: " << m_version_tag << endl;
+	cerr << "m_head: " << m_head << endl;
 	cerr << "m_checkout_dir: " << m_checkout_dir << endl;
 	cerr << "m_version_dir: " << m_version_dir << endl;
@@ -62,5 +67,5 @@
   static void checkout_module (const Checkout& checkout,
 			       bool config, bool with_version_directory,
-			       const cmt_string& module, cmt_string version_tag,
+			       cmt_string module, cmt_string version_tag,
 			       VcsType type);
   static void checkout_from_requirements (const Checkout& checkout,
@@ -68,4 +73,7 @@
 					  const cmt_string& requirements,
 					  VcsType type);
+  static void checkout_context (const Checkout& checkout, Modules modules,
+				bool config, bool with_version_directory,
+				VcsType type);
 
  private:
@@ -74,6 +82,13 @@
   static void add_cmtpath (const cmt_string& dir);
   static bool need_version_directory ();
-  static int parse_checkout (const CmtSystem::cmt_string_vector& arguments,
-			     Checkout& checkout, bool& config);
+  static int parse_arguments (const CmtSystem::cmt_string_vector& arguments,
+			      Checkout& checkout, bool& config);
+  static int parse_checkout (Checkout& checkout, Modules& modules);
+  //  static int parse_checkout (const Checkout& checkout, cmt_string& uses);
+  static int resolve_uses (const cmt_string& text, cmt_string& uses);
+  static int resolve_uses (const cmt_string& text, Use::UsePtrVector& uses);
+  static int resolve_uses (const Checkout& checkout, const cmt_string& uses);
+  //  static int resolve_uses (const Checkout& checkout, const Modules& modules);
+  //  static void start_visit (IUseVisitor& visitor);
 };
 
@@ -82,7 +97,16 @@
  public:
   
-  static void checkout (Vcs::Checkout checkout,
+  static void checkout (Vcs::Checkout checkout, Modules modules,
 		       bool config, bool with_version_directory);
 };
 
+class IUseVisitor
+{
+ public:
+  //virtual void pre (Project* p) = 0;
+  virtual void in (Use* use) = 0;
+  //virtual void in_again (Project* p) = 0;
+  //virtual void post (Project* p) = 0;
+};
+
 #endif
Index: /CMT/HEAD/src/Makefile.core
===================================================================
--- /CMT/HEAD/src/Makefile.core	(revision 534)
+++ /CMT/HEAD/src/Makefile.core	(revision 535)
@@ -76,5 +76,5 @@
 ifdef cmtmsg
 export cmtmsg
-echo = @- echo "$(CMTMSGPREFIX)"
+echo = @echo "$(CMTMSGPREFIX)"
 else
 echo = @:
Index: /CMT/HEAD/src/Makefile.header
===================================================================
--- /CMT/HEAD/src/Makefile.header	(revision 534)
+++ /CMT/HEAD/src/Makefile.header	(revision 535)
@@ -42,5 +42,6 @@
 	  $(MAKE) --no-print-directory target="all" common_target; \
 	else \
-	  echo "#CMT> There are configuration errors. Please correct them before running gmake"; \
+	  test -z "$(cmtmsg)" || \
+	  echo "$(CMTMSGPREFIX)" "(Makefile.header) Configuration error(s). Please correct" >&2; \
 	fi
 
@@ -53,5 +54,5 @@
 	    test -z "$(cmtmsg)" || \
 	    echo "$(CMTMSGPREFIX)" "(Makefile.header) Removing binary directory $(bin)"; \
-	    /bin/rm -rf $(bin) ; \
+	    \rm -rf $(bin) ; \
 	  fi ; \
 	fi
