Index: CMT/v1r25-branch/ChangeLog
===================================================================
--- CMT/v1r25-branch/ChangeLog	(revision 646)
+++ CMT/v1r25-branch/ChangeLog	(revision 664)
@@ -1,2 +1,362 @@
+2014-01-10    <rybkin@lal.in2p3.fr> 522
+
+	* source/cmt_tag.cxx: Update authorship info
+	* source/cmt_std.h: idem
+	* source/cmt_awk.cxx: idem
+	* source/cmt_system.cxx: idem
+	* source/cmt_symbol.h: idem
+	* source/cmt_project.h: idem
+	* source/cmt_use.cxx: idem
+	* source/cmt_install_area.cxx: idem
+	* source/cmt_tag.h: idem
+	* source/cmt_deps_builder.cxx: idem
+	* source/cmt_fragment.cxx: idem
+	* source/cmt_generators.cxx: idem
+	* source/cmt_constituent.cxx: idem
+	* source/cmt.cxx: idem
+	* source/cmt_deps_builder.h: idem
+	* source/cmt_syntax.cxx: idem
+	* source/cmt_triggers.cxx: idem
+	* source/cmt_fragment.h: idem
+	* source/cmt_database.h: idem
+	* source/cmt_error.cxx: idem
+	* source/cmt_generators.h: idem
+	* source/cmt_model.cxx: idem
+	* source/cmt_commands.cxx: idem
+	* source/cmt_constituent.h: idem
+	* source/cmt_project.cxx: idem
+	* source/cmt_generator.h: idem
+	* source/cmt_pattern.cxx: idem
+	* source/cmt_error.h: idem
+	* source/cmt_regexp.h: idem
+	* source/cmt_parser.h: idem
+	* source/cmt_language.cxx: idem
+	* source/cmt_commands.h: idem
+	* source/cmt_lock.cxx: idem
+	* source/cmt_string.h: idem
+	* source/cmt_vcs.cxx: idem
+	* source/cmt_cmtpath_pattern.cxx: idem
+	* source/cmt_map.h: idem
+	* source/cmt_database.cxx: idem
+	* source/cmt_log.h: idem
+	* source/cmt_language.h: idem
+	* source/cmt_system.h: idem
+	* source/cmt_vcs.h: idem
+	* source/cmt_use.h: idem
+	* source/cmt_cmtpath_pattern.h: idem
+	* source/cmt_generator.cxx: idem
+	* source/cmt_regexp.cxx: idem
+	* source/cmt_cvs.cxx: idem
+	* source/cmt_parser.cxx: idem
+	* source/cmt_symbol.cxx: idem
+	* source/cmt.h: idem
+	* source/cmt_string.cxx: idem
+	* mgr/fragments/nmake/packages_header: idem
+	* mgr/fragments/packages_header: idem
+	* src/NMakefile.core: idem
+	* src/NMakefile.header: idem
+	* src/setup.tcsh: idem
+	* src/setup.zsh: idem
+	* src/Makefile.core: idem
+	* src/Makefile.header: idem
+
+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
+
+	* mgr/CMT.dtd: Correct CMT site URL
+	
+2013-12-13    <rybkin@lal.in2p3.fr> 519
+
+	* source/cmt_symbol.cxx: In class Symbol function action, fully resolve
+	setup, cleanup script path except for setup, cleanup shell script
+	generation, in function print_clean, use unalias command to remove alias
+	with Bourne syntax shell, in function print, fully resolve set value, do
+	not mangle set, path name in Xml mode
+	* source/cmt_parser.cxx: In class Cmt function print_context, do not mangle
+	use prefix in Xml mode
+	
+2013-12-11    <rybkin@lal.in2p3.fr> 518
+
+	* source/cmt_commands.cxx: In class ArgParser, functions
+	option(_no)_path_strip renamed option(_no)_strip_path, command line options
+	-(no_)path_strip renamed -(no_)strip_path
+	* source/cmt_commands.h: idem
+	* source/cmt_symbol.h: In class class Symbol, function set_path_strip
+	renamed set_strip_path
+	* source/cmt_symbol.cxx: In class PathBuilder, functions get/set_path_strip
+	renamed get/set_strip_path, member m_path_strip renamed m_strip_path
+	* source/cmt.h: In class CmtContext, member m_path_strip renamed
+	m_strip_path, in class Cmt, function get_path_strip renamed get_strip_path
+	* source/cmt_parser.cxx: In class Cmt function do_setup, use
+	-no_strip_path,	-strip_path option names, function get_strip_path, class
+	Symbol function	set_strip_path
+	
+2013-12-06    <rybkin@lal.in2p3.fr> 517
+
+	* source/cmt_deps_builder.cxx: In helper function in_line_action, fix
+	parsing in case neither quotes or comments are found
+	
+2013-12-05    <rybkin@lal.in2p3.fr> 516
+
+	* source/cmt_deps_builder.cxx: In helper function at_start_action, fix
+	parsing Fortran INCLUDE statement, optimise in_line_action helper function,
+	in helper function build_deps_text, fix parsing C++ style comments in case
+	without other characters
+	* source/cmt_parser.cxx: In class Cmt function do_broadcast, add package,
+	version, offset info to printout of "cmt broadcast" command, similar to
+	printout in CMTBCAST mode
+	
+2013-12-03    <rybkin@lal.in2p3.fr> 515
+
+	* source/cmt_symbol.h: In class SymbolValueList function print, class
+	Symbol functions all_print, print introduce optional argument of type
+	ostream	reference, in class Symbol, declare static functions std_env_vars,
+	set_path_strip
+	* source/cmt_symbol.cxx: In class PathBuilder, introduce and implement
+	functions filter_path_value, get/set_path_strip, constructor with
+	path_strip argument and member m_path_strip to indicate whether to strip
+	paths of non-existent directories, in unnamed namespace, introduce cache
+	of command outputs for use in functions resolve_value,
+	resolve_value_for_macros, suppress_OS_delimiters, in class Symbol function
+	create, create PathBuilder instance with configured value of path_strip,
+	in class Symbol, implement static functions std_env_vars, set_path_strip,
+	control access to environment in functions resolve_value, class Symbol
+	functions all_set, get_env_value, class SetBuilder function build, class
+	PathBuilder function build, systematically use class PathBuilder function
+	filter_path_value in class Symbol functions all_set, check_all_paths,
+	print, in class PathBuilder function build, in class SymbolValueList
+	function print, modify helper function find_path_entry so as not to access
+	file system and return index of entry found, in class PathBuilder function
+	build, make use of signature to enhance implementation of path_append /
+	prepend commands, drop redundant cleaning of repeating path separators, in
+	class SymbolValueList function print, implement enhanced cached
+	requirements file generation, i.e., resolve sets for macros if possible,
+	resolve paths fully if possible, so as to strip path of non-existent
+	directories, implement use of argument of type ostream reference
+	* source/cmt_use.cxx: In class Use function fill_standard_macros, generate
+	CONFIG macros, if CONFIG environment variables are relevant, in setup
+	Requirements mode
+	* source/cmt_error.cxx: Cosmetic modifications to error messages
+	* source/cmt_commands.h: In class ArgParser, declare functions
+	option_with(out)_projects, option(_no)_path_strip
+	* source/cmt_commands.cxx: In class ArgParser, implement introduced
+	functions
+	* source/cmt.h: In class CmtContext, introduce member m_use_projects to
+	indicate whether to parse project files, member m_env_access to indicate
+	whether symbols values can be taken from environment, member m_print_mode
+	to hold	corresponding value from class ArgParser instance, member
+	m_path_strip to indicate whether to strip paths of non-existent
+	directories, in class Cmt functions print, print_context introduce optional
+	argument of type ostream reference, declare and implement inline functions
+	get/set_env_access, get/set_print_mode, get_path_strip
+	* source/cmt_parser.cxx: In class Cmt function configure_cmt_path, do not
+	create projects if m_use_projects is false, in function do_broadcast, set
+	cmtpath for all uses so as to fill in templates correctly, in function
+	do_check_configuration, do not run class Symbol function check_all_paths
+	for setup unless in Requirements mode (since paths checks are done in class
+	Symbol function print), in function do_setup, implement procedure of cached
+	requirements file generation, i.e., do not access environment to set
+	symbols values and, by default, strip paths of non-existent directories if
+	possible, in function guess_current_project, return if projects are not
+	used, do not change m_autoconfigure_cmtpath value, in functions print,
+	print_context, implement use of argument of type ostream reference, in
+	function print_context, in Requirements mode, generate CONFIG sets if
+	CONFIG environment variables are relevant, in function
+	use_special_requirements, handle case when projects are not used
+	* mgr/requirements: Associate CMTr25 tag with HEAD, append CMT to PATH as
+	in CMT setup scripts
+	
+2013-11-13    <rybkin@lal.in2p3.fr> 514
+
+	* source/cmt_use.cxx: In class Use get_strategy function, make use of now
+	fast get_project function rather than compute, in fill_standard_macros,
+	get_package_name, get_project functions, simplify code
+	* source/cmt_parser.cxx: In class Cmt install_scripts functions, make
+	generated setup and cleanup scrips call CMT executable directly rather than
+	via shell script wrapper
+	* src/setup.sh: Reduce usage of external shell utilities by using POSIX
+	shell features instead
+	* src/cleanup.sh: idem, unset everything set by setup.sh
+	* src/setup.csh: Reduce usage of external shell utilities by using C shell
+	features instead
+	* src/cleanup.csh: idem, unset everything set by setup.csh
+	* src/cleanup.tcsh: Add script to unset TCSH specific environment setup
+	* src/cleanup.zsh: Add script to unset Z shell specific environment setup
+	* src/cleanup.bash: Add script to unset BASH specific environment setup
+	
+2013-11-08    <rybkin@lal.in2p3.fr> 513
+
+	* source/cmt.h: In class CmtContext, make assignment operator and copy
+	constructor private to forbid copying, in class Cmt, inline simple member
+	functions for speed-up, add static member to hold reference to CmtContext
+	instance
+	* source/cmt_parser.cxx: Initialize static class Cmt member, comment out
+	inlined class Cmt methods implementation
+	
+2013-11-07    <rybkin@lal.in2p3.fr> 512
+
+	* source/cmt_tag.cxx: In class Tag mark function, do not activate tag if
+	in list of tags to remove, making -tag_remove=<tag-list> option functional
+	on any tags (rather than only those specified on the command line or in
+	CMTEXTRATAGS environment variable)
+	* source/cmt_syntax.cxx: In classes KwdBuildStrategy, KwdSetupStrategy,
+	KwdStructureStrategy action project function, make error description
+	detailed, in class SyntaxParser do_parse_words project function, print
+	error message in case of syntax error encountered in value
+	* source/cmt_parser.cxx: In class CmtContext, factor out processing of
+	CMTEXTRATAGS environment variable value into separate initialize function,
+	in class Cmt, move restore_all_tags call into configure function before all
+	system tags handling to make all initially known tags available while
+	reading project files, implement get_tags_remove function, in parser
+	function initialise static CmtContext instance at very beginning
+	* source/cmt.h: In class Cmt, declare get_tags_remove function
+	
+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
+
+	* mgr/cmt-make-time-sub-mem-io.awk: Add script to profile CMT commands
+	utilisation in the Makefiles
+
+2013-07-31    <rybkin@lal.in2p3.fr> 509
+
+	* mgr/cmt_svn_checkout.py: Add support for devbranches directory -
+	additional branches location - in Subversion repository.
+
+2013-07-10    <rybkin@lal.in2p3.fr> 508
+
+	* source/cmt_commands.cxx: In class ArgParser function option_use, make
+	-use=<package>:<version>:<path> option fully functional with standard use
+	statement syntax, in function option_path, make -path=<path> option
+	functional for relative <path> as with standard use statement syntax
+	* source/cmt_parser.cxx: In class Cmt functions reach_current_package,
+	use_extra_file make diagnostic message more informative
+
+2013-07-09    <rybkin@lal.in2p3.fr> 507
+
+	* mgr/cmt_svn_checkout.py: Use a different algorithm in the class Checkout
+	function trunk_tag in order to optimise the performance, suggested by
+	Wim Lavrijsen. Add --debug command line option and SVNDEBUG environment
+	variable to facilitate debugging
+
+2013-06-25    <rybkin@lal.in2p3.fr> 506
+
+	* mgr/fragments/application: Test use_stamps variable for a non-empty value
+	since POSIX requires a non-null list of targets in rules
+
 2013-06-24    <rybkin@lal.in2p3.fr> 505
 
Index: CMT/v1r25-branch/mgr/CMT.dtd
===================================================================
--- CMT/v1r25-branch/mgr/CMT.dtd	(revision 646)
+++ CMT/v1r25-branch/mgr/CMT.dtd	(revision 664)
@@ -1,3 +1,3 @@
-<!ENTITY  % cmtns   "xmlns CDATA #FIXED 'http://www.cmtsite.org/cmt'">
+<!ENTITY  % cmtns   "xmlns CDATA #FIXED 'http://www.cmtsite.net/cmt'">
 <!ATTLIST setup     %cmtns;>
 <!ATTLIST projects  %cmtns;>
Index: CMT/v1r25-branch/mgr/cmt-make-time-sub-mem-io.awk
===================================================================
--- CMT/v1r25-branch/mgr/cmt-make-time-sub-mem-io.awk	(revision 664)
+++ CMT/v1r25-branch/mgr/cmt-make-time-sub-mem-io.awk	(revision 664)
@@ -0,0 +1,105 @@
+#! /usr/bin/awk -f
+#
+# Profile CMT commands utilisation in the Makefiles
+#
+# Usage:
+#
+# export VERBOSE=1
+# export TIME="%U user %S system %e elapsed %P CPU %C (%Xtext+%Ddata %Mmax)k %Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps %cswitch %wswitch voluntarily"
+# 
+# \time cmt br make -j1 cmtexe="'\time ${CMTROOT}/${CMTBIN}/cmt.exe'" >&cmt-br-make-time.log&
+# OR
+# \time cmt br make -j1 cmtexe="'\time ${CMTROOT}/${CMTBIN}/cmt.exe'" cpp="'\time c++'" cc="'\time cc'" make_shlib="'\time ${CMTROOT}/mgr/cmt_make_shlib_common.sh extract'" >&cmt-br-make-time.log&
+#
+# ./cmt-make-time-sub-mem-io.awk cmt-br-make-time.log
+#
+$2 == "user" && $4 == "system" && $6 == "elapsed" {
+#if ($9 == "g++") {
+  if ($9 ~ /([gc]\+\+|g?cc)$/) {
+    gxx_u += $1; gxx_s += $3; gxx_e += $5; gxx_i += 1
+    if ($0 ~ /-MM/) {
+      dep_u += $1; dep_s += $3; dep_e += $5; dep_i += 1
+    }
+  }
+  else if ($9 ~ /cmt_make_shlib_common\.sh$/) {
+    make_shlib_u += $1; make_shlib_s += $3; make_shlib_e += $5; make_shlib_i += 1
+  }
+  else if ($9 ~ /\/CMT\/(v[[:digit:]]+(r[[:digit:]]+)?(p[[:digit:]]+)?)|HEAD\//) {
+    cmt_tot_u += $1; cmt_tot_s += $3; cmt_tot_e += $5; cmt_tot_i += 1
+    if ($0 ~ /-f=.+/) fast=1
+    else fast=0
+    for (i=10; i<=NF; i++) {
+      if ($i ~ /-.+/) continue
+      k=$i" "$(i+1)
+      if (fast == 1) {
+	cmt_f_u[k] += $1; cmt_f_s[k] += $3; cmt_f_e[k] += $5; cmt_f_i[k] += 1
+      }
+      else {
+	cmt_u[k] += $1; cmt_s[k] += $3; cmt_e[k] += $5; cmt_i[k] += 1
+      }
+      break
+    }
+# Maximum resident set size of the process during its lifetime, in Kilobytes
+    _rss_max = $(NF - 6)
+    sub("max)k", "", _rss_max)
+    rss_max += _rss_max
+    rss_max_i += 1
+
+    _major = gensub(/\(([[:digit:]]+)major\+([[:digit:]]+)minor\)pagefaults/, "\\1", "1", $(NF - 4))
+    _minor = gensub(/\(([[:digit:]]+)major\+([[:digit:]]+)minor\)pagefaults/, "\\2", "1", $(NF - 4))
+    major_pf += _major
+    minor_pf += _minor
+
+    cswitch += gensub(/([[:digit:]]+)switch/, "\\1", "1", $(NF - 2))
+    wswitch += gensub(/([[:digit:]]+)switch/, "\\1", "1", $(NF - 1))
+  }
+#  else
+#    print "Ignoring command: "$9
+}
+function prec (val)
+{
+  if (val >= 100) return 0
+  else if (val >= 10) return 1
+  else return 2
+}
+END {
+  printf "\nFile(s):"
+  for (i = 1; i < ARGC; i++) {
+    if (ARGV[i] ~ /^(_|[[:alpha:]])_*[[:alpha:]]*[[:digit:]]*=/) continue
+    printf " %s", ARGV[i]
+  }
+  printf "\n"
+
+  if (make_shlib_i != 0)
+    printf "cmt_make_shlib_common.sh[%d]: %.*f user %.*f system %.*f elapsed\n"	\
+      , make_shlib_i, prec(make_shlib_u), make_shlib_u, prec(make_shlib_s), make_shlib_s, prec(make_shlib_e), make_shlib_e
+  if (gxx_i != 0)
+    printf "c++/cc[%d]: %.*f user %.*f system %.*f elapsed\n"	\
+      , gxx_i, prec(gxx_u), gxx_u, prec(gxx_s), gxx_s, prec(gxx_e), gxx_e
+  if (dep_i != 0)
+    printf "dep[%d]: %.*f user %.*f system %.*f elapsed\n"	\
+      , dep_i, prec(dep_u), dep_u, prec(dep_s), dep_s, prec(dep_e), dep_e
+  printf "cmt[%d]: %.*f user %.*f system %.*f elapsed\n"	\
+    , cmt_tot_i, prec(cmt_tot_u), cmt_tot_u, prec(cmt_tot_s), cmt_tot_s, prec(cmt_tot_e), cmt_tot_e
+  printf "average rss_max: %.0fk\npage faults: %d major + %d minor\ncontext switch: %d involuntarily + %d voluntarily\n" \
+    , (rss_max_i != 0 ? rss_max/rss_max_i : 0), major_pf, minor_pf, cswitch, wswitch
+  print "Breakdown:"
+  for (n in cmt_f_i) {
+    printf "cmt fast [%s] [%d]: %.*f user %.*f system %.*f elapsed\n"	\
+      , n, cmt_f_i[n], prec(cmt_f_u[n]), cmt_f_u[n], prec(cmt_f_s[n]), cmt_f_s[n], prec(cmt_f_e[n]), cmt_f_e[n]
+    f_i += cmt_f_i[n]; f_u += cmt_f_u[n]; f_s += cmt_f_s[n]; f_e += cmt_f_e[n]
+  }
+  printf "cmt fast [%d]: %.*f user %.*f system %.*f elapsed\n"	\
+    , f_i, prec(f_u), f_u, prec(f_s), f_s, prec(f_e), f_e
+  i=0
+  for (n in cmt_i) {
+    printf "cmt [%s] [%d]: %.*f user %.*f system %.*f elapsed\n"	\
+      , n, cmt_i[n], prec(cmt_u[n]), cmt_u[n], prec(cmt_s[n]), cmt_s[n], prec(cmt_e[n]), cmt_e[n]
+    i += cmt_i[n]; u += cmt_u[n]; s += cmt_s[n]; e += cmt_e[n]
+  }
+  printf "cmt [%d]: %.*f user %.*f system %.*f elapsed\n"	\
+    , i, prec(u), u, prec(s), s, prec(e), e
+
+  if ($0 != "")
+    printf "\n%s\n", $0
+}
Index: CMT/v1r25-branch/mgr/cmt_svn_checkout.py
===================================================================
--- CMT/v1r25-branch/mgr/cmt_svn_checkout.py	(revision 646)
+++ CMT/v1r25-branch/mgr/cmt_svn_checkout.py	(revision 664)
@@ -15,14 +15,15 @@
       --with_version_directory create version directory upon PATH checkout (default)
       --url=URL                checkout PATH from repository URL
+      --debug                  print lots of debugging information
   -h, --help                   display this help and exit
       --version                output version information and exit
 
-The SVNROOT, SVNTRUNK, SVNTAGS, and SVNBRANCHES environment variables specify repository URL of PATH, location of PATH trunk, tags, and branches (relatively to PATH) respectively.
+The SVNROOT, SVNTRUNK, SVNTAGS, and SVNBRANCHES (also SVNDEVBRANCHES) environment variables specify repository URL of PATH, location of PATH trunk, tags, and branches (also devbranches) (relatively to PATH) respectively.
 
 Report bugs to <CMT-L@IN2P3.FR>.
 """
 
-__version__ = '0.6.0'
-__date__ = 'Fri Mar 09 2012'
+__version__ = '0.8.0'
+__date__ = 'Wed Jul 31 2013'
 __author__ = 'Grigory Rybkin'
 
@@ -40,4 +41,6 @@
 import tempfile
 import re
+
+import logging
 
 self = 'cmt_svn_checkout.py'
@@ -298,4 +301,5 @@
                  tags = None,
                  branches = None,
+                 devbranches = None,
                  version = None,
                  version_dir = None,
@@ -307,4 +311,5 @@
         self.tags = tags
         self.branches = branches
+        self.devbranches = devbranches
         self.version = version
         self.version_dir = version_dir
@@ -327,4 +332,6 @@
         if self.branches is None:
             self.branches = os.getenv('SVNBRANCHES', 'branches')
+        if self.devbranches is None:
+            self.devbranches = os.getenv('SVNDEVBRANCHES', 'devbranches')
 
     def cmtRepos(self):
@@ -333,4 +340,5 @@
         self.tags= '.'
         self.branches = '.'
+        self.devbranches = '.'
 
     def add(self, module):
@@ -378,48 +386,152 @@
         """Attempt to determine the tag of the module's trunk.
         
-        Return the tag if its contents are the same as those of the trunk, and
-        its last_changed_rev is greater than the trunk created_rev, None otherwise.
+        Return the tag if its files are copied from the trunk and
+        their last_changed_rev numbers are the same as those of the trunk files.
         """
         trunk = posixpath.join(module.url, self.trunk)
 #        trunk = posixpath.normpath(posixpath.join(module.url, self.trunk))
+        cmd = 'svn ls -vR %s' % trunk
+        sc, out = Utils.getstatusoutput(cmd)
+        logger.debug('%s\n%s' % (cmd, out))
+        if sc != 0:
+            return None
+        trunk_dirent = [line.split() for line in out.splitlines()]
+        trunk_revs = dict([(line[-1], int(line[0])) for line in trunk_dirent if not line[-1].endswith(posixpath.sep)])
+        logger.debug('%s' % trunk_revs)
+
+        curdir = posixpath.curdir + posixpath.sep
+        for line in trunk_dirent:
+            if line[-1] == curdir:
+                class info(object): pass
+                info.last_changed_rev = int(line[0])
+                self.info_receiver(trunk, info, module)
+                logger.debug('last_changed_rev: %d' % info.last_changed_rev)
+                break
+
+#        cmd = 'svn info %s' % trunk
+#         p = r'last\s+changed\s+rev:\s+(?P<rev>\d+)'
+#         m = re.search(p, out, re.I)
+#         if m:
+#             class info(object): pass
+#             info.last_changed_rev = int(m.group('rev'))
+#             self.info_receiver(trunk, info, module)
+# #            self.info_receiver(trunk, info, None)
+# #             print >>sys.stderr, '%s: last_changed_rev %i' % \
+# #                   (trunk, self.info.last_changed_rev)
+# #            last_changed_rev = int(m.group('rev'))
+#         else:
+#             return None
+
+        tags = posixpath.join(module.url, self.tags)
+#        tags = posixpath.normpath(posixpath.join(module.url, self.tags))
+        cmd = 'svn ls -vR %s' % tags
+#        cmd = 'svn ls -v %s' % tags
+        sc, out = Utils.getstatusoutput(cmd)
+        logger.debug('%s\n%s' % (cmd, out))
+        if sc != 0:
+            return None
+        tags_dirent = [line.split() for line in out.splitlines()]
+        tags_revs = dict()
+        for ent in tags_dirent:
+            try:
+                tag, path = ent[-1].split(posixpath.sep, 1)
+            except ValueError:
+                continue
+            if tag not in tags_revs:
+                tags_revs[tag] = dict()
+            if path and not path.endswith(posixpath.sep):
+                # assume there are no empty directories in the tag
+                tags_revs[tag][path] = int(ent[0])
+        logger.debug('%s' % tags_revs)
+
         cmd = 'svn info %s' % trunk
         sc, out = Utils.getstatusoutput(cmd)
+        logger.debug('%s\n%s' % (cmd, out))
         if sc != 0:
             return None
-        p = r'last\s+changed\s+rev:\s+(?P<rev>\d+)'
+        p = r'repository\s+root:\s+(?P<root>%s://\S+)' % \
+            ('(?:' + '|'.join(map(re.escape, client_context.schemes)) + ')')
         m = re.search(p, out, re.I)
+        logger.debug('pattern: %r' % (p))
         if m:
-            class info(object): pass
-            info.last_changed_rev = int(m.group('rev'))
-            self.info_receiver(trunk, info, module)
-#            self.info_receiver(trunk, info, None)
-#             print >>sys.stderr, '%s: last_changed_rev %i' % \
-#                   (trunk, self.info.last_changed_rev)
-#            last_changed_rev = int(m.group('rev'))
+            root = m.group('root')
         else:
             return None
-
-        tags = posixpath.join(module.url, self.tags)
-#        tags = posixpath.normpath(posixpath.join(module.url, self.tags))
-        cmd = 'svn ls -v %s' % tags
+        logger.debug('root: %s' % root)
+        trunk_path = trunk[len(root):]
+        tags_path = tags[len(root):]
+        logger.debug('trunk_path: %s' % trunk_path)
+        logger.debug('tags_path: %s' % tags_path)
+        offset = len(trunk) - len(root) + len(posixpath.sep)
+        
+        # Usually, a tag is created as a server-side copy.
+        # Sometimes, a tag is created as a copy of WC (working copy)
+        # after commit.
+        # Below, we try to take into account the latter case.
+        cmd = 'svn log -v -q %s' % tags
         sc, out = Utils.getstatusoutput(cmd)
+        logger.debug('%s\n%s' % (cmd, out))
         if sc != 0:
             return None
-
-        tags_dirent = [line.split() for line in out.splitlines()]
-        rev_tag = dict([(int(line[0]), line[-1].rstrip(posixpath.sep)) for line in tags_dirent if line[-1].endswith(posixpath.sep)])
-        revs = rev_tag.keys()
-        revs.sort()
-        revs.reverse()
-
-        for rev in revs:
-            if rev < self.info.last_changed_rev: break
-#            if rev < last_changed_rev: break
-            tag = posixpath.join(tags, rev_tag[rev])
-#            tag = posixpath.normpath(posixpath.join(tags, rev_tag[rev]))
-            if 0 == self.cmp(trunk, tag, client_context):
-                return rev_tag[rev]
+        p = re.compile(
+            r'^-{5,}$\s^r\d+.+$\s^Changed paths:$\s^\s+A\s+%s%s(?P<tag>[^%s]+)\s+\(from %s:\d+\)$(?P<replaced>(?:\s^\s+(?:R|A|D)\s+%s%s(?P=tag)%s(?P<path>.+)(?:\s+\(from %s%s(?P=path):\d+\))?$)*)' % (re.escape(tags_path), posixpath.sep, posixpath.sep, re.escape(trunk_path), re.escape(tags_path), posixpath.sep, posixpath.sep, re.escape(trunk_path), posixpath.sep)
+            , re.M
+            )
+        tags_copied = list()
+        tags_replaced_revs = dict()
+        for m in p.finditer(out):
+            logger.debug('tag: %s replaced: %r' % (m.group('tag'), m.group('replaced')))
+            tags_copied.append(m.group('tag'))
+            for line in m.group('replaced').strip().splitlines():
+                l = line.split()
+                if len(l) == 2: continue # action code D - deleted paths
+                repl = l[3].rstrip(')')
+                i = repl.rindex(':')
+                path = repl[offset:i]
+                rev = int(repl[i + 1:])
+                logger.debug('path: %s rev: %d' % (path, rev))
+
+                if m.group('tag') not in tags_replaced_revs:
+                    tags_replaced_revs[m.group('tag')] = dict()
+                if path and not path.endswith(posixpath.sep):
+                    # assume there are no empty directories in the tag
+                    tags_replaced_revs[m.group('tag')][path] = rev
+
+        logger.debug('copied: %s' % tags_copied)
+        logger.debug('replaced: %s' % tags_replaced_revs)
+
+        for t in tags_revs.keys():
+            if t not in tags_copied:
+                del tags_revs[t]
+                logger.debug('%s: Not a trunk copy' % t)
+
+        for t in tags_replaced_revs:
+            if t in tags_revs:
+                tags_revs[t].update(tags_replaced_revs[t])
+                
+        for tag in tags_revs:
+            logger.debug('Compare: %s -> %s' % (tag, tags_revs[tag]))
+            if trunk_revs == tags_revs[tag]:
+                return tag
 
         return None
+
+#         tags_dirent = [line.split() for line in out.splitlines()]
+#         rev_tag = dict([(int(line[0]), line[-1].rstrip(posixpath.sep)) for line in tags_dirent if line[-1].endswith(posixpath.sep)])
+#         revs = rev_tag.keys()
+#         revs.sort()
+#         revs.reverse()
+
+#         for rev in revs:
+#             logger.debug('rev: %s' % rev)
+#             if rev < self.info.last_changed_rev: break
+# #            if rev < last_changed_rev: break
+#             tag = posixpath.join(tags, rev_tag[rev])
+# #            tag = posixpath.normpath(posixpath.join(tags, rev_tag[rev]))
+#             logger.debug('comparing: %s %s(%d)' % (trunk, tag, rev))
+#             if 0 == self.cmp(trunk, tag, client_context):
+#                 return rev_tag[rev]
+
+#         return None
 
 #         try:
@@ -496,5 +608,5 @@
             else:
                 m.URL = [posixpath.join(m.url, p, m.version)
-                         for p in (self.tags, self.branches)]
+                         for p in (self.tags, self.branches, self.devbranches)]
             m.URL = [client_context.svn_path_canonicalize(url) for url in m.URL]
 #            m.URL = [core.svn_path_canonicalize(url) for url in m.URL]
@@ -572,9 +684,16 @@
                                     "offset=", "no_config",
                                     "with_version_directory",
-                                    "without_version_directory", "url="])
+                                    "without_version_directory", "url=", "debug"])
     except getopt.error, e:
         print >>sys.stderr, '%s: %s' % (self, str(e))
         print >>sys.stderr, "Try '%s --help' for more information." % self
         return 1
+
+    global logger
+    logging.basicConfig()
+    logger = logging.getLogger(self)
+    logger.setLevel(logging.INFO)
+    if os.getenv('SVNDEBUG'):
+        logger.setLevel(logging.DEBUG)
 
     cmt_context = CmtContext()
@@ -605,4 +724,6 @@
         elif o in ("--url",):
             checkout.url = v
+        elif o in ("--debug",):
+            logger.setLevel(logging.DEBUG)
 
     if not args:
Index: CMT/v1r25-branch/mgr/fragments/application
===================================================================
--- CMT/v1r25-branch/mgr/fragments/application	(revision 646)
+++ CMT/v1r25-branch/mgr/fragments/application	(revision 664)
@@ -5,5 +5,5 @@
 	$(link_silent) ${LINKMACRO} -o $(@).new ${OBJS} $(cmt_installarea_linkopts) $(${CONSTITUENT}_use_linkopts) $(${CONSTITUENT}linkopts) && mv -f $(@).new $(@)
 
-ifdef use_stamps
+ifneq ($(strip $(use_stamps)),)
 # Work around Make errors if stamps files do not exist
 $(use_stamps) :
Index: CMT/v1r25-branch/mgr/fragments/nmake/package
===================================================================
--- CMT/v1r25-branch/mgr/fragments/nmake/package	(revision 646)
+++ CMT/v1r25-branch/mgr/fragments/nmake/package	(revision 664)
@@ -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/v1r25-branch/mgr/fragments/nmake/packages_header
===================================================================
--- CMT/v1r25-branch/mgr/fragments/nmake/packages_header	(revision 646)
+++ CMT/v1r25-branch/mgr/fragments/nmake/packages_header	(revision 664)
@@ -27,5 +27,5 @@
 #    ignore: try all the groups even if one fails before going to the next package
 #            (may result in duplicated errors within a package)
-# Unix version taken from https://svnweb.cern.ch/trac/gaudi/browser/Gaudi/trunk/Makefile.cmt (Modified)
+# Unix version taken from https://svnweb.cern.ch/trac/gaudi/browser/Gaudi/trunk/Makefile.cmt (Modified by Grigory Rybkin)
 Package_failure_handler = || exit
 !if "$(PACKAGE_FAILURE_POLICY)" != ""
Index: CMT/v1r25-branch/mgr/fragments/package
===================================================================
--- CMT/v1r25-branch/mgr/fragments/package	(revision 646)
+++ CMT/v1r25-branch/mgr/fragments/package	(revision 664)
@@ -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/v1r25-branch/mgr/fragments/packages_header
===================================================================
--- CMT/v1r25-branch/mgr/fragments/packages_header	(revision 646)
+++ CMT/v1r25-branch/mgr/fragments/packages_header	(revision 664)
@@ -42,5 +42,5 @@
 #    ignore: try all the groups even if one fails before going to the next package
 #            (may result in duplicated errors within a package)
-# Taken from https://svnweb.cern.ch/trac/gaudi/browser/Gaudi/trunk/Makefile.cmt (Modified)
+# Taken from https://svnweb.cern.ch/trac/gaudi/browser/Gaudi/trunk/Makefile.cmt (Modified by Grigory Rybkin)
 Package_failure_handler = || exit
 ifdef PACKAGE_FAILURE_POLICY
Index: CMT/v1r25-branch/mgr/requirements
===================================================================
--- CMT/v1r25-branch/mgr/requirements	(revision 646)
+++ CMT/v1r25-branch/mgr/requirements	(revision 664)
@@ -6,6 +6,7 @@
 tag CMTr16 CMTr14
 tag CMTr18 CMTr16
-tag CMTr0  CMTr18
-
+tag CMTr0  CMTr25
+
+tag CMTv0  CMTv1
 #
 #  Automatic detection of some system features.
@@ -125,5 +126,5 @@
              WIN32     "CMT\v"
 
-path_prepend PATH      "${CMTROOT}/${CMTBIN}" \
+path_append  PATH      "${CMTROOT}/${CMTBIN}" \
              WIN32     "%CMTROOT%\%CMTBIN%"
 
Index: CMT/v1r25-branch/source/cmt.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt.cxx	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt.h
===================================================================
--- CMT/v1r25-branch/source/cmt.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt.h	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -24,4 +25,5 @@
 
   void clear ();
+  int initialize ();
 
   ActionType m_action;
@@ -34,4 +36,5 @@
   cmt_string m_cmt_version;
   bool m_use_cmt;
+  bool m_use_projects;
   
   cmt_string m_current_dir;
@@ -52,5 +55,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;
   
@@ -68,4 +76,13 @@
 
   bool m_autoconfigure_cmtpath;
+
+  bool m_env_access;
+  PrintMode m_print_mode;
+  bool m_strip_path;
+
+private:
+
+  CmtContext& operator = (const CmtContext& other);
+  CmtContext (const CmtContext& other);
 };
 
@@ -79,5 +96,5 @@
   static void build_vsnet_file (const cmt_string& target);
 
-  static bool build_nmake ();
+  static inline bool build_nmake ();
   static void build_OS9_makefile (const cmt_string& target);
   static void build_prefix (const cmt_string& package, cmt_string& prefix);
@@ -90,5 +107,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);
@@ -212,27 +230,28 @@
   static const cmt_string& filter_dir (const cmt_string& dir);
 
-  static ActionType get_action ();
-
-  static const cmt_string& get_cmt_home ();
-  static const cmt_string& get_cmt_user_context ();
-  static const cmt_string& get_cmt_version ();
-  static const cmt_string& get_current_dir ();
+  static inline ActionType get_action ();
+
+  static inline const cmt_string& get_cmt_home ();
+  static inline const cmt_string& get_cmt_user_context ();
+  static inline const cmt_string& get_cmt_version ();
+  static inline const cmt_string& get_current_dir ();
   static const cmt_string get_current_dir_real ();
-  static const cmt_string& get_current_package ();
+  static inline const cmt_string& get_current_package ();
   static const cmt_string& get_current_path ();
   static const cmt_string& get_current_cmtpath ();
   static const cmt_string& get_current_offset ();
-  static AccessMode get_current_access ();
-  static CmtStructuringStyle get_current_structuring_style ();
-  static CmtDirStyle get_current_style ();
+  static inline AccessMode get_current_access ();
+  static inline CmtStructuringStyle get_current_structuring_style ();
+  static inline CmtDirStyle get_current_style ();
   static const cmt_string& get_current_version ();
-  static const cmt_string& get_current_target ();
-  static bool get_debug ();
-  static bool get_disable_warnings ();  
-  static bool get_quiet ();
-  static bool get_warnings ();
-  static bool get_recursive ();
+  static inline const cmt_string& get_current_target ();
+  static inline const CmtSystem::cmt_string_vector& get_tags_remove ();
+  static inline bool get_debug ();
+  static inline bool get_disable_warnings ();  
+  static inline bool get_quiet ();
+  static inline bool get_warnings ();
+  static inline bool get_recursive ();
   static CmtScopeFilteringMode get_scope_filtering_mode ();
-  static bool get_all_sets_done ();
+  static inline bool get_all_sets_done ();
 
   static void get_cmt_flags (CmtSystem::cmt_string_vector& flags);
@@ -259,7 +278,9 @@
   static int parser (const cmt_string& command_line);
   static int parser (int argc, char* argv[]);
-  static void print (PrintMode mode);
+  static void print (PrintMode mode, ostream& out = cout);
+  //static void print (PrintMode mode);
   static void print_clean (PrintMode mode);
-  static void print_context (Use& use, PrintMode mode, const cmt_string& tag);
+  static void print_context (Use& use, PrintMode mode, const cmt_string& tag, ostream& out = cout);
+  //static void print_context (Use& use, PrintMode mode, const cmt_string& tag);
   static void print_macros (PrintMode mode, const cmt_string& pattern = "",
 			    ostream& out = cout);
@@ -268,13 +289,15 @@
   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);
-  static void set_recursive (bool mode);
-  static void set_scope_filtering_mode (CmtScopeFilteringMode mode);
+  static inline void set_current_access (AccessMode mode);
+  static inline void set_recursive (bool mode);
+  static inline void set_scope_filtering_mode (CmtScopeFilteringMode mode);
   static void set_standard_macros ();
-  static void set_all_sets_done ();
-  static void reset_all_sets_done ();
+  static inline void set_all_sets_done ();
+  static inline void reset_all_sets_done ();
   static void use_cmt ();
   static void use_home_requirements ();
@@ -287,5 +310,159 @@
                                 const cmt_string& separator,
                                 cmt_string& result);
+
+  static inline const bool& get_env_access ();
+  static inline void set_env_access (const bool& access);
+  static inline const PrintMode& get_print_mode ();
+  static inline void set_print_mode (const PrintMode& mode);
+  static inline const bool& get_strip_path ();
+
+private:
+  static CmtContext& m_cmt_context;
+  //  static CmtContext * m_cmt_context;
 };
 
+//----------------------------------------------------------
+inline bool Cmt::build_nmake ()
+{
+  return (m_cmt_context.m_build_nmake);
+}
+
+inline ActionType Cmt::get_action ()
+{
+  return (m_cmt_context.m_action);
+}
+
+inline const cmt_string& Cmt::get_cmt_home ()
+{
+  return (m_cmt_context.m_cmt_home);
+}
+
+inline const cmt_string& Cmt::get_cmt_user_context ()
+{
+  return (m_cmt_context.m_cmt_user_context);
+}
+
+inline const cmt_string& Cmt::get_cmt_version ()
+{
+  return (m_cmt_context.m_cmt_version);
+}
+
+inline const cmt_string& Cmt::get_current_dir ()
+{
+  return (m_cmt_context.m_current_dir);
+}
+
+inline const cmt_string& Cmt::get_current_package ()
+{
+  return (m_cmt_context.m_current_package);
+}
+
+inline AccessMode Cmt::get_current_access ()
+{
+  return (m_cmt_context.m_current_access);
+}
+
+inline CmtStructuringStyle Cmt::get_current_structuring_style ()
+{
+  return (m_cmt_context.m_current_structuring_style);
+}
+
+inline CmtDirStyle Cmt::get_current_style ()
+{
+  return (m_cmt_context.m_current_style);
+}
+
+inline const cmt_string& Cmt::get_current_target ()
+{
+  return (m_cmt_context.m_current_target);
+}
+
+inline const CmtSystem::cmt_string_vector& Cmt::get_tags_remove ()
+{
+  return m_cmt_context.m_tags_remove;
+}
+
+inline bool Cmt::get_debug ()
+{
+  return (m_cmt_context.m_debug);
+}
+
+inline bool Cmt::get_quiet ()
+{
+  return (m_cmt_context.m_quiet);
+}
+
+inline bool Cmt::get_disable_warnings ()
+{
+  return (m_cmt_context.m_disable_warnings);
+}
+
+inline bool Cmt::get_warnings ()
+{
+  return (m_cmt_context.m_warnings);
+}
+
+inline bool Cmt::get_recursive ()
+{
+  return (m_cmt_context.m_recursive);
+}
+
+inline bool Cmt::get_all_sets_done ()
+{
+  return (m_cmt_context.m_all_sets_done);
+}
+
+inline void Cmt::set_current_access (AccessMode mode)
+{
+  m_cmt_context.m_current_access = mode;
+}
+
+//----------------------------------------------------------
+inline void Cmt::set_recursive (bool mode)
+{
+  m_cmt_context.m_recursive = mode;
+}
+
+//----------------------------------------------------------
+inline void Cmt::set_scope_filtering_mode (CmtScopeFilteringMode mode)
+{
+  m_cmt_context.m_scope_filtering_mode = mode;
+}
+
+inline void Cmt::set_all_sets_done ()
+{
+  m_cmt_context.m_all_sets_done = true;
+}
+
+inline void Cmt::reset_all_sets_done ()
+{
+  m_cmt_context.m_all_sets_done = false;
+}
+
+inline const bool& Cmt::get_env_access ()
+{
+  return m_cmt_context.m_env_access;
+}
+
+inline void Cmt::set_env_access (const bool& access)
+{
+  m_cmt_context.m_env_access = access;
+}
+
+inline const PrintMode& Cmt::get_print_mode ()
+{
+  return m_cmt_context.m_print_mode;
+}
+
+inline void Cmt::set_print_mode (const PrintMode& mode)
+{
+  m_cmt_context.m_print_mode = mode;
+}
+
+inline const bool& Cmt::get_strip_path ()
+{
+  return m_cmt_context.m_strip_path;
+}
+//----------------------------------------------------------
+
 #endif
Index: CMT/v1r25-branch/source/cmt_awk.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_awk.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_awk.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_cmtpath_pattern.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_cmtpath_pattern.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_cmtpath_pattern.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_cmtpath_pattern.h
===================================================================
--- CMT/v1r25-branch/source/cmt_cmtpath_pattern.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_cmtpath_pattern.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_commands.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_commands.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_commands.cxx	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -256,4 +257,10 @@
   pv.push_back (&ArgParser::option_no_cleanup); i++;
 
+  parsers.add ("-no_strip_p", i);
+  parsers.add ("-no_strip_pa", i);
+  parsers.add ("-no_strip_pat", i);
+  parsers.add ("-no_strip_path", i);
+  pv.push_back (&ArgParser::option_no_strip_path); i++;
+
   parsers.add ("-pac", i);
   parsers.add ("-pack", i);
@@ -263,4 +270,10 @@
   parsers.add ("-path", i);
   pv.push_back (&ArgParser::option_path); i++;
+
+  parsers.add ("-strip_p", i);
+  parsers.add ("-strip_pa", i);
+  parsers.add ("-strip_pat", i);
+  parsers.add ("-strip_path", i);
+  pv.push_back (&ArgParser::option_strip_path); i++;
 
   parsers.add ("-pr", i);
@@ -346,4 +359,24 @@
   parsers.add ("-without_cmt", i);
   pv.push_back (&ArgParser::option_without_cmt); i++;
+
+  parsers.add ("-with_p", i);
+  parsers.add ("-with_pr", i);
+  parsers.add ("-with_pro", i);
+  parsers.add ("-with_proj", i);
+  parsers.add ("-with_proje", i);
+  parsers.add ("-with_projec", i);
+  parsers.add ("-with_project", i);
+  parsers.add ("-with_projects", i);
+  pv.push_back (&ArgParser::option_with_projects); i++;
+
+  parsers.add ("-without_p", i);
+  parsers.add ("-without_pr", i);
+  parsers.add ("-without_pro", i);
+  parsers.add ("-without_proj", i);
+  parsers.add ("-without_proje", i);
+  parsers.add ("-without_projec", i);
+  parsers.add ("-without_project", i);
+  parsers.add ("-without_projects", i);
+  pv.push_back (&ArgParser::option_without_projects); i++;
 
   parsers.add ("-warn", i);
@@ -1903,6 +1936,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 +1945,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 +1955,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'");
 }
 
@@ -1952,35 +1991,15 @@
     {
       CmtSystem::cmt_string_vector words;
-
       CmtSystem::split (arg, ":", words);
 
       cmt.m_current_access = UserMode;
+
+      cmt.m_current_package = "";
+      cmt.m_current_version = "";
+      cmt.m_current_path = "";
 
       if (words.size () > 0) cmt.m_current_package = words[0];
       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 ("", true))
-	{
-	  CmtError::set (CmtError::package_not_found, use.get_info ());
-	  return;
-	}
-      Project::order_all ();
-      Cmt::guess_current_project ();
     }
 }
@@ -1995,16 +2014,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 = "";
+
     }
 }
@@ -2016,15 +2025,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);
     }
 }
@@ -2036,37 +2034,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 ("", true))
-	{
-	  CmtError::set (CmtError::package_not_found, use.get_info ());
-	  return;
-	}
-      Project::order_all ();
-      Cmt::guess_current_project ();
     }
 }
@@ -2079,5 +2044,4 @@
 void ArgParser::option_e ()
 {
-  //CmtMessage::warning ("extra statement = " + arg);
   extra_line = arg;
 }
@@ -2089,4 +2053,18 @@
       cmt.m_cmt_home = arg;
     }
+}
+
+void ArgParser::option_no_strip_path ()
+{
+  cmt.m_strip_path = false;
+  if (!Cmt::add_cmt_flag ("-no_strip_path"))
+    CmtMessage::error ("Cannot add flag `-no_strip_path'");
+}
+
+void ArgParser::option_strip_path ()
+{
+  cmt.m_strip_path = true;
+  if (!Cmt::add_cmt_flag ("-strip_path"))
+    CmtMessage::error ("Cannot add flag `-strip_path'");
 }
 
@@ -2098,4 +2076,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;
@@ -2151,4 +2155,5 @@
 	// To be sure that a tag
 	Cmt::guess_current_project ();
+      */
     }
 }
@@ -2156,4 +2161,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;
@@ -2188,23 +2221,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;
@@ -2259,6 +2325,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 ())
@@ -2283,4 +2347,5 @@
 	      tag->mark ("arguments");
 	  }
+  */
 }
 
@@ -2307,14 +2372,25 @@
 }
 
+void ArgParser::option_with_projects ()
+{
+  cmt.m_use_projects = true;
+  if (!Cmt::add_cmt_flag ("-with_projects"))
+    CmtMessage::error ("Cannot add flag `-with_projects'");
+}
+
+void ArgParser::option_without_projects ()
+{
+  cmt.m_use_projects = false;
+  if (!Cmt::add_cmt_flag ("-without_projects"))
+    CmtMessage::error ("Cannot add flag `-without_projects'");
+}
+
 void ArgParser::option_with_version_directory ()
 {
   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'");
+
 }
 
@@ -2323,10 +2399,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'");
+
 }
 
@@ -2398,5 +2471,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;
@@ -2408,4 +2481,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/v1r25-branch/source/cmt_commands.h
===================================================================
--- CMT/v1r25-branch/source/cmt_commands.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_commands.h	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -83,7 +84,11 @@
   void option_with_cmt ();
   void option_without_cmt ();
+  void option_with_projects ();
+  void option_without_projects ();
   void option_with_version_directory ();
   void option_without_version_directory ();
   void option_no_cleanup ();
+  void option_no_strip_path ();
+  void option_strip_path ();
   void option_private ();
   void option_public ();
Index: CMT/v1r25-branch/source/cmt_constituent.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_constituent.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_constituent.cxx	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_constituent.h
===================================================================
--- CMT/v1r25-branch/source/cmt_constituent.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_constituent.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_cvs.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_cvs.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_cvs.cxx	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by: garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_database.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_database.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_database.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_database.h
===================================================================
--- CMT/v1r25-branch/source/cmt_database.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_database.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_deps_builder.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_deps_builder.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_deps_builder.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -226,9 +227,12 @@
         }
     }
-  else if (!strncmp (ptr, "      include", 13))
+  else if (!strncmp (ptr, "include", 7) ||
+	   !strncmp (ptr, "INCLUDE", 7))
+  //  else if (!strncmp (ptr, "      include", 13))
     {
       // fortran include statement
 
-      ptr += 13;
+      ptr += 7;
+      //ptr += 13;
 
       while ((*ptr == ' ') || (*ptr == '\t')) ptr++;
@@ -239,4 +243,9 @@
           ptr++;
         }
+      else if (*ptr == '(')
+	{
+	  term = ')';
+	  ptr++;
+	}
       else
         {
@@ -245,4 +254,5 @@
         }
     }
+  /*
   else if (!strncmp (ptr, "\tinclude", 8))
     {
@@ -264,4 +274,5 @@
         }
     }
+  */
   else
     {
@@ -308,6 +319,6 @@
 static char* in_line_action (char* ptr, state_def& state)
 {
-  char* pattern = ptr + strlen (ptr);
-  int length = 0;
+  //  char* pattern = ptr + strlen (ptr);\
+  //  int length = 0;
 
   /*
@@ -318,4 +329,48 @@
   */
 
+  char* beg = ptr;
+  while (char* p = strpbrk (beg, "\"\'/"))
+    if (*p == '"')
+      {
+	if (p == ptr || (p > ptr && *(p - 1) != '\\'))
+	  {
+	    state = in_string;
+	    return p + 1;
+	  }
+	else
+	  { // '"' is escaped
+	    beg = p + 1;
+	  }
+      }
+    else if (*p == '\'')
+      {
+	if (p == ptr || (p > ptr && *(p - 1) != '\\'))
+	  {
+	    state = in_char;
+	    return p + 1;
+	  }
+	else
+	  { // '\'' is escaped
+	    beg = p + 1;
+	  }
+      }
+    else
+      { // we have '/'
+	if (*(p + 1) == '*')
+	  {
+	    state = in_comment;
+	    return p + 2;
+	  }
+	else if (*(p + 1) == '/')
+	  {
+	    state = in_line_comment;
+	    return p + 2;
+	  }
+	else
+	  {
+	    beg = p + 1;
+	  }
+      }
+  /*
   char* pos = strchr (ptr, '"');
   if ((pos != 0) && (pos < pattern) && (pos > ptr) && (*(pos-1) != '\\'))
@@ -334,5 +389,5 @@
     }
 
-  pos = strstr (ptr, "/*");   //*/
+  pos = strstr (ptr, "/*");
   if ((pos != 0) && (pos < pattern))
     {
@@ -351,6 +406,7 @@
 
   ptr = pattern + length;
-
   return (ptr);
+*/
+  return  ptr + strlen (ptr);
 }
 
@@ -650,5 +706,12 @@
 	} // while (strlen (ptr) > 0)
       
-      if (state == in_line) state = at_start;
+      //if (state == in_line) state = at_start;
+      switch (state)
+	{
+	case in_line:
+	case in_line_comment:
+	  state = at_start;
+	  break;
+	}
       line_number++;
 
Index: CMT/v1r25-branch/source/cmt_deps_builder.h
===================================================================
--- CMT/v1r25-branch/source/cmt_deps_builder.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_deps_builder.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_error.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_error.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_error.cxx	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -18,5 +19,5 @@
   {
     error_names.add() = "ok";
-    error_names.add() = "Warning";
+    error_names.add() = "warning";
     error_names.add() = "symbol not found";
     error_names.add() = "pattern not found";
@@ -159,5 +160,5 @@
 
   result = get_error_name (e.get_code ());
-  result += " : ";
+  result += ": ";
   result += e.get_text ();
 
Index: CMT/v1r25-branch/source/cmt_error.h
===================================================================
--- CMT/v1r25-branch/source/cmt_error.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_error.h	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_fragment.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_fragment.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_fragment.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_fragment.h
===================================================================
--- CMT/v1r25-branch/source/cmt_fragment.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_fragment.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_generator.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_generator.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_generator.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_generator.h
===================================================================
--- CMT/v1r25-branch/source/cmt_generator.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_generator.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_generators.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_generators.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_generators.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -2809,4 +2810,5 @@
   m_PACKAGEFULLNAME.set ("PACKAGEFULLNAME");
   m_ISLOCAL.set ("ISLOCAL");
+  m_ISINCLUDED.set ("ISINCLUDED");
 
   packages_header_fragment.set ("packages_header");
@@ -2822,4 +2824,5 @@
   m_PACKAGEFULLNAME = "";
   m_ISLOCAL = "";
+  m_ISINCLUDED = "";
 
   packages_header_fragment.reset ();
@@ -2867,11 +2870,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;
@@ -2879,8 +2887,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 ();
@@ -2895,4 +2943,6 @@
 	      temp += "mgr";
 	      break;
+	    default:
+	      break;
 	    }
 #ifdef WIN32
@@ -2900,5 +2950,4 @@
 #endif
 	  m_PACKAGEMGRPATH = temp;
-	  //	  fprintf (m_output_file, "%s\n", temp.c_str());
 
 	  temp = "";
@@ -2924,5 +2973,4 @@
 #endif
 	  m_PACKAGEFULLNAME = temp;
-	  //	  fprintf (m_output_file, "%s\n", temp.c_str());
 
 	  m_PACKAGE = use->get_package_name ();
@@ -2959,9 +3007,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;
 	}
 
@@ -2984,5 +3032,4 @@
 
       CmtSystem::close_ostream (m_output_file, new_file_name);
-      //  fclose (m_output_file);
 
       commit (new_file_name);
Index: CMT/v1r25-branch/source/cmt_generators.h
===================================================================
--- CMT/v1r25-branch/source/cmt_generators.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_generators.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -238,4 +239,5 @@
   Variable m_PACKAGEFULLNAME;
   Variable m_ISLOCAL;
+  Variable m_ISINCLUDED;
 
   FragmentHandle packages_header_fragment;
Index: CMT/v1r25-branch/source/cmt_install_area.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_install_area.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_install_area.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_language.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_language.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_language.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_language.h
===================================================================
--- CMT/v1r25-branch/source/cmt_language.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_language.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_lock.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_lock.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_lock.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_log.h
===================================================================
--- CMT/v1r25-branch/source/cmt_log.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_log.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_map.h
===================================================================
--- CMT/v1r25-branch/source/cmt_map.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_map.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -276,5 +277,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 +506,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/v1r25-branch/source/cmt_model.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_model.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_model.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_parser.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_parser.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_parser.cxx	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -10,4 +11,5 @@
 #include <string.h>
 #include <ctype.h>
+#include <errno.h>
 
 //----------------------------------------------------------
@@ -50,8 +52,10 @@
 }
 
+//----------------------------------------------------------
 CmtContext::~CmtContext ()
 {
 }
 
+//----------------------------------------------------------
 void CmtContext::clear ()
 {
@@ -59,10 +63,12 @@
   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_use_projects   = true;
+
   m_current_dir     = "";
   m_current_file_path = "";
@@ -74,13 +80,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,13 +108,38 @@
 
   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;
-}
-
+
+  m_env_access = true;
+  m_print_mode = Csh;
+  m_strip_path = false;
+}
+//----------------------------------------------------------
+
+int CmtContext::initialize ()
+{
+  int errors (0);
+
+  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]);
+    }
+
+  return - errors;
+}
 //----------------------------------------------------------
 
@@ -357,4 +399,12 @@
 
 
+//----------------------------------------------------------
+//
+//   The static Cmt member
+//
+//----------------------------------------------------------
+
+CmtContext& Cmt::m_cmt_context = Me;
+//CmtContext * Cmt::m_cmt_context = &Me;
 
 //----------------------------------------------------------
@@ -462,9 +512,10 @@
 
 //----------------------------------------------------------
+/*
 bool Cmt::build_nmake ()
 {
   return (Me.m_build_nmake);
 }
-
+*/
 //----------------------------------------------------------
 void Cmt::build_OS9_makefile (const cmt_string& target)
@@ -497,6 +548,6 @@
 void Cmt::clear ()
 {
-  Me.m_quiet = false;
   Me.clear ();
+  //Me.m_quiet = false;
 
   Database::clear ();
@@ -507,4 +558,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)
@@ -515,5 +616,5 @@
   if (configured) return;
 
-  Me.clear ();
+  //  Me.clear ();
 
   log << "configure_cmt_message" << log_endl;
@@ -523,4 +624,7 @@
   log << "configure_default_path" << log_endl;
   configure_default_path ();
+
+  log << "restore_all_tags" << log_endl;
+  restore_all_tags (0);
   log << "configure_version_tag" << log_endl;
   configure_version_tag ();
@@ -533,4 +637,58 @@
   log << "configure_site_tag" << log_endl;
   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")
+      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
+	    }
+	}
+
+      if (use.located ())
+	{
+	  // parse additional options
+	  parse_cmt_flags ("requirements", m_cmt_context);
+	}
+    }
+  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;
+	}
+
+      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);
+	}
+    }
+
   log << "configure_current_dir" << log_endl;
   configure_current_dir ();
@@ -540,5 +698,4 @@
   //  log << "configure_current_dir" << log_endl;
 
-
   bool save_quiet = Me.m_quiet;
   Me.m_quiet = true;
@@ -546,5 +703,5 @@
   Me.m_autoconfigure_cmtpath = true;
   configure_cmt_path (0);
-  Me.m_autoconfigure_cmtpath = false;
+  //  Me.m_autoconfigure_cmtpath = false;
 
   Me.m_quiet = save_quiet;
@@ -553,4 +710,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;
@@ -558,19 +750,32 @@
   configure_current_structuring_style (ap);
 
+//   if (requirements.size () == 0)
+//     {
   log << "configure_current_package" << log_endl;
   configure_current_package ();
+//     }
 
   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 ()) 
@@ -584,4 +789,6 @@
 {
   if (!Me.m_autoconfigure_cmtpath) return;
+
+  if (!m_cmt_context.m_use_projects) return;
 
   cmt_string s;
@@ -621,5 +828,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 +841,5 @@
 
       Me.m_current_offset = current_use.path;
-
+  */
       /**
 	 try to remove this current CMTPATH entry from path.  This
@@ -639,5 +847,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 +856,5 @@
 	}
     }
+  */
 }
 
@@ -731,4 +940,6 @@
 void Cmt::configure_current_dir ()
 {
+  if (Me.m_current_dir.size () != 0) return;
+
   cmt_string file_name;
 
@@ -788,9 +999,10 @@
   Me.m_current_file_path = mount_filter.get_current_dir ();
 
-  cmt_string t = Me.m_current_file_path;
-}
-
-//----------------------------------------------------------
-void Cmt::configure_current_package ()
+  //  cmt_string t = Me.m_current_file_path;
+}
+
+//----------------------------------------------------------
+cmt_string Cmt::configure_current_package ()
+//void Cmt::configure_current_package ()
 {
   /*
@@ -800,4 +1012,30 @@
     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);
+
+      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;
+    }
 
   cmt_string req = "..";
@@ -813,5 +1051,6 @@
   else
     {
-      cmt_string req = "..";
+      req = "..";
+      //      cmt_string req = "..";
       req += CmtSystem::file_separator ();
       req += "mgr";
@@ -827,4 +1066,9 @@
 	  // This package is probably a standalone one
 	  Me.m_current_style = none_style;
+	  req = "requirements";
+	  if (!CmtSystem::test_file (req))
+	    {
+	      req = "";
+	    }
 	}
     }
@@ -1062,9 +1306,11 @@
       // 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);
       build_config (Me.m_current_prefix, Me.m_current_config);
     }
+
+  return req;
 }
 
@@ -1074,82 +1320,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 +1376,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 +1401,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 +1479,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 +1524,5 @@
   */
 
+  /*
   if (CmtSystem::testenv ("CMTEXTRATAGS"))
     {
@@ -1309,4 +1557,5 @@
         }
     }
+  */
 }
 
@@ -1319,4 +1568,6 @@
 
   log << "current_tag=" << Me.m_current_tag << log_endl;
+
+  cmt_string s = "CMTCONFIG";
 
   Symbol* symbol = Symbol::find ("CMTCONFIG");
@@ -1347,4 +1598,5 @@
     {
       config_tag = CmtSystem::getenv ("CMTBIN");
+      s = "CMTBIN";
     }
 
@@ -1352,9 +1604,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 +1805,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 +1854,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 +1866,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 +1888,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 +1938,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 +1964,6 @@
           else if (w.substr (0, 7) == "-global")
             {
-              path_selections.clear ();
-
+              //path_selections.clear ();
+	      global = true;
               local = false;
             }
@@ -1745,4 +1971,5 @@
             {
               local = true;
+	      global = false;
             }
           else if (w.substr (0, 8) == "-select=")
@@ -1787,7 +2014,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 +2053,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 +2059,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 +2069,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 +2144,7 @@
 	cmt_string& p = packages.add ();
 	p = use->get_package_name ();
+	  
+	int& use_index = use_indexes.add ();
+	use_index = -1;
       }
     }
@@ -1891,38 +2160,71 @@
     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;
         }
+      else if (up)
+	cmtpath = up->get_cmtpath ();
 
       if (ok)
@@ -1960,5 +2262,4 @@
         }
 
-
       if (ok)
         {
@@ -1974,4 +2275,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 +2349,5 @@
         }
 
+      /*
       if (cmtpath == "")
         {
@@ -2026,4 +2355,5 @@
 	  cmtpath = Project::find_in_cmt_paths (sel);
         }
+      */
 
       cmt_string cmd = command;
@@ -2041,24 +2371,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);
 
@@ -2067,5 +2404,5 @@
     {
       cout << "#--------------------------------------------------------------" << endl;
-      cout << "# Now trying [" << cmd << "] in " << s << " (" << i+1 << "/" << uses.size () 
+      cout << "# " << p << " " << v << " " << offset << ": Now trying [" << cmd << "] in " << s << " (" << i+1 << "/" << uses.size () 
            << ")" << endl;
       cout << "#--------------------------------------------------------------" << endl;
@@ -2904,24 +3241,50 @@
     }
 
-  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;
-	}
-    }
-
-  Symbol::check_all_paths ();
+    {
+    //    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");
+	    }
+	}
+    }
+
+  if (action_setup != get_action () ||
+      Requirements == ap.mode)
+    // PathBuilder::filter_path_value is called
+    // for each path in Symbol::print
+    Symbol::check_all_paths ();
 
   env = CmtSystem::getenv ("CMTSITE");
@@ -2940,5 +3303,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;
     }
 
@@ -4323,7 +4685,9 @@
       break;
     case Requirements :
+      /*
       CmtSystem::cmt_string_vector flags;
       get_cmt_flags (flags);
       cout << "\n# CMTFLAGS: -without_cmt";
+      cout << " -without_projects" ;
       for (int i = 0; i < flags.size (); i++)
 	{
@@ -4332,11 +4696,126 @@
 	  else if (flags[i] == "-with_cmt")
 	    cout << " -without_cmt";
+	  else if (flags[i] == "-without_projects")
+	    cout << " -with_projects";
+	  else if (flags[i] == "-with_projects")
+	    cout << " -without_projects";
 	  else
 	    cout << " " << flags[i]; 
 	}
       cout << endl;
+      */
       break;
-    }
-  print (ap.mode);
+    default:
+      break;
+    }
+
+  ostringstream os;
+  ostringstream oh;
+  bool reset (false);
+  CmtSystem::cmt_string_vector flags;
+  cmt_string strip_path_flag;
+  bool strip_path (false);
+
+  bool strip_saved (get_strip_path ());
+  bool access_saved (Cmt::get_env_access ());
+
+  switch (ap.mode)
+    {
+    case Requirements :
+
+      get_cmt_flags (flags);
+      for (int i = 0; i < flags.size (); i++)
+	{
+	  if (flags[i] == "-no_strip_path")
+	    strip_path_flag = "-no_strip_path";
+	  else if (flags[i] == "-strip_path")
+	    strip_path_flag = "-strip_path";
+	}
+      if (strip_path_flag != "-no_strip_path" &&
+	  !get_strip_path ())
+	reset = Symbol::set_strip_path (true);
+
+      if (get_strip_path () || reset)
+	strip_path = true;
+      else
+	strip_path = false;
+
+      Cmt::set_env_access (false);
+
+      print (ap.mode, os);
+
+      if (CmtError::get_last_error_code () == CmtError::warning &&
+	  (get_strip_path () || reset))
+	{
+	  reset = Symbol::set_strip_path (false);
+	  if (reset)
+	    {
+	      strip_path = false;
+
+	      CmtError::print ();
+	      CmtError::clear ();
+
+	      if (Cmt::get_debug ())
+		{
+		  cerr << "|Cmt::do_setup> Failure with:\n" << os.str ()
+		       << "|Cmt::do_setup> Trying again." << endl;
+		}
+
+	      // Try again
+	      os.str ("");
+	      print (ap.mode, os);
+	    }
+	}
+
+      if (reset) Symbol::set_strip_path (strip_saved);
+      Cmt::set_env_access (access_saved);
+
+      //get_cmt_flags (flags);
+      oh << "\n# CMTFLAGS:"
+	" -without_cmt"
+	" -without_projects"
+	//" -strip_path"
+	;
+      for (int i = 0; i < flags.size (); i++)
+	{
+	  if (flags[i] == "-without_cmt")
+	    oh << " -with_cmt";
+	  else if (flags[i] == "-with_cmt")
+	    oh << " -without_cmt";
+	  else if (flags[i] == "-without_projects")
+	    oh << " -with_projects";
+	  else if (flags[i] == "-with_projects")
+	    oh << " -without_projects";
+	  /*
+	  else if (flags[i] == "-no_strip_path")
+	    oh << " -strip_path";
+	  else if (flags[i] == "-strip_path")
+	    oh << " -no_strip_path";
+	  */
+	  else if (flags[i] == "-no_strip_path" ||
+		   flags[i] == "-strip_path")
+	    continue;
+	  else
+	    oh << " " << flags[i]; 
+	}
+      //if (reset) oh << " -strip_path";
+      if (strip_path)
+	oh << " -no_strip_path";
+      else
+	oh << " -strip_path";
+      oh << endl;
+
+      cout << oh.str ();
+      cout << os.str ();
+
+      break;
+
+    default:
+
+      print (ap.mode);
+
+      break;
+    }
+
   switch (ap.mode)
     {
@@ -4476,9 +4955,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 +4984,9 @@
   ClientCollector collector (package, version);
 
+  /*
   clear     ();
   //  configure ();
   configure (ap);
+  */
 
   cout << "# ----------- Clients of " << package
@@ -5164,9 +5647,10 @@
 
 //----------------------------------------------------------
+/*
 ActionType Cmt::get_action ()
 {
   return (Me.m_action);
 }
-
+*/
 /*
   const CmtSystem::cmt_string_vector& Cmt::get_cmt_path ()
@@ -5185,5 +5669,5 @@
   }
 */
-
+ /*
 const cmt_string& Cmt::get_cmt_home ()
 {
@@ -5205,5 +5689,5 @@
   return (Me.m_current_dir);
 }
-
+*/
 const cmt_string Cmt::get_current_dir_real ()
 {
@@ -5213,10 +5697,10 @@
   return (Me.m_current_dir);
 }
-
+/*
 const cmt_string& Cmt::get_current_package ()
 {
   return (Me.m_current_package);
 }
-
+*/
 const cmt_string& Cmt::get_current_path ()
 {
@@ -5233,5 +5717,5 @@
   return (Me.m_current_offset);
 }
-
+/*
 AccessMode Cmt::get_current_access ()
 {
@@ -5248,15 +5732,22 @@
   return (Me.m_current_style);
 }
-
+*/
 const cmt_string& Cmt::get_current_version ()
 {
   return (Me.m_current_version);
 }
-
+/*
 const cmt_string& Cmt::get_current_target ()
 {
   return (Me.m_current_target);
 }
-
+*/
+/*
+const CmtSystem::cmt_string_vector& Cmt::get_tags_remove ()
+{
+  return (Me.m_tags_remove);
+}
+*/
+ /*
 bool Cmt::get_debug ()
 {
@@ -5283,5 +5774,5 @@
   return (Me.m_recursive);
 }
-
+ */
 CmtScopeFilteringMode Cmt::get_scope_filtering_mode ()
 {
@@ -5297,9 +5788,10 @@
 
 //----------------------------------------------------------
+/*
 bool Cmt::get_all_sets_done ()
 {
   return (Me.m_all_sets_done);
 }
-
+*/
 //----------------------------------------------------------
 void Cmt::get_cmt_flags (CmtSystem::cmt_string_vector& flags)
@@ -5421,9 +5913,11 @@
 void Cmt::guess_current_project ()
 {
+  if (!m_cmt_context.m_use_projects) return;
+
   Log;
 
   log << "guess_current_project" << log_endl;
 
-  cmt_string here = CmtSystem::pwd ();
+  //  cmt_string here = CmtSystem::pwd ();
 
   Use& use = Use::current();
@@ -5438,4 +5932,5 @@
     //  if (Project::find_in_cmt_paths (Me.m_current_dir) == "")
     {
+      /*
       if (!CmtSystem::cd (current_path))
 	{
@@ -5444,13 +5939,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 +5966,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 +5989,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";
@@ -5487,4 +6017,6 @@
   //  Use& use = Use::current();
 
+  bool autoconfigure_cmtpath_saved (Me.m_autoconfigure_cmtpath);
+  Me.m_autoconfigure_cmtpath = false;
   bool save_quiet = Me.m_quiet;
   Me.m_quiet = true;
@@ -5493,8 +6025,9 @@
 
   Me.m_quiet = save_quiet;
-
-  Me.m_autoconfigure_cmtpath = true;
-
-  CmtSystem::cd (here);
+  Me.m_autoconfigure_cmtpath = autoconfigure_cmtpath_saved;
+  //  Me.m_autoconfigure_cmtpath = true;
+
+  //  CmtSystem::cd (Me.m_current_dir);
+  //CmtSystem::cd (here);
 }
 
@@ -5966,8 +6499,7 @@
               fprintf (f, "endif\n");
               fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
-              fprintf (f, "set cmt%stempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n", mangled_package.c_str ());
+              fprintf (f, "set cmt%stempfile=`${CMTROOT}/${CMTBIN}/cmt.exe -quiet build temporary_name`\n", mangled_package.c_str ());
               fprintf (f, "if $status != 0 then\n  set cmt%stempfile=/tmp/cmt.$$\nendif\n", mangled_package.c_str ());
-              //fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
-              fprintf (f, "${CMTROOT}/mgr/cmt %s -%s "
+              fprintf (f, "${CMTROOT}/${CMTBIN}/cmt.exe %s -%s "
                        "-pack=%s -version=%s -path=%s %s $* >${cmt%stempfile}\n",
 		       action.c_str (),
@@ -5980,5 +6512,5 @@
 	      fprintf (f,
 		       "if ( $status != 0 ) then\n"
-		       "  echo \"${CMTROOT}/mgr/cmt %s -%s "
+		       "  echo \"${CMTROOT}/${CMTBIN}/cmt.exe %s -%s "
                        "-pack=%s -version=%s -path=%s %s $* >${cmt%stempfile}\"\n"
 		       "  set cmt%sstatus=2\n"
@@ -6026,8 +6558,7 @@
               fprintf (f, "fi\n");
               fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
-              fprintf (f, "cmt%stempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n", mangled_package.c_str ());
+              fprintf (f, "cmt%stempfile=`${CMTROOT}/${CMTBIN}/cmt.exe -quiet build temporary_name`\n", mangled_package.c_str ());
               fprintf (f, "if test ! $? = 0 ; then cmt%stempfile=/tmp/cmt.$$; fi\n", mangled_package.c_str ());
-              //fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
-              fprintf (f, "${CMTROOT}/mgr/cmt %s -%s "
+              fprintf (f, "${CMTROOT}/${CMTBIN}/cmt.exe %s -%s "
                        "-pack=%s -version=%s -path=%s %s $* >${cmt%stempfile}\n",
 		       action.c_str (),
@@ -6040,5 +6571,5 @@
               fprintf (f,
 		       "if test $? != 0 ; then\n"
-		       "  echo >&2 \"${CMTROOT}/mgr/cmt %s -%s "
+		       "  echo >&2 \"${CMTROOT}/${CMTBIN}/cmt.exe %s -%s "
                        "-pack=%s -version=%s -path=%s %s $* >${cmt%stempfile}\"\n"
 		       "  cmt%sstatus=2\n"
@@ -6074,5 +6605,4 @@
           else if (mode[i] == Bat)
             {
-              //fprintf (f, "rem Setting %s %s in %%~d0%%~p0\n",
               fprintf (f, "rem %s %s %s in %%~d0%%~p0\n",
 		       action.c_str (),
@@ -6409,5 +6939,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 +6974,5 @@
   Me.m_action = action_none;
 
-  restore_all_tags (0);
+  //  restore_all_tags (0);
 
 #ifdef WIN32
@@ -6481,4 +7011,10 @@
 int Cmt::parser (int argc, char* argv[])
 {
+  // save CMTFLAGS
+  cmt_string cmtflags (get_cmt_flags ());
+
+  clear ();
+  Me.initialize ();
+
   ArgParser ap (Me);
   
@@ -6493,23 +7029,38 @@
     }
 
-  // save CMTFLAGS
-  cmt_string cmtflags (get_cmt_flags ());
-
-  clear ();
+  //  clear ();
+
+  //  Me.clear ();
+
+  parse_arguments (ap);
+  // Copy ap.mode into cmt_context member/instance
+  set_print_mode (ap.mode);
 
   //  configure ();
-  configure (ap);
-
-  CmtError::clear ();
+  switch (Me.m_action)
+    {
+    case action_none :
+    case action_build_temporary_name :
+    case action_help :
+      break;
+    default:
+      configure (ap);
+      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 +7071,5 @@
     }
   
-  parse_arguments (ap);
+  //  parse_arguments (ap);
   
   if (ap.help_action == action_help)
@@ -6826,5 +7377,5 @@
   switch (Me.m_action)
     {
-    case action_none :
+      //case action_none :
     case action_awk :
     case action_broadcast :
@@ -6929,5 +7480,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 +7487,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 +7504,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 ())
@@ -7424,5 +7979,5 @@
  * joined with semi-colons to form one shell command.
  */
-void Cmt::print (PrintMode mode)
+void Cmt::print (PrintMode mode, ostream& out)
 {
   Use::UsePtrVector& Uses = Use::get_ordered_uses ();
@@ -7452,4 +8007,5 @@
   //
 
+  /*
   {
     CmtSystem::cmt_string_vector words;
@@ -7477,5 +8033,5 @@
       }
   }
-
+  */
   if (mode == Requirements)
     {
@@ -7487,5 +8043,5 @@
 	  if (tag != 0)
 	    {
-	      tag->show (true, cout, "apply_tag ");
+	      tag->show (true, out, "apply_tag ");
 	    }
 	}
@@ -7508,9 +8064,9 @@
           if (use.m_hidden) continue;
           
-          print_context (use, mode, tag);
-        }
-    }
-
-  print_context (Use::current (), mode, tag);
+          print_context (use, mode, tag, out);
+        }
+    }
+
+  print_context (Use::current (), mode, tag, out);
 
   if (Me.m_debug)
@@ -7519,5 +8075,5 @@
     }
 
-  Symbol::all_print (mode);
+  Symbol::all_print (mode, out);
   // Script::all_print (mode);
 
@@ -7532,5 +8088,5 @@
       break;
     default :
-  cout << endl;
+      out << endl;
       break;
     }
@@ -7638,5 +8194,5 @@
 
 //----------------------------------------------------------
-void Cmt::print_context (Use& use, PrintMode mode, const cmt_string& tag)
+void Cmt::print_context (Use& use, PrintMode mode, const cmt_string& tag, ostream& out)
 {
   if (use.get_package_name () == "cmt_standalone") return;
@@ -7654,4 +8210,5 @@
   switch (mode)
     {
+    case Xml :
     case Requirements :
       break;
@@ -7670,5 +8227,5 @@
       if (do_root)
 	{
-	  cout << "setenv " << prefix << "ROOT \"" <<
+	  out << "setenv " << prefix << "ROOT \"" <<
 	    use.get_full_path () << "\"" << endl;
 	}
@@ -7676,5 +8233,5 @@
       if (use.get_package_name () == "CMT")
         {
-          cout << "setenv CMTCONFIG " << system << endl;
+          out << "setenv CMTCONFIG " << system << endl;
         }
       else
@@ -7682,5 +8239,5 @@
 	  if (do_config)
 	    {
-	      cout << "setenv " << prefix << "CONFIG \"" << tag << "\"" << endl;
+	      out << "setenv " << prefix << "CONFIG \"" << tag << "\"" << endl;
 	    }
 	}
@@ -7690,5 +8247,5 @@
       if (do_root)
 	{
-	  cout << prefix << "ROOT=\"" <<
+	  out << prefix << "ROOT=\"" <<
 	    use.get_full_path () << "\"; export " <<
 	    prefix << "ROOT" << endl;
@@ -7697,5 +8254,5 @@
       if (use.get_package_name () == "CMT")
         {
-          cout << "CMTCONFIG=" << system << "; export CMTCONFIG" << endl;
+          out << "CMTCONFIG=" << system << "; export CMTCONFIG" << endl;
         }
       else
@@ -7703,5 +8260,5 @@
 	  if (do_config)
 	    {
-	      cout << prefix << "CONFIG=\"" <<
+	      out << prefix << "CONFIG=\"" <<
 		tag << "\"; export " <<
 		prefix << "CONFIG" << endl;
@@ -7713,5 +8270,5 @@
       if (do_root)
 	{
-	  cout << "set " << prefix << "ROOT=" <<
+	  out << "set " << prefix << "ROOT=" <<
 	    CmtSystem::quote (use.get_full_path (), " \t") << endl;
 	}
@@ -7719,5 +8276,5 @@
       if (use.get_package_name () == "CMT")
         {
-          cout << "set CMTCONFIG=" << system << endl;
+          out << "set CMTCONFIG=" << system << endl;
         }
       else
@@ -7725,5 +8282,5 @@
 	  if (do_config)
 	    {
-	      cout << "set " << prefix << "CONFIG=" << CmtSystem::quote (tag, " \t") << endl;
+	      out << "set " << prefix << "CONFIG=" << CmtSystem::quote (tag, " \t") << endl;
 	    }
 	}
@@ -7733,12 +8290,12 @@
       if (do_root)
 	{
-	  cout << "<variable><name>" << prefix << "ROOT</name>"
-	       << "<value>" << use.get_full_path () << "</value></variable>";
+	  out << "<variable><name>" << prefix << "ROOT</name>"
+	      << "<value>" << use.get_full_path () << "</value></variable>";
 	}
 
       if (use.get_package_name () == "CMT")
         {
-	  cout << "<variable><name>CMTCONFIG</name>"
-	       << "<value>" << system << "</value></variable>";
+	  out << "<variable><name>CMTCONFIG</name>"
+	      << "<value>" << system << "</value></variable>";
         }
       else
@@ -7746,6 +8303,6 @@
 	  if (do_config)
 	    {
-	      cout << "<variable><name>" << prefix << "CONFIG</name>"
-		   << "<value>" << tag << "</value></variable>";
+	      out << "<variable><name>" << prefix << "CONFIG</name>"
+		  << "<value>" << tag << "</value></variable>";
 	    }
 	}
@@ -7756,5 +8313,5 @@
 	  use.get_package_name () != "CMT")
 	{
-	  cout << "set " << use.prefix << "ROOT " <<
+	  out << "set " << use.prefix << "ROOT " <<
 	    CmtSystem::quote (use.get_full_path (), " \t") << endl;
 
@@ -7775,5 +8332,5 @@
       if (use.get_package_name () == "CMT")
         {
-	  cout << "set CMTCONFIG " << system << endl;
+	  out << "set CMTCONFIG " << system << endl;
         }
       else
@@ -7781,5 +8338,18 @@
 	  if (do_config)
 	    {
-	      cout << "set " << use.prefix << "CONFIG " << CmtSystem::quote (tag, " \t") << endl;
+	      out << "set " << use.prefix << "CONFIG " << CmtSystem::quote (tag, " \t") << endl;
+	      
+	      cmt_string name (use.prefix + "CONFIG");
+	      Symbol* symbol = Symbol::find (name);
+	      if (symbol != 0) 
+		{
+		  symbol->printed = true;
+		}
+	      if (symbol == 0 || symbol->type != Symbol::SymbolMacro)
+		{
+		  CmtMessage::warning
+		    (CmtError::get_error_name (CmtError::symbol_not_found)
+		     + ": macro " + name);
+		}
 	    }
 	}
@@ -7939,5 +8509,5 @@
 
 //----------------------------------------------------------
-int Cmt::reach_current_package ()
+int Cmt::use_current_package ()
 {
   Use& use = Use::current ();
@@ -7946,5 +8516,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 +8529,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,16 +8547,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,
-                         "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
@@ -8024,5 +8613,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);
             }
@@ -8030,4 +8620,6 @@
       else
 	Me.m_current_style = none_style;
+
+      Me.m_current_access = DeveloperMode;
 
       dir = CmtSystem::pwd ();
@@ -8057,9 +8649,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);
+  */
 
   /*
@@ -8067,5 +8665,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 == "")
@@ -8078,9 +8676,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;
 
         }
@@ -8100,5 +8698,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 ()
+{
 
   /**
@@ -8131,141 +8870,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,
-                         "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;
 }
 
@@ -9676,4 +10281,5 @@
 
 //----------------------------------------------------------
+/*
 void Cmt::set_current_access (AccessMode mode)
 {
@@ -9692,5 +10298,5 @@
   Me.m_scope_filtering_mode = mode;
 }
-
+*/
 //----------------------------------------------------------
 void Cmt::set_standard_macros ()
@@ -9836,5 +10442,5 @@
   builder.fill_for_constituent_macros ();
 }
-
+/*
 void Cmt::set_all_sets_done ()
 {
@@ -9846,5 +10452,5 @@
   Me.m_all_sets_done = false;
 }
-
+*/
 //----------------------------------------------------------
 void Cmt::use_cmt ()
@@ -9905,7 +10511,46 @@
   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 ())
+	    {
+	      if (m_cmt_context.m_use_projects)
+		{
+		  CmtError::set(CmtError::configuration_error,
+				"No such ordered project: " + use->get_info ());
+		  return;
+		}
+	      else
+		{
+		  use->change_path (path);
+		}
+	    }
+	  else
+	    {
+	      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;
@@ -9922,9 +10567,9 @@
     {
       const cmt_string& s = v[i];
-      if (s == "") continue;
+      if (s.size () == 0) continue;
 
       if (result.size () != 0) result += separator;
       //if (i > 0) result += separator;
-      result += v[i];
+      result += s;
     }
 }
Index: CMT/v1r25-branch/source/cmt_parser.h
===================================================================
--- CMT/v1r25-branch/source/cmt_parser.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_parser.h	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_pattern.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_pattern.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_pattern.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -771,5 +772,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 +780,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/v1r25-branch/source/cmt_project.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_project.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_project.cxx	(revision 664)
@@ -1,7 +1,7 @@
-
 //-----------------------------------------------------------
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -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/v1r25-branch/source/cmt_project.h
===================================================================
--- CMT/v1r25-branch/source/cmt_project.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_project.h	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -97,4 +98,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 +122,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/v1r25-branch/source/cmt_regexp.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_regexp.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_regexp.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_regexp.h
===================================================================
--- CMT/v1r25-branch/source/cmt_regexp.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_regexp.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_std.h
===================================================================
--- CMT/v1r25-branch/source/cmt_std.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_std.h	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_string.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_string.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_string.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_string.h
===================================================================
--- CMT/v1r25-branch/source/cmt_string.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_string.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_symbol.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_symbol.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_symbol.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -15,4 +16,5 @@
 #include "cmt_database.h"
 #include "cmt_log.h"
+#include "cmt_error.h"
 
 // Global inhibitor of any display
@@ -42,4 +44,23 @@
   const cmt_string clean (const Symbol& symbol,
                           const cmt_string& tag_name = "");
+
+  void filter_path_value (const Symbol& symbol,
+			  cmt_string& value,
+			  const cmt_string& tag_name = "") const;
+  void filter_path_value (const Symbol& symbol,
+			  CmtSystem::cmt_string_vector& value,
+			  const cmt_string& tag_name = "") const;
+  inline const bool& get_strip_path () const;
+  inline void set_strip_path (const bool& strip_path);
+
+  static PathBuilder* get_path_builder ();
+
+private:
+  PathBuilder ();
+  PathBuilder (bool strip_path);
+  PathBuilder (const PathBuilder& other);
+  PathBuilder& operator = (const PathBuilder& other);
+
+  bool m_strip_path;
 };
 //-------------------------------------------------------------
@@ -248,4 +269,11 @@
 }
 
+//
+// Global cache
+//
+namespace
+{
+  cmt_vmap <cmt_string, cmt_string> cmdoutputs;
+}
 /**
 
@@ -285,4 +313,6 @@
   int start = 0;
 
+  //  static cmt_vmap <cmt_string, cmt_string> cmdoutputs;
+
   for (;;)
     {
@@ -337,24 +367,30 @@
             // to be applied. The output of the command is then substituted
 
+	  Symbol::all_set ();
+
           cmt_string result;
-
-          Symbol::all_set ();
-          CmtSystem::execute (command, result);
-          
-	  /*
-          int pos;
-          pos = result.find ('\n');
-          if (pos != cmt_string::npos) result.erase (pos);
-          pos = result.find ('\r');
-          if (pos != cmt_string::npos) result.erase (pos);
-	  */          
-	  process_cmd_output (result);
-
-          if (Cmt::get_debug ())
-            {
-              cout << "resolve_value: Executing [" << command << "] to expand a symbol value =>[" 
-                   << result << "]" << endl;
-            }
-          
+	  const cmt_string * presult;
+	  if (!(presult = cmdoutputs.find (command)))
+	    {
+	      CmtSystem::execute (command, result);
+	      
+	      process_cmd_output (result);
+	      cmdoutputs.add (command, result);
+	      if (Cmt::get_debug ())
+		{
+		  cout << "resolve_value: Executing [" << command << "] to expand a symbol value =>[" 
+		       << result << "]" << endl;
+		}
+	    }
+	  else
+	    {
+	      result = *presult;
+	      if (Cmt::get_debug ())
+		{
+		  cout << "resolve_value: Found in cache [" << command << "] to expand a symbol value =>[" 
+		       << result << "]" << endl;
+		}
+	    }
+
           text.replace_all (pattern, result);
 
@@ -378,14 +414,33 @@
           else
             {
+	      if (Cmt::get_env_access () ||
+		  Symbol::std_env_vars ().has (symbol_name))
+		{
                 // Symbol not found. Look for env. variable
               cmt_string value = CmtSystem::getenv (symbol_name);
-              
                 // When the env. variable is not defined, the replacement is empty
                 // thus all $(xxx) ${xxx} %xxx% patterns are always filtered away.
               text.replace_all (pattern, value);
               
+		  if (Cmt::get_debug ())
+		    {
+		      cerr << "resolve_value: getenv (" << symbol_name
+			   << ") => " << value << endl;
+		    }
                 // The substitution will restart from the same place
                 // allowing for recursive replacements
               start = begin;
+		}
+	      else
+		{
+		  if (Cmt::get_debug ())
+		    {
+		      cerr << "resolve_value: getenv (" << symbol_name
+			   << ") denied" << endl;
+		    }
+		  CmtError::set (CmtError::warning,
+				 "getenv (" + symbol_name + ") denied");
+		  return;
+		}
             }
         }
@@ -484,24 +539,30 @@
             // to be applied. The output of the command is substituted
 
+	  Symbol::all_set ();
+
           cmt_string result;
-
-          Symbol::all_set ();
-          CmtSystem::execute (command, result);
-          
-	  /*
-          int pos;
-          pos = result.find ('\n');
-          if (pos != cmt_string::npos) result.erase (pos);
-          pos = result.find ('\r');
-          if (pos != cmt_string::npos) result.erase (pos);
-	  */
-	  process_cmd_output (result);
-          
-          if (Cmt::get_debug ())
-            {
-              cout << "   Executing [" << command << "] to expand a macro value =>[" 
-                   << result << "]" << endl;
-            }
-          
+	  const cmt_string * presult;
+	  if (!(presult = cmdoutputs.find (command)))
+	    {
+	      CmtSystem::execute (command, result);
+	      
+	      process_cmd_output (result);
+	      cmdoutputs.add (command, result);
+	      if (Cmt::get_debug ())
+		{
+		  cout << "resolve_value_for_macros: Executing [" << command << "] to expand a symbol value =>[" 
+		       << result << "]" << endl;
+		}
+	    }
+	  else
+	    {
+	      result = *presult;
+	      if (Cmt::get_debug ())
+		{
+		  cout << "resolve_value_for_macros: Found in cache [" << command << "] to expand a symbol value =>[" 
+		       << result << "]" << endl;
+		}
+	    }
+
           text.replace_all (pattern, result);
 
@@ -621,24 +682,30 @@
             // to be applied. The output of the command is substituted
 
+	  Symbol::all_set ();
+
           cmt_string result;
-
-          Symbol::all_set ();
-          CmtSystem::execute (command, result);
-          
-	  /*
-          int pos;
-          pos = result.find ('\n');
-          if (pos != cmt_string::npos) result.erase (pos);
-          pos = result.find ('\r');
-          if (pos != cmt_string::npos) result.erase (pos);
-	  */          
-	  process_cmd_output (result);
-          
-          if (Cmt::get_debug ())
-            {
-              cout << "   Executing [" << command << "] to expand a macro value =>[" 
-                   << result << "]" << endl;
-            }
-          
+	  const cmt_string * presult;
+	  if (!(presult = cmdoutputs.find (command)))
+	    {
+	      CmtSystem::execute (command, result);
+	      
+	      process_cmd_output (result);
+	      cmdoutputs.add (command, result);
+	      if (Cmt::get_debug ())
+		{
+		  cout << "suppress_OS_delimiters: Executing [" << command << "] to expand a symbol value =>[" 
+		       << result << "]" << endl;
+		}
+	    }
+	  else
+	    {
+	      result = *presult;
+	      if (Cmt::get_debug ())
+		{
+		  cout << "suppress_OS_delimiters: Found in cache [" << command << "] to expand a symbol value =>[" 
+		       << result << "]" << endl;
+		}
+	    }
+
           text.replace_all (pattern, result);
 
@@ -692,5 +759,7 @@
 {
   static SetBuilder Set;
-  static PathBuilder Path;
+  static PathBuilder* PathPtr (PathBuilder::get_path_builder ());
+  //static PathBuilder Path (Cmt::get_strip_path ());
+  //static PathBuilder Path;
   static MacroBuilder Macro;
   static ScriptBuilder Script;
@@ -852,5 +921,6 @@
       break;
     case SymbolPath:
-      symbol.builder = &Path;
+      symbol.builder = PathPtr;
+      //symbol.builder = &Path;
       break;
     case SymbolAlias:
@@ -911,4 +981,28 @@
 
   return (SymbolMap);
+}
+
+//-------------------------------------------------------------
+Symbol::SymbolMap& Symbol::std_env_vars ()
+{
+  static SymbolMap env_vars;
+  static Symbol std_sym;
+  static bool initialized (false);
+  if (!initialized)
+    {
+      env_vars.add ("SITEROOT", std_sym);
+      env_vars.add ("CMTCONFIG", std_sym);
+      env_vars.add ("CMTBIN", std_sym);
+      env_vars.add ("CMTPATH", std_sym);
+      env_vars.add ("CMTHEADVERSION", std_sym);
+      env_vars.add ("CMTPROJECTPATH", std_sym);
+      env_vars.add ("CMTSITE", std_sym);
+      env_vars.add ("CMTEXTRATAGS", std_sym);
+      env_vars.add ("CMTSTRUCTURINGSTYLE", std_sym);
+      env_vars.add ("CMTHOME", std_sym);
+      env_vars.add ("CMTUSERCONTEXT", std_sym);
+      initialized = true;
+    }
+  return env_vars;
 }
 
@@ -1021,5 +1115,9 @@
             {
 	      if (use->get_strategy ("SetupRoot") &&
-		  use->get_package_name () != "cmt_standalone")
+		  use->get_package_name () != "cmt_standalone" &&
+		  (action_setup == Cmt::get_action () ||
+		   action_cleanup == Cmt::get_action ()) &&
+		  Requirements != Cmt::get_print_mode () &&
+		  Xml != Cmt::get_print_mode ())
 		{
 #ifdef WIN32
@@ -1084,5 +1182,5 @@
 	   */
 	  if (name == "constituents") return;
-	  if (name == "constituentscclean") return;
+	  if (name == "constituentsclean") return;
 
           if (use->get_current_scope () == ScopePrivate) return;
@@ -1165,4 +1263,26 @@
         }
     }
+}
+
+//-------------------------------------------------------------
+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++)
+    {
+      Symbol& symbol = Symbol::symbol (number);
+      
+      if (symbol.type == Symbol::SymbolPath)
+	{
+	  static_cast<PathBuilder*> (symbol.builder)->set_strip_path (strip_path);
+	  return true;
+	}
+    }
+
+  return false;
+  */
 }
 
@@ -1422,4 +1542,6 @@
   cmt_string value;
 
+  if (Cmt::get_env_access ())
+    {
   for (number = 0; number < Symbol::symbol_number (); number++)
     {
@@ -1433,6 +1555,12 @@
 	  Symbol::expand (value);
 
+          if (Cmt::get_debug ())
+            {
+              cerr << "Symbol::all_set (set)> " << symbol.name << " = " << value << endl;
+            }
+
 	  CmtSystem::putenv (symbol.name, value);
 	}
+    }
     }
 
@@ -1500,4 +1628,8 @@
   }
 
+  static PathBuilder* pb (0);
+
+  if (Cmt::get_env_access ())
+    {
   for (number = 0; number < Symbol::symbol_number (); number++)
     {
@@ -1510,5 +1642,8 @@
 	{
 	  Symbol::expand (value);
-	  filter_path_value (symbol.name, value);
+	  if (!pb)
+	    pb = static_cast<PathBuilder*> (symbol.builder);
+	  pb->filter_path_value (symbol, value);
+	  //filter_path_value (symbol.name, value);
 
 #ifdef WIN32
@@ -1518,5 +1653,5 @@
           if (Cmt::get_debug ())
             {
-              cerr << "Symbol::all_set-2> " << symbol.name << " = " << value << endl;
+              cerr << "Symbol::all_set (path)> " << symbol.name << " = " << value << endl;
             }
 
@@ -1524,4 +1659,5 @@
 	}
     }
+    }
 
   running = false;
@@ -1529,5 +1665,6 @@
 
 //-------------------------------------------------------------
-void Symbol::all_print (PrintMode mode)
+void Symbol::all_print (PrintMode mode, ostream& out)
+//void Symbol::all_print (PrintMode mode)
 {
   static SymbolVector& Symbols = symbols ();
@@ -1550,5 +1687,5 @@
 	      (symbol.type == SymbolMacro))
 	    {
-	      if (symbol.print_macro (mode))
+	      if (symbol.print_macro (mode, out))
 		{
 		  //		  cout << endl;
@@ -1567,9 +1704,9 @@
 	      (symbol.type == SymbolPath))
 	    {
-	      if (symbol.print (mode))
+	      if (symbol.print (mode, out))
 		{
 		  if (mode == Bat)
 		    {
-		      cout << endl;
+		      out << endl;
 		    }
 		  else if (mode == Xml)
@@ -1579,5 +1716,5 @@
 		  else
 		    {
-		      cout << endl;
+		      out << endl;
 		    }
 		}
@@ -1593,4 +1730,6 @@
   static SymbolVector& Symbols = symbols ();
 
+  static PathBuilder* pb (0);
+
   int number;
 
@@ -1608,5 +1747,8 @@
 	  expand (temp);
 
-	  Symbol::filter_path_value (symbol.name, temp);
+	  if (!pb)
+	    pb = static_cast<PathBuilder*> (symbol.builder);
+	  pb->filter_path_value (symbol, temp);
+	  //Symbol::filter_path_value (symbol.name, temp);
         }
     }
@@ -1696,6 +1838,5 @@
             break;
           case Sh :
-	    cout << "[ -z ${" << name << "+CMT} ] || unset " << name;
-	  //            cout << "unset " << name;
+	    cout << "alias " << name << " >/dev/null 2>&1 && unalias " << name;
             result = 1;
             break;
@@ -1762,6 +1903,8 @@
 
 //-------------------------------------------------------------
-int Symbol::print (PrintMode mode)
-{
+int Symbol::print (PrintMode mode, ostream& out)
+{
+  static PathBuilder* pb (0);
+
   int result = 0;
 
@@ -1769,31 +1912,58 @@
   bool empty = (temp.size () == 0) ? true : false;
 
+  cmt_string _name (name);
+  switch (type)
+    {
+    case SymbolSet :
+    case SymbolPath :
+      expand (temp);
+      if (type == SymbolPath)
+	{
+	  if (!pb)
+	    pb = static_cast<PathBuilder*> (builder);
+	  pb->filter_path_value (*this, temp);
+	}
+      switch (mode)
+	{
+	case Xml :
+	  break;
+	default:
+	  if (0 != CmtSystem::mangle (name, _name))
+	    CmtMessage::info ("Replace " + name + " with " + _name);
+	  break;
+	}
+      break;
+    default:
+      break;
+    }
+
+  /*
   if (type == SymbolPath)
     {
       expand (temp);
-      Symbol::filter_path_value (name, temp);
-    }
-
-  cmt_string _name;
+      //Symbol::filter_path_value (name, temp);
+      if (!pb)
+	pb = static_cast<PathBuilder*> (builder);
+      pb->filter_path_value (*this, temp);
+    }
+  */
   switch (type)
     {
       case SymbolSet :
       case SymbolPath :
-	if (0 != CmtSystem::mangle (name, _name))
-	  CmtMessage::info ("Replace " + name + " with " + _name);
         switch (mode)
           {
             case Csh :
-              if (empty) cout << "unsetenv " << _name;
-              else cout << "setenv " << _name << " \"" << temp << "\"";
-              //else cout << "setenv " << name << " " << CmtSystem::quote (temp, " \t");
+              if (empty) out << "unsetenv " << _name;
+              else out << "setenv " << _name << " \"" << temp << "\"";
+              //else out << "setenv " << name << " " << CmtSystem::quote (temp, " \t");
 
               result = 1;
               break;
             case Sh :
-              if (empty) cout << "[ -z ${" << _name << "+CMT} ] || unset " << _name;
-	      //              if (empty) cout << "unset " << _name;
-              else cout << _name << "=\"" << temp << "\"; export " << _name;
-              //else cout << name << "=" << CmtSystem::quote (temp, " \t") << "; export " << name;
+              if (empty) out << "[ -z ${" << _name << "+CMT} ] || unset " << _name;
+	      //              if (empty) out << "unset " << _name;
+              else out << _name << "=\"" << temp << "\"; export " << _name;
+              //else out << name << "=" << CmtSystem::quote (temp, " \t") << "; export " << name;
 
               result = 1;
@@ -1801,10 +1971,10 @@
             case Bat :
               temp.replace_all ("/", "\\");
-              cout << "set " << _name << "=" << CmtSystem::quote (temp, " \t");
-              //cout << "set " << name << "=" << temp;
+              out << "set " << _name << "=" << CmtSystem::quote (temp, " \t");
+              //out << "set " << name << "=" << temp;
               result = 1;
               break;
             case Xml :
-              cout << "<variable><name>" << _name << "</name>"
+              out << "<variable><name>" << _name << "</name>"
 		   << "<value>" << temp << "</value></variable>";
               result = 1;
@@ -1816,5 +1986,5 @@
           {
             case Csh :
-              cout << "alias " << name <<
+              out << "alias " << name <<
 		" \"" << temp << "\"";
 	      //CmtSystem::quote (temp, " \t");
@@ -1822,5 +1992,5 @@
               break;
             case Sh :
-              cout << "alias " << name <<
+              out << "alias " << name <<
 		"=\"" << temp << "\"";
 	      //"=" << CmtSystem::quote (temp, " \t");
@@ -1828,5 +1998,5 @@
               break;
             case Bat :
-              cout << "set " << name <<
+              out << "set " << name <<
 		"=" << CmtSystem::quote (temp, " \t");
 	      //"=" << temp;
@@ -1834,5 +2004,5 @@
               break;
             case Xml :
-              cout << "<alias><name>" << name << "</name>"
+              out << "<alias><name>" << name << "</name>"
 		   << "<value>" << temp << "</value></alias>";
               result = 1;
@@ -1852,29 +2022,29 @@
               {
                 case Csh :
-                  cout << "if ( -f " << CmtSystem::quote (name, " \t") << ".csh ) then" << endl;
-                  cout << "  source " << CmtSystem::quote (name, " \t") << ".csh" << endl;
-                  cout <<
+                  out << "if ( -f " << CmtSystem::quote (name, " \t") << ".csh ) then" << endl;
+                  out << "  source " << CmtSystem::quote (name, " \t") << ".csh" << endl;
+                  out <<
 		    "if ( $status != 0 ) then\n"
 		    "    set cmtsetupstatus=1\n"
 		    "endif\n";
-                  cout << "endif" << endl;
+                  out << "endif" << endl;
                   result = 1;
                   break;
                 case Sh :
-                  cout << "if test -f " << CmtSystem::quote (name, " \t") << ".sh; then" << endl;
-                  cout << "  . " << CmtSystem::quote (name, " \t") << ".sh" << endl;
-                  cout <<
+                  out << "if test -f " << CmtSystem::quote (name, " \t") << ".sh; then" << endl;
+                  out << "  . " << CmtSystem::quote (name, " \t") << ".sh" << endl;
+                  out <<
 		    "if test $? != 0; then\n"
 		    "    cmtsetupstatus=1\n"
 		    "fi\n";
-                  cout << "fi" << endl;
+                  out << "fi" << endl;
                   result = 1;
                   break;
                 case Bat :
-                  cout << "call " << CmtSystem::quote (name, " \t");
+                  out << "call " << CmtSystem::quote (name, " \t");
                   result = 1;
                   break;
                 case Xml :
-                  cout << "<script>" << name << "</script>";
+                  out << "<script>" << name << "</script>";
                   result = 1;
                   break;
@@ -2124,5 +2294,5 @@
       SymbolValue& value = value_list.values[selected];
 
-      result += value_list.print (symbol, value, first_definition);
+      result += value_list.print (symbol, value, first_definition, out);
     }
 
@@ -2202,5 +2372,25 @@
             else if (temp == "")
               {
-                temp = CmtSystem::getenv (symbol.name);
+		if (Cmt::get_env_access () ||
+		    Symbol::std_env_vars ().has (symbol.name))
+		  {
+		    temp = CmtSystem::getenv (symbol.name);
+		    if (Cmt::get_debug ())
+		      {
+			cerr << "SetBuilder::build> getenv (" << symbol.name
+			     << ") => " << temp << endl;
+		      }
+		  }
+		else
+		  {
+		    if (Cmt::get_debug ())
+		      {
+			cerr << "SetBuilder::build> getenv (" << symbol.name
+			     << ") denied" << endl;
+		      }
+		    CmtError::set (CmtError::warning,
+				   "getenv (" + symbol.name + ") denied");
+		    return "";
+		  }
               }
 
@@ -2263,10 +2453,109 @@
 }
 
+namespace
+{
+int find_path_entry (const CmtSystem::cmt_string_vector& items, const cmt_string& value)
+{
+  //  if (value.size () == 0) return true;
+  
+  static cmt_vmap <cmt_string, cmt_string> realpaths;
+
+  cmt_string rvalue;
+  const cmt_string * prvalue;
+
+  if (!(prvalue = realpaths.find (value)))
+    {
+      // if (!CmtSystem::realpath_ (value, rvalue))
+      //{
+	  rvalue = value;
+	  CmtSystem::compress_path (rvalue);
+      //}
+      prvalue = &rvalue;
+      realpaths.add (value, rvalue);
+      //      cerr << "realpaths.add: " << value << " , " << rvalue << endl;
+    }
+
+  for (int i = 0; i < items.size (); i++)
+    {
+      const cmt_string& item = items[i];
+      if (item.size () == 0) continue;
+      cmt_string ritem;
+      const cmt_string * pritem;
+
+      if (!(pritem = realpaths.find (item)))
+	{
+	  //if (!CmtSystem::realpath_ (item, ritem))
+	  //{
+	      ritem = item;
+	      CmtSystem::compress_path (ritem);
+	  //}
+	  pritem = &ritem;
+	  realpaths.add (item, ritem);
+	  //  cerr << "realpaths.add: " << item << " , " << ritem << endl;
+	}
+      if (*pritem == *prvalue)
+	{
+	  return i;
+	}
+    }
+
+  return -1;
+}
+
+}
+/*
 static bool find_path_entry (const CmtSystem::cmt_string_vector& items, const cmt_string& value)
+{
+  if (value.size () == 0) return true;
+
+  static cmt_vmap <cmt_string, cmt_string> realpaths;
+
+  cmt_string rvalue;
+  const cmt_string * prvalue;
+
+  if (!(prvalue = realpaths.find (value)))
+    {
+      // if (!CmtSystem::realpath_ (value, rvalue))
+      //{
+	  rvalue = value;
+	  CmtSystem::compress_path (rvalue);
+      //}
+      prvalue = &rvalue;
+      realpaths.add (value, rvalue);
+      //      cerr << "realpaths.add: " << value << " , " << rvalue << endl;
+    }
+
+  for (int i = 0; i < items.size (); i++)
+    {
+      const cmt_string& item = items[i];
+      if (item.size () == 0) continue;
+      cmt_string ritem;
+      const cmt_string * pritem;
+
+      if (!(pritem = realpaths.find (item)))
+	{
+	  //if (!CmtSystem::realpath_ (item, ritem))
+	  //{
+	      ritem = item;
+	      CmtSystem::compress_path (ritem);
+	  //}
+	  pritem = &ritem;
+	  realpaths.add (item, ritem);
+	  //  cerr << "realpaths.add: " << item << " , " << ritem << endl;
+	}
+      if (*pritem == *prvalue)
+	{
+	  return true;
+	}
+    }
+
+  return false;
+}
+*/
+/*
+static bool find_path_entry (const cmt_string& paths, const cmt_string& value)
 {
   static const cmt_string path_separator = CmtSystem::path_separator ();
   static cmt_vmap <cmt_string, cmt_string> realpaths;
-
-  if (value.size () == 0) return true;
 
   cmt_string rvalue;
@@ -2285,6 +2574,6 @@
     }
 
-  //  CmtSystem::cmt_string_vector items;
-  //  CmtSystem::split (paths, path_separator, items);
+  CmtSystem::cmt_string_vector items;
+  CmtSystem::split (paths, path_separator, items);
 
   bool found = false;
@@ -2293,5 +2582,4 @@
     {
       const cmt_string& item = items[i];
-      if (item.size () == 0) continue;
       cmt_string ritem;
       const cmt_string * pritem;
@@ -2317,55 +2605,23 @@
   return (found);
 }
-
-static bool find_path_entry (const cmt_string& paths, const cmt_string& value)
-{
-  static const cmt_string path_separator = CmtSystem::path_separator ();
-  static cmt_vmap <cmt_string, cmt_string> realpaths;
-
-  cmt_string rvalue;
-  const cmt_string * prvalue;
-
-  if (!(prvalue = realpaths.find (value)))
-    {
-      if (!CmtSystem::realpath_ (value, rvalue))
-	{
-	  rvalue = value;
-	  CmtSystem::compress_path (rvalue);
-	}
-      prvalue = &rvalue;
-      realpaths.add (value, rvalue);
-      //      cerr << "realpaths.add: " << value << " , " << rvalue << endl;
-    }
-
-  CmtSystem::cmt_string_vector items;
-  CmtSystem::split (paths, path_separator, items);
-
-  bool found = false;
-
-  for (int i = 0; i < items.size (); i++)
-    {
-      const cmt_string& item = items[i];
-      cmt_string ritem;
-      const cmt_string * pritem;
-
-      if (!(pritem = realpaths.find (item)))
-	{
-	  if (!CmtSystem::realpath_ (item, ritem))
-	    {
-	      ritem = item;
-	      CmtSystem::compress_path (ritem);
-	    }
-	  pritem = &ritem;
-	  realpaths.add (item, ritem);
-	  //  cerr << "realpaths.add: " << item << " , " << ritem << endl;
-	}
-      if (*pritem == *prvalue)
-	{
-	  found = true;
-	  break;
-	}
-    }
-
-  return (found);
+*/
+//-------------------------------------------------------------
+PathBuilder* PathBuilder::get_path_builder ()
+{
+  static PathBuilder Path (Cmt::get_strip_path ());
+  return &Path;
+}
+
+//-------------------------------------------------------------
+PathBuilder::PathBuilder ()
+  : m_strip_path (false)
+{
+}
+
+//-------------------------------------------------------------
+PathBuilder::PathBuilder (bool strip_path)
+{
+  PathBuilder ();
+  m_strip_path = strip_path;
 }
 
@@ -2401,6 +2657,29 @@
   level++;
 
+		if (Cmt::get_env_access () ||
+		    Symbol::std_env_vars ().has (symbol.name))
+		  {
+  //temp = CmtSystem::getenv (symbol.name);
   CmtSystem::split (CmtSystem::getenv (symbol.name), path_separator, temp_vector);
-  //temp = CmtSystem::getenv (symbol.name);
+  filter_path_value (symbol, temp_vector);
+		    if (Cmt::get_debug ())
+		      {
+			cmt_string temp_txt;
+			Cmt::vector_to_string (temp_vector, path_separator, temp_txt);
+			cerr << "PathBuilder::build> getenv (" << symbol.name
+			     << ") => " << temp_txt << endl;
+		      }
+		  }
+		else
+		  {
+		    if (Cmt::get_debug ())
+		      {
+			cerr << "PathBuilder::build> getenv (" << symbol.name
+			     << ") denied" << endl;
+		      }
+		    CmtError::set (CmtError::warning,
+				   "getenv (" + symbol.name + ") denied");
+		    return "";
+		  }
 
   bool first_definition = true;
@@ -2442,4 +2721,5 @@
 		CmtSystem::split (new_value, path_separator, temp_vector);
                 //temp = new_value;
+		filter_path_value (symbol, temp_vector);
               }
 
@@ -2451,14 +2731,17 @@
 		CmtSystem::split (new_value, path_separator, new_value_vector);
 		for (int i = 0; i < new_value_vector.size (); i++)
-		  if (!find_path_entry (temp_vector, new_value_vector[i]))
-		    //if (!find_path_entry (temp, new_value))
-		    {
-		      temp_vector.push_back (new_value_vector[i]);
-		      /*
-			if (temp != "") temp += path_separator;
-			
-			temp += new_value;
-		      */
-		    }
+		  {
+		    if (new_value_vector[i].size () == 0) continue;
+		    int j = find_path_entry (temp_vector, new_value_vector[i]);
+		    if (j < 0)
+		      {
+			temp_vector.push_back (new_value_vector[i]);
+		      }
+		    else if (j < temp_vector.size () - 1)
+		      {
+			temp_vector [j] = "";
+			temp_vector.push_back (new_value_vector[i]);
+		      }
+		  }
               }
                   
@@ -2473,18 +2756,20 @@
 		for (int i = temp_vector.size () - 1; i > n - 1; i--)
 		  temp_vector [i] = temp_vector [i - n];
+		for (int i = 0; i < n; i++)
+		  temp_vector [i] = "";
 		for (int i = 0; i < new_value_vector.size (); i++)
-		  if (!find_path_entry (temp_vector, new_value_vector[i]))
-		    //if (!find_path_entry (temp, new_value))
-		    {
-		      temp_vector [i] = new_value_vector[i];
-		      /*
-			previous_temp = temp;
-			temp = new_value;
-			if (previous_temp != "") temp += path_separator;
-			temp += previous_temp;
-		      */
-		    }
-		  else
-		    temp_vector [i] = "";
+		  {
+		    if (new_value_vector[i].size () == 0) continue;
+		    int j = find_path_entry (temp_vector, new_value_vector[i]);
+		    if (j < 0)
+		      {
+			temp_vector [i] = new_value_vector[i];
+		      }
+		    else if (j >= n)
+		      {
+			temp_vector [i] = new_value_vector[i];
+			temp_vector [j] = "";
+		      }
+		  }
               }
 	    
@@ -2614,5 +2899,5 @@
 
   level--;
-
+  /*
   for (;;)
     {
@@ -2637,5 +2922,5 @@
   temp.replace_all ("::", ":");
   temp.replace_all (";;", ";");
-  
+  */
   return (temp);
 }
@@ -2767,4 +3052,90 @@
   
   return (temp);
+}
+
+//-------------------------------------------------------------
+void PathBuilder::filter_path_value (const Symbol& symbol,
+				     CmtSystem::cmt_string_vector& value,
+				     const cmt_string& /* tag_name */) const
+{
+  static cmt_regexp reg ("[$%`]");
+
+  cmt_vector<int> path (value.size ());
+  int n (0);
+
+  for (int j = 0; j < value.size (); j++)
+    {
+      const cmt_string& v = value[j];
+      bool exists (false);  
+      for (int i = 0; i < j; i++)
+	{
+          if (value[i] == v)
+	    {
+	      exists = true;
+	      break;
+	    }
+	}	  	  
+      if (!exists)
+	{
+	  if (m_strip_path)
+	    {
+	      if (!reg.match (v))
+		{
+		  if (!CmtSystem::test_directory (v))
+		    {
+		      CmtMessage::verbose ("Non-existent directory " + v + " in " + symbol.name + " skipped");
+		      continue;
+		    }
+		}
+	      else
+		{
+		  if (CmtMessage::active (Verbose))
+		    {
+		      CmtMessage::warning ("Unresolved directory name " + v + " in " + symbol.name);
+		    }
+		}
+	    }
+	  else
+	    {
+	      if (CmtMessage::active (Verbose))
+		if (!reg.match (v) &&
+		    !CmtSystem::test_directory (v))
+		  {
+		    CmtMessage::warning ("Non-existent directory " + v + " in " + symbol.name);
+		  }
+	    }
+	  path[n++] = j;
+	}
+    }
+
+  for (int i = 0; i < n; i++)
+    if (i != path[i]) value[i] = value[path[i]];
+  
+  value.resize (n);
+}
+
+//-------------------------------------------------------------
+void PathBuilder::filter_path_value (const Symbol& symbol,
+				     cmt_string& value,
+				     const cmt_string& tag_name) const
+{
+  static cmt_string ps (CmtSystem::path_separator ());
+  CmtSystem::cmt_string_vector paths;
+
+  CmtSystem::split (value, ps, paths);
+  filter_path_value (symbol, paths, tag_name);
+  Cmt::vector_to_string (paths, ps, value);
+}
+
+//-------------------------------------------------------------
+inline const bool& PathBuilder::get_strip_path () const
+{
+  return m_strip_path;
+}
+
+//-------------------------------------------------------------
+inline void PathBuilder::set_strip_path (const bool& strip_path)
+{
+  m_strip_path = strip_path;
 }
 
@@ -3275,13 +3646,15 @@
 int SymbolValueList::print (const Symbol& symbol, 
 			    const SymbolValue& value, 
-			    bool& first_definition) const
+			    bool& first_definition,
+			    ostream& out) const
 {
   int result (0);
-
-  //if (use->get_package_name () == "CMT") return result;
 
   cmt_string discarded_text;
   cmt_string define_text;
   ActionType action = Cmt::get_action ();
+
+  static PathBuilder* pb (0);
+  cmt_string rvalue (value.text);
 
   switch (command_type)
@@ -3306,5 +3679,200 @@
       case CommandMacroRemoveAllRegexp :
 	//case CommandAction :
-	if (value.text == "") return result;
+	if (value.text.size () == 0) return result;
+        break;
+    }
+
+  CmtError::code code (CmtError::ok);
+  cmt_string msg, n;
+  int exec_err (0);
+
+  switch (command_type)
+    {
+      case CommandSet :
+      case CommandSetAppend :
+      case CommandSetPrepend :
+      case CommandSetRemove :
+      case CommandSetRemoveRegexp :
+
+	if (CmtError::has_pending_error ())
+	  {
+	    code = CmtError::get_last_error_code ();
+	    msg = CmtError::get_last_error ();
+	    exec_err = CmtError::get_last_execution_error ();
+	    n = CmtError::get_error_name (code);
+	    CmtError::clear ();
+	  }
+	resolve_value_for_macros (rvalue);
+	if (CmtError::get_last_error_code () != CmtError::warning)
+	  {
+	    if (CmtError::has_pending_error ())
+	      {
+		CmtError::print ();
+		CmtError::clear ();
+	      }
+	    if (CmtError::ok != code)
+	      {
+		// restore error occurred before value expansion
+		CmtError::set (code,
+			       (msg.replace (n + ": ", cmt_string ("")), msg),
+			       exec_err);
+	      }
+	    if (CommandSet != command_type &&
+		rvalue.size () == 0)
+	      return result;
+	  }
+	else
+	  {
+	    if (CmtMessage::active (Verbose))
+	      CmtError::print ();
+	    CmtError::clear ();
+	    if (CmtError::ok != code)
+	      {
+		// restore error occurred before value expansion
+		CmtError::set (code,
+			       (msg.replace (n + ": ", cmt_string ("")), msg),
+			       exec_err);
+	      }
+	    // Ignore the error, keep the value unresolved
+	    rvalue = value.text;
+	  }
+
+        break;
+
+	//case CommandAlias :
+      case CommandPath :
+      case CommandPathAppend :
+      case CommandPathPrepend :
+      case CommandPathRemove :
+      case CommandPathRemoveRegexp :
+	//case CommandMacroPrepend :
+	//case CommandMacro :
+	//case CommandMacroAppend :
+	//case CommandMacroRemove :
+	//case CommandMacroRemoveRegexp :
+	//case CommandMacroRemoveAll :
+	//case CommandMacroRemoveAllRegexp :
+	//case CommandAction :
+
+	if (!pb)
+	  pb = static_cast<PathBuilder*> (symbol.builder);
+	if (pb->get_strip_path ())
+	  {
+	    /*
+	    CmtError::code code (CmtError::ok);
+	    cmt_string msg, n;
+	    int exec_err (0);
+	    */
+	    if (CmtError::has_pending_error ())
+	      {
+		code = CmtError::get_last_error_code ();
+		msg = CmtError::get_last_error ();
+		exec_err = CmtError::get_last_execution_error ();
+		n = CmtError::get_error_name (code);
+		CmtError::clear ();
+	      }
+	    resolve_value (rvalue);
+	    if (CmtError::get_last_error_code () != CmtError::warning)
+	      {
+		if (CmtError::has_pending_error ())
+		  {
+		    CmtError::print ();
+		    CmtError::clear ();
+		  }
+		if (CmtError::ok != code)
+		  {
+		    // restore error occurred before value expansion
+		    CmtError::set (code,
+				   (msg.replace (n + ": ", cmt_string ("")), msg),
+				   exec_err);
+		  }
+		if (CommandPath != command_type &&
+		    rvalue.size () == 0)
+		  return result;
+	      }
+	    else
+	      {
+		if (CommandPathRemove == command_type ||
+		    CommandPathRemoveRegexp == command_type)
+		  {
+		    // This means that the value is not resolved via symbols
+		    // and, possibly, standard environment variables and
+		    //   * either has no effect on the path at all,
+		    //     or
+		    //   * there should be similar contribution from
+		    //     and, hence, we should get the same error with 
+		    //     CommandPath, CommandPathAppend, or CommandPathPrepend
+		    //  Either way, we can ignore this error.
+
+		    if (CmtMessage::active (Verbose))
+		      CmtError::print ();
+		    CmtError::clear ();
+		    if (CmtError::ok != code)
+		      {
+			// restore error occurred before value expansion
+			CmtError::set (code,
+				       (msg.replace (n + ": ", cmt_string ("")), msg),
+				       exec_err);
+		      }
+		  }
+		else if (CmtError::ok != code)
+		  {
+		    // print error occurred before value expansion
+		    CmtMessage::error (msg);
+		  }
+		// We keep CmtError::warning to indicate that
+		// we could not resolve path
+		// (without referencing the environment)
+		// and strip path of non-existent directories
+		//
+		rvalue = value.text;
+	      }
+	  }
+	else // (!pb->get_strip_path ())
+	  {
+	    if (CmtError::has_pending_error ())
+	      {
+		code = CmtError::get_last_error_code ();
+		msg = CmtError::get_last_error ();
+		exec_err = CmtError::get_last_execution_error ();
+		n = CmtError::get_error_name (code);
+		CmtError::clear ();
+	      }
+	    resolve_value_for_macros (rvalue);
+	    if (CmtError::get_last_error_code () != CmtError::warning)
+	      {
+		if (CmtError::has_pending_error ())
+		  {
+		    CmtError::print ();
+		    CmtError::clear ();
+		  }
+		if (CmtError::ok != code)
+		  {
+		    // restore error occurred before value expansion
+		    CmtError::set (code,
+				   (msg.replace (n + ": ", cmt_string ("")), msg),
+				   exec_err);
+		  }
+		if (CommandPath != command_type &&
+		    rvalue.size () == 0)
+		  return result;
+	      }
+	    else
+	      {
+		if (CmtMessage::active (Verbose))
+		  CmtError::print ();
+		CmtError::clear ();
+		if (CmtError::ok != code)
+		  {
+		    // restore error occurred before value expansion
+		    CmtError::set (code,
+				   (msg.replace (n + ": ", cmt_string ("")), msg),
+				   exec_err);
+		  }
+		// Ignore the error, keep the value unresolved
+		rvalue = value.text;
+	      }
+	  }
+
         break;
     }
@@ -3317,11 +3885,5 @@
 
   if (CmtMessage::active (Verbose))
-    cout << "# Package " << (use != 0 ? use->get_package_name () + " " + use->version : "");
-  /*
-  if (use != 0)
-    {
-      cout << use->get_package_name () << " " << use->version;
-    }
-  */
+    out << "# Package " << (use ? use->get_package_name () + " " + use->version : "");
 
   switch (command_type)
@@ -3329,7 +3891,7 @@
       case CommandSet :
 	if (CmtMessage::active (Verbose))
-	  cout << " " << define_text << " set " << symbol.name << " as " << endl;
-	//        cout << " " << define_text << " set " << symbol.name << " as ";
-        cout << "set " << symbol.name;
+	  out << " " << define_text << " set " << symbol.name << " as " << endl;
+	//        out << " " << define_text << " set " << symbol.name << " as ";
+        out << "set " << symbol.name;
         first_definition = false;
 	result = 1;
@@ -3337,43 +3899,51 @@
       case CommandSetAppend :
 	if (CmtMessage::active (Verbose))
-	  cout << " appends to set " << symbol.name << " : " << endl;
-	//        cout << " appends to set " << symbol.name << " : ";
-        cout << "set_append " << symbol.name;
+	  out << " appends to set " << symbol.name << " : " << endl;
+	//        out << " appends to set " << symbol.name << " : ";
+        out << "set_append " << symbol.name;
 	result = 1;
         break;
       case CommandSetPrepend :
 	if (CmtMessage::active (Verbose))
-	  cout << " prepends to set " << symbol.name << " : " << endl;
-	//        cout << " prepends to set " << symbol.name << " : ";
-        cout << "set_prepend " << symbol.name;
+	  out << " prepends to set " << symbol.name << " : " << endl;
+	//        out << " prepends to set " << symbol.name << " : ";
+        out << "set_prepend " << symbol.name;
 	result = 1;
         break;
       case CommandSetRemove :
 	if (CmtMessage::active (Verbose))
-	  cout << " removes from set " << symbol.name << " : " << endl;
-	//        cout << " removes from set " << symbol.name << " : ";
-        cout << "set_remove " << symbol.name;
+	  out << " removes from set " << symbol.name << " : " << endl;
+	//        out << " removes from set " << symbol.name << " : ";
+        out << "set_remove " << symbol.name;
 	result = 1;
         break;
       case CommandSetRemoveRegexp :
 	if (CmtMessage::active (Verbose))
-	  cout << " removes RE from set " << symbol.name << " : " << endl;
-	//        cout << " removes RE from set " << symbol.name << " : ";
-        cout << "set_remove_regexp " << symbol.name;
+	  out << " removes RE from set " << symbol.name << " : " << endl;
+	//        out << " removes RE from set " << symbol.name << " : ";
+        out << "set_remove_regexp " << symbol.name;
 	result = 1;
         break;
       case CommandAlias :
 	if (CmtMessage::active (Verbose))
-	  cout << " " << define_text << " alias " << symbol.name << endl;
-	//        cout << " " << define_text << " alias " << symbol.name << " as ";
-        cout << "alias " << symbol.name;
+	  out << " " << define_text << " alias " << symbol.name << endl;
+	//        out << " " << define_text << " alias " << symbol.name << " as ";
+        out << "alias " << symbol.name;
         first_definition = false;
 	result = 1;
         break;
-      case CommandPath :
+    case CommandPath :
 	if (CmtMessage::active (Verbose))
-	  cout << " " << define_text << " path " << symbol.name << endl;
-	//        cout << " " << define_text << " path " << symbol.name << " as ";
-        cout << "path " << symbol.name;
+	  out << " " << define_text << " path " << symbol.name << endl;
+	//        out << " " << define_text << " path " << symbol.name << " as ";
+	pb->filter_path_value (symbol, rvalue);
+
+	if (Cmt::get_debug ())
+	  {
+	    cerr << "|SymbolValueList::print> path " << symbol.name
+		 << " " << value.text << " => " << rvalue << endl;
+	  }
+
+        out << "path " << symbol.name;
         first_definition = false;
 	result = 1;
@@ -3381,84 +3951,116 @@
       case CommandPathAppend :
 	if (CmtMessage::active (Verbose))
-	  cout << " appends to path " << symbol.name << endl;
-	//        cout << " appends to path " << symbol.name << " : ";
-        cout << "path_append " << symbol.name;
+	  out << " appends to path " << symbol.name << endl;
+	//        out << " appends to path " << symbol.name << " : ";
+	pb->filter_path_value (symbol, rvalue);
+
+	if (Cmt::get_debug ())
+	  {
+	    cerr << "|SymbolValueList::print> path_append " << symbol.name
+		 << " " << value.text << " => " << rvalue << endl;
+	  }
+
+	if (rvalue.size () == 0) return result;
+        out << "path_append " << symbol.name;
 	result = 1;
         break;
       case CommandPathPrepend :
 	if (CmtMessage::active (Verbose))
-	  cout << " prepends to path " << symbol.name << " : " << endl;
-	//        cout << " prepends to path " << symbol.name << " : ";
-        cout << "path_prepend " << symbol.name;
+	  out << " prepends to path " << symbol.name << " : " << endl;
+	//        out << " prepends to path " << symbol.name << " : ";
+	pb->filter_path_value (symbol, rvalue);
+
+	if (Cmt::get_debug ())
+	  {
+	    cerr << "|SymbolValueList::print> path_prepend " << symbol.name
+		 << " " << value.text << " => " << rvalue << endl;
+	  }
+
+	if (rvalue.size () == 0) return result;
+        out << "path_prepend " << symbol.name;
 	result = 1;
         break;
       case CommandPathRemove :
 	if (CmtMessage::active (Verbose))
-	  cout << " removes from path " << symbol.name << " : " << endl;
-	//        cout << " removes from path " << symbol.name << " : ";
-        cout << "path_remove " << symbol.name;
+	  out << " removes from path " << symbol.name << " : " << endl;
+	//        out << " removes from path " << symbol.name << " : ";
+
+	if (Cmt::get_debug ())
+	  {
+	    cerr << "|SymbolValueList::print> path_remove " << symbol.name
+		 << " " << value.text << " => " << rvalue << endl;
+	  }
+
+        out << "path_remove " << symbol.name;
 	result = 1;
         break;
       case CommandPathRemoveRegexp :
 	if (CmtMessage::active (Verbose))
-	  cout << " removes RE from path " << symbol.name << " : " << endl;
-	//        cout << " removes RE from path " << symbol.name << " : ";
-        cout << "path_remove_regexp " << symbol.name;
+	  out << " removes RE from path " << symbol.name << " : " << endl;
+	//        out << " removes RE from path " << symbol.name << " : ";
+
+	if (Cmt::get_debug ())
+	  {
+	    cerr << "|SymbolValueList::print> path_remove_regexp " << symbol.name
+		 << " " << value.text << " => " << rvalue << endl;
+	  }
+
+        out << "path_remove_regexp " << symbol.name;
 	result = 1;
         break;
       case CommandMacro :
 	if (CmtMessage::active (Verbose))
-	  cout << " " << define_text << " macro " << symbol.name << " as " << endl;
-	//        cout << " " << define_text << " macro " << symbol.name << " as ";
-        cout << "macro " << symbol.name;
+	  out << " " << define_text << " macro " << symbol.name << " as " << endl;
+	//        out << " " << define_text << " macro " << symbol.name << " as ";
+        out << "macro " << symbol.name;
 	result = 1;
         break;
       case CommandMacroPrepend :
 	if (CmtMessage::active (Verbose))
-	  cout << " prepends to macro " << symbol.name << " : " << endl;
-	//        cout << " prepends to macro " << symbol.name << " : ";
-        cout << "macro_prepend " << symbol.name;
+	  out << " prepends to macro " << symbol.name << " : " << endl;
+	//        out << " prepends to macro " << symbol.name << " : ";
+        out << "macro_prepend " << symbol.name;
 	result = 1;
         break;
       case CommandMacroAppend :
 	if (CmtMessage::active (Verbose))
-	  cout << " appends to macro " << symbol.name << " : " << endl;
-	//        cout << " appends to macro " << symbol.name << " : ";
-        cout << "macro_append " << symbol.name;
+	  out << " appends to macro " << symbol.name << " : " << endl;
+	//        out << " appends to macro " << symbol.name << " : ";
+        out << "macro_append " << symbol.name;
 	result = 1;
         break;
       case CommandMacroRemove :
 	if (CmtMessage::active (Verbose))
-	  cout << " remove from macro " << symbol.name << " : " << endl;
-	//        cout << " remove from macro " << symbol.name << " : ";
-        cout << "macro_remove " << symbol.name;
+	  out << " remove from macro " << symbol.name << " : " << endl;
+	//        out << " remove from macro " << symbol.name << " : ";
+        out << "macro_remove " << symbol.name;
 	result = 1;
         break;
       case CommandMacroRemoveRegexp :
 	if (CmtMessage::active (Verbose))
-	  cout << " remove RE from macro " << symbol.name << " : " << endl;
-	//        cout << " remove RE from macro " << symbol.name << " : ";
-        cout << "macro_remove_regexp " << symbol.name;
+	  out << " remove RE from macro " << symbol.name << " : " << endl;
+	//        out << " remove RE from macro " << symbol.name << " : ";
+        out << "macro_remove_regexp " << symbol.name;
 	result = 1;
         break;
       case CommandMacroRemoveAll :
 	if (CmtMessage::active (Verbose))
-	  cout << " remove all from macro " << symbol.name << " : " << endl;
-	//        cout << " remove all from macro " << symbol.name << " : ";
-        cout << "macro_remove_all " << symbol.name;
+	  out << " remove all from macro " << symbol.name << " : " << endl;
+	//        out << " remove all from macro " << symbol.name << " : ";
+        out << "macro_remove_all " << symbol.name;
 	result = 1;
         break;
       case CommandMacroRemoveAllRegexp :
 	if (CmtMessage::active (Verbose))
-	  cout << " remove all RE from macro " << symbol.name << " : " << endl;
-	//        cout << " remove all RE from macro " << symbol.name << " : ";
-        cout << "macro_remove_all_regexp " << symbol.name;
+	  out << " remove all RE from macro " << symbol.name << " : " << endl;
+	//        out << " remove all RE from macro " << symbol.name << " : ";
+        out << "macro_remove_all_regexp " << symbol.name;
 	result = 1;
         break;
       case CommandSetupScript :
 	if (CmtMessage::active (Verbose))
-	  cout << " " << define_text << " setup script " << symbol.name << endl;
-	//       cout << " " << define_text << " action " << symbol.name << " as ";
-        cout << "setup_script" /* << symbol.name */;
+	  out << " " << define_text << " setup script " << symbol.name << endl;
+	//       out << " " << define_text << " action " << symbol.name << " as ";
+        out << "setup_script" /* << symbol.name */;
         first_definition = false;
 	result = 1;
@@ -3466,5 +4068,5 @@
 	/*
       case CommandAction :
-        cout << " " << define_text << " action " << symbol.name << " as ";
+        out << " " << define_text << " action " << symbol.name << " as ";
         first_definition = false;
         break;
@@ -3472,6 +4074,7 @@
     }
 
-  cout << " " << CmtSystem::quote (value.text, " \t");
-  //  cout << "'" << value.text << "'";
+  out << " " << CmtSystem::quote (rvalue, " \t");
+  //  out << " " << CmtSystem::quote (value.text, " \t");
+  //  out << "'" << value.text << "'";
           
   /*
@@ -3481,14 +4084,14 @@
       (selected_tag == Tag::get_default ()))
     {
-      cout << " for default tag";
+      out << " for default tag";
     }
   else
     {
-      cout << " for tag '" << selected_tag->get_name () << "'";
+      out << " for tag '" << selected_tag->get_name () << "'";
     }
   */
 
-  cout << endl;
-  //  cout << discarded_text << endl;
+  out << endl;
+  //  out << discarded_text << endl;
   return result;
 }
@@ -3547,5 +4150,25 @@
   else
     {
+		if (Cmt::get_env_access () ||
+		    Symbol::std_env_vars ().has (name))
+		  {
       s = CmtSystem::getenv (name);
+		    if (Cmt::get_debug ())
+		      {
+			cerr << "Symbol::get_env_value> getenv (" << name
+			     << ") => " << s << endl;
+		      }
+		  }
+		else
+		  {
+		    if (Cmt::get_debug ())
+		      {
+			cerr << "Symbol::get_env_value> getenv (" << name
+			     << ") denied" << endl;
+		      }
+		    CmtError::set (CmtError::warning,
+				   "getenv (" + name + ") denied");
+		    return (s);
+		  }
     }
 
Index: CMT/v1r25-branch/source/cmt_symbol.h
===================================================================
--- CMT/v1r25-branch/source/cmt_symbol.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_symbol.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -34,5 +35,5 @@
   int select_last () const;
   void show (const Symbol& symbol, const SymbolValue& value, bool& first_definition) const;
-  int print (const Symbol& symbol, const SymbolValue& value, bool& first_definition) const;
+  int print (const Symbol& symbol, const SymbolValue& value, bool& first_definition, ostream& out = cout) const;
 
   CommandType command_type;
@@ -89,5 +90,6 @@
 
   static void all_set ();
-  static void all_print (PrintMode mode);
+  static void all_print (PrintMode mode, ostream& out = cout);
+  //static void all_print (PrintMode mode);
   static void all_print_clean (PrintMode mode);
   static void check_all_paths ();
@@ -96,4 +98,5 @@
   static SymbolVector& symbols ();
   static SymbolMap& symbol_map ();
+  static SymbolMap& std_env_vars ();
   static Symbol& symbol (int index);
   static void clear_all ();
@@ -107,4 +110,5 @@
 
   static bool get_inhibit_display ();
+  static bool set_strip_path (const bool& strip_path);
 
 public:
@@ -118,5 +122,6 @@
 
   int print_clean (PrintMode mode);
-  int print (PrintMode mode);
+  int print (PrintMode mode, ostream& out = cout);
+  //int print (PrintMode mode);
   cmt_string build_macro_value (bool display_it = false) const;
   int print_macro (PrintMode mode, ostream& out = cout) const;
Index: CMT/v1r25-branch/source/cmt_syntax.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_syntax.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_syntax.cxx	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -212,5 +213,5 @@
 	       int line_number)
   {
-        
+    /*        
     cmt_string cmtpath;
     cmt_string offset;
@@ -219,4 +220,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++)
@@ -287,6 +291,11 @@
 	  {
 	    in_error = true;
-
-	    CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
+	    char num[32]; sprintf (num, "%d", line_number);
+	    CmtError::set (CmtError::syntax_error,
+			   project->get_name ()
+			   + " project file: " + file_name
+			   + ": line: " + num
+			   + ": " + value + ": Bad strategy value");
+	    //CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
 	  }
       }
@@ -1060,4 +1069,5 @@
 	       int line_number)
   {
+    /*
     cmt_string cmtpath;
     cmt_string offset;
@@ -1066,4 +1076,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++)
@@ -1126,6 +1139,11 @@
 	  {
 	    in_error = true;
-
-	    CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
+	    char num[32]; sprintf (num, "%d", line_number);
+	    CmtError::set (CmtError::syntax_error,
+			   project->get_name ()
+			   + " project file: " + file_name
+			   + ": line: " + num
+			   + ": " + value + ": Bad strategy value");
+	    //CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
 	  }
       }
@@ -1164,4 +1182,5 @@
 	       int line_number)
   {
+    /*
     cmt_string cmtpath;
     cmt_string offset;
@@ -1170,4 +1189,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++)
@@ -1231,6 +1253,11 @@
 	  {
 	    in_error = true;
-
-	    CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
+	    char num[32]; sprintf (num, "%d", line_number);
+	    CmtError::set (CmtError::syntax_error,
+			   project->get_name ()
+			   + " project file: " + file_name
+			   + ": line: " + num
+			   + ": " + value + ": Bad strategy value");
+	    //CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
 	  }
       }
@@ -1403,5 +1430,5 @@
       //
       
-      Project* p = use->get_project ();
+      const Project* p = use->get_project ();
       if (p != 0)
         {      
@@ -2054,3 +2081,6 @@
 
   keyword->action (words, project, file_name, line_number);
+
+  if (CmtError::get_last_error_code () == CmtError::syntax_error)
+    CmtError::print ();
 }
Index: CMT/v1r25-branch/source/cmt_system.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_system.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_system.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_system.h
===================================================================
--- CMT/v1r25-branch/source/cmt_system.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_system.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_tag.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_tag.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_tag.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -99,4 +100,8 @@
 
   Log;
+
+  const CmtSystem::cmt_string_vector& tags_remove = Cmt::get_tags_remove ();
+  for (int i = tags_remove.size () - 1; i >= 0; i--)
+    if (tags_remove[i] == m_name) return;
 
   if (m_tag_excludes.size () > 0)
@@ -231,4 +236,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);
+	}
+
     }
 }
@@ -603,6 +631,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;
 }
 
@@ -823,4 +859,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/v1r25-branch/source/cmt_tag.h
===================================================================
--- CMT/v1r25-branch/source/cmt_tag.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_tag.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -19,4 +20,6 @@
   typedef cmt_vector<Tag> TagVector;
   typedef cmt_vector<Tag*> TagPtrVector;
+
+  typedef cmt_vmap<const Tag*, Use::UsePtrVector> TagUses;
 
   static void action (const CmtSystem::cmt_string_vector& words, Use* use);
@@ -40,4 +43,6 @@
 
   static bool check_tag_used (const Tag* tag);
+
+  static TagUses& apply_tag ();
 
 public:
Index: CMT/v1r25-branch/source/cmt_triggers.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_triggers.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_triggers.cxx	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_use.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_use.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_use.cxx	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -1826,4 +1827,5 @@
   m_located = false;
   m_package = 0;
+  m_project = 0;
   m_index = -1;
 
@@ -1848,4 +1850,5 @@
       m_package = 0;
     }
+  m_project = 0;
 
   version   = "";
@@ -1923,5 +1926,5 @@
 
 //----------------------------------------------------------
-void Use::change_path (const cmt_string& new_path)
+void Use::change_path (const cmt_string& new_path, const Project* project)
 {
   // 
@@ -1929,9 +1932,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")
+	   << " use: " << 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 +1963,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 +1971,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")
+	   << " use: " << get_info () << endl;
+    }
 }
 
@@ -2347,5 +2370,5 @@
 	  }
 	
-	m_use->change_path (path);
+	m_use->change_path (path, &project);
 
 	m_found = true;
@@ -2355,5 +2378,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 +2471,5 @@
               cout << "move_to2> " << expanded_path << endl;
             }
-
           change_path (here);
-
           return (true);
         }
@@ -2461,8 +2482,12 @@
                   cout << "move_to5> " << real_path << endl;
                 }
-              
               return (true);
             }
         }
+
+      if (!CmtSystem::cd (here))
+	{
+	  CmtError::set (CmtError::file_access_error, here);
+	}
       return (false);
 //     }
@@ -2482,5 +2507,5 @@
 
 //----------------------------------------------------------
-bool Use::select_alternate ()
+bool Use::select_alternate (const Project* project)
 {
   int i;
@@ -2567,5 +2592,5 @@
                 }
 
-              change_path (alternate_paths[selected_index]);
+              change_path (alternate_paths[selected_index], project);
               return (true);
             }
@@ -3568,10 +3593,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 +3624,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;
@@ -3619,10 +3654,11 @@
 bool Use::get_strategy (const cmt_string& name) const
 {
-  const Project* p =
+  const Project* p = get_project ();
+    /*
     Project::find_by_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 (Project::find_in_cmt_paths (real_path));
+    */
 
   bool strategy;
@@ -3705,5 +3741,6 @@
   buffer += "\n";
 
-  if (located ())
+  if (m_located)
+    //  if (located ())
     {
       buffer += "macro ";
@@ -3725,5 +3762,4 @@
 	  buffer += package_name;
 	}
-      //      if (style != no_version_style)
       if (structuring_style == with_version_directory)
 	{
@@ -3733,4 +3769,22 @@
       buffer += "\"";
       buffer += "\n";
+    }
+
+  if (action_setup == Cmt::get_action () &&
+      Requirements == Cmt::get_print_mode ())
+    {
+      //cerr << "|Use::fill_standard_macros> Checking for " << prefix << "CONFIG" << endl;
+      if (!discarded &&
+	  get_package_name () != "cmt_standalone" &&
+	  get_strategy ("SetupConfig"))
+	{
+	  buffer += "macro ";
+	  buffer += prefix;
+	  buffer += "CONFIG";
+	  buffer += " \"";
+	  buffer += CmtSystem::get_cmt_config ();
+	  buffer += "\"";
+	  buffer += "\n";
+	}
     }
 
@@ -3764,5 +3818,13 @@
   buffer += "\n";
   
-  Project* p = Project::find_by_cmtpath (cmtpath);
+  const Project* p = m_project
+    ? m_project
+    : Project::find_by_cmtpath (cmtpath)
+    ;
+  /*
+  const Project* p (m_project);
+  if (!p)
+    p = Project::find_by_cmtpath (cmtpath);
+  */
 
   buffer += "macro ";
@@ -4520,8 +4582,11 @@
   static const cmt_string null = "";
 
+  return m_package ? m_package->get_name () : null ;
+  /*
   Package* p = m_package;
   if (p == 0) return (null);
 
   return (p->get_name ());
+  */
 }
 
@@ -4829,10 +4894,4 @@
 
   return (is_in_path);
-}
-
-//----------------------------------------------------------
-bool Use::located () const
-{
-  return (m_located);
 }
 
@@ -5736,6 +5795,21 @@
 
 //----------------------------------------------------------
-Project* Use::get_project ()
+const Project* Use::get_project () const
 {    
+  if (m_project)
+    return m_project;
+
+  return Project::find_by_cmtpath (m_realpath.size ()
+				   ? Project::find_in_cmt_paths (m_realpath, true)
+				   : Project::find_in_cmt_paths (real_path)
+				   );
+  /*
+  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 +5818,5 @@
   p = Project::find_by_cmtpath (cmtpath);
   return p;   
+  */
 }
 
Index: CMT/v1r25-branch/source/cmt_use.h
===================================================================
--- CMT/v1r25-branch/source/cmt_use.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_use.h	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
@@ -128,7 +129,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 +154,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 +184,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 +215,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 +237,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/v1r25-branch/source/cmt_vcs.cxx
===================================================================
--- CMT/v1r25-branch/source/cmt_vcs.cxx	(revision 646)
+++ CMT/v1r25-branch/source/cmt_vcs.cxx	(revision 664)
@@ -3,4 +3,5 @@
 // arnault@lal.in2p3.fr
 // Modified by: garonne@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/source/cmt_vcs.h
===================================================================
--- CMT/v1r25-branch/source/cmt_vcs.h	(revision 646)
+++ CMT/v1r25-branch/source/cmt_vcs.h	(revision 664)
@@ -2,4 +2,5 @@
 // Copyright Christian Arnault LAL-Orsay CNRS
 // arnault@lal.in2p3.fr
+// Modified by Grigory Rybkin
 // See the complete license in cmt_license.txt "http://www.cecill.info". 
 //-----------------------------------------------------------
Index: CMT/v1r25-branch/src/Makefile.core
===================================================================
--- CMT/v1r25-branch/src/Makefile.core	(revision 646)
+++ CMT/v1r25-branch/src/Makefile.core	(revision 664)
@@ -2,4 +2,5 @@
 # Copyright Christian Arnault LAL-Orsay CNRS
 # arnault@lal.in2p3.fr
+# Modified by Grigory Rybkin
 # See the complete license in cmt_license.txt "http://www.cecill.info". 
 #-----------------------------------------------------------
Index: CMT/v1r25-branch/src/Makefile.header
===================================================================
--- CMT/v1r25-branch/src/Makefile.header	(revision 646)
+++ CMT/v1r25-branch/src/Makefile.header	(revision 664)
@@ -2,4 +2,5 @@
 # Copyright Christian Arnault LAL-Orsay CNRS
 # arnault@lal.in2p3.fr
+# Modified by Grigory Rybkin
 # See the complete license in cmt_license.txt "http://www.cecill.info". 
 #-----------------------------------------------------------
@@ -198,6 +199,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 +209,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))"; \
Index: CMT/v1r25-branch/src/NMakefile.core
===================================================================
--- CMT/v1r25-branch/src/NMakefile.core	(revision 646)
+++ CMT/v1r25-branch/src/NMakefile.core	(revision 664)
@@ -2,4 +2,5 @@
 # Copyright Christian Arnault LAL-Orsay CNRS
 # arnault@lal.in2p3.fr
+# Modified by Grigory Rybkin
 # See the complete license in cmt_license.txt "http://www.cecill.info". 
 #-----------------------------------------------------------
Index: CMT/v1r25-branch/src/NMakefile.header
===================================================================
--- CMT/v1r25-branch/src/NMakefile.header	(revision 646)
+++ CMT/v1r25-branch/src/NMakefile.header	(revision 664)
@@ -2,4 +2,5 @@
 # Copyright Christian Arnault LAL-Orsay CNRS
 # arnault@lal.in2p3.fr
+# Modified by Grigory Rybkin
 # See the complete license in cmt_license.txt "http://www.cecill.info". 
 #-----------------------------------------------------------
Index: CMT/v1r25-branch/src/cleanup.bash
===================================================================
--- CMT/v1r25-branch/src/cleanup.bash	(revision 664)
+++ CMT/v1r25-branch/src/cleanup.bash	(revision 664)
@@ -0,0 +1,16 @@
+#-----------------------------------------------------------
+# Copyright Christian Arnault LAL-Orsay CNRS
+# arnault@lal.in2p3.fr
+# Written by Grigory Rybkin
+# See the complete license in cmt_license.txt "http://www.cecill.info". 
+#-----------------------------------------------------------
+
+if complete -p cmt >/dev/null 2>&1; then
+  complete -r cmt
+fi
+
+unset -f _cmt
+
+unset -f _cmt_escape_compreply
+
+shopt -u extglob
Index: CMT/v1r25-branch/src/cleanup.csh
===================================================================
--- CMT/v1r25-branch/src/cleanup.csh	(revision 646)
+++ CMT/v1r25-branch/src/cleanup.csh	(revision 664)
@@ -2,23 +2,74 @@
 # Copyright Christian Arnault LAL-Orsay CNRS
 # arnault@lal.in2p3.fr
+# Modified by Grigory Rybkin
 # See the complete license in cmt_license.txt "http://www.cecill.info". 
 #-----------------------------------------------------------
 
-set newpath=
+unsetenv CMTBIN
+unsetenv CMTCONFIG
 
-foreach p ( `echo ${PATH} | sed 's#:# #g'` )
-  echo ${p} | egrep '/CMT/' >& /dev/null
-  set s=${status}
-  if ( "${s}" != 0 ) then
-    if ( ${newpath} == "" ) then
-      set newpath=${p}
+if ( $?CMTROOT == 1 ) then
+if ( $?0 == 0 ) then
+if ( $?tcsh == 1 ) then
+  source ${CMTROOT}/src/cleanup.tcsh
+else if ( "${shell:t}" == "tcsh" ) then
+  source ${CMTROOT}/src/cleanup.tcsh
+endif
+endif
+endif
+
+unsetenv CMTROOT
+
+# Remove CMT entries, if any
+set newpath=()
+foreach p (${path:q})
+  if ( "${p}" !~ "*/CMT/*" ) then
+    if ( ${#newpath} != 0 ) then
+      set newpath=(${newpath:q} ${p:q})
     else
-      set newpath=${newpath}:${p}
+      set newpath=(${p:q})
     endif
   endif
 end
 
-setenv PATH ${newpath}
-unsetenv CMTCONFIG
-unsetenv CMTROOT
+set path=(${newpath:q})
+unset newpath
 
+unalias cmt
+
+if ( $?CLASSPATH == 1 ) then
+if ( "${CLASSPATH}" =~ "*/CMT/*" ) then
+# Remove CMT entries
+  set _p="${CLASSPATH}"
+  while ( "$_p" =~ "*:*" )
+  set _p="${_p:s/:/ /}"
+  end
+
+  set newpath=
+  foreach p (${_p})
+    if ( "${p}" !~ "*/CMT/*" ) then
+      if ( "${newpath}" != "" ) then
+        set newpath=${newpath}:${p}
+      else
+        set newpath=${p}
+      endif
+    endif
+  end
+
+  if ( "${newpath}" != "" ) then
+    setenv CLASSPATH ${newpath}
+  else
+    unsetenv CLASSPATH
+  endif
+  unset _p newpath
+endif
+endif
+
+unalias jcmt
+
+# Unset MAKEFLAGS, if looks set by CMT
+if ( $?MAKEFLAGS == 1 ) then
+if ( "$MAKEFLAGS" =~ "*QUICK=1" ) then
+  unsetenv MAKEFLAGS
+endif
+endif
Index: CMT/v1r25-branch/src/cleanup.sh
===================================================================
--- CMT/v1r25-branch/src/cleanup.sh	(revision 646)
+++ CMT/v1r25-branch/src/cleanup.sh	(revision 664)
@@ -2,20 +2,80 @@
 # Copyright Christian Arnault LAL-Orsay CNRS
 # arnault@lal.in2p3.fr
+# Modified by Grigory Rybkin
 # See the complete license in cmt_license.txt "http://www.cecill.info". 
 #-----------------------------------------------------------
 
-newpath=""
-for p in `echo ${PATH} | sed 's/:/ /g'`; do
-  if test ! "`echo ${p} | egrep CMT`" ; then
-    if test "${newpath}" = "" ; then
-      newpath=${p}
-    else
-      newpath=${newpath}:${p}
+[ -z ${CMTBIN+CMT} ] || unset CMTBIN
+[ -z ${CMTCONFIG+CMT} ] || unset CMTCONFIG
+
+if [ "${CMTROOT+CMT}" = CMT ]; then
+if [ -n "$-" ] && [ "${-#*i}" != "$-" ]; then
+if [ -n "${ZSH_NAME-}" ]; then
+  . ${CMTROOT}/src/cleanup.zsh
+elif [ -n "${BASH-}" ]; then
+  . ${CMTROOT}/src/cleanup.bash
+fi
+fi
+fi
+
+[ -z ${CMTROOT+CMT} ] || unset CMTROOT
+
+cmt_clean_path()
+{
+# Remove CMT entries, if any
+  _np=
+  _p="$1"
+  while [ -n "$_p" ]; do
+    __p="${_p#:}"
+    while [ "$__p" != "$_p" ]; do
+      _p="${__p}"
+      __p="${_p#:}"
+    done
+    _e="${_p%%:*}"
+    _p="${_p#${_e}}"
+    if [ "${_e%/CMT/*}" = "${_e}" ] && [ -n "${_e}" ]; then
+      if [ -n "${_np}" ]; then
+        _np="${_np}:${_e}"
+      else
+        _np="${_e}"
+      fi
     fi
+  done
+  echo "$_np"
+  unset _np _p __p _e
+}
+
+if [ "${PATH%/CMT/*}" != "${PATH}" ]; then
+  newpath=`cmt_clean_path "${PATH}"`
+  PATH=${newpath}
+  unset newpath
+fi
+
+if alias cmt >/dev/null 2>&1; then
+  unalias cmt
+fi
+
+if [ -n "${CLASSPATH-}" ]; then
+if [ "${CLASSPATH%/CMT/*}" != "${CLASSPATH}" ]; then
+  newpath=`cmt_clean_path "${CLASSPATH}"`
+  if [ -n "${newpath}" ]; then
+    CLASSPATH=${newpath}
+  else
+    unset CLASSPATH
   fi
-done
+  unset newpath
+fi
+fi
 
-PATH=${newpath}; export PATH
+if alias jcmt >/dev/null 2>&1; then
+  unalias jcmt
+fi
 
-CMTCONFIG=; export CMTCONFIG
-CMTROOT=; export CMTROOT
+unset -f cmt_clean_path
+
+# Unset MAKEFLAGS, if looks set by CMT
+if [ "${MAKEFLAGS+CMT}" = CMT ]; then
+if [ "${MAKEFLAGS%QUICK=1}" != "${MAKEFLAGS}" ]; then
+  unset MAKEFLAGS
+fi
+fi
Index: CMT/v1r25-branch/src/cleanup.tcsh
===================================================================
--- CMT/v1r25-branch/src/cleanup.tcsh	(revision 664)
+++ CMT/v1r25-branch/src/cleanup.tcsh	(revision 664)
@@ -0,0 +1,8 @@
+#-----------------------------------------------------------
+# Copyright Christian Arnault LAL-Orsay CNRS
+# arnault@lal.in2p3.fr
+# Written by Grigory Rybkin
+# See the complete license in cmt_license.txt "http://www.cecill.info". 
+#-----------------------------------------------------------
+
+uncomplete cmt
Index: CMT/v1r25-branch/src/cleanup.zsh
===================================================================
--- CMT/v1r25-branch/src/cleanup.zsh	(revision 664)
+++ CMT/v1r25-branch/src/cleanup.zsh	(revision 664)
@@ -0,0 +1,14 @@
+#-----------------------------------------------------------
+# Copyright Christian Arnault LAL-Orsay CNRS
+# arnault@lal.in2p3.fr
+# Written by Grigory Rybkin
+# See the complete license in cmt_license.txt "http://www.cecill.info". 
+#-----------------------------------------------------------
+
+[ -z "${ARGC-}" ] && return
+
+compctl + cmt.exe
+
+for fn in $(functions -m + 'cmt_*'); do
+  unset -f $fn
+done
Index: CMT/v1r25-branch/src/setup.csh
===================================================================
--- CMT/v1r25-branch/src/setup.csh	(revision 646)
+++ CMT/v1r25-branch/src/setup.csh	(revision 664)
@@ -6,5 +6,11 @@
 #-----------------------------------------------------------
 
-setenv CMTBIN `uname`-`uname -m | tr -d ' '`
+# Remove spaces, if any
+set _m="`uname -m`"
+while ( "$_m" =~ "* *" )
+set _m="${_m:s/ //}"
+end
+setenv CMTBIN `uname`-"$_m"
+unset _m
 
 if ( $?CMTCONFIG == 0 ) then
@@ -15,23 +21,25 @@
 if ( $?tcsh == 1 ) then
   source ${CMTROOT}/src/setup.tcsh
-else if ( `basename "$shell"` == "tcsh" ) then
+else if ( "${shell:t}" == "tcsh" ) then
   source ${CMTROOT}/src/setup.tcsh
 endif
 endif
 
+# Remove CMT entries, if any
 set newpath=()
-foreach p (${path})
+foreach p (${path:q})
   if ( "${p}" !~ "*/CMT/*" ) then
     if ( ${#newpath} != 0 ) then
-      set newpath=(${newpath} ${p})
+      set newpath=(${newpath:q} ${p:q})
     else
-      set newpath=(${p})
+      set newpath=(${p:q})
     endif
   endif
 end
 
-set path=(${newpath} "${CMTROOT}/${CMTBIN}")
+set path=(${newpath:q} "${CMTROOT}/${CMTBIN}")
+unset newpath
+
 alias cmt '${CMTROOT}/${CMTBIN}/cmt.exe'
-unset newpath
 
 if ( $?CLASSPATH == 0 ) then
@@ -42,6 +50,12 @@
   setenv CLASSPATH ${CLASSPATH}:${CMTROOT}/java/cmt.jar
 else
+# Remove CMT entries
+  set _p="${CLASSPATH}"
+  while ( "$_p" =~ "*:*" )
+  set _p="${_p:s/:/ /}"
+  end
+
   set newpath=
-  foreach p ( `echo ${CLASSPATH} | tr ':' ' '` )
+  foreach p (${_p})
     if ( "${p}" !~ "*/CMT/*" ) then
       if ( "${newpath}" != "" ) then
@@ -58,5 +72,5 @@
     setenv CLASSPATH ${CMTROOT}/java/cmt.jar
   endif
-  unset newpath
+  unset _p newpath
 endif
 
Index: CMT/v1r25-branch/src/setup.sh
===================================================================
--- CMT/v1r25-branch/src/setup.sh	(revision 646)
+++ CMT/v1r25-branch/src/setup.sh	(revision 664)
@@ -6,5 +6,17 @@
 #-----------------------------------------------------------
 
-CMTBIN=`uname`-`uname -m | tr -d ' '`; export CMTBIN
+# Remove spaces, if any
+_m="`uname -m`"
+_nm=
+while [ -n "$_m" ]; do
+  _t="${_m#?}"
+  _a="${_m%${_t}}"
+  if [ "${_a}" != " " ]; then
+    _nm="${_nm}${_a}"
+  fi
+  _m="$_t"
+done
+CMTBIN=`uname`-"$_nm"; export CMTBIN
+unset _m _nm _t _a
 
 if test "${CMTCONFIG}" = "" ; then
@@ -20,23 +32,38 @@
 fi
 
+cmt_clean_path()
+{
+# Remove CMT entries, if any
+  _np=
+  _p="$1"
+  while [ -n "$_p" ]; do
+    __p="${_p#:}"
+    while [ "$__p" != "$_p" ]; do
+      _p="${__p}"
+      __p="${_p#:}"
+    done
+    _e="${_p%%:*}"
+    _p="${_p#${_e}}"
+    if [ "${_e%/CMT/*}" = "${_e}" ] && [ -n "${_e}" ]; then
+      if [ -n "${_np}" ]; then
+        _np="${_np}:${_e}"
+      else
+        _np="${_e}"
+      fi
+    fi
+  done
+  echo "$_np"
+  unset _np _p __p _e
+}
+
 if [ "${PATH%/CMT/*}" = "${PATH}" ]; then
   PATH=${PATH}:${CMTROOT}/${CMTBIN}; export PATH
 else
-  newpath=
-  for p in `echo ${PATH} | tr ':' ' '`; do
-    if [ "${p%/CMT/*}" = "${p}" ]; then
-      if [ -n "${newpath}" ]; then
-        newpath=${newpath}:${p}
-      else
-        newpath=${p}
-      fi
-    fi
-  done
-
+  newpath=`cmt_clean_path "${PATH}"`
   PATH=${newpath}:${CMTROOT}/${CMTBIN}; export PATH
   unset newpath
 fi
 
-alias cmt='${CMTROOT}/${CMTBIN}/cmt.exe'; export cmt
+alias cmt='${CMTROOT}/${CMTBIN}/cmt.exe'
 
 if [ -z "${CLASSPATH-}" ]; then
@@ -45,15 +72,5 @@
   CLASSPATH=${CLASSPATH}:${CMTROOT}/java/cmt.jar; export CLASSPATH
 else
-  newpath=
-  for p in `echo ${CLASSPATH-} | tr ':' ' '`; do
-    if [ "${p%/CMT/*}" = "${p}" ]; then
-      if [ -n "${newpath}" ]; then
-        newpath=${newpath}:${p}
-      else
-        newpath=${p}
-      fi
-    fi
-  done
-
+  newpath=`cmt_clean_path "${CLASSPATH}"`
   if [ -n "${newpath}" ]; then
     CLASSPATH=${newpath}:${CMTROOT}/java/cmt.jar; export CLASSPATH
@@ -64,5 +81,7 @@
 fi
 
-alias jcmt='(java cmt_parser)'; export jcmt
+alias jcmt='(java cmt_parser)'
+
+unset -f cmt_clean_path
 
 # Set MAKEFLAGS, if unset (similar to NPROC with Plan 9 mk utility)
Index: CMT/v1r25-branch/src/setup.tcsh
===================================================================
--- CMT/v1r25-branch/src/setup.tcsh	(revision 646)
+++ CMT/v1r25-branch/src/setup.tcsh	(revision 664)
@@ -2,5 +2,6 @@
 # Copyright Christian Arnault LAL-Orsay CNRS
 # arnault@lal.in2p3.fr
-# Modified by garonne@lal.in2p3.fr, Grigory Rybkin
+# Modified by garonne@lal.in2p3.fr
+# Modified by Grigory Rybkin
 # See the complete license in cmt_license.txt "http://www.cecill.info". 
 #-----------------------------------------------------------
Index: CMT/v1r25-branch/src/setup.zsh
===================================================================
--- CMT/v1r25-branch/src/setup.zsh	(revision 646)
+++ CMT/v1r25-branch/src/setup.zsh	(revision 664)
@@ -2,5 +2,6 @@
 # Copyright Christian Arnault LAL-Orsay CNRS
 # arnault@lal.in2p3.fr
-# Modified by garonne@lal.in2p3.fr, Grigory Rybkin
+# Modified by garonne@lal.in2p3.fr
+# Modified by Grigory Rybkin
 # See the complete license in cmt_license.txt "http://www.cecill.info". 
 #-----------------------------------------------------------
