Index: CMT/HEAD/ChangeLog
===================================================================
--- CMT/HEAD/ChangeLog	(revision 651)
+++ CMT/HEAD/ChangeLog	(revision 652)
@@ -1,2 +1,92 @@
+2013-11-05    <rybkin@lal.in2p3.fr> 511
+
+	* source/cmt_project.h: In class Project, change fill_selection function
+	signature to return projects (pointers), introduce function fill_exclusion
+	* source/cmt_project.cxx: In class ProjectFactory create_project function,
+	use change_path function on project use object, in class Project implement
+	fill_selection function for enhanced handling of special CMTHOME,
+	CMTUSERCONTEXT projects (selected if current project only) and special
+	depth values (0: CMTUSERCONTEXT project	only, -1: CMTHOME project only),
+	implement fill_exclusion function to exclude special CMTHOME,
+	CMTUSERCONTEXT projects unless current project, in find_in_cmt_paths
+	function fix search condition and comment out never used code, in
+	container_action function issue warning	or set error if container package
+	cannot be located
+	* source/cmt_use.h: In class Use, add member to hold project (pointer)
+	package	found in, add optional argument project (pointer) to change_path,
+	select_alternate functions, add	set_project function, inline located
+	function, make m_located member private
+	* source/cmt_use.cxx: In class Use, assign use project in function
+	change_path, in class UseProjectAction run and class Use select_alternate
+	functions, in particular, in functions get_cmtpath_and_offset,
+	fill_standard_macros, get_project make use of added class member (project)
+	for optimisation
+	* source/cmt_generators.h: In class PackagesMakefileGenerator, add member
+	m_ISINCLUDED
+	* source/cmt_generators.cxx: In class PackagesMakefileGenerator
+	constructor, reset function handle added member m_ISINCLUDED, in build
+	function make use of class Project fill_exclusion function and added
+	member to ensure packages from special CMTHOME, CMTUSERCONTEXT projects
+	are only visited, if in current project
+	* source/cmt_syntax.cxx: In class KwdBuildStrategy, KwdSetupStrategy,
+	KwdStructureStrategy action functions use class Use get_project function
+	for optimisation
+	* source/cmt_commands.cxx: In class ArgParser option_disable_warnings,
+	option_quiet, option_warnings functions, do not set CmtMessage level, add
+	option value to CMTFLAGS, in option_use, option_pack, option_version,
+	option_path functions only record option value, in option_tag,
+	option_tag_add, option_tag_remove functions, only record option values, in
+	option_with_version_directory, option_without_version_directory functions
+	do not change strategy, add option value to CMTFLAGS, in class CommandHelp
+	show_all function, add message for -home, -user_context options
+	* source/cmt_pattern.cxx: In class Pattern expand function, use class Use
+	get_project function for optimisation
+	* source/cmt_parser.cxx: In class CmtContext constructor, process
+	CMTEXTRATAGS environment variable value, in clear function, reset all
+	members, in class Cmt configure function, attempt to locate current use
+	or package if at least name is available from command line options before
+	configure_current_package for optimisation, in configure_current_cmtpath
+	function make use of class Use get_cmtpath_and_offset function,
+	return from configure_current_package if current use is located, in
+	configure_current_structuring_style function, do not parse command line
+	arguments, make use of value from command line or parse CMTFLAGS to set
+	strategy accordingly, in configure_home, configure_user_context functions,
+	use value from command line if any, in restore_all_tags function, add tags
+	from CmtContext m_extra_tags, m_tags, m_tags_add vectors, in
+	configure_cmt_message function do not parse command line arguments, parse
+	CMTFLAGS, in do_broadcast function, set error if depth option value cannot
+	be parsed or is out of range (< -1), make use of class Project
+	fill_selection, fill_exclusion functions to implement enhanced handling of
+	special CMTHOME, CMTUSERCONTEXT projects packages (visited if in current
+	project only) and and special depth values (0: CMTUSERCONTEXT project
+	packages only, -1: CMTHOME project packages only), in
+	do_check_configuration function, check tags from CmtContext m_extra_tags,
+	m_tags, m_tags_add vectors, in do_show_clients function do not re-run
+	configure, in guess_current_project function, do not use CmtSystem cd or
+	pwd functions for optimisation, in parse_arguments function do not call
+	restore_all_tags function, in parser function call parse_arguments first
+	and then configure, restore_all_tags to make configuration process cleaner,
+	do not call configure for action_build_temporary_name, in print function do
+	not check tags or change m_extra_tags since that change affects nothing, in
+	use_current_package, use_extra_file functions do not attempt to locate
+	current package if current use located already, factor out
+	Pattern::apply_all_globalsize and Tag::restore_tree calls into separate
+	apply_globals function called after all requirements are read, in
+	use_special_requirements function set special use style, structuring_style,
+	project members if located, otherwise discard, in particular, that means
+	that requirements file in special CMTHOME, CMTUSERCONTEXT projects is not
+	mandatory
+	* source/cmt_symbol.cxx: In class Symbol action function, make
+	constituentsclean symbol private (like constituents)
+	* source/cmt.h: In class CmtContext, add string vector members
+	m_extra_tags, m_tags, m_tags_add, m_tags_remove instead of string
+	m_extra_tags, in class Cmt, function reach_current_package renamed
+	use_current_package, introduce apply_globals function
+	* mgr/fragments/nmake/package: Ensure that not included packages are
+	not visited
+	* mgr/fragments/package: idem
+	* src/Makefile.header: Update help messages for BCAST mode in presence of
+	special CMTHOME, CMTUSERCONTEXT packages/projects
+
 2013-10-04    <rybkin@lal.in2p3.fr> 510
 
Index: CMT/HEAD/mgr/fragments/nmake/package
===================================================================
--- CMT/HEAD/mgr/fragments/nmake/package	(revision 651)
+++ CMT/HEAD/mgr/fragments/nmake/package	(revision 652)
@@ -1,3 +1,4 @@
 
+cmt_${PACKAGE}_${ISINCLUDED} = 1
 cmt_${PACKAGE}_${ISLOCAL} = 1
 
@@ -6,4 +7,5 @@
 
 !if "$(LOG_LOCATION)" != ""
+!if "$(cmt_${PACKAGE}_is_included)" != ""
 !if "$(cmt_${PACKAGE}_is_local)" != ""
 ${PACKAGE}OutErr = >>$(LOG_LOCATION)\$(${PACKAGE}FullName)$(LOG_SUFFIX) 2>&1
@@ -11,4 +13,5 @@
 !if "$(BCAST_GLOBAL)" != ""
 ${PACKAGE}OutErr = >>$(LOG_LOCATION)\$(${PACKAGE}FullName)$(LOG_SUFFIX) 2>&1
+!endif
 !endif
 !endif
@@ -20,4 +23,5 @@
 ${PACKAGE} : $(${PACKAGE}MgrPath)\NMake
 !endif
+!if "$(cmt_${PACKAGE}_is_included)" != ""
 !if "$(cmt_${PACKAGE}_is_local)" != ""
 	@echo "#--------------------------------------------------------------" \
@@ -73,6 +77,10 @@
 !endif
 !endif
+!else
+	
+!endif
 
 $(${PACKAGE}MgrPath)\NMake :
+!if "$(cmt_${PACKAGE}_is_included)" != ""
 !if "$(cmt_${PACKAGE}_is_local)" != ""
 	$(echo) configuring ${PACKAGE}
@@ -85,4 +93,7 @@
 	
 !endif
+!endif
+!else
+	
 !endif
 
@@ -96,4 +107,5 @@
 
 ${PACKAGE}clean : $(${PACKAGE}MgrPath)\NMake
+!if "$(cmt_${PACKAGE}_is_included)" != ""
 !if "$(cmt_${PACKAGE}_is_local)" != ""
 	@echo "#--------------------------------------------------------------" \
@@ -125,6 +137,10 @@
 !endif
 !endif
+!else
+	
+!endif
 
 ${PACKAGE}binclean : $(${PACKAGE}MgrPath)\NMake
+!if "$(cmt_${PACKAGE}_is_included)" != ""
 !if "$(cmt_${PACKAGE}_is_local)" != ""
 	@echo "#--------------------------------------------------------------" \
@@ -156,6 +172,10 @@
 !endif
 !endif
+!else
+	
+!endif
 
 ${PACKAGE}uninstall : $(${PACKAGE}MgrPath)\NMake
+!if "$(cmt_${PACKAGE}_is_included)" != ""
 !if "$(cmt_${PACKAGE}_is_local)" != ""
 	@echo "#--------------------------------------------------------------" \
@@ -187,6 +207,10 @@
 !endif
 !endif
+!else
+	
+!endif
 
 ${PACKAGE}check : $(${PACKAGE}MgrPath)\NMake
+!if "$(cmt_${PACKAGE}_is_included)" != ""
 !if "$(cmt_${PACKAGE}_is_local)" != ""
 	@echo "#--------------------------------------------------------------" \
@@ -218,4 +242,7 @@
 !endif
 !endif
+!else
+	
+!endif
 
 ${PACKAGE} ${PACKAGE}clean ${PACKAGE}binclean ${PACKAGE}uninstall ${PACKAGE}check : FORCE
Index: CMT/HEAD/mgr/fragments/package
===================================================================
--- CMT/HEAD/mgr/fragments/package	(revision 651)
+++ CMT/HEAD/mgr/fragments/package	(revision 652)
@@ -1,3 +1,4 @@
 
+cmt_${PACKAGE}_${ISINCLUDED} = 1
 cmt_${PACKAGE}_${ISLOCAL} = 1
 
@@ -6,4 +7,5 @@
 
 ifdef LOG_LOCATION
+ifdef cmt_${PACKAGE}_is_included
 ifdef cmt_${PACKAGE}_is_local
 ${PACKAGE}OutErr = >>$(LOG_LOCATION)/$(${PACKAGE}FullName)$(LOG_SUFFIX) 2>&1
@@ -11,4 +13,5 @@
 ifdef BCAST_GLOBAL
 ${PACKAGE}OutErr = >>$(LOG_LOCATION)/$(${PACKAGE}FullName)$(LOG_SUFFIX) 2>&1
+endif
 endif
 endif
@@ -20,4 +23,5 @@
 ${PACKAGE} : $(${PACKAGE}MgrPath)/Makefile
 endif
+ifdef cmt_${PACKAGE}_is_included
 ifdef cmt_${PACKAGE}_is_local
 	@echo "#--------------------------------------------------------------" \
@@ -67,6 +71,10 @@
 endif
 endif
+else
+	
+endif
 
 $(${PACKAGE}MgrPath)/Makefile :
+ifdef cmt_${PACKAGE}_is_included
 ifdef cmt_${PACKAGE}_is_local
 	$(echo) configuring ${PACKAGE}
@@ -80,4 +88,7 @@
 endif
 endif
+else
+	
+endif
 
 ifndef BCAST_ONLY
@@ -90,4 +101,5 @@
 
 ${PACKAGE}clean ${PACKAGE}binclean ${PACKAGE}uninstall ${PACKAGE}check : $(${PACKAGE}MgrPath)/Makefile
+ifdef cmt_${PACKAGE}_is_included
 ifdef cmt_${PACKAGE}_is_local
 	@echo "#--------------------------------------------------------------" \
@@ -119,4 +131,7 @@
 endif
 endif
+else
+	
+endif
 
 ${PACKAGE} ${PACKAGE}clean ${PACKAGE}binclean ${PACKAGE}uninstall ${PACKAGE}check : FORCE
Index: CMT/HEAD/source/cmt.h
===================================================================
--- CMT/HEAD/source/cmt.h	(revision 651)
+++ CMT/HEAD/source/cmt.h	(revision 652)
@@ -52,5 +52,10 @@
   cmt_string m_current_version;
   
-  cmt_string m_extra_tags;
+  //  cmt_string m_extra_tags;
+  CmtSystem::cmt_string_vector m_extra_tags;
+  CmtSystem::cmt_string_vector m_tags;
+  CmtSystem::cmt_string_vector m_tags_add;
+  CmtSystem::cmt_string_vector m_tags_remove;
+
   cmt_string m_configure_error;
   
@@ -268,6 +273,8 @@
   static void print_tabs (int tabs);
   static void print_xml_prolog (const cmt_string& root = "cmt", ostream& out = cout);
-  static int reach_current_package ();
+  //  static int reach_current_package ();
+  static int use_current_package ();
   static int use_extra_file (const cmt_string& file);
+  static int apply_globals ();
   static void restore_all_tags (Use* use);
   static void set_current_access (AccessMode mode);
Index: CMT/HEAD/source/cmt_commands.cxx
===================================================================
--- CMT/HEAD/source/cmt_commands.cxx	(revision 651)
+++ CMT/HEAD/source/cmt_commands.cxx	(revision 652)
@@ -1903,6 +1903,8 @@
 {
   cmt.m_disable_warnings = true;
-  if (CmtMessage::level () <= Warning)
-    CmtMessage::set_level (Error);
+//   if (CmtMessage::level () <= Warning)
+//     CmtMessage::set_level (Error);
+  if (!Cmt::add_cmt_flag ("-disable_warnings"))
+    CmtError::set (CmtError::system_error, "Cannot add flag `-disable_warnings'");
 }
 
@@ -1910,6 +1912,8 @@
 {
   cmt.m_quiet = true;
-  if (CmtMessage::level () <= Error)
-    CmtMessage::set_level (Fatal);
+//   if (CmtMessage::level () <= Error)
+//     CmtMessage::set_level (Fatal);
+  if (!Cmt::add_cmt_flag ("-quiet"))
+    CmtError::set (CmtError::system_error, "Cannot add flag `-quiet'");
 }
 
@@ -1918,6 +1922,8 @@
 {
   cmt.m_warnings = true;
-  if (CmtMessage::level () != Warning)
-    CmtMessage::set_level (Warning);
+//   if (CmtMessage::level () != Warning)
+//     CmtMessage::set_level (Warning);
+  if (!Cmt::add_cmt_flag ("-warnings"))
+    CmtError::set (CmtError::system_error, "Cannot add flag `-warnings'");
 }
 
@@ -1963,27 +1969,4 @@
       if (words.size () > 1) cmt.m_current_version = words[1];
       if (words.size () > 2) cmt.m_current_path    = words[2];
-      (Use::current()).set (cmt.m_current_package, 
-			    cmt.m_current_version, 
-			    cmt.m_current_path);
-
-      Use& use = Use::current();
-      if (use.get_package_name () == "cmt_standalone")
-	{
-          if (!CmtSystem::cd (use.path) || !CmtSystem::test_file ("requirements"))
-            {
-	      CmtError::set (CmtError::package_not_found, use.get_info ());
-	      return;
-	    }
-	  use.style = none_style;
-	  use.structuring_style = without_version_directory;
-	  use.change_path (CmtSystem::pwd ());
-	}
-      else if (!use.move_to ())
-	{
-	  CmtError::set (CmtError::package_not_found, use.get_info ());
-	  return;
-	}
-      Project::order_all ();
-      Cmt::guess_current_project ();
     }
 }
@@ -1998,16 +1981,6 @@
 
       cmt.m_current_package = arg;
-      cmt.m_current_version = "";
-
-      /*
-      cerr << "ArgParser::option_pack> "
-	   << " cp=" << cmt.m_current_package
-	   << " cv=" << cmt.m_current_version
-	   << " cp=" << cmt.m_current_path << endl;
-      */
-
-      (Use::current()).set (cmt.m_current_package, 
-			    cmt.m_current_version, 
-			    cmt.m_current_path);
+      //      cmt.m_current_version = "";
+
     }
 }
@@ -2019,15 +1992,4 @@
       cmt.m_current_access = UserMode;
       cmt.m_current_version = arg;
-
-      /*
-      cerr << "ArgParser::option_version> "
-	   << " cp=" << cmt.m_current_package
-	   << " cv=" << cmt.m_current_version
-	   << " cp=" << cmt.m_current_path << endl;
-      */
-
-      (Use::current()).set (cmt.m_current_package, 
-			    cmt.m_current_version, 
-			    cmt.m_current_path);
     }
 }
@@ -2039,37 +2001,4 @@
       cmt.m_current_access = UserMode;
       cmt.m_current_path = arg;
-
-      /*
-      cerr << "ArgParser::option_path> "
-	   << " cp=" << cmt.m_current_package
-	   << " cv=" << cmt.m_current_version
-	   << " cp=" << cmt.m_current_path << endl;
-      */
-
-      (Use::current()).set (cmt.m_current_package, 
-			    cmt.m_current_version, 
-			    cmt.m_current_path);
-
-      //IProjectFactory& factory = ProjectFactory::instance ();
-      //CmtSystem::add_cmt_path (cmt.m_current_path, "argument", factory);
-      Use& use = Use::current();
-      if (use.get_package_name () == "cmt_standalone")
-	{
-          if (!CmtSystem::cd (use.path) || !CmtSystem::test_file ("requirements"))
-            {
-	      CmtError::set (CmtError::package_not_found, use.get_info ());
-	      return;
-	    }
-	  use.style = none_style;
-	  use.structuring_style = without_version_directory;
-	  use.change_path (CmtSystem::pwd ());
-	}
-      else if (!use.move_to ())
-	{
-	  CmtError::set (CmtError::package_not_found, use.get_info ());
-	  return;
-	}
-      Project::order_all ();
-      Cmt::guess_current_project ();
     }
 }
@@ -2082,5 +2011,4 @@
 void ArgParser::option_e ()
 {
-  //CmtMessage::warning ("extra statement = " + arg);
   extra_line = arg;
 }
@@ -2101,4 +2029,30 @@
   if (arg != "")
     {
+      cmt.m_tags.clear ();
+      CmtSystem::cmt_string_vector words;
+      CmtSystem::split (arg, " \t,", words);
+      for (int i = 0; i < words.size (); i++)
+	{
+	  bool has (false);
+	  for (int j = 0; j < cmt.m_tags.size (); j++)
+	    {
+	      if (cmt.m_tags[j] == words[i])
+		{
+		  has = true;
+		  break;
+		}
+	    }
+	  if (!has)
+	    cmt.m_tags.push_back (words[i]);
+	}
+
+      if (cmt.m_tags.size () != 0)
+	{
+	  cmt.m_extra_tags.clear ();
+	  cmt.m_tags_add.clear ();
+	  cmt.m_tags_remove.clear ();
+	}
+
+      /*
       Tag* tag;
       CmtSystem::cmt_string_vector words;
@@ -2154,4 +2108,5 @@
 	// To be sure that a tag
 	Cmt::guess_current_project ();
+      */
     }
 }
@@ -2159,4 +2114,32 @@
 void ArgParser::option_tag_add ()
 {
+  CmtSystem::cmt_string_vector words;
+  CmtSystem::split (arg, " \t,", words);
+  for (int i = 0; i < words.size (); i++)
+    {
+      bool has (false);
+      for (int j = 0; j < cmt.m_tags_add.size (); j++)
+	{
+	  if (cmt.m_tags_add[j] == words[i])
+	    {
+	      has = true;
+	      break;
+	    }
+	}
+      if (!has)
+	{
+	  cmt.m_tags_add.push_back (words[i]);
+	}
+      
+      for (int j = 0; j < cmt.m_tags_remove.size (); j++)
+	{
+	  if (cmt.m_tags_remove[j] == words[i])
+	    {
+	      cmt.m_tags_remove.erase(j);
+	      break;
+	    }
+	}
+    }
+  /*
   Tag* tag;
   CmtSystem::cmt_string_vector words;
@@ -2191,23 +2174,56 @@
 	}
     }
+  */
 }
 
 void ArgParser::option_tag_remove ()
 {
+  CmtSystem::cmt_string_vector words;
+  CmtSystem::split (arg, " \t,", words);
+  for (int i = 0; i < words.size (); i++)
+    {
+      bool has (false);
+      for (int j = 0; j < cmt.m_tags_remove.size (); j++)
+	{
+	  if (cmt.m_tags_remove[j] == words[i])
+	    {
+	      has = true;
+	      break;
+	    }
+	}
+      if (!has)
+	{
+	  cmt.m_tags_remove.push_back (words[i]);
+	}
+
+      for (int j = 0; j < cmt.m_extra_tags.size (); j++)
+	{
+	  if (cmt.m_extra_tags[j] == words[i])
+	    {
+	      cmt.m_extra_tags.erase(j);
+	      break;
+	    }
+	}
+      for (int j = 0; j < cmt.m_tags.size (); j++)
+	{
+	  if (cmt.m_tags[j] == words[i])
+	    {
+	      cmt.m_tags.erase(j);
+	      break;
+	    }
+	}
+      for (int j = 0; j < cmt.m_tags_add.size (); j++)
+	{
+	  if (cmt.m_tags_add[j] == words[i])
+	    {
+	      cmt.m_tags_add.erase(j);
+	      break;
+	    }
+	}
+    }
+  /*
   Tag::TagPtrVector tags = Tag::tags ();
   int i;
   Tag* tag;
-
-  /*
-    for (i = 0; i < tags.size (); i++)
-    {
-    tag = tags[i];
-    if ((tag != 0) &&
-    (tag->selected))
-    {
-    if (!cmt.m_quiet) cerr << "  original tag_list=" << tag->name << tag->priority << endl;
-    }
-    }
-  */
 
   CmtSystem::cmt_string_vector words;
@@ -2262,6 +2278,4 @@
 	    const cmt_string& a = words[i];
 
-	    //fprintf (stderr, "  a=[%s]\n", a.c_str ());
-
 	    /// Then restore uname if the specified tag is CMTCONFIG
 	      if (a == CmtSystem::get_cmt_config ())
@@ -2286,4 +2300,5 @@
 	      tag->mark ("arguments");
 	  }
+  */
 }
 
@@ -2314,10 +2329,7 @@
   cmt.m_current_structuring_style = with_version_directory;
 
-  StrategyDef* def = StrategyMgr::find_strategy ("VersionDirectory");
-  if (def != 0)
-    {
-      def->m_default_value = true;
-      def->m_priority_value = false;
-    }
+  if (!Cmt::add_cmt_flag ("-with_version_directory"))
+    CmtError::set (CmtError::system_error, "Cannot add flag `-with_version_directory'");
+
 }
 
@@ -2326,10 +2338,7 @@
   cmt.m_current_structuring_style = without_version_directory;
 
-  StrategyDef* def = StrategyMgr::find_strategy ("VersionDirectory");
-  if (def != 0)
-    {
-      def->m_default_value = false;
-      def->m_priority_value = true;
-    }
+  if (!Cmt::add_cmt_flag ("-without_version_directory"))
+    CmtError::set (CmtError::system_error, "Cannot add flag `-without_version_directory'");
+
 }
 
@@ -2401,5 +2410,5 @@
   cout << "#   -path=<path>            : set root path" << endl;
   cout << "#   -f=<requirements-file>  : set input file" << endl;
-  cout << "#   -e=<statement>          : add a one line statement" << endl;
+  cout << "#   -e=<statement(s)>       : add (multiple) statement(s)" << endl;
   cout << "#   -tag=<tag-list>         : select a new tag-set" << endl;
   cout << "#   -tag_add=<tag-list>     : add specific comma-separated tag(s)" << endl;
@@ -2411,4 +2420,6 @@
   cout << "#   -no_cleanup             : inhibit install area cleanup" << endl;
   cout << "#   -xml                    : output in XML format (cmt setup, cmt show projects, cmt show uses)" << endl;
+  cout << "#   -user_context=<path>    : set user context package/project directory" << endl;
+  cout << "#   -home=<path>            : set home package/project directory" << endl;
 }
 
Index: CMT/HEAD/source/cmt_generators.cxx
===================================================================
--- CMT/HEAD/source/cmt_generators.cxx	(revision 651)
+++ CMT/HEAD/source/cmt_generators.cxx	(revision 652)
@@ -2841,4 +2841,5 @@
   m_PACKAGEFULLNAME.set ("PACKAGEFULLNAME");
   m_ISLOCAL.set ("ISLOCAL");
+  m_ISINCLUDED.set ("ISINCLUDED");
 
   packages_header_fragment.set ("packages_header");
@@ -2854,4 +2855,5 @@
   m_PACKAGEFULLNAME = "";
   m_ISLOCAL = "";
+  m_ISINCLUDED = "";
 
   packages_header_fragment.reset ();
@@ -2899,11 +2901,16 @@
       if (!packages_header_fragment.copy (m_output_file, 1, &m_PACKAGE)) return;
 
-      Project* cur = Project::get_current ();
+      const Project* p_cur (Project::get_current ());
       Use::UsePtrVector uses (Use::get_ordered_uses ());
       uses.push_back (&Use::current ());
+
+      Project::ConstProjectPtrVector path_exclusions;
+      Project::fill_exclusion (path_exclusions);
+
       cmt_string temp;
       for (int i = uses.size () - 1; i >= 0; i--)
 	{
 	  Use* use = uses[i];
+
 	  if (use->discarded) continue;
 	  if (use->m_hidden) continue;
@@ -2911,8 +2918,48 @@
 	  if (use->get_package ()->is_cmt ()) continue;
 
-	  if (use->get_project () == cur)
-	    m_ISLOCAL = "is_local";
-	  else
-	    m_ISLOCAL = "is_not_local";
+	  const Project* up = use->get_project ();
+
+	  m_ISLOCAL = "is_not_local";
+	  if (p_cur)
+	    {
+	      if (up)
+		{
+		  if (up == p_cur)
+		    {
+		      m_ISLOCAL = "is_local";
+		    }
+		}
+	      else
+		{
+		  if (use->get_realpath ().find (p_cur->get_cmtpath_real ()) == 0)
+		    {
+		      m_ISLOCAL = "is_local";
+		    }
+		}
+	    }
+	  else if (use == &Use::current ())
+	    {
+	      m_ISLOCAL = "is_local";
+	    }
+
+	  m_ISINCLUDED = "is_included";
+          for (int j = 0; j < path_exclusions.size (); j++)
+            {
+              const Project* sp = path_exclusions[j];
+	      if (up)
+		{
+		  if (up == sp)
+		    {
+		      m_ISINCLUDED = "is_not_included";
+		    }
+		}
+	      else
+		{
+		  if (use->get_realpath ().find (sp->get_cmtpath_real ()) == 0)
+		    {
+		      m_ISINCLUDED = "is_not_included";
+		    }
+		}
+            }
 
 	  temp = use->get_full_path ();
@@ -2927,4 +2974,6 @@
 	      temp += "mgr";
 	      break;
+	    default:
+	      break;
 	    }
 #ifdef WIN32
@@ -2932,5 +2981,4 @@
 #endif
 	  m_PACKAGEMGRPATH = temp;
-	  //	  fprintf (m_output_file, "%s\n", temp.c_str());
 
 	  temp = "";
@@ -2956,5 +3004,4 @@
 #endif
 	  m_PACKAGEFULLNAME = temp;
-	  //	  fprintf (m_output_file, "%s\n", temp.c_str());
 
 	  m_PACKAGE = use->get_package_name ();
@@ -2991,9 +3038,9 @@
 	    }
 
-	  if (!package_fragment.copy (m_output_file, 6,
+	  if (!package_fragment.copy (m_output_file, 7,
 				      &m_PACKAGE, &m_PACKAGEPREFIX,
 				      &m_DEPENDENCIES,
 				      &m_PACKAGEMGRPATH, &m_PACKAGEFULLNAME,
-				      &m_ISLOCAL)) return;
+				      &m_ISLOCAL, &m_ISINCLUDED)) return;
 	}
 
@@ -3016,5 +3063,4 @@
 
       CmtSystem::close_ostream (m_output_file, new_file_name);
-      //  fclose (m_output_file);
 
       commit (new_file_name);
Index: CMT/HEAD/source/cmt_generators.h
===================================================================
--- CMT/HEAD/source/cmt_generators.h	(revision 651)
+++ CMT/HEAD/source/cmt_generators.h	(revision 652)
@@ -239,4 +239,5 @@
   Variable m_PACKAGEFULLNAME;
   Variable m_ISLOCAL;
+  Variable m_ISINCLUDED;
 
   FragmentHandle packages_header_fragment;
Index: CMT/HEAD/source/cmt_parser.cxx
===================================================================
--- CMT/HEAD/source/cmt_parser.cxx	(revision 651)
+++ CMT/HEAD/source/cmt_parser.cxx	(revision 652)
@@ -10,4 +10,5 @@
 #include <string.h>
 #include <ctype.h>
+#include <errno.h>
 
 //----------------------------------------------------------
@@ -48,4 +49,22 @@
 {
   clear ();
+
+  cmt_string tags = CmtSystem::getenv ("CMTEXTRATAGS");
+  CmtSystem::cmt_string_vector words;
+  CmtSystem::split (tags, " \t,", words);
+  for (int i = 0; i < words.size (); i++)
+    {
+      bool has (false);
+      for (int j = 0; j < m_extra_tags.size (); j++)
+	{
+	  if (m_extra_tags[j] == words[i])
+	    {
+	      has = true;
+	      break;
+	    }
+	}
+      if (!has)
+	m_extra_tags.push_back (words[i]);
+    }
 }
 
@@ -59,10 +78,11 @@
   m_build_nmake    = false;
   m_cmt_config     = "";
-  //m_cmt_path.clear ();
-  //m_cmt_path_pwds.clear ();
-  //m_cmt_path_sources.clear ();
   m_cmt_root       = "";
+  m_cmt_home       = "";
+  m_cmt_user_context = "";
+  m_cmt_site       = "";
   m_cmt_version    = "";
   m_use_cmt        = true;
+
   m_current_dir     = "";
   m_current_file_path = "";
@@ -74,13 +94,24 @@
   m_current_offset  = "";
 
-  m_current_access   = DeveloperMode;
+  m_current_access  = UserMode;
+  m_current_style   = cmt_style;
+  m_current_structuring_style = default_structuring_style;
 
   m_current_tag      = "";
   m_current_target   = "";
   m_current_version  = "";
+
+  //  m_extra_tags       = "";
+  m_extra_tags.clear ();
+  m_tags.clear ();
+  m_tags_add.clear ();
+  m_tags_remove.clear ();
+
+  m_configure_error  = "";
+
+  m_debug = (::getenv ("CMTDEBUG") != 0) ? true : false;
+
   m_default_path     = "";
-
-  //m_quiet            = false;
-
+  m_quiet            = false;
   m_disable_warnings = false;
   m_warnings         = false;
@@ -91,11 +122,7 @@
 
   m_standard_macros_done = false;
-  m_current_access = UserMode;
-  m_current_style = cmt_style;
-  m_current_structuring_style = default_structuring_style;
   m_all_sets_done = false;
+
   m_autoconfigure_cmtpath = false;
-  m_debug = false;
-  if (getenv ("CMTDEBUG") != 0) m_debug = true;
 }
 
@@ -497,6 +524,6 @@
 void Cmt::clear ()
 {
-  Me.m_quiet = false;
   Me.clear ();
+  //Me.m_quiet = false;
 
   Database::clear ();
@@ -515,5 +542,5 @@
   if (configured) return;
 
-  Me.clear ();
+  //  Me.clear ();
 
   log << "configure_cmt_message" << log_endl;
@@ -533,4 +560,38 @@
   log << "configure_site_tag" << log_endl;
   configure_site_tag (0);
+
+  if (Me.m_current_package.size () != 0 &&
+      Me.m_current_package != "cmt_standalone")
+    { // we have a package name (not "cmt_standalone")
+      Use& use = Use::current();
+      use.set (Me.m_current_package, 
+	       Me.m_current_version, 
+	       Me.m_current_path);
+      if (CmtSystem::absolute_path (Me.m_current_path))
+	{
+	  if (!use.move_to ())
+	    {
+	      CmtError::set (CmtError::package_not_found, use.get_info ());
+	      return;
+	    }
+	}
+      else
+	{
+	  if (!use.move_to ("", true))
+	    {
+	      // will try again later from CMTPATH entries
+	    }
+	}
+    }
+  else
+    {
+      if (Me.m_current_path.size () != 0 &&
+	  !CmtSystem::cd (Me.m_current_path))
+	{
+	  CmtError::set (CmtError::path_not_found, Me.m_current_path);
+	  return;
+	}
+    }
+
   log << "configure_current_dir" << log_endl;
   configure_current_dir ();
@@ -540,5 +601,4 @@
   //  log << "configure_current_dir" << log_endl;
 
-
   bool save_quiet = Me.m_quiet;
   Me.m_quiet = true;
@@ -554,4 +614,39 @@
   guess_current_project ();
 
+  if (Me.m_current_package.size () != 0 &&
+      Me.m_current_package != "cmt_standalone")
+    {
+      Use& use = Use::current();
+      if (!use.located ())
+	{
+	  if (!use.move_to ())
+	    {
+	      CmtError::set (CmtError::package_not_found, use.get_info ());
+	      return;
+	    }
+	  else
+	    {
+	      use.get_full_path (Me.m_current_dir);
+	      switch (use.style)
+		{
+		case cmt_style:
+		  Me.m_current_dir += CmtSystem::file_separator ();
+		  Me.m_current_dir += "cmt";
+		  break;
+		case mgr_style:
+		  Me.m_current_dir += CmtSystem::file_separator ();
+		  Me.m_current_dir += "mgr";
+		  break;
+		default:
+		  break;
+		}
+	      Me.m_current_file_path = Me.m_current_dir;
+
+	      Project::order_all ();
+	      Cmt::guess_current_project ();
+	    }
+	}
+    }
+
   log << "configure_current_structuring_style" << log_endl;
   //  configure_current_structuring_style ();
@@ -562,15 +657,25 @@
 
   Use& use = Use::current();
-
-  use.set (Me.m_current_package,
-           Me.m_current_version,
-           Me.m_current_path,
-           "",
-           "");
-
-  use.style = Me.m_current_style;
-  use.structuring_style = Me.m_current_structuring_style;
-
-  use.change_path (Me.m_current_path);
+  if (!use.located ())
+    {
+      use.set (Me.m_current_package,
+	       Me.m_current_version,
+	       Me.m_current_path);
+      use.style = Me.m_current_style;
+
+      if (use.style != none_style)
+	{
+	  use.structuring_style = Me.m_current_structuring_style;
+	  use.change_path (Me.m_current_path, Project::get_current ());
+	}
+      else
+	{
+	  use.real_path = Me.m_current_path;
+	}
+    }
+  else if (const Project * p = Project::get_current ())
+    {
+      use.set_project (p);
+    }
 
   if (CmtError::has_pending_error ()) 
@@ -621,5 +726,6 @@
 {
   Use& current_use = Use::current ();
-
+  current_use.get_cmtpath_and_offset (Me.m_current_cmtpath, Me.m_current_offset);
+  /*
   Me.m_current_cmtpath = "";
   Me.m_current_offset = "";
@@ -633,5 +739,5 @@
 
       Me.m_current_offset = current_use.path;
-
+  */
       /**
 	 try to remove this current CMTPATH entry from path.  This
@@ -639,5 +745,5 @@
 	 absolute path.
       */
-      
+  /*      
       Me.m_current_offset.replace (Me.m_current_cmtpath, empty_string);
       if (Me.m_current_offset[0] == CmtSystem::file_separator ())
@@ -648,4 +754,5 @@
 	}
     }
+  */
 }
 
@@ -788,5 +895,5 @@
   Me.m_current_file_path = mount_filter.get_current_dir ();
 
-  cmt_string t = Me.m_current_file_path;
+  //  cmt_string t = Me.m_current_file_path;
 }
 
@@ -800,4 +907,12 @@
     standard directory tree (i.e. <package>/<version>/cmt or mgr)
   */
+  Use& use = Use::current();
+  if (use.located ())
+    {
+      Me.m_current_style = use.style;
+      build_prefix (Me.m_current_package, Me.m_current_prefix);
+      build_config (Me.m_current_prefix, Me.m_current_config);
+      return;
+    }
 
   cmt_string req = "..";
@@ -1062,5 +1177,5 @@
       // Do NOT (re)set m_current_structuring_style yet
       // (as requirements may NOT exist, so this is not a package)
-      // rather do it in reach_current_package (if/when requirements is read)
+      // rather do it in use_current_package (if/when requirements is read)
       //Me.m_current_structuring_style = without_version_directory;
       build_prefix (Me.m_current_package, Me.m_current_prefix);
@@ -1074,82 +1189,41 @@
 {
   cmt_string s;
-  s = CmtSystem::getenv ("CMTSTRUCTURINGSTYLE");
-  if (s == "without_version_directory")
-    {
-      Me.m_current_structuring_style = without_version_directory;
-    }
-  else if (s == "with_version_directory")
-    {
-      Me.m_current_structuring_style = with_version_directory;
-    } 
-
-  CmtSystem::cmt_string_vector flags;
-  Cmt::get_cmt_flags (flags);
-  for (int i = 0; i < flags.size (); i++)
-    {
-      const cmt_string& flag = flags[i];
-      if (flag == "-without_version_directory")
+  if (Me.m_current_structuring_style == default_structuring_style)
+    {
+      s = CmtSystem::getenv ("CMTSTRUCTURINGSTYLE");
+      if (s == "without_version_directory")
 	{
 	  Me.m_current_structuring_style = without_version_directory;
 	}
-      else if (flag == "-with_version_directory")
+      else if (s == "with_version_directory")
 	{
 	  Me.m_current_structuring_style = with_version_directory;
-	} 
-    }
-
-  for (int i = 1; i < ap.argc; i++)
-    {
-      const cmt_string& arg = ap.argv[i];
-      if (arg[0] != '-') break;
-      if (arg == "-without_v" ||
-	  arg == "-without_ve" ||
-	  arg == "-without_ver" ||
-	  arg == "-without_vers" ||
-	  arg == "-without_versi" ||
-	  arg == "-without_versio" ||
-	  arg == "-without_version" ||
-	  arg == "-without_version_" ||
-	  arg == "-without_version_d" ||
-	  arg == "-without_version_di" ||
-	  arg == "-without_version_dir" ||
-	  arg == "-without_version_dire" ||
-	  arg == "-without_version_direc" ||
-	  arg == "-without_version_direct" ||
-	  arg == "-without_version_directo" ||
-	  arg == "-without_version_director" ||
-	  arg == "-without_version_directory")
-	{
-	  Me.m_current_structuring_style = without_version_directory;
-	  //	  if (!CmtSystem::putenv ("CMTSTRUCTURINGSTYLE", "without_version_directory"))
-	  //	    CmtMessage::error ("Cannot set `CMTSTRUCTURINGSTYLE' to"
-	  //			       " `without_version_directory' in the environment");
-	  if (!Cmt::add_cmt_flag ("-without_version_directory"))
-	    CmtMessage::error ("Cannot add flag `-without_version_directory'");
-	}
-      else if (arg == "-with_v" ||
-	       arg == "-with_ve" ||
-	       arg == "-with_ver" ||
-	       arg == "-with_vers" ||
-	       arg == "-with_versi" ||
-	       arg == "-with_versio" ||
-	       arg == "-with_version" ||
-	       arg == "-with_version_" ||
-	       arg == "-with_version_d" ||
-	       arg == "-with_version_di" ||
-	       arg == "-with_version_dir" ||
-	       arg == "-with_version_dire" ||
-	       arg == "-with_version_direc" ||
-	       arg == "-with_version_direct" ||
-	       arg == "-with_version_directo" ||
-	       arg == "-with_version_director" ||
-	       arg == "-with_version_directory")
-	{
-	  Me.m_current_structuring_style = with_version_directory;
-	  //	  if (!CmtSystem::putenv ("CMTSTRUCTURINGSTYLE", "with_version_directory"))
-	  //	    CmtMessage::error ("Cannot set `CMTSTRUCTURINGSTYLE' to"
-	  //			       " `with_version_directory' in the environment");
-	  if (!Cmt::add_cmt_flag ("-with_version_directory"))
-	    CmtMessage::error ("Cannot add flag `-with_version_directory'");
+	}
+      
+      CmtSystem::cmt_string_vector flags;
+      Cmt::get_cmt_flags (flags);
+      for (int i = 0; i < flags.size (); i++)
+	{
+	  const cmt_string& flag = flags[i];
+	  if (flag == "-without_version_directory")
+	    {
+	      Me.m_current_structuring_style = without_version_directory;
+	    }
+	  else if (flag == "-with_version_directory")
+	    {
+	      Me.m_current_structuring_style = with_version_directory;
+	    } 
+	}
+    }
+  
+  if (Me.m_current_structuring_style != default_structuring_style)
+    {
+      StrategyDef* def = StrategyMgr::find_strategy ("VersionDirectory");
+      if (def != 0)
+	{
+	  def->m_default_value =
+	    Me.m_current_structuring_style == with_version_directory;
+	  def->m_priority_value =
+	    Me.m_current_structuring_style == without_version_directory;
 	}
     }
@@ -1171,15 +1245,16 @@
 void Cmt::configure_home (Use* use)
 {
-  Me.m_cmt_home = "";
-
-  Symbol* symbol = Symbol::find ("CMTHOME");
-  if (symbol != 0)
-    {
-      Me.m_cmt_home = symbol->build_macro_value ();
-      Symbol::expand (Me.m_cmt_home);
-    }
-  else if (CmtSystem::testenv ("CMTHOME"))
-    {
-      Me.m_cmt_home = CmtSystem::getenv ("CMTHOME");
+  if (Me.m_cmt_home.size () == 0)
+    {
+      // if not passed on the command line
+      if (const Symbol* symbol = Symbol::find ("CMTHOME"))
+	{
+	  Me.m_cmt_home = symbol->build_macro_value ();
+	  Symbol::expand (Me.m_cmt_home);
+	}
+      else if (CmtSystem::testenv ("CMTHOME"))
+	{
+	  Me.m_cmt_home = CmtSystem::getenv ("CMTHOME");
+	}
     }
 
@@ -1195,15 +1270,16 @@
 void Cmt::configure_user_context (Use* use)
 {
-  Me.m_cmt_user_context = "";
-
-  Symbol* symbol = Symbol::find ("CMTUSERCONTEXT");
-  if (symbol != 0)
-    {
-      Me.m_cmt_user_context = symbol->build_macro_value ();
-      Symbol::expand (Me.m_cmt_user_context);
-    }
-  else if (CmtSystem::testenv ("CMTUSERCONTEXT"))
-    {
-      Me.m_cmt_user_context = CmtSystem::getenv ("CMTUSERCONTEXT");
+  if (Me.m_cmt_user_context.size () == 0)
+    {
+      // if not passed on the command line
+      if (const Symbol* symbol = Symbol::find ("CMTUSERCONTEXT"))
+	{
+	  Me.m_cmt_user_context = symbol->build_macro_value ();
+	  Symbol::expand (Me.m_cmt_user_context);
+	}
+      else if (CmtSystem::testenv ("CMTUSERCONTEXT"))
+	{
+	  Me.m_cmt_user_context = CmtSystem::getenv ("CMTUSERCONTEXT");
+	}
     }
 
@@ -1272,4 +1348,44 @@
 
   Cmt::configure_tags (use);
+
+  cmt_string s, t;
+  if (0 < Me.m_extra_tags.size ())
+    {
+      s = "CMTEXTRATAGS";
+      t = use != 0 ? use->get_package_name () : s;
+    }
+  for (int i = 0; i < Me.m_extra_tags.size (); i++)
+    {
+      Tag* tag = Tag::add (Me.m_extra_tags[i], PriorityUserTag, s, use);
+      tag->mark (t);
+    }
+
+  for (int i = 0; i < Me.m_tags.size (); i++)
+    {
+      const cmt_string& a = Me.m_tags[i];
+      if (i == 0)
+	{
+	  Me.m_current_tag = a;
+	}
+//       // Then restore uname if the specified tag is CMTCONFIG
+//       if (a == CmtSystem::get_cmt_config ())
+// 	{
+// 	  Cmt::configure_uname_tag ();
+// 	}
+      Tag* tag = Tag::add (a, PriorityArgument, "arguments", 0);
+      tag->mark ("arguments");
+    }
+
+  for (int i = 0; i < Me.m_tags_add.size (); i++)
+    {
+      const cmt_string& a = Me.m_tags_add[i];
+//       // Then restore uname if the specified tag is CMTCONFIG
+//       if (a == CmtSystem::get_cmt_config ())
+// 	{
+// 	  Cmt::configure_uname_tag ();
+// 	}
+      Tag* tag = Tag::add (a, PriorityUserTag, "arguments", 0);
+      tag->mark ("arguments");
+    }
 
   /*
@@ -1277,4 +1393,5 @@
   */
 
+  /*
   if (CmtSystem::testenv ("CMTEXTRATAGS"))
     {
@@ -1309,4 +1426,5 @@
         }
     }
+  */
 }
 
@@ -1319,4 +1437,6 @@
 
   log << "current_tag=" << Me.m_current_tag << log_endl;
+
+  cmt_string s = "CMTCONFIG";
 
   Symbol* symbol = Symbol::find ("CMTCONFIG");
@@ -1347,4 +1467,5 @@
     {
       config_tag = CmtSystem::getenv ("CMTBIN");
+      s = "CMTBIN";
     }
 
@@ -1352,9 +1473,10 @@
     {
       CmtSystem::get_uname (config_tag);
+      s = "uname";
     }
 
   log << "current_tag=" << Me.m_current_tag << log_endl;
 
-  cmt_string s = "CMTCONFIG";
+  //  cmt_string s = "CMTCONFIG";
   cmt_string t = s;
 
@@ -1552,71 +1674,4 @@
 	  if (CmtMessage::level () != Warning)
 	    CmtMessage::set_level (Warning);
-	  //	  if (CmtMessage::level () > Warning)
-	}
-    }
-
-  for (int i = 1; i < ap.argc; i++)
-    {
-      const cmt_string& arg = ap.argv[i];
-      if (arg[0] != '-') break;
-      if (arg == "-d" ||
-	  arg == "-di" ||
-	  arg == "-dis" ||
-	  arg == "-disa" ||
-	  arg == "-disab" ||
-	  arg == "-disabl" ||
-	  arg == "-disable" ||
-	  arg == "-disable_" ||
-	  arg == "-disable_w" ||
-	  arg == "-disable_wa" ||
-	  arg == "-disable_war" ||
-	  arg == "-disable_warn" ||
-	  arg == "-disable_warni" ||
-	  arg == "-disable_warnin" ||
-	  arg == "-disable_warning" ||
-	  arg == "-disable_warnings")
-	{
-	  Me.m_disable_warnings = true;
-	  if (CmtMessage::level () <= Warning)
-	    {
-	      CmtMessage::set_level (Error);
-	      //	      if (!CmtSystem::putenv ("CMTERROR", "1"))
-	      //		CmtMessage::error ("Cannot set `CMTERROR' in the environment");
-	    }
-	  if (!Cmt::add_cmt_flag ("-disable_warnings"))
-	    CmtMessage::error ("Cannot add flag `-disable_warnings'");
-	}
-      else if (arg == "-q" ||
-	       arg == "-qu" ||
-	       arg == "-qui" ||
-	       arg == "-quie" ||
-	       arg == "-quiet")
-	{
-	  Me.m_quiet = true;
-	  if (CmtMessage::level () <= Error)
-	    {
-	      CmtMessage::set_level (Fatal);
-	      //	      if (!CmtSystem::putenv ("CMTFATAL", "1"))
-	      //		CmtMessage::error ("Cannot set `CMTFATAL' in the environment");
-	    }
-	  if (!Cmt::add_cmt_flag ("-quiet"))
-	    CmtMessage::error ("Cannot add flag `-quiet'");
-	}
-      else if (arg == "-warn" ||
-	       arg == "-warni" ||
-	       arg == "-warnin" ||
-	       arg == "-warning" ||
-	       arg == "-warnings")
-	{
-	  Me.m_warnings = true;
-	  //	  if (CmtMessage::level () > Warning)
-	  if (CmtMessage::level () != Warning)
-	    {
-	      CmtMessage::set_level (Warning);
-	      //	      if (!CmtSystem::putenv ("CMTWARNING", "1"))
-	      //		CmtMessage::error ("Cannot set `CMTWARNING' in the environment");
-	    }
-	  if (!Cmt::add_cmt_flag ("-warnings"))
-	    CmtMessage::error ("Cannot add flag `-warnings'");
 	}
     }
@@ -1668,7 +1723,10 @@
 
   CmtSystem::cmt_string_vector uses;
+  cmt_vector<int> use_indexes;
   CmtSystem::cmt_string_vector packages;
   CmtSystem::cmt_string_vector versions;
-  CmtSystem::cmt_string_vector path_selections;
+  Project::ConstProjectPtrVector path_selections;
+  //  CmtSystem::cmt_string_vector path_selections;
+  Project::ConstProjectPtrVector path_exclusions;
   CmtSystem::cmt_string_vector selections;
   CmtSystem::cmt_string_vector exclusions;
@@ -1677,11 +1735,11 @@
   bool is_cmt = false;
   int first = 0;
-  int i;
   bool ignore_errors = false;
   bool all_packages = false;
-
+  int depth (1);
   bool local = true;
-
-  for (i = 0; i < ap.arguments.size (); i++)
+  bool global (false);
+
+  for (int i = 0; i < ap.arguments.size (); i++)
     {
       const cmt_string& w = ap.arguments[i];
@@ -1699,12 +1757,49 @@
             {
               local = false;
+              global = false;
 
               cmt_string depth_str;
-              int depth_value = 0;
+              int depth_value;
                           
               w.substr (7, depth_str);
-              if ((sscanf (depth_str.c_str (), "%d", &depth_value) < 1) ||
-                  (depth_value < 1))
-                {
+              int n = sscanf (depth_str.c_str (), "%d", &depth_value);
+	      cmt_string msg;
+	      switch (n)
+		{
+		case EOF:
+		  msg = "Cannot read `depth' value `";
+		  msg += depth_str;
+		  msg += cmt_string ("'");
+		  if (errno)
+		    msg += cmt_string (strerror (errno));
+		  CmtError::set (CmtError::system_error, msg);
+		  return;
+		  break;
+		case 0:
+		  msg = "Invalid `depth' value `";
+		  msg += depth_str;
+		  msg += cmt_string ("'");
+		  CmtError::set (CmtError::syntax_error, msg);
+		  return;
+		  break;
+		case 1:
+		  if (depth_value < -1)
+		    {
+		      char num[32]; sprintf (num, "%lu", -depth_value);
+		      msg = "Invalid `depth' value `-";
+		      msg += num;
+		      msg += cmt_string ("'");
+		      CmtError::set (CmtError::syntax_error, msg);
+		      return;
+		    }
+		  depth = depth_value;
+		  //cerr << "depth: " << depth << endl;
+		  break;
+		default:
+		  break;
+		}
+//               if ((sscanf (depth_str.c_str (), "%d", &depth_value) < 1) ||
+//                   (depth_value < 1))
+//                {
                   // Syntax error
                   //  We shall restrict to packages found within 
@@ -1712,7 +1807,7 @@
                   //  If CMTPATH is empty, nothing is selected.
                   // depth=1 is equivalent to local
-                }
-
-	      Project::fill_selection (depth_value, path_selections);
+//                }
+
+//	      Project::fill_selection (depth_value, path_selections);
             }
           else if (w.substr (0, 9) == "-exclude=")
@@ -1738,6 +1833,6 @@
           else if (w.substr (0, 7) == "-global")
             {
-              path_selections.clear ();
-
+              //path_selections.clear ();
+	      global = true;
               local = false;
             }
@@ -1745,4 +1840,5 @@
             {
               local = true;
+	      global = false;
             }
           else if (w.substr (0, 8) == "-select=")
@@ -1787,7 +1883,33 @@
     }
 
-  if (local)
-    {
-      Project::fill_selection (1, path_selections);
+  const Project* p_cur (Project::get_current ());
+  if (global)
+    {
+      Project::fill_exclusion (path_exclusions);
+    }
+  else if (local)
+    {
+      if (p_cur)
+	Project::fill_selection (1, path_selections);
+      else
+ 	path_selections.push_back (0); // means that we want Use::current ()
+      //	path_selections.push_back ((Use::current ()).get_realpath ());
+    }
+  else
+    {
+      if (!p_cur
+	  && depth != 0
+	  && depth != -1)
+ 	path_selections.push_back (0); // means that we want Use::current ()
+// 	path_selections.push_back ((Use::current ()).get_realpath ());
+      Project::fill_selection (depth, path_selections);
+      /*
+      cerr << "depth: " << depth << endl;
+      for (int j = 0; j < path_selections.size (); j++)
+	{
+	  const Project* sp = path_selections[j];
+	  cerr << "path_selections: " << (sp ? sp->get_cmtpath () : "current use") << endl;
+	}
+      */
     }
 
@@ -1800,5 +1922,5 @@
   //if (command.substr (0, 3) == "cmt") is_cmt = true;
 
-  cmt_string curuse = CmtSystem::pwd ();
+  //cmt_string curuse = CmtSystem::pwd ();
   if (all_packages)
     {
@@ -1806,8 +1928,9 @@
       PathScanner scanner;
       Project::scan_paths (scanner, selector);
+      return;
     }
   else
     {
-      for (i = Uses.size () - 1; i >= 0; i--)
+      for (int i = Uses.size () - 1; i >= 0; i--)
         {
           Use* use = Uses[i];
@@ -1815,61 +1938,73 @@
           if (use->discarded) continue;
           if (use->m_hidden) continue;
-
           if (!use->located ())
             {
-	      CmtMessage::warning ("package " + use->get_package_name ()
-				   + " " + use->version + " " + use->path
-				   + " not found");
-	      /*
-              if (!Me.m_quiet)
-                {
-                  cerr << "#CMT> package " << use->get_package_name () <<
-		    " " << use->version << " " << use->path <<
-		    " not found" <<
-		    endl;
-                }
-	      */
+	      CmtMessage::warning
+		(CmtError::get_error_name (CmtError::package_not_found)
+		 + ": " + use->get_info ());
+	      continue;
             }
-          else
-            {
-              if (use->get_package_name () != "CMT")
-                {
-                  cmt_string& s = uses.add ();
-
-                  use->get_full_path (s);
-
-                  s += CmtSystem::file_separator ();
-                  if (use->style == mgr_style) s += "mgr";
-                  else s += "cmt";
-
-                  cmt_string& v = versions.add ();
-		  v = use->version;
-
-                  cmt_string& p = packages.add ();
-		  p = use->get_package_name ();
-                }
-            }
-        }
+	  if (use->get_package_name () == "CMT") continue;
+
+	  cmt_string& s = uses.add ();
+	  use->get_full_path (s);
+	  switch (use->style)
+	    {
+	    case cmt_style:
+	      s += CmtSystem::file_separator ();
+	      s += "cmt";
+	      break;
+	    case mgr_style:
+	      s += CmtSystem::file_separator ();
+	      s += "mgr";
+	      break;
+	    default:
+	      break;
+	    }
+//                   if (use->style == mgr_style) s += "mgr";
+//                   else s += "cmt";
+
+	  cmt_string& v = versions.add ();
+	  v = use->version;
+	  
+	  cmt_string& p = packages.add ();
+	  p = use->get_package_name ();
+	  
+	  int& use_index = use_indexes.add ();
+	  use_index = i;
+	}
           
       {
+        Use* use = &(Use::current ());
+	
         cmt_string& s = uses.add ();
+	use->get_full_path (s);
+	switch (use->style)
+	  {
+	  case cmt_style:
+	    s += CmtSystem::file_separator ();
+	    s += "cmt";
+	    break;
+	  case mgr_style:
+	    s += CmtSystem::file_separator ();
+	    s += "mgr";
+	    break;
+	  default:
+	    break;
+	  }
+//         if (use->get_package_name ().find ("cmt_standalone") != cmt_string::npos)
+//           {
+//             s = CmtSystem::pwd ();
+//           }
+//         else
+//           {
+//             use->get_full_path (s);
+
+//             s += CmtSystem::file_separator ();
                   
-        Use* use = &(Use::current ());
-
-        if (use->get_package_name ().find ("cmt_standalone") != cmt_string::npos)
-          {
-            s = CmtSystem::pwd ();
-          }
-        else
-          {
-            use->get_full_path (s);
-
-            s += CmtSystem::file_separator ();
-                  
-            if (use->style == mgr_style) s += "mgr";
-            else s += "cmt";
-          }
-
-	curuse = s;
+//             if (use->style == mgr_style) s += "mgr";
+//             else s += "cmt";
+//           }
+	//curuse = s;
 
 	cmt_string& v = versions.add ();
@@ -1878,4 +2013,7 @@
 	cmt_string& p = packages.add ();
 	p = use->get_package_name ();
+	  
+	int& use_index = use_indexes.add ();
+	use_index = -1;
       }
     }
@@ -1891,36 +2029,67 @@
     CmtSystem::putenv ("CMTBCAST", "");
 
-  for (i = 0; i < uses.size (); i++)
+  for (int i = 0; i < uses.size (); i++)
     {
       const cmt_string& s = uses[i];
       const cmt_string& v = versions[i];
       const cmt_string& p = packages[i];
+      const int use_index = use_indexes[i];
+
+      const Use* use = use_index >= 0 ? Uses[use_index] : &(Use::current ());
+      const Project* up = use->get_project ();
+
       cmt_string cmtpath;
 
       bool ok = true;
-      bool selected = true;
+      bool selected = global ? true : false;
       bool excluded = false;
 
-      /**
-	 Ensure that the current package is not skipped
-	 due to symlinks in the paths
-       */
-      //      if (path_selections.size () > 0)
-      if (path_selections.size () > 0 && s != curuse)
+      ok = selected;
+      if (path_selections.size () > 0)
         {
           selected = false;
-
           for (int j = 0; j < path_selections.size (); j++)
             {
-              const cmt_string& sel = path_selections[j];
-              
-              if (s.find (sel) != cmt_string::npos) 
-                {
-		  cmtpath = sel;
-                  selected = true;
-                  break;
-                }
-            }
-
+              const Project* sp = path_selections[j];
+	      if (sp)
+		{
+		  if (up)
+		    {
+		      if (up == sp)
+			{
+			  cmtpath = sp->get_cmtpath ();
+			  selected = true;
+			  break;
+			}
+		    }
+		  else
+		    {
+		      if (use->get_realpath ().find (sp->get_cmtpath_real ()) == 0)
+			{
+			  cmtpath = sp->get_cmtpath ();
+			  selected = true;
+			  break;
+			}
+		    }
+		}
+	      else if (use == &(Use::current ()))
+		{
+		  // means that we want Use::current ()
+		  // cmtpath = sp->get_cmtpath ();
+		  if (up)
+		    cmtpath = up->get_cmtpath ();
+		  else
+		    cmtpath = "";
+		  selected = true;
+		  break;
+		}
+	      // const cmt_string& sel = path_selections[j];
+	      // if (s.find (sel) != cmt_string::npos) 
+//                 {
+// 		  cmtpath = sel;
+//                   selected = true;
+//                   break;
+//                 }
+	    }
           ok = selected;
         }
@@ -1960,5 +2129,4 @@
         }
 
-
       if (ok)
         {
@@ -1974,4 +2142,31 @@
                   break;
                 }
+            }
+
+          if (excluded) ok = false;
+        }
+
+      if (ok)
+        {
+          excluded = false;
+          for (int j = 0; j < path_exclusions.size (); j++)
+            {
+              const Project* sp = path_exclusions[j];
+	      if (up)
+		{
+		  if (up == sp)
+		    {
+		      excluded = true;
+		      break;
+		    }
+		}
+	      else
+		{
+		  if (use->get_realpath ().find (sp->get_cmtpath_real ()) == 0)
+		    {
+		      excluded = true;
+		      break;
+		    }
+		}
             }
 
@@ -2021,4 +2216,5 @@
         }
 
+      /*
       if (cmtpath == "")
         {
@@ -2026,4 +2222,5 @@
 	  cmtpath = Project::find_in_cmt_paths (sel);
         }
+      */
 
       cmt_string cmd = command;
@@ -2041,24 +2238,31 @@
       static const cmt_string empty_string;
       static const cmt_string fs = CmtSystem::file_separator ();
-      cmt_string offset = s;
-      offset.replace (cmtpath, empty_string);
-      if (offset[0] == CmtSystem::file_separator ())
-	{
-	  offset.replace (fs, empty_string);
-	}
-      CmtSystem::dirname (offset, offset);
-
-      cmt_string n;
-      CmtSystem::basename (offset, n);
-      if (n == p)
-	{
+      cmt_string offset;
+      if (cmtpath.size ())
+	{
+	  offset = s;
+	  offset.replace (cmtpath, empty_string);
+	  if (offset[0] == CmtSystem::file_separator ())
+	    {
+	      offset.replace (fs, empty_string);
+	    }
 	  CmtSystem::dirname (offset, offset);
+	  
+	  cmt_string n;
+	  CmtSystem::basename (offset, n);
+	  if (n == p)
+	    {
+	      CmtSystem::dirname (offset, offset);
+	    }
+	  else
+	    {
+	      CmtSystem::dirname (offset, offset);
+	      CmtSystem::dirname (offset, offset);
+	    }
 	}
       else
 	{
-	  CmtSystem::dirname (offset, offset);
-	  CmtSystem::dirname (offset, offset);
-	}
-
+	  offset = use->real_path;
+	}
       cmd.replace_all (offset_template, offset);
 
@@ -2904,20 +3108,42 @@
     }
 
-  static CmtSystem::cmt_string_vector tags;
+  //  static CmtSystem::cmt_string_vector tags;
 
   if (action_build_constituents_config != get_action ())
-    CmtSystem::split (Me.m_extra_tags, " \t,", tags);
-
-  for (int i = 0; i < tags.size (); i++)
-    {
-      const cmt_string& t = tags[i];
-
-      tag = Tag::find (t);
-      if (tag == 0) continue;
-
-      if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag)) 
-	{
-	  CmtMessage::warning ("The tag " + t + " is not used in any tag expression. Please check spelling");
-	  //	  cerr << "#CMT> The tag " << t << " is not used in any tag expression. Please check spelling" << endl;
+    {
+    //    CmtSystem::split (Me.m_extra_tags, " \t,", tags);
+
+    //  for (int i = 0; i < tags.size (); i++)
+      //    {
+      //      const cmt_string& t = tags[i];
+      for (int i = 0; i < Me.m_extra_tags.size (); i++)
+	{
+	  const cmt_string& t = Me.m_extra_tags[i];
+	  tag = Tag::find (t);
+	  if (tag == 0) continue;
+	  if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag)) 
+	    {
+	      CmtMessage::warning ("The tag " + t + " is not used in any tag expression. Please check spelling");
+	    }
+	}
+      for (int i = 0; i < Me.m_tags.size (); i++)
+	{
+	  const cmt_string& t = Me.m_tags[i];
+	  tag = Tag::find (t);
+	  if (tag == 0) continue;
+	  if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag)) 
+	    {
+	      CmtMessage::warning ("The tag " + t + " is not used in any tag expression. Please check spelling");
+	    }
+	}
+      for (int i = 0; i < Me.m_tags_add.size (); i++)
+	{
+	  const cmt_string& t = Me.m_tags_add[i];
+	  tag = Tag::find (t);
+	  if (tag == 0) continue;
+	  if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag)) 
+	    {
+	      CmtMessage::warning ("The tag " + t + " is not used in any tag expression. Please check spelling");
+	    }
 	}
     }
@@ -2940,5 +3166,4 @@
     {
       CmtMessage::warning ("The CMTSITE value " + env + " is not used in any tag expression. Please check spelling");
-      //      cerr << "#CMT> The CMTSITE value " << env << " is not used in any tag expression. Please check spelling" << endl;
     }
 
@@ -4476,9 +4701,11 @@
 
   Use& use = Use::current();    
+  /*
   use.get_cmtpath_and_offset (cmtpath, offset);
 
   Project* p = Project::find_by_cmtpath (cmtpath);
-
-  cout << p->get_author () << endl;
+  */
+  if (const Project* p = use.get_project ())
+    cout << p->get_author () << endl;
 }
 
@@ -4503,7 +4730,9 @@
   ClientCollector collector (package, version);
 
+  /*
   clear     ();
   //  configure ();
   configure (ap);
+  */
 
   cout << "# ----------- Clients of " << package
@@ -5425,5 +5654,5 @@
   log << "guess_current_project" << log_endl;
 
-  cmt_string here = CmtSystem::pwd ();
+  //  cmt_string here = CmtSystem::pwd ();
 
   Use& use = Use::current();
@@ -5438,4 +5667,5 @@
     //  if (Project::find_in_cmt_paths (Me.m_current_dir) == "")
     {
+      /*
       if (!CmtSystem::cd (current_path))
 	{
@@ -5444,13 +5674,22 @@
 	  return;
 	}
+      */
       cmt_string project_file = "cmt";
       project_file += CmtSystem::file_separator ();
       project_file += Project::get_project_file_name ();
 
-      cmt_string pwd;
+      /*
+      cmt_string pwd (CmtSystem::pwd ());
+      cmt_string pwd_prev;
+      */
+      cmt_string dir_cur (current_path);
+      cmt_string dir_par;
+
+      cmt_string proj_file_cur;
 
       for (;;)
 	{
-	  pwd = CmtSystem::pwd ();
+	  /*
+	  //	  pwd = CmtSystem::pwd ();
 	  if (CmtSystem::test_file (project_file))
 	    {
@@ -5462,6 +5701,20 @@
 	      break;
 	    }
-
-	  log << "pwd=" << CmtSystem::pwd () << log_endl;
+	  */
+	  proj_file_cur = dir_cur;
+	  proj_file_cur += CmtSystem::file_separator ();
+	  proj_file_cur += project_file;
+	  if (CmtSystem::test_file (proj_file_cur))
+	    {
+	      //this directory should become the first entry of the CMTPATH
+
+	      IProjectFactory& factory = ProjectFactory::instance ();
+	      factory.create_project ("", dir_cur, "CurrentProject", 0);
+
+	      break;
+	    }
+
+	  /*
+	  log << "pwd=" << pwd << log_endl;
 	  
 	  if (!CmtSystem::cd (".."))
@@ -5471,13 +5724,25 @@
 	    }
 
-	  if (CmtSystem::pwd () == pwd)
+	  pwd_prev = pwd;
+	  pwd = CmtSystem::pwd ();
+	  if (pwd == pwd_prev)
+	    //	  if (CmtSystem::pwd () == pwd)
 	    {
 	      log << "Looks the same pwd..." << log_endl;
 	      break;
 	    }
-	}
-
-      CmtSystem::cd (Me.m_current_dir);
-    }
+	  */
+	  log << "dir_cur=`" << dir_cur << "'" << log_endl;
+	  CmtSystem::dirname (dir_cur, dir_par);
+	  if (dir_par == dir_cur)
+	    {
+	      log << "Looks the same dir_cur..." << log_endl;
+	      break;
+	    }
+	  dir_cur = dir_par;
+	}
+
+      //      CmtSystem::cd (Me.m_current_dir);
+    } // if (Project::find_in_cmt_paths (current_path) == "")
 
   //cmt_string buffer = "path CMTPATH \n";
@@ -5496,5 +5761,6 @@
   Me.m_autoconfigure_cmtpath = true;
 
-  CmtSystem::cd (here);
+  //  CmtSystem::cd (Me.m_current_dir);
+  //CmtSystem::cd (here);
 }
 
@@ -6409,5 +6675,5 @@
 
   /**
-   * See reach_current_package for an explanation of this call
+   * See apply_globals for an explanation of this call
    */
   Pattern::apply_all_globals ();
@@ -6444,5 +6710,5 @@
   Me.m_action = action_none;
 
-  restore_all_tags (0);
+  //  restore_all_tags (0);
 
 #ifdef WIN32
@@ -6498,18 +6764,35 @@
   clear ();
 
+  //  Me.clear ();
+
+  parse_arguments (ap);
+
   //  configure ();
-  configure (ap);
-
-  CmtError::clear ();
+  switch (Me.m_action)
+    {
+    case action_none :
+    case action_build_temporary_name :
+    case action_help :
+      break;
+    default:
+      configure (ap);
+      restore_all_tags (0);
+      break;
+    }
+  
+  //  CmtError::clear ();
 
   /*
-    Set private if positioned inside the package
+    Set DeveloperMode if positioned inside the package
     (which is detected since we were able to retreive the
     Version, Package and Path)
   */
 
+  if (!Use::current().located ())
+  /*
   if ((Me.m_current_path.size () == 0) ||
       (Me.m_current_package.size () == 0) ||
       (Me.m_current_version.size () == 0))
+  */
     {
       Me.m_current_access = UserMode;
@@ -6520,5 +6803,5 @@
     }
   
-  parse_arguments (ap);
+  //  parse_arguments (ap);
   
   if (ap.help_action == action_help)
@@ -6929,5 +7212,6 @@
 	Me.m_warnings = false;
 	if (strlen (ap.extra_file.c_str ()) == 0)
-	  reach_current_package ();
+	  use_current_package ();
+	//	  reach_current_package ();
 	else
 	  use_extra_file (ap.extra_file);
@@ -6935,6 +7219,6 @@
 	if (strlen (ap.extra_line.c_str ()) > 0)
 	  SyntaxParser::parse_requirements_text (ap.extra_line, "extra statement(s)", (Use*) 0);
+	apply_globals ();
 	Me.m_warnings = w;
-	//if (strlen (ap.extra_line.c_str ()) > 0) SyntaxParser::parse_requirements_line (ap.extra_line, &(Use::current ()));
       }
       break;
@@ -6952,5 +7236,8 @@
   if (use != 0 && !use->discarded && !use->m_hidden && use->located ())
     uses.push_back (use);
-  uses.push_back (&(Use::current()));
+  use = &(Use::current());
+  if (use != 0 && !use->discarded && !use->m_hidden && use->located ())
+    uses.push_back (use);
+  //  uses.push_back (&(Use::current()));
   use = Use::find (CmtSystem::get_user_context_package ());
   if (use != 0 && !use->discarded && !use->m_hidden && use->located ())
@@ -7452,4 +7739,5 @@
   //
 
+  /*
   {
     CmtSystem::cmt_string_vector words;
@@ -7477,5 +7765,5 @@
       }
   }
-
+  */
   if (mode == Requirements)
     {
@@ -7939,5 +8227,5 @@
 
 //----------------------------------------------------------
-int Cmt::reach_current_package ()
+int Cmt::use_current_package ()
 {
   Use& use = Use::current ();
@@ -7946,5 +8234,5 @@
   if (Me.m_debug)
     {
-      cout << "Cmt::reach_current_package> pwd = " 
+      cout << "Cmt::use_current_package> pwd = " 
 	   << CmtSystem::pwd () 
 	   << " path=" << Me.m_current_path
@@ -7959,10 +8247,12 @@
   if (Me.m_current_package == "cmt_standalone")
     {
-      if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
+      if ((Me.m_current_path != "") && (Me.m_current_path != Me.m_current_dir))
+//      if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
         {
           if (!CmtSystem::cd (Me.m_current_path))
             {
               CmtError::set (CmtError::package_not_found,
-                             "ReachCurrentPackage> Cannot reach the path directory");
+                             "Cannot reach the path directory: "
+			     + Me.m_current_path);
               return (0);
             }
@@ -7975,17 +8265,33 @@
 
       Me.m_current_structuring_style = without_version_directory;
+      use.structuring_style = Me.m_current_structuring_style;
+      use.change_path (Me.m_current_path, Project::get_current ());
+      Me.m_current_access = DeveloperMode;
     }
   else if (Me.m_current_package != "")
     {
-      if (!use.move_to () && !use.move_to ("", true))
-	//      if (!use.move_to ())
-        {
-	  CmtError::set (CmtError::package_not_found, use.get_info ());
-//           CmtError::set (CmtError::package_not_found,
-//                          "ReachCurrentPackage> Cannot reach the path directory");
-          return (0);
-        }
-
-      Me.m_current_path = use.real_path;
+      if (!use.located ())
+	{
+	  //	  if (!use.move_to () && !use.move_to ("", true))
+	    //      if (!use.move_to ())
+	  if (!use.move_to ())
+	    {
+	      if (!CmtSystem::cd (Cmt::get_current_dir ()))
+		{
+		  CmtError::set (CmtError::file_access_error,
+				 Cmt::get_current_dir ()
+				 + " (use_current_package)");
+		  return 0;
+		}
+	      if (!use.move_to ("", true))
+		{
+		  CmtError::set (CmtError::package_not_found, use.get_info ());
+		  return 0;
+		}
+	    }
+	  
+	  Me.m_current_path = use.real_path;
+	  Me.m_current_access = DeveloperMode;
+	}
     }
   else
@@ -8025,5 +8331,6 @@
               
               CmtError::set (CmtError::package_not_found,
-                             "ReachCurrentPackage> Cannot reach the mgr/cmt directory");
+                             "Cannot reach the mgr/cmt directory: "
+			     + use.get_info ());
               return (0);
             }
@@ -8031,4 +8338,6 @@
       else
 	Me.m_current_style = none_style;
+
+      Me.m_current_access = DeveloperMode;
 
       dir = CmtSystem::pwd ();
@@ -8058,9 +8367,15 @@
       use.style   = Me.m_current_style;
       use.structuring_style = Me.m_current_structuring_style;
-    }
-
+
+      configure_current_dir ();
+      build_prefix (Me.m_current_package, Me.m_current_prefix);
+      build_config (Me.m_current_prefix, Me.m_current_config);
+    }
+
+  /*
   configure_current_dir ();
   build_prefix (Me.m_current_package, Me.m_current_prefix);
   build_config (Me.m_current_prefix, Me.m_current_config);
+  */
 
   /*
@@ -8068,5 +8383,5 @@
   */
 
-  if (Me.m_debug) cout << "reach_current_package0> current_tag=" << Me.m_current_tag << endl;
+  if (Me.m_debug) cout << "use_current_package0> current_tag=" << Me.m_current_tag << endl;
 
   if (Me.m_current_tag == "")
@@ -8079,9 +8394,9 @@
           Tag* tag;
 
-          tag = Tag::add (env, PriorityConfig, "reach current package", 0);
+          tag = Tag::add (env, PriorityConfig, "current package", 0);
           tag->mark (use.get_package_name ());
 	  //Me.m_current_tag = env;
 
-          //if (!Me.m_quiet) cerr << "reach_current_package1> current_tag=" << Me.m_current_tag << endl;
+          //if (!Me.m_quiet) cerr << "use_current_package1> current_tag=" << Me.m_current_tag << endl;
 
         }
@@ -8101,5 +8416,146 @@
   SyntaxParser::parse_requirements (dir, &use);
 
-  if (Me.m_debug) cout << "reach_current_package2> current_tag=" << Me.m_current_tag << endl;
+  if (CmtError::has_pending_error ()) return 0;
+
+  if (Me.m_debug) cout << "use_current_package2> current_tag=" << Me.m_current_tag << endl;
+
+  return 1;
+}
+
+//----------------------------------------------------------
+int Cmt::use_extra_file (const cmt_string& file)
+{
+  if (!CmtSystem::test_file (file))
+    {
+      CmtError::set (CmtError::path_not_found, file);
+      return 0;
+    }
+
+  // (almost) Cmt::use_current_package ()
+  Use& use = Use::current ();
+  /*
+    Try to access the package.
+  */
+
+  if (Me.m_current_package == "cmt_standalone")
+    {
+      if ((Me.m_current_path != "") && (Me.m_current_path != Me.m_current_dir))
+//      if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
+        {
+          if (!CmtSystem::cd (Me.m_current_path))
+            {
+              CmtError::set (CmtError::package_not_found,
+                             "Cannot reach the path directory: "
+			     + Me.m_current_path);
+              return (0);
+            }
+        }
+      /*
+      if (!CmtSystem::test_file ("requirements"))
+        {
+          return (0);
+        }
+      */
+      Me.m_current_structuring_style = without_version_directory;
+      use.structuring_style = Me.m_current_structuring_style;
+      use.change_path (Me.m_current_path, Project::get_current ());
+      Me.m_current_access = DeveloperMode;
+    }
+  else if (Me.m_current_package != "")
+    {
+      if (!use.located ())
+	{
+	  //	  if (!use.move_to () && !use.move_to ("", true))
+	    //      if (!use.move_to ())
+	  if (!use.move_to ())
+	    {
+	      if (!CmtSystem::cd (Cmt::get_current_dir ()))
+		{
+		  CmtError::set (CmtError::file_access_error,
+				 Cmt::get_current_dir ()
+				 + " (use_extra_file)");
+		  return 0;
+		}
+	      if (!use.move_to ("", true))
+		{
+		  CmtError::set (CmtError::package_not_found, use.get_info ());
+		  return 0;
+		}
+	    }
+	  
+	  Me.m_current_path = use.real_path;
+	  Me.m_current_access = DeveloperMode;
+	}
+    }
+  else
+    {
+      //
+      // The cmt command has been given without explicit search for 
+      // a package. Thus it is expected that we are in the context of a
+      // true package.
+      //
+      //  This means that there should be a requirements file visible.
+      //
+      //  If this is not true, we'll make a try into ../cmt and then
+      // a last try into ../mgr
+      //
+
+      Me.m_current_access = DeveloperMode;
+      //...
+      configure_current_dir ();
+      build_prefix (Me.m_current_package, Me.m_current_prefix);
+      build_config (Me.m_current_prefix, Me.m_current_config);
+    }
+
+  /*
+  configure_current_dir ();
+  build_prefix (Me.m_current_package, Me.m_current_prefix);
+  build_config (Me.m_current_prefix, Me.m_current_config);
+  */
+
+  /*
+    Check Tag is always set up
+  */
+
+  if (Me.m_debug) cout << "use_extra_file0> current_tag=" << Me.m_current_tag << endl;
+
+  if (Me.m_current_tag == "")
+    {
+      cmt_string env;
+
+      env = CmtSystem::getenv (Me.m_current_config);
+      if (env != "")
+        {
+          Tag* tag;
+
+          tag = Tag::add (env, PriorityConfig, "current package", 0);
+          tag->mark (use.get_package_name ());
+	  //Me.m_current_tag = env;
+
+          //if (!Me.m_quiet) cerr << "use_extra_file1> current_tag=" << Me.m_current_tag << endl;
+
+        }
+    }
+
+  if (Me.m_debug)
+    {
+      cout << "pwd = " << CmtSystem::pwd () << endl;
+    }
+
+  /*
+    Work on the requirements file.
+  */
+
+  SyntaxParser::parse_requirements (file, &use);
+
+  if (CmtError::has_pending_error ()) return 0;
+
+  if (Me.m_debug) cout << "use_extra_file2> current_tag=" << Me.m_current_tag << endl;
+  return 1;
+}
+
+//----------------------------------------------------------
+int Cmt::apply_globals ()
+{
 
   /**
@@ -8132,142 +8588,7 @@
   Tag::restore_tree ();
 
-  return (1);
-}
-
-//----------------------------------------------------------
-int Cmt::use_extra_file (const cmt_string& file)
-{
-  if (!CmtSystem::test_file (file))
-    {
-      CmtError::set (CmtError::path_not_found, file);
-      return 0;
-    }
-
-  // (almost) Cmt::reach_current_package ()
-  Use& use = Use::current ();
-  /*
-    Try to access the package.
-  */
-
-  if (Me.m_current_package == "cmt_standalone")
-    {
-      if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
-        {
-          if (!CmtSystem::cd (Me.m_current_path))
-            {
-              CmtError::set (CmtError::package_not_found,
-                             "ReachCurrentPackage> Cannot reach the path directory");
-              return (0);
-            }
-        }
-      /*
-      if (!CmtSystem::test_file ("requirements"))
-        {
-          return (0);
-        }
-      */
-      Me.m_current_structuring_style = without_version_directory;
-    }
-  else if (Me.m_current_package != "")
-    {
-      if (!use.move_to () && !use.move_to ("", true))
-	//      if (!use.move_to ())
-        {
-	  CmtError::set (CmtError::package_not_found, use.get_info ());
-//           CmtError::set (CmtError::package_not_found,
-//                          "ReachCurrentPackage> Cannot reach the path directory");
-	  //          return -1;
-	  return (0);
-        }
-
-      Me.m_current_path = use.real_path;
-    }
-  else
-    {
-      //
-      // The cmt command has been given without explicit search for 
-      // a package. Thus it is expected that we are in the context of a
-      // true package.
-      //
-      //  This means that there should be a requirements file visible.
-      //
-      //  If this is not true, we'll make a try into ../cmt and then
-      // a last try into ../mgr
-      //
-
-      //...
-    }
-
-  configure_current_dir ();
-  build_prefix (Me.m_current_package, Me.m_current_prefix);
-  build_config (Me.m_current_prefix, Me.m_current_config);
-
-  /*
-    Check Tag is always set up
-  */
-
-  if (Me.m_debug) cout << "use_extra_file0> current_tag=" << Me.m_current_tag << endl;
-
-  if (Me.m_current_tag == "")
-    {
-      cmt_string env;
-
-      env = CmtSystem::getenv (Me.m_current_config);
-      if (env != "")
-        {
-          Tag* tag;
-
-          tag = Tag::add (env, PriorityConfig, "reach current package", 0);
-          tag->mark (use.get_package_name ());
-	  //Me.m_current_tag = env;
-
-          //if (!Me.m_quiet) cerr << "use_extra_file1> current_tag=" << Me.m_current_tag << endl;
-
-        }
-    }
-
-  if (Me.m_debug)
-    {
-      cout << "pwd = " << CmtSystem::pwd () << endl;
-    }
-
-  /*
-    Work on the requirements file.
-  */
-
-  SyntaxParser::parse_requirements (file, &use);
-
-  if (Me.m_debug) cout << "use_extra_file2> current_tag=" << Me.m_current_tag << endl;
-
-  /**
-   *   It would be useful to change this mechanism. Instead of
-   *  applying all global patterns at once to all use contexts, it
-   *  would be much better to apply it at the end of each
-   *  requirements file parsing, and only in the context the
-   *  appropriate Use.
-   *
-   *   This would avoid the current flaw which is that when a global
-   *  pattern specifies a "private" definition, it is actually
-   *  applied in the scope context of the Current Use and not in
-   *  each individual Use. Therefore the private is lost.
-   *
-   *   However, this induces problems since some pattern definitions
-   *  are done AFTER the use statements, which will NOT receive the
-   *  pattern aplications.
-   *
-   *   Therefore it is decided to leave this "bad" mechanism until
-   *  everybody is aware of this constraint.
-   *
-   * 
-   */
-  Pattern::apply_all_globals ();
-
-  /*
-    Select all possible tags
-  */
-
-  Tag::restore_tree ();
-
-  return (1);
+  if (CmtError::has_pending_error ()) return 0;
+
+  return 1;
 }
 
@@ -9972,7 +10293,36 @@
   if (CmtSystem::test_file (f))
     {
-      use->m_located = true;
-    }
-  SyntaxParser::parse_requirements (f, use);
+      use->style = none_style;
+      use->structuring_style = without_version_directory;
+
+      if (name == CmtSystem::get_home_package () ||
+	  name == CmtSystem::get_user_context_package ())
+	{
+	  const Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
+	  if (0 == Ordered.size ())
+	    {
+	      CmtError::set(CmtError::configuration_error,
+			    "No ordered project: " + use->get_info ());
+	      return;
+	    }
+	  if (name == CmtSystem::get_home_package ())
+	    use->change_path (path, Ordered[Ordered.size () - 1]);
+	  else if (name == CmtSystem::get_user_context_package ())
+	    use->change_path (path, Ordered[0]);
+	}
+      else
+	{
+	  CmtMessage::verbose
+	    (CmtError::get_error_name (CmtError::configuration_error)
+	     + ": Unknown special use: " + use->get_info ());
+	  use->change_path (path);
+	}
+      //      use->m_located = true;
+      SyntaxParser::parse_requirements (f, use);
+    }
+  else
+    {
+      use->discard ();
+    }
 
   Me.m_recursive = recursive_copy;
Index: CMT/HEAD/source/cmt_pattern.cxx
===================================================================
--- CMT/HEAD/source/cmt_pattern.cxx	(revision 651)
+++ CMT/HEAD/source/cmt_pattern.cxx	(revision 652)
@@ -771,5 +771,5 @@
       replacement.replace_all ("<version>", context_use->version.c_str ());
       replacement.replace_all ("<path>",    context_use->real_path.c_str ());
-
+      /*
       cmt_string cmtpath = "";
       cmt_string offset = "";
@@ -779,7 +779,9 @@
       Project* p = Project::find_by_cmtpath (cmtpath);
       if (p != 0)
+      */
+      if (const Project* p = context_use->get_project ())
         {
-          const cmt_string& n = p->get_name ();
-          replacement.replace_all ("<project>", n.c_str ());
+	  //          const cmt_string& n = p->get_name ();
+          replacement.replace_all ("<project>", p->get_name ().c_str ());
         }
 
Index: CMT/HEAD/source/cmt_project.cxx
===================================================================
--- CMT/HEAD/source/cmt_project.cxx	(revision 651)
+++ CMT/HEAD/source/cmt_project.cxx	(revision 652)
@@ -646,5 +646,6 @@
       project_use->m_hidden  = true;
       project_use->selected  = true;
-      project_use->m_located = true;
+      project_use->change_path (project->get_cmtpath(), project);
+      //      project_use->m_located = true;
       cmt_map <Use*, bool> visited;
       project_use->set_auto_imports(Unspecified, Off, visited);
@@ -864,6 +865,4 @@
   static ProjectVector& Projects = projects ();
 
-  Project* result = 0;
-
   for (int i = (Projects.size () - 1); i >= 0; i--)
     {
@@ -879,9 +878,9 @@
 	//      if (here_real.find (p.m_cmtpath_real) == 0) 
 	{
-	  result = &p;
-	}
-    }
-
-  return (result);
+	  return &p;
+	}
+    }
+
+  return 0;
 }
 
@@ -1523,5 +1522,187 @@
 
 //----------------------------------------------------------
-void Project::fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections)
+/**
+ *  Fill with projects (pointers) for CMTPATH entries >=1 and <= depth
+ *  except for CMTUSERCONTEXT project or CMTHOME project
+ *  unless either is current project.
+ *  Special values of depth:
+ *   0: CMTUSERCONTEXT project only
+ *  -1: CMTHOME project only
+ *
+ *  @param depth in CMTPATH up to which fill
+ *  @param path_selections vector to fill
+ */
+void Project::fill_selection (int depth, ConstProjectPtrVector& path_selections)
+{
+  static ProjectPtrVector& Ordered = Project::ordered_projects ();
+  int curdepth = depth;
+  for (int i = 0; i < Ordered.size (); i++)
+    {
+      const Project* project = Ordered[i];
+      const cmt_string& src = project->get_cmtpath_source ();
+
+      if (src == "default path") continue;
+
+      if (depth > 0)
+	{
+	  // project for CMTPATH entries >=1 and <= depth
+	  // except for CMTUSERCONTEXT path or CMTHOME path
+	  // OR
+	  // CMTUSERCONTEXT path if it's current project
+	  // CMTHOME        path if it's current project
+	  if (i == 0
+	      && !project->is_current ()
+	      && src == "CMTUSERCONTEXT") continue;
+	  // this is CMTUSERCONTEXT
+	  if (i == Ordered.size () - 1
+	      && !project->is_current ()
+	      && src == "CMTHOME") continue;
+	  // this is CMTHOME
+	  path_selections.push_back (project);
+	  //cerr << "fill: " << i << ": " << project->get_cmtpath () << ": " << curdepth << endl;
+	  if (--curdepth == 0) break;
+	}
+      else if (depth == 0)
+	{
+	  // CMTUSERCONTEXT path only
+	  if (i == 0
+	      && src == "CMTUSERCONTEXT")
+	    {
+	      path_selections.push_back (project);
+	      break;
+	    }
+	}
+      else if (depth == -1)
+	{
+	  // CMTHOME path only
+	  if (i == Ordered.size () - 1
+	      && src == "CMTHOME")
+	    {
+	      path_selections.push_back (project);
+	      break;
+	    }
+	}
+    }
+}
+
+//----------------------------------------------------------
+// void Project::fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections)
+// {
+//   static ProjectPtrVector& Ordered = Project::ordered_projects ();
+//   int curdepth = depth;
+//   for (int i = 0; i < Ordered.size (); i++)
+//     {
+//       const Project* project = Ordered[i];
+
+//       const cmt_string& p = project->get_cmtpath ();
+//       const cmt_string& pwd = project->get_cmtpath_pwd ();
+//       const cmt_string& p_real = project->get_cmtpath_real ();
+//       const cmt_string& src = project->get_cmtpath_source ();
+
+//       if (src == "default path") continue;
+
+//       if (depth > 0)
+// 	{
+// 	  // packages from CMTPATH entries >=1 and <= depth
+// 	  // except for CMTUSERCONTEXT path or CMTHOME path
+// 	  // OR
+// 	  // CMTUSERCONTEXT path if it's current project
+// 	  // CMTHOME        path if it's current project
+// 	  if (i == 0
+// 	      && !project->is_current ()
+// 	      && src == "CMTUSERCONTEXT") continue;
+// 	  // this is CMTUSERCONTEXT
+// 	  if (i = Ordered.size () - 1
+// 	      && !project->is_current ()
+// 	      && src == "CMTHOME") continue;
+// 	  // this is CMTHOME
+// 	  cmt_string& s1 = path_selections.add ();
+// 	  s1 = p;
+// 	  if (pwd != p)
+// 	    {
+// 	      cmt_string& s2 = path_selections.add ();
+// 	      s2 = pwd;
+// 	    }
+// 	  if (p_real != p && p_real != pwd)
+// 	    {
+// 	      cmt_string& s3 = path_selections.add ();
+// 	      s3 = p_real;
+// 	    }
+// 	  if (--curdepth == 0) break;
+// 	}
+//       else if (depth == 0)
+// 	{
+// 	  // CMTUSERCONTEXT path only
+// 	  if (i == 0
+// 	      && src == "CMTUSERCONTEXT")
+// 	    {
+// 	      cmt_string& s1 = path_selections.add ();
+// 	      s1 = p;
+// 	      if (pwd != p)
+// 		{
+// 		  cmt_string& s2 = path_selections.add ();
+// 		  s2 = pwd;
+// 		}
+// 	      if (p_real != p && p_real != pwd)
+// 		{
+// 		  cmt_string& s3 = path_selections.add ();
+// 		  s3 = p_real;
+// 		}
+// 	      break;
+// 	    }
+// 	}
+//       else if (depth == -1)
+// 	{
+// 	  // CMTHOME path only
+// 	  if (i = Ordered.size () - 1
+// 	      && src == "CMTHOME")
+// 	    {
+// 	      cmt_string& s1 = path_selections.add ();
+// 	      s1 = p;
+// 	      if (pwd != p)
+// 		{
+// 		  cmt_string& s2 = path_selections.add ();
+// 		  s2 = pwd;
+// 		}
+// 	      if (p_real != p && p_real != pwd)
+// 		{
+// 		  cmt_string& s3 = path_selections.add ();
+// 		  s3 = p_real;
+// 		}
+// 	      break;
+// 	    }
+// 	}
+// // 	  if (depth > 0)
+// // 	    {
+// // 	      cmt_string& s1 = path_selections.add ();
+// // 	      s1 = p;
+// // 	      if (pwd != p)
+// // 		{
+// // 		  cmt_string& s2 = path_selections.add ();
+// // 		  s2 = pwd;
+// // 		}
+// // 	      if (p_real != p && p_real != pwd)
+// // 		{
+// // 		  cmt_string& s3 = path_selections.add ();
+// // 		  s3 = p_real;
+// // 		}
+// // 	      if (src != "CMTHOME" && src != "CMTUSERCONTEXT")
+// // 		depth--;
+
+// // 	      if (depth == 0) break;
+// // 	    }
+
+//     }
+// }
+
+//----------------------------------------------------------
+/**
+ *  Fill with projects (pointers) for CMTUSERCONTEXT and CMTHOME projects
+ *  (if any exists)
+ *  unless either is current project.
+ *  
+ *  @param path_exclusions vector to fill
+ */
+void Project::fill_exclusion (ConstProjectPtrVector& path_exclusions)
 {
   static ProjectPtrVector& Ordered = Project::ordered_projects ();
@@ -1529,43 +1710,9 @@
     {
       const Project* project = Ordered[i];
-
-      const cmt_string& p = project->get_cmtpath ();
-      const cmt_string& pwd = project->get_cmtpath_pwd ();
-      const cmt_string& p_real = project->get_cmtpath_real ();
       const cmt_string& src = project->get_cmtpath_source ();
-      /*
-  static ProjectVector& Projects = projects ();
-
-  for (int i = 0; i < Projects.size (); i++)
-    {
-      Project& project = Projects[i];
-
-      const cmt_string& p = project.get_cmtpath ();
-      const cmt_string& pwd = project.get_cmtpath_pwd ();
-      const cmt_string& p_real = project.get_cmtpath_real ();
-      const cmt_string& src = project.get_cmtpath_source ();
-      */
-      if (src != "default path")
-	{
-	  if (depth > 0)
-	    {
-	      cmt_string& s1 = path_selections.add ();
-	      s1 = p;
-	      if (pwd != p)
-		{
-		  cmt_string& s2 = path_selections.add ();
-		  s2 = pwd;
-		}
-	      if (p_real != p && p_real != pwd)
-		{
-		  cmt_string& s3 = path_selections.add ();
-		  s3 = p_real;
-		}
-	      if (src != "CMTHOME" && src != "CMTUSERCONTEXT")
-		depth--;
-
-	      if (depth == 0) break;
-	    }
-	}
+
+      if (!project->is_current ()
+	  && (src == "CMTUSERCONTEXT" || src == "CMTHOME"))
+	path_exclusions.push_back (project);
     }
 }
@@ -1694,5 +1841,5 @@
 // 	    }
 
-	  if (path_real.find (p_real) != cmt_string::npos)
+	  if (path_real.find (p_real) == 0) //!= cmt_string::npos)
 	    {
 	      return (p);
@@ -1700,5 +1847,5 @@
 
 	  // To become the current area, a path must correspond to the current package
-	  if (path.find (w) != cmt_string::npos)
+	  if (path.find (w) == 0)// != cmt_string::npos)
 	    {
 	      return (p);
@@ -1706,4 +1853,5 @@
 	}
 
+	/* This code is never used since p is returned above
       if (p == w) continue;
 
@@ -1711,9 +1859,10 @@
       //      if (CmtSystem::test_directory (w))
 	{
-	  if (path.find (w) != cmt_string::npos)
+	  if (path.find (w) == 0)// != cmt_string::npos)
 	    {
 	      return (w);
 	    }
 	}
+	*/
     }
 
@@ -2362,10 +2511,23 @@
   use->get_package ()->remove_use (use);
   CmtSystem::cd (m_cmtpath_pwd);
-  if (use->move_to ("", true) &&
-      !CmtSystem::absolute_path (use->real_path))
-    {
-      use->change_path (m_cmtpath_pwd);
-    }
+  if (use->move_to ("", true))
+    {
+      if (use->get_realpath ().find (this->get_cmtpath_real ()) == 0)
+	use->set_project (this);
+    }
+  else
+    if (0 == CmtSystem::getenv ("CMTPEDANTIC").size () &&
+	0 == CmtSystem::getenv ("PEDANTIC").size ())
+      CmtMessage::warning
+	(CmtError::get_error_name (CmtError::configuration_error)
+	 + ": Cannot locate container: " + use->get_info ());
+    else
+      CmtError::set(CmtError::configuration_error,
+		    "Cannot locate container: " + use->get_info ());
+  
   CmtSystem::cd (m_cmtpath_pwd + CmtSystem::file_separator () + "cmt");
+
+  if (CmtError::get_last_error_code () == CmtError::configuration_error)
+    return;
 
   set_container_name (name);
Index: CMT/HEAD/source/cmt_project.h
===================================================================
--- CMT/HEAD/source/cmt_project.h	(revision 651)
+++ CMT/HEAD/source/cmt_project.h	(revision 652)
@@ -97,4 +97,5 @@
   typedef cmt_vector<Project> ProjectVector;
   typedef cmt_vector<Project*> ProjectPtrVector;
+  typedef cmt_vector<const Project*> ConstProjectPtrVector;
 
   static bool create (const cmt_string& name, 
@@ -120,5 +121,7 @@
   static const cmt_string& get_project_file_name ();
 
-  static void fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections);
+  static void fill_selection (int depth, ConstProjectPtrVector& path_selections);
+  //  static void fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections);
+  static void fill_exclusion (ConstProjectPtrVector& path_exclusions);
 
   static void broadcast (IProjectAction& action);
Index: CMT/HEAD/source/cmt_symbol.cxx
===================================================================
--- CMT/HEAD/source/cmt_symbol.cxx	(revision 651)
+++ CMT/HEAD/source/cmt_symbol.cxx	(revision 652)
@@ -1084,5 +1084,5 @@
 	   */
 	  if (name == "constituents") return;
-	  if (name == "constituentscclean") return;
+	  if (name == "constituentsclean") return;
 
           if (use->get_current_scope () == ScopePrivate) return;
Index: CMT/HEAD/source/cmt_syntax.cxx
===================================================================
--- CMT/HEAD/source/cmt_syntax.cxx	(revision 651)
+++ CMT/HEAD/source/cmt_syntax.cxx	(revision 652)
@@ -212,5 +212,5 @@
 	       int line_number)
   {
-        
+    /*        
     cmt_string cmtpath;
     cmt_string offset;
@@ -219,4 +219,7 @@
 
     Project* p = Project::find_by_cmtpath (cmtpath);
+    */
+    Project* p = const_cast<Project*>(use->get_project ());
+    //    const Project* p = use->get_project ();
 
     for (int i = 1; i < words.size (); i++)
@@ -1060,4 +1063,5 @@
 	       int line_number)
   {
+    /*
     cmt_string cmtpath;
     cmt_string offset;
@@ -1066,4 +1070,7 @@
 
     Project* p = Project::find_by_cmtpath (cmtpath);
+    */
+    Project* p = const_cast<Project*>(use->get_project ());
+    //    const Project* p = use->get_project ();
 
     for (int i = 1; i < words.size (); i++)
@@ -1164,4 +1171,5 @@
 	       int line_number)
   {
+    /*
     cmt_string cmtpath;
     cmt_string offset;
@@ -1170,4 +1178,7 @@
 
     Project* p = Project::find_by_cmtpath (cmtpath);
+    */
+    Project* p = const_cast<Project*>(use->get_project ());
+    //    const Project* p = use->get_project ();
 
     for (int i = 1; i < words.size (); i++)
@@ -1403,5 +1414,5 @@
       //
       
-      Project* p = use->get_project ();
+      const Project* p = use->get_project ();
       if (p != 0)
         {      
Index: CMT/HEAD/source/cmt_use.cxx
===================================================================
--- CMT/HEAD/source/cmt_use.cxx	(revision 651)
+++ CMT/HEAD/source/cmt_use.cxx	(revision 652)
@@ -1826,4 +1826,5 @@
   m_located = false;
   m_package = 0;
+  m_project = 0;
   m_index = -1;
 
@@ -1848,4 +1849,5 @@
       m_package = 0;
     }
+  m_project = 0;
 
   version   = "";
@@ -1923,5 +1925,5 @@
 
 //----------------------------------------------------------
-void Use::change_path (const cmt_string& new_path)
+void Use::change_path (const cmt_string& new_path, const Project* project)
 {
   // 
@@ -1929,9 +1931,18 @@
   // where this package/version has been found.
   //
+  if (Cmt::get_debug ())
+    {
+      cout << "|Use::change_path> path: " << new_path
+	   << ": project: " << (project ? project->get_cmtpath () : "0")
+	   << ": " << get_info () << endl;
+    }
 
   real_path = "";
   m_realpath = "";
 
-  if (new_path != "")
+  m_project = 0;
+
+  if (new_path.size () != 0)
+    //  if (new_path != "")
     {
       if ((path.size () > 0) &&
@@ -1951,6 +1962,7 @@
       if (!CmtSystem::realpath_ (real_path, m_realpath))
 	{
-	  CmtError::set (CmtError::file_access_error, "Cannot compute real path `" +
-			 real_path + "'");
+	  CmtError::set (CmtError::file_access_error,
+			 "Cannot compute real path `" + real_path + "': " +
+			 get_info ());
 	  CmtError::print ();
 	  return;
@@ -1958,5 +1970,15 @@
     }
   
+  if (project)
+    m_project = project;
+
   m_located = true;
+
+  if (Cmt::get_debug ())
+    {
+      cout << "<Use::change_path| real_path: " << real_path
+	   << ": m_project: " << (m_project ? m_project->get_cmtpath () : "0")
+	   << ": " << get_info () << endl;
+    }
 }
 
@@ -2347,5 +2369,5 @@
 	  }
 	
-	m_use->change_path (path);
+	m_use->change_path (path, &project);
 
 	m_found = true;
@@ -2355,5 +2377,5 @@
     else if (m_use->alternate_versions.size () > 0)
       {
-	if (m_use->select_alternate ()) 
+	if (m_use->select_alternate (&project)) 
 	  {
 	    if (Cmt::get_debug ())
@@ -2448,7 +2470,5 @@
               cout << "move_to2> " << expanded_path << endl;
             }
-
           change_path (here);
-
           return (true);
         }
@@ -2461,8 +2481,12 @@
                   cout << "move_to5> " << real_path << endl;
                 }
-              
               return (true);
             }
         }
+
+      if (!CmtSystem::cd (here))
+	{
+	  CmtError::set (CmtError::file_access_error, here);
+	}
       return (false);
 //     }
@@ -2482,5 +2506,5 @@
 
 //----------------------------------------------------------
-bool Use::select_alternate ()
+bool Use::select_alternate (const Project* project)
 {
   int i;
@@ -2567,5 +2591,5 @@
                 }
 
-              change_path (alternate_paths[selected_index]);
+              change_path (alternate_paths[selected_index], project);
               return (true);
             }
@@ -3568,10 +3592,19 @@
   offset = "";
 
-  cmtpath = m_realpath.size ()
-    ? Project::find_in_cmt_paths (m_realpath, true)
-    : Project::find_in_cmt_paths (real_path)
-    ;
-  const Project* p = Project::find_by_cmtpath (cmtpath);
-
+  const Project* p (0);
+  if (m_project)
+    {
+      p = m_project;
+      cmtpath = p->get_cmtpath ();
+    }
+  else
+    {
+      cmtpath = m_realpath.size ()
+	? Project::find_in_cmt_paths (m_realpath, true)
+	: Project::find_in_cmt_paths (real_path)
+	;
+      p = Project::find_by_cmtpath (cmtpath);
+  //  const Project* p = Project::find_by_cmtpath (cmtpath);
+    }
   //  if (cmtpath != "")
   if (p != 0)
@@ -3590,6 +3623,7 @@
       else if (!CmtSystem::realpath_ (real_path, offset))
 	{
-	  CmtError::set (CmtError::file_access_error, "Cannot compute real path `" +
-			 real_path + "'");
+	  CmtError::set (CmtError::file_access_error,
+			 "Cannot compute real path `" + real_path + "': " +
+			 get_info ());
 	  CmtError::print ();
 	  return;
@@ -3705,5 +3739,6 @@
   buffer += "\n";
 
-  if (located ())
+  if (m_located)
+    //  if (located ())
     {
       buffer += "macro ";
@@ -3725,5 +3760,4 @@
 	  buffer += package_name;
 	}
-      //      if (style != no_version_style)
       if (structuring_style == with_version_directory)
 	{
@@ -3764,5 +3798,7 @@
   buffer += "\n";
   
-  Project* p = Project::find_by_cmtpath (cmtpath);
+  const Project* p (m_project);
+  if (!p)
+    p = Project::find_by_cmtpath (cmtpath);
 
   buffer += "macro ";
@@ -4829,10 +4865,4 @@
 
   return (is_in_path);
-}
-
-//----------------------------------------------------------
-bool Use::located () const
-{
-  return (m_located);
 }
 
@@ -5736,6 +5766,15 @@
 
 //----------------------------------------------------------
-Project* Use::get_project ()
+const Project* Use::get_project () const
 {    
+  if (m_project)
+    return m_project;
+
+  cmt_string cmtpath = m_realpath.size ()
+    ? Project::find_in_cmt_paths (m_realpath, true)
+    : Project::find_in_cmt_paths (real_path)
+    ;
+  return Project::find_by_cmtpath (cmtpath);
+  /*
   Project* p;
   cmt_string cmtpath = "";
@@ -5744,4 +5783,5 @@
   p = Project::find_by_cmtpath (cmtpath);
   return p;   
+  */
 }
 
Index: CMT/HEAD/source/cmt_use.h
===================================================================
--- CMT/HEAD/source/cmt_use.h	(revision 651)
+++ CMT/HEAD/source/cmt_use.h	(revision 652)
@@ -128,7 +128,7 @@
   bool get_paths (Use* to, UsePtrVector& list);
 
-  bool located () const;
-
-  void change_path (const cmt_string& path);
+  inline bool located () const { return m_located; }
+
+  void change_path (const cmt_string& path, const Project* project = 0);
   void set_auto_imports (State context_state, State specified_state,
 			 cmt_map <Use*, bool>& visited);
@@ -153,5 +153,6 @@
   ScopeType get_current_scope () const;
 
-  Project* get_project ();
+  const Project* get_project () const;
+  inline void set_project (const Project* project) { m_project = project; }
   cmt_string get_info () const;
   bool is_head_version (const cmt_string& version);
@@ -182,5 +183,5 @@
   bool discarded;                /* discarded by version strategy   */
   bool selected;                 /* used for recursive access       */
-  bool m_located;
+  //  bool m_located;
   bool m_hidden;
   ScopeType initial_scope;
@@ -213,5 +214,5 @@
 		      bool skip_discarded = false, ostream& out = cout);
   //  void show_sub_uses (const cmt_string& request, bool skip_discarded = false);
-  bool select_alternate ();
+  bool select_alternate (const Project* project = 0);
   Use* get_selected_version ();
   Use* set_selected_version (Use* selected_use);
@@ -235,4 +236,9 @@
   //cmt_string m_package_name; /* directly read from requirements */
 
+  //  Project* m_project;  /* the project the use is found in */
+  const Project* m_project;  /* the project the use is found in */
+
+  bool m_located;
+
   bool m_has_native_version;
 
Index: CMT/HEAD/src/Makefile.header
===================================================================
--- CMT/HEAD/src/Makefile.header	(revision 651)
+++ CMT/HEAD/src/Makefile.header	(revision 652)
@@ -198,6 +198,6 @@
 	@echo
 ifndef BCAST_GLOBAL
-	@uses=`$(cmtexe) -private show macros '_project$$|package$$' -tag=$(tags)| \
-	  awk -F = '{if ($$1 ~ /_project$$/) {uses[substr($$1,1,length($$1)-8)]=$$2}else if ($$1 == "package") {cur = $$2;gsub("'\''","",cur)}}END{for (u in uses){if (uses[u]==uses[cur]) print u}}'`; \
+	@uses=`$(cmtexe) -private show macros '_project$$|package$$|_offset$$' -tag=$(tags)| \
+	  awk -F = '{if ($$1 ~ /_project$$/) {p = $$2;gsub("'\''","",p);uses[substr($$1,1,length($$1)-8)]=p} else if ($$1 == "package") {cur = $$2;gsub("'\''","",cur)}else if ($$1 ~ /_offset$$/) {u = substr($$1,1,length($$1)-7);if (!(u in uses))uses[u]=""}}END{for (u in uses){if ((uses[cur] != "" && uses[u] == uses[cur] || u == cur) && u != "CMT" && u != "CMTHOME" && u != "CMTUSERCONTEXT") print u}}'`; \
 	  for u in $${uses}; do \
 	    echo "$${u} : (re)build package $${u} ($(_groups))"; \
@@ -208,6 +208,6 @@
 	  done
 else
-	@uses=`$(cmtexe) -private show macros '_root$$' -tag=$(tags)| \
-	  awk -F = '{u=substr($$1,1,length($$1)-5);if (u != "CMT" && u != "CMTHOME" && u != "CMTUSERCONTEXT") print u}'`; \
+	@uses=`$(cmtexe) -private show macros '_project$$|package$$|_offset$$' -tag=$(tags)| \
+	  awk -F = '{if ($$1 ~ /_project$$/) {p = $$2;gsub("'\''","",p);uses[substr($$1,1,length($$1)-8)]=p} else if ($$1 == "package") {cur = $$2;gsub("'\''","",cur)}else if ($$1 ~ /_offset$$/) {u = substr($$1,1,length($$1)-7);if (!(u in uses))uses[u]=""}}END{for (u in uses){if (uses[u] != uses[cur] && (uses[u] == "CMTHOME" || uses[u] == "CMTUSERCONTEXT")) {continue} else if (u != "CMT" && u != "CMTHOME" && u != "CMTUSERCONTEXT") print u}}'`; \
 	  for u in $${uses}; do \
 	    echo "$${u} : (re)build package $${u} ($(_groups))"; \
