Index: CMT/HEAD/ChangeLog
===================================================================
--- CMT/HEAD/ChangeLog	(revision 661)
+++ CMT/HEAD/ChangeLog	(revision 662)
@@ -1,2 +1,29 @@
+2014-01-06    <rybkin@lal.in2p3.fr> 521
+
+	* source/cmt_tag.h: In class Tag, introduce static function apply_tag to
+	return map of tags and uses in which apply_tag statement appears for tag
+	* source/cmt_tag.cxx: In class Tag, in function action_apply update map of
+	tags and uses returned by function apply_tag, in function check_tag_used
+	return true if tag appears in apply_tag statement, in function
+	show_definition print uses in which apply_tag statement appears for tag
+	* source/cmt_map.h: In templated class cmt_vnode, remove const modifiers
+	for function find to allow for cmt_vnode value to be modified, in templated
+	class cmt_vmap, in function find remove const modifier for return value
+	to allow for cmt_vmap values to be modified
+	* source/cmt_parser.cxx: Implement helper function parse_cmt_flags to parse
+	-with(out)_cmt, -with(out)_projects, -(no)_strip_path flags from
+	requirements file, in class Cmt, modify function configure_current_package
+	to return location of requirements file if found, in function configure
+	make use of function parse_cmt_flags, do not read user requirements file(s)
+	for action_none
+	* source/cmt_symbol.cxx: In class PathBuilder, introduce static function
+	get_path_builder to return unique class instance, make assignment operator
+	and copy constructor private to forbid copying, make other constructors
+	private, in class Symbol functions create and set_strip_path make use of
+	function get_path_builder
+	* source/cmt.h: In class Cmt, modify function configure_current_package
+	signature
+	* mgr/requirements: Associate CMTv1 tag with with HEAD
+	
 2013-12-13    <rybkin@lal.in2p3.fr> 520
 
Index: CMT/HEAD/mgr/requirements
===================================================================
--- CMT/HEAD/mgr/requirements	(revision 661)
+++ CMT/HEAD/mgr/requirements	(revision 662)
@@ -8,4 +8,5 @@
 tag CMTr0  CMTr25
 
+tag CMTv0  CMTv1
 #
 #  Automatic detection of some system features.
Index: CMT/HEAD/source/cmt.h
===================================================================
--- CMT/HEAD/source/cmt.h	(revision 661)
+++ CMT/HEAD/source/cmt.h	(revision 662)
@@ -106,5 +106,6 @@
   static void configure_current_cmtpath ();
   static void configure_current_dir ();
-  static void configure_current_package ();
+  static cmt_string configure_current_package ();
+  //  static void configure_current_package ();
   //  static void configure_current_structuring_style ();
   static void configure_current_structuring_style (const ArgParser& ap);
Index: CMT/HEAD/source/cmt_map.h
===================================================================
--- CMT/HEAD/source/cmt_map.h	(revision 661)
+++ CMT/HEAD/source/cmt_map.h	(revision 662)
@@ -276,5 +276,6 @@
    *   Return 0 if not found
    */
-  const T* find (const K& key) const
+  T* find (const K& key)
+    //  const T* find (const K& key) const
   {
     if (key < m_key)
@@ -504,5 +505,6 @@
    *   Returns 0 if not found
    */
-  const T* find (const K& key) const
+  T* find (const K& key) const
+    //  const T* find (const K& key) const
   {
     if (m_top != 0)
Index: CMT/HEAD/source/cmt_parser.cxx
===================================================================
--- CMT/HEAD/source/cmt_parser.cxx	(revision 661)
+++ CMT/HEAD/source/cmt_parser.cxx	(revision 662)
@@ -557,4 +557,54 @@
 
 //----------------------------------------------------------
+namespace {
+
+bool parse_cmt_flags (const cmt_string& file_name, CmtContext& cmt)
+{
+  cmt_string Flags (Cmt::get_cmt_flags (file_name));
+  if (CmtError::get_last_error_code () == CmtError::file_access_error)
+    return false;
+  if (Flags.size () == 0)
+    return true;
+
+  cmt_string CmtFlags (Cmt::get_cmt_flags ());
+  if (CmtFlags.size () != 0)
+    Flags += " " + CmtFlags;
+
+  CmtSystem::cmt_string_vector flags;
+  CmtSystem::split (Flags, " \t", flags);
+  for (int i = 0; i < flags.size (); i++)
+    {
+      if (flags[i] == "-without_cmt" &&
+	  cmt.m_use_cmt)
+	cmt.m_use_cmt = false;
+      else if (flags[i] == "-with_cmt" &&
+	       !cmt.m_use_cmt)
+	cmt.m_use_cmt = true;
+      else if (flags[i] == "-without_projects" &&
+	       cmt.m_use_projects)
+	cmt.m_use_projects = false;
+      else if (flags[i] == "-with_projects" &&
+	       !cmt.m_use_projects)
+	cmt.m_use_projects = true;
+      else if (flags[i] == "-no_strip_path" &&
+	       cmt.m_strip_path)
+	{
+	  cmt.m_strip_path = false;
+	  Symbol::set_strip_path (false);
+	}
+      else if (flags[i] == "-strip_path" &&
+	       !cmt.m_strip_path)
+	{
+	  cmt.m_strip_path = true;
+	  Symbol::set_strip_path (true);
+	}
+    }
+
+  return true;
+}
+
+}
+
+//----------------------------------------------------------
 //void Cmt::configure ()
 void Cmt::configure (const ArgParser& ap)
@@ -587,7 +637,10 @@
   configure_site_tag (0);
 
+  cmt_string requirements;
+
   if (Me.m_current_package.size () != 0 &&
       Me.m_current_package != "cmt_standalone")
-    { // we have a package name (not "cmt_standalone")
+    {
+      // we have a package name (not "cmt_standalone")
       Use& use = Use::current();
       use.set (Me.m_current_package, 
@@ -609,4 +662,10 @@
 	    }
 	}
+
+      if (use.located ())
+	{
+	  // parse additional options
+	  parse_cmt_flags ("requirements", m_cmt_context);
+	}
     }
   else
@@ -617,4 +676,15 @@
 	  CmtError::set (CmtError::path_not_found, Me.m_current_path);
 	  return;
+	}
+
+      configure_current_dir ();
+      configure_current_structuring_style (ap);
+      cmt_string current_package_saved (Me.m_current_package);
+      requirements = configure_current_package ();
+      Me.m_current_package = current_package_saved;
+      if (requirements.size () != 0)
+	{
+	  // parse additional options
+	  parse_cmt_flags (requirements, m_cmt_context);
 	}
     }
@@ -679,6 +749,9 @@
   configure_current_structuring_style (ap);
 
+//   if (requirements.size () == 0)
+//     {
   log << "configure_current_package" << log_endl;
   configure_current_package ();
+//     }
 
   Use& use = Use::current();
@@ -866,4 +939,6 @@
 void Cmt::configure_current_dir ()
 {
+  if (Me.m_current_dir.size () != 0) return;
+
   cmt_string file_name;
 
@@ -927,5 +1002,6 @@
 
 //----------------------------------------------------------
-void Cmt::configure_current_package ()
+cmt_string Cmt::configure_current_package ()
+//void Cmt::configure_current_package ()
 {
   /*
@@ -941,5 +1017,23 @@
       build_prefix (Me.m_current_package, Me.m_current_prefix);
       build_config (Me.m_current_prefix, Me.m_current_config);
-      return;
+
+      cmt_string req;
+      use.get_full_path (req);
+      switch (use.style)
+	{
+	case cmt_style:
+	  req += CmtSystem::file_separator ();
+	  req += "cmt";
+	  break;
+	case mgr_style:
+	  req += CmtSystem::file_separator ();
+	  req += "mgr";
+	  break;
+	default:
+	  break;
+	}
+      req += CmtSystem::file_separator ();
+      req += "requirements";
+      return req;
     }
 
@@ -956,5 +1050,6 @@
   else
     {
-      cmt_string req = "..";
+      req = "..";
+      //      cmt_string req = "..";
       req += CmtSystem::file_separator ();
       req += "mgr";
@@ -970,4 +1065,9 @@
 	  // This package is probably a standalone one
 	  Me.m_current_style = none_style;
+	  req = "requirements";
+	  if (!CmtSystem::test_file (req))
+	    {
+	      req = "";
+	    }
 	}
     }
@@ -1210,4 +1310,6 @@
       build_config (Me.m_current_prefix, Me.m_current_config);
     }
+
+  return req;
 }
 
@@ -6943,5 +7045,4 @@
     default:
       configure (ap);
-      //restore_all_tags (0);
       break;
     }
@@ -7275,5 +7376,5 @@
   switch (Me.m_action)
     {
-    case action_none :
+      //case action_none :
     case action_awk :
     case action_broadcast :
Index: CMT/HEAD/source/cmt_symbol.cxx
===================================================================
--- CMT/HEAD/source/cmt_symbol.cxx	(revision 661)
+++ CMT/HEAD/source/cmt_symbol.cxx	(revision 662)
@@ -53,8 +53,12 @@
   inline void set_strip_path (const bool& strip_path);
 
+  static PathBuilder* get_path_builder ();
+
+private:
   PathBuilder ();
   PathBuilder (bool strip_path);
-
-private:
+  PathBuilder (const PathBuilder& other);
+  PathBuilder& operator = (const PathBuilder& other);
+
   bool m_strip_path;
 };
@@ -754,5 +758,6 @@
 {
   static SetBuilder Set;
-  static PathBuilder Path (Cmt::get_strip_path ());
+  static PathBuilder* PathPtr (PathBuilder::get_path_builder ());
+  //static PathBuilder Path (Cmt::get_strip_path ());
   //static PathBuilder Path;
   static MacroBuilder Macro;
@@ -915,5 +920,6 @@
       break;
     case SymbolPath:
-      symbol.builder = &Path;
+      symbol.builder = PathPtr;
+      //symbol.builder = &Path;
       break;
     case SymbolAlias:
@@ -1261,4 +1267,7 @@
 bool Symbol::set_strip_path (const bool& strip_path)
 {
+  PathBuilder::get_path_builder ()->set_strip_path (strip_path);
+  return true;
+  /*
   // searching for a path symbol
   for (int number = 0; number < Symbol::symbol_number (); number++)
@@ -1274,4 +1283,5 @@
 
   return false;
+  */
 }
 
@@ -2595,4 +2605,11 @@
 }
 */
+//-------------------------------------------------------------
+PathBuilder* PathBuilder::get_path_builder ()
+{
+  static PathBuilder Path (Cmt::get_strip_path ());
+  return &Path;
+}
+
 //-------------------------------------------------------------
 PathBuilder::PathBuilder ()
Index: CMT/HEAD/source/cmt_tag.cxx
===================================================================
--- CMT/HEAD/source/cmt_tag.cxx	(revision 661)
+++ CMT/HEAD/source/cmt_tag.cxx	(revision 662)
@@ -235,4 +235,27 @@
 
       tag->mark (use ? use->get_package_name () : "");
+
+      Use::UsePtrVector * puses;
+      if (!(puses = apply_tag ().find (tag)))
+	{
+	  Use::UsePtrVector uses;
+	  uses.push_back (use);
+	  apply_tag ().add (tag, uses);
+	}
+      else
+	{
+	  bool have (false);
+	  for (int i = 0; i < puses->size (); i++)
+	    {
+	      if ((*puses)[i] == use)
+		{
+		  have = true;
+		  break;
+		}
+	    }
+	  if (!have)
+	    puses->push_back (use);
+	}
+
     }
 }
@@ -607,6 +630,14 @@
   if (tag->m_tag_refs.size () > 0) return (true);
   if (tag->m_tag_excludes.size () > 0) return (true);
+  if (apply_tag ().has (tag)) return (true);
 
   return (false);
+}
+
+/*----------------------------------------------------------*/
+Tag::TagUses& Tag::apply_tag ()
+{
+  static TagUses tag_uses;
+  return tag_uses;
 }
 
@@ -827,4 +858,24 @@
 	  out << "]";
 	}
+
+      if (Use::UsePtrVector * puses = apply_tag ().find (this))
+	{
+	  out << " applied [";
+	  for (int i = 0; i < puses->size (); i++)
+	    {
+	      if (i > 0) out << " ";
+	      Use * use = (*puses)[i];
+	      if (use)
+		{
+		  out << use->get_package_name ();
+		}
+	      else
+		{
+		  out << "current";
+		}
+	    }
+	  out << "]";
+	}
+
       if (m_act_context.size () != 0 &&
 	  (m_def_use != 0 &&
Index: CMT/HEAD/source/cmt_tag.h
===================================================================
--- CMT/HEAD/source/cmt_tag.h	(revision 661)
+++ CMT/HEAD/source/cmt_tag.h	(revision 662)
@@ -20,4 +20,6 @@
   typedef cmt_vector<Tag*> TagPtrVector;
 
+  typedef cmt_vmap<const Tag*, Use::UsePtrVector> TagUses;
+
   static void action (const CmtSystem::cmt_string_vector& words, Use* use);
   static void action_apply (const CmtSystem::cmt_string_vector& words, Use* use);
@@ -40,4 +42,6 @@
 
   static bool check_tag_used (const Tag* tag);
+
+  static TagUses& apply_tag ();
 
 public:
