Ignore:
Timestamp:
Jan 13, 2014, 4:09:37 PM (10 years ago)
Author:
rybkin
Message:

merge -r 646:663 HEAD

Location:
CMT/v1r25-branch
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CMT/v1r25-branch

  • CMT/v1r25-branch/source/cmt_parser.cxx

    r642 r664  
    33// arnault@lal.in2p3.fr
    44// Modified by garonne@lal.in2p3.fr
     5// Modified by Grigory Rybkin
    56// See the complete license in cmt_license.txt "http://www.cecill.info".
    67//-----------------------------------------------------------
     
    1011#include <string.h>
    1112#include <ctype.h>
     13#include <errno.h>
    1214
    1315//----------------------------------------------------------
     
    5052}
    5153
     54//----------------------------------------------------------
    5255CmtContext::~CmtContext ()
    5356{
    5457}
    5558
     59//----------------------------------------------------------
    5660void CmtContext::clear ()
    5761{
     
    5963  m_build_nmake    = false;
    6064  m_cmt_config     = "";
    61   //m_cmt_path.clear ();
    62   //m_cmt_path_pwds.clear ();
    63   //m_cmt_path_sources.clear ();
    6465  m_cmt_root       = "";
     66  m_cmt_home       = "";
     67  m_cmt_user_context = "";
     68  m_cmt_site       = "";
    6569  m_cmt_version    = "";
    6670  m_use_cmt        = true;
     71  m_use_projects   = true;
     72
    6773  m_current_dir     = "";
    6874  m_current_file_path = "";
     
    7480  m_current_offset  = "";
    7581
    76   m_current_access   = DeveloperMode;
     82  m_current_access  = UserMode;
     83  m_current_style   = cmt_style;
     84  m_current_structuring_style = default_structuring_style;
    7785
    7886  m_current_tag      = "";
    7987  m_current_target   = "";
    8088  m_current_version  = "";
     89
     90  //  m_extra_tags       = "";
     91  m_extra_tags.clear ();
     92  m_tags.clear ();
     93  m_tags_add.clear ();
     94  m_tags_remove.clear ();
     95
     96  m_configure_error  = "";
     97
     98  m_debug = (::getenv ("CMTDEBUG") != 0) ? true : false;
     99
    81100  m_default_path     = "";
    82 
    83   //m_quiet            = false;
    84 
     101  m_quiet            = false;
    85102  m_disable_warnings = false;
    86103  m_warnings         = false;
     
    91108
    92109  m_standard_macros_done = false;
    93   m_current_access = UserMode;
    94   m_current_style = cmt_style;
    95   m_current_structuring_style = default_structuring_style;
    96110  m_all_sets_done = false;
     111
    97112  m_autoconfigure_cmtpath = false;
    98   m_debug = false;
    99   if (getenv ("CMTDEBUG") != 0) m_debug = true;
    100 }
    101 
     113
     114  m_env_access = true;
     115  m_print_mode = Csh;
     116  m_strip_path = false;
     117}
     118//----------------------------------------------------------
     119
     120int CmtContext::initialize ()
     121{
     122  int errors (0);
     123
     124  cmt_string tags = CmtSystem::getenv ("CMTEXTRATAGS");
     125  CmtSystem::cmt_string_vector words;
     126  CmtSystem::split (tags, " \t,", words);
     127  for (int i = 0; i < words.size (); i++)
     128    {
     129      bool has (false);
     130      for (int j = 0; j < m_extra_tags.size (); j++)
     131        {
     132          if (m_extra_tags[j] == words[i])
     133            {
     134              has = true;
     135              break;
     136            }
     137        }
     138      if (!has)
     139        m_extra_tags.push_back (words[i]);
     140    }
     141
     142  return - errors;
     143}
    102144//----------------------------------------------------------
    103145
     
    357399
    358400
     401//----------------------------------------------------------
     402//
     403//   The static Cmt member
     404//
     405//----------------------------------------------------------
     406
     407CmtContext& Cmt::m_cmt_context = Me;
     408//CmtContext * Cmt::m_cmt_context = &Me;
    359409
    360410//----------------------------------------------------------
     
    462512
    463513//----------------------------------------------------------
     514/*
    464515bool Cmt::build_nmake ()
    465516{
    466517  return (Me.m_build_nmake);
    467518}
    468 
     519*/
    469520//----------------------------------------------------------
    470521void Cmt::build_OS9_makefile (const cmt_string& target)
     
    497548void Cmt::clear ()
    498549{
    499   Me.m_quiet = false;
    500550  Me.clear ();
     551  //Me.m_quiet = false;
    501552
    502553  Database::clear ();
     
    507558
    508559//----------------------------------------------------------
     560namespace {
     561
     562bool parse_cmt_flags (const cmt_string& file_name, CmtContext& cmt)
     563{
     564  cmt_string Flags (Cmt::get_cmt_flags (file_name));
     565  if (CmtError::get_last_error_code () == CmtError::file_access_error)
     566    return false;
     567  if (Flags.size () == 0)
     568    return true;
     569
     570  cmt_string CmtFlags (Cmt::get_cmt_flags ());
     571  if (CmtFlags.size () != 0)
     572    Flags += " " + CmtFlags;
     573
     574  CmtSystem::cmt_string_vector flags;
     575  CmtSystem::split (Flags, " \t", flags);
     576  for (int i = 0; i < flags.size (); i++)
     577    {
     578      if (flags[i] == "-without_cmt" &&
     579          cmt.m_use_cmt)
     580        cmt.m_use_cmt = false;
     581      else if (flags[i] == "-with_cmt" &&
     582               !cmt.m_use_cmt)
     583        cmt.m_use_cmt = true;
     584      else if (flags[i] == "-without_projects" &&
     585               cmt.m_use_projects)
     586        cmt.m_use_projects = false;
     587      else if (flags[i] == "-with_projects" &&
     588               !cmt.m_use_projects)
     589        cmt.m_use_projects = true;
     590      else if (flags[i] == "-no_strip_path" &&
     591               cmt.m_strip_path)
     592        {
     593          cmt.m_strip_path = false;
     594          Symbol::set_strip_path (false);
     595        }
     596      else if (flags[i] == "-strip_path" &&
     597               !cmt.m_strip_path)
     598        {
     599          cmt.m_strip_path = true;
     600          Symbol::set_strip_path (true);
     601        }
     602    }
     603
     604  return true;
     605}
     606
     607}
     608
     609//----------------------------------------------------------
    509610//void Cmt::configure ()
    510611void Cmt::configure (const ArgParser& ap)
     
    515616  if (configured) return;
    516617
    517   Me.clear ();
     618  //  Me.clear ();
    518619
    519620  log << "configure_cmt_message" << log_endl;
     
    523624  log << "configure_default_path" << log_endl;
    524625  configure_default_path ();
     626
     627  log << "restore_all_tags" << log_endl;
     628  restore_all_tags (0);
    525629  log << "configure_version_tag" << log_endl;
    526630  configure_version_tag ();
     
    533637  log << "configure_site_tag" << log_endl;
    534638  configure_site_tag (0);
     639
     640  cmt_string requirements;
     641
     642  if (Me.m_current_package.size () != 0 &&
     643      Me.m_current_package != "cmt_standalone")
     644    {
     645      // we have a package name (not "cmt_standalone")
     646      Use& use = Use::current();
     647      use.set (Me.m_current_package,
     648               Me.m_current_version,
     649               Me.m_current_path);
     650      if (CmtSystem::absolute_path (Me.m_current_path))
     651        {
     652          if (!use.move_to ())
     653            {
     654              CmtError::set (CmtError::package_not_found, use.get_info ());
     655              return;
     656            }
     657        }
     658      else
     659        {
     660          if (!use.move_to ("", true))
     661            {
     662              // will try again later from CMTPATH entries
     663            }
     664        }
     665
     666      if (use.located ())
     667        {
     668          // parse additional options
     669          parse_cmt_flags ("requirements", m_cmt_context);
     670        }
     671    }
     672  else
     673    {
     674      if (Me.m_current_path.size () != 0 &&
     675          !CmtSystem::cd (Me.m_current_path))
     676        {
     677          CmtError::set (CmtError::path_not_found, Me.m_current_path);
     678          return;
     679        }
     680
     681      configure_current_dir ();
     682      configure_current_structuring_style (ap);
     683      cmt_string current_package_saved (Me.m_current_package);
     684      requirements = configure_current_package ();
     685      Me.m_current_package = current_package_saved;
     686      if (requirements.size () != 0)
     687        {
     688          // parse additional options
     689          parse_cmt_flags (requirements, m_cmt_context);
     690        }
     691    }
     692
    535693  log << "configure_current_dir" << log_endl;
    536694  configure_current_dir ();
     
    540698  //  log << "configure_current_dir" << log_endl;
    541699
    542 
    543700  bool save_quiet = Me.m_quiet;
    544701  Me.m_quiet = true;
     
    546703  Me.m_autoconfigure_cmtpath = true;
    547704  configure_cmt_path (0);
    548   Me.m_autoconfigure_cmtpath = false;
     705  //  Me.m_autoconfigure_cmtpath = false;
    549706
    550707  Me.m_quiet = save_quiet;
     
    553710
    554711  guess_current_project ();
     712
     713  if (Me.m_current_package.size () != 0 &&
     714      Me.m_current_package != "cmt_standalone")
     715    {
     716      Use& use = Use::current();
     717      if (!use.located ())
     718        {
     719          if (!use.move_to ())
     720            {
     721              CmtError::set (CmtError::package_not_found, use.get_info ());
     722              return;
     723            }
     724          else
     725            {
     726              use.get_full_path (Me.m_current_dir);
     727              switch (use.style)
     728                {
     729                case cmt_style:
     730                  Me.m_current_dir += CmtSystem::file_separator ();
     731                  Me.m_current_dir += "cmt";
     732                  break;
     733                case mgr_style:
     734                  Me.m_current_dir += CmtSystem::file_separator ();
     735                  Me.m_current_dir += "mgr";
     736                  break;
     737                default:
     738                  break;
     739                }
     740              Me.m_current_file_path = Me.m_current_dir;
     741
     742              Project::order_all ();
     743              Cmt::guess_current_project ();
     744            }
     745        }
     746    }
    555747
    556748  log << "configure_current_structuring_style" << log_endl;
     
    558750  configure_current_structuring_style (ap);
    559751
     752//   if (requirements.size () == 0)
     753//     {
    560754  log << "configure_current_package" << log_endl;
    561755  configure_current_package ();
     756//     }
    562757
    563758  Use& use = Use::current();
    564 
    565   use.set (Me.m_current_package,
    566            Me.m_current_version,
    567            Me.m_current_path,
    568            "",
    569            "");
    570 
    571   use.style = Me.m_current_style;
    572   use.structuring_style = Me.m_current_structuring_style;
    573 
    574   use.change_path (Me.m_current_path);
     759  if (!use.located ())
     760    {
     761      use.set (Me.m_current_package,
     762               Me.m_current_version,
     763               Me.m_current_path);
     764      use.style = Me.m_current_style;
     765
     766      if (use.style != none_style)
     767        {
     768          use.structuring_style = Me.m_current_structuring_style;
     769          use.change_path (Me.m_current_path, Project::get_current ());
     770        }
     771      else
     772        {
     773          use.real_path = Me.m_current_path;
     774        }
     775    }
     776  else if (const Project * p = Project::get_current ())
     777    {
     778      use.set_project (p);
     779    }
    575780
    576781  if (CmtError::has_pending_error ())
     
    584789{
    585790  if (!Me.m_autoconfigure_cmtpath) return;
     791
     792  if (!m_cmt_context.m_use_projects) return;
    586793
    587794  cmt_string s;
     
    621828{
    622829  Use& current_use = Use::current ();
    623 
     830  current_use.get_cmtpath_and_offset (Me.m_current_cmtpath, Me.m_current_offset);
     831  /*
    624832  Me.m_current_cmtpath = "";
    625833  Me.m_current_offset = "";
     
    633841
    634842      Me.m_current_offset = current_use.path;
    635 
     843  */
    636844      /**
    637845         try to remove this current CMTPATH entry from path.  This
     
    639847         absolute path.
    640848      */
    641      
     849  /*     
    642850      Me.m_current_offset.replace (Me.m_current_cmtpath, empty_string);
    643851      if (Me.m_current_offset[0] == CmtSystem::file_separator ())
     
    648856        }
    649857    }
     858  */
    650859}
    651860
     
    731940void Cmt::configure_current_dir ()
    732941{
     942  if (Me.m_current_dir.size () != 0) return;
     943
    733944  cmt_string file_name;
    734945
     
    788999  Me.m_current_file_path = mount_filter.get_current_dir ();
    7891000
    790   cmt_string t = Me.m_current_file_path;
    791 }
    792 
    793 //----------------------------------------------------------
    794 void Cmt::configure_current_package ()
     1001  //  cmt_string t = Me.m_current_file_path;
     1002}
     1003
     1004//----------------------------------------------------------
     1005cmt_string Cmt::configure_current_package ()
     1006//void Cmt::configure_current_package ()
    7951007{
    7961008  /*
     
    8001012    standard directory tree (i.e. <package>/<version>/cmt or mgr)
    8011013  */
     1014  Use& use = Use::current();
     1015  if (use.located ())
     1016    {
     1017      Me.m_current_style = use.style;
     1018      build_prefix (Me.m_current_package, Me.m_current_prefix);
     1019      build_config (Me.m_current_prefix, Me.m_current_config);
     1020
     1021      cmt_string req;
     1022      use.get_full_path (req);
     1023      switch (use.style)
     1024        {
     1025        case cmt_style:
     1026          req += CmtSystem::file_separator ();
     1027          req += "cmt";
     1028          break;
     1029        case mgr_style:
     1030          req += CmtSystem::file_separator ();
     1031          req += "mgr";
     1032          break;
     1033        default:
     1034          break;
     1035        }
     1036      req += CmtSystem::file_separator ();
     1037      req += "requirements";
     1038      return req;
     1039    }
    8021040
    8031041  cmt_string req = "..";
     
    8131051  else
    8141052    {
    815       cmt_string req = "..";
     1053      req = "..";
     1054      //      cmt_string req = "..";
    8161055      req += CmtSystem::file_separator ();
    8171056      req += "mgr";
     
    8271066          // This package is probably a standalone one
    8281067          Me.m_current_style = none_style;
     1068          req = "requirements";
     1069          if (!CmtSystem::test_file (req))
     1070            {
     1071              req = "";
     1072            }
    8291073        }
    8301074    }
     
    10621306      // Do NOT (re)set m_current_structuring_style yet
    10631307      // (as requirements may NOT exist, so this is not a package)
    1064       // rather do it in reach_current_package (if/when requirements is read)
     1308      // rather do it in use_current_package (if/when requirements is read)
    10651309      //Me.m_current_structuring_style = without_version_directory;
    10661310      build_prefix (Me.m_current_package, Me.m_current_prefix);
    10671311      build_config (Me.m_current_prefix, Me.m_current_config);
    10681312    }
     1313
     1314  return req;
    10691315}
    10701316
     
    10741320{
    10751321  cmt_string s;
    1076   s = CmtSystem::getenv ("CMTSTRUCTURINGSTYLE");
    1077   if (s == "without_version_directory")
    1078     {
    1079       Me.m_current_structuring_style = without_version_directory;
    1080     }
    1081   else if (s == "with_version_directory")
    1082     {
    1083       Me.m_current_structuring_style = with_version_directory;
    1084     }
    1085 
    1086   CmtSystem::cmt_string_vector flags;
    1087   Cmt::get_cmt_flags (flags);
    1088   for (int i = 0; i < flags.size (); i++)
    1089     {
    1090       const cmt_string& flag = flags[i];
    1091       if (flag == "-without_version_directory")
     1322  if (Me.m_current_structuring_style == default_structuring_style)
     1323    {
     1324      s = CmtSystem::getenv ("CMTSTRUCTURINGSTYLE");
     1325      if (s == "without_version_directory")
    10921326        {
    10931327          Me.m_current_structuring_style = without_version_directory;
    10941328        }
    1095       else if (flag == "-with_version_directory")
     1329      else if (s == "with_version_directory")
    10961330        {
    10971331          Me.m_current_structuring_style = with_version_directory;
    1098         }
    1099     }
    1100 
    1101   for (int i = 1; i < ap.argc; i++)
    1102     {
    1103       const cmt_string& arg = ap.argv[i];
    1104       if (arg[0] != '-') break;
    1105       if (arg == "-without_v" ||
    1106           arg == "-without_ve" ||
    1107           arg == "-without_ver" ||
    1108           arg == "-without_vers" ||
    1109           arg == "-without_versi" ||
    1110           arg == "-without_versio" ||
    1111           arg == "-without_version" ||
    1112           arg == "-without_version_" ||
    1113           arg == "-without_version_d" ||
    1114           arg == "-without_version_di" ||
    1115           arg == "-without_version_dir" ||
    1116           arg == "-without_version_dire" ||
    1117           arg == "-without_version_direc" ||
    1118           arg == "-without_version_direct" ||
    1119           arg == "-without_version_directo" ||
    1120           arg == "-without_version_director" ||
    1121           arg == "-without_version_directory")
    1122         {
    1123           Me.m_current_structuring_style = without_version_directory;
    1124           //      if (!CmtSystem::putenv ("CMTSTRUCTURINGSTYLE", "without_version_directory"))
    1125           //        CmtMessage::error ("Cannot set `CMTSTRUCTURINGSTYLE' to"
    1126           //                           " `without_version_directory' in the environment");
    1127           if (!Cmt::add_cmt_flag ("-without_version_directory"))
    1128             CmtMessage::error ("Cannot add flag `-without_version_directory'");
    1129         }
    1130       else if (arg == "-with_v" ||
    1131                arg == "-with_ve" ||
    1132                arg == "-with_ver" ||
    1133                arg == "-with_vers" ||
    1134                arg == "-with_versi" ||
    1135                arg == "-with_versio" ||
    1136                arg == "-with_version" ||
    1137                arg == "-with_version_" ||
    1138                arg == "-with_version_d" ||
    1139                arg == "-with_version_di" ||
    1140                arg == "-with_version_dir" ||
    1141                arg == "-with_version_dire" ||
    1142                arg == "-with_version_direc" ||
    1143                arg == "-with_version_direct" ||
    1144                arg == "-with_version_directo" ||
    1145                arg == "-with_version_director" ||
    1146                arg == "-with_version_directory")
    1147         {
    1148           Me.m_current_structuring_style = with_version_directory;
    1149           //      if (!CmtSystem::putenv ("CMTSTRUCTURINGSTYLE", "with_version_directory"))
    1150           //        CmtMessage::error ("Cannot set `CMTSTRUCTURINGSTYLE' to"
    1151           //                           " `with_version_directory' in the environment");
    1152           if (!Cmt::add_cmt_flag ("-with_version_directory"))
    1153             CmtMessage::error ("Cannot add flag `-with_version_directory'");
     1332        }
     1333     
     1334      CmtSystem::cmt_string_vector flags;
     1335      Cmt::get_cmt_flags (flags);
     1336      for (int i = 0; i < flags.size (); i++)
     1337        {
     1338          const cmt_string& flag = flags[i];
     1339          if (flag == "-without_version_directory")
     1340            {
     1341              Me.m_current_structuring_style = without_version_directory;
     1342            }
     1343          else if (flag == "-with_version_directory")
     1344            {
     1345              Me.m_current_structuring_style = with_version_directory;
     1346            }
     1347        }
     1348    }
     1349 
     1350  if (Me.m_current_structuring_style != default_structuring_style)
     1351    {
     1352      StrategyDef* def = StrategyMgr::find_strategy ("VersionDirectory");
     1353      if (def != 0)
     1354        {
     1355          def->m_default_value =
     1356            Me.m_current_structuring_style == with_version_directory;
     1357          def->m_priority_value =
     1358            Me.m_current_structuring_style == without_version_directory;
    11541359        }
    11551360    }
     
    11711376void Cmt::configure_home (Use* use)
    11721377{
    1173   Me.m_cmt_home = "";
    1174 
    1175   Symbol* symbol = Symbol::find ("CMTHOME");
    1176   if (symbol != 0)
    1177     {
    1178       Me.m_cmt_home = symbol->build_macro_value ();
    1179       Symbol::expand (Me.m_cmt_home);
    1180     }
    1181   else if (CmtSystem::testenv ("CMTHOME"))
    1182     {
    1183       Me.m_cmt_home = CmtSystem::getenv ("CMTHOME");
     1378  if (Me.m_cmt_home.size () == 0)
     1379    {
     1380      // if not passed on the command line
     1381      if (const Symbol* symbol = Symbol::find ("CMTHOME"))
     1382        {
     1383          Me.m_cmt_home = symbol->build_macro_value ();
     1384          Symbol::expand (Me.m_cmt_home);
     1385        }
     1386      else if (CmtSystem::testenv ("CMTHOME"))
     1387        {
     1388          Me.m_cmt_home = CmtSystem::getenv ("CMTHOME");
     1389        }
    11841390    }
    11851391
     
    11951401void Cmt::configure_user_context (Use* use)
    11961402{
    1197   Me.m_cmt_user_context = "";
    1198 
    1199   Symbol* symbol = Symbol::find ("CMTUSERCONTEXT");
    1200   if (symbol != 0)
    1201     {
    1202       Me.m_cmt_user_context = symbol->build_macro_value ();
    1203       Symbol::expand (Me.m_cmt_user_context);
    1204     }
    1205   else if (CmtSystem::testenv ("CMTUSERCONTEXT"))
    1206     {
    1207       Me.m_cmt_user_context = CmtSystem::getenv ("CMTUSERCONTEXT");
     1403  if (Me.m_cmt_user_context.size () == 0)
     1404    {
     1405      // if not passed on the command line
     1406      if (const Symbol* symbol = Symbol::find ("CMTUSERCONTEXT"))
     1407        {
     1408          Me.m_cmt_user_context = symbol->build_macro_value ();
     1409          Symbol::expand (Me.m_cmt_user_context);
     1410        }
     1411      else if (CmtSystem::testenv ("CMTUSERCONTEXT"))
     1412        {
     1413          Me.m_cmt_user_context = CmtSystem::getenv ("CMTUSERCONTEXT");
     1414        }
    12081415    }
    12091416
     
    12721479
    12731480  Cmt::configure_tags (use);
     1481
     1482  cmt_string s, t;
     1483  if (0 < Me.m_extra_tags.size ())
     1484    {
     1485      s = "CMTEXTRATAGS";
     1486      t = use != 0 ? use->get_package_name () : s;
     1487    }
     1488  for (int i = 0; i < Me.m_extra_tags.size (); i++)
     1489    {
     1490      Tag* tag = Tag::add (Me.m_extra_tags[i], PriorityUserTag, s, use);
     1491      tag->mark (t);
     1492    }
     1493
     1494  for (int i = 0; i < Me.m_tags.size (); i++)
     1495    {
     1496      const cmt_string& a = Me.m_tags[i];
     1497      if (i == 0)
     1498        {
     1499          Me.m_current_tag = a;
     1500        }
     1501//       // Then restore uname if the specified tag is CMTCONFIG
     1502//       if (a == CmtSystem::get_cmt_config ())
     1503//      {
     1504//        Cmt::configure_uname_tag ();
     1505//      }
     1506      Tag* tag = Tag::add (a, PriorityArgument, "arguments", 0);
     1507      tag->mark ("arguments");
     1508    }
     1509
     1510  for (int i = 0; i < Me.m_tags_add.size (); i++)
     1511    {
     1512      const cmt_string& a = Me.m_tags_add[i];
     1513//       // Then restore uname if the specified tag is CMTCONFIG
     1514//       if (a == CmtSystem::get_cmt_config ())
     1515//      {
     1516//        Cmt::configure_uname_tag ();
     1517//      }
     1518      Tag* tag = Tag::add (a, PriorityUserTag, "arguments", 0);
     1519      tag->mark ("arguments");
     1520    }
    12741521
    12751522  /*
     
    12771524  */
    12781525
     1526  /*
    12791527  if (CmtSystem::testenv ("CMTEXTRATAGS"))
    12801528    {
     
    13091557        }
    13101558    }
     1559  */
    13111560}
    13121561
     
    13191568
    13201569  log << "current_tag=" << Me.m_current_tag << log_endl;
     1570
     1571  cmt_string s = "CMTCONFIG";
    13211572
    13221573  Symbol* symbol = Symbol::find ("CMTCONFIG");
     
    13471598    {
    13481599      config_tag = CmtSystem::getenv ("CMTBIN");
     1600      s = "CMTBIN";
    13491601    }
    13501602
     
    13521604    {
    13531605      CmtSystem::get_uname (config_tag);
     1606      s = "uname";
    13541607    }
    13551608
    13561609  log << "current_tag=" << Me.m_current_tag << log_endl;
    13571610
    1358   cmt_string s = "CMTCONFIG";
     1611  //  cmt_string s = "CMTCONFIG";
    13591612  cmt_string t = s;
    13601613
     
    15521805          if (CmtMessage::level () != Warning)
    15531806            CmtMessage::set_level (Warning);
    1554           //      if (CmtMessage::level () > Warning)
    1555         }
    1556     }
    1557 
    1558   for (int i = 1; i < ap.argc; i++)
    1559     {
    1560       const cmt_string& arg = ap.argv[i];
    1561       if (arg[0] != '-') break;
    1562       if (arg == "-d" ||
    1563           arg == "-di" ||
    1564           arg == "-dis" ||
    1565           arg == "-disa" ||
    1566           arg == "-disab" ||
    1567           arg == "-disabl" ||
    1568           arg == "-disable" ||
    1569           arg == "-disable_" ||
    1570           arg == "-disable_w" ||
    1571           arg == "-disable_wa" ||
    1572           arg == "-disable_war" ||
    1573           arg == "-disable_warn" ||
    1574           arg == "-disable_warni" ||
    1575           arg == "-disable_warnin" ||
    1576           arg == "-disable_warning" ||
    1577           arg == "-disable_warnings")
    1578         {
    1579           Me.m_disable_warnings = true;
    1580           if (CmtMessage::level () <= Warning)
    1581             {
    1582               CmtMessage::set_level (Error);
    1583               //              if (!CmtSystem::putenv ("CMTERROR", "1"))
    1584               //                CmtMessage::error ("Cannot set `CMTERROR' in the environment");
    1585             }
    1586           if (!Cmt::add_cmt_flag ("-disable_warnings"))
    1587             CmtMessage::error ("Cannot add flag `-disable_warnings'");
    1588         }
    1589       else if (arg == "-q" ||
    1590                arg == "-qu" ||
    1591                arg == "-qui" ||
    1592                arg == "-quie" ||
    1593                arg == "-quiet")
    1594         {
    1595           Me.m_quiet = true;
    1596           if (CmtMessage::level () <= Error)
    1597             {
    1598               CmtMessage::set_level (Fatal);
    1599               //              if (!CmtSystem::putenv ("CMTFATAL", "1"))
    1600               //                CmtMessage::error ("Cannot set `CMTFATAL' in the environment");
    1601             }
    1602           if (!Cmt::add_cmt_flag ("-quiet"))
    1603             CmtMessage::error ("Cannot add flag `-quiet'");
    1604         }
    1605       else if (arg == "-warn" ||
    1606                arg == "-warni" ||
    1607                arg == "-warnin" ||
    1608                arg == "-warning" ||
    1609                arg == "-warnings")
    1610         {
    1611           Me.m_warnings = true;
    1612           //      if (CmtMessage::level () > Warning)
    1613           if (CmtMessage::level () != Warning)
    1614             {
    1615               CmtMessage::set_level (Warning);
    1616               //              if (!CmtSystem::putenv ("CMTWARNING", "1"))
    1617               //                CmtMessage::error ("Cannot set `CMTWARNING' in the environment");
    1618             }
    1619           if (!Cmt::add_cmt_flag ("-warnings"))
    1620             CmtMessage::error ("Cannot add flag `-warnings'");
    16211807        }
    16221808    }
     
    16681854
    16691855  CmtSystem::cmt_string_vector uses;
     1856  cmt_vector<int> use_indexes;
    16701857  CmtSystem::cmt_string_vector packages;
    16711858  CmtSystem::cmt_string_vector versions;
    1672   CmtSystem::cmt_string_vector path_selections;
     1859  Project::ConstProjectPtrVector path_selections;
     1860  //  CmtSystem::cmt_string_vector path_selections;
     1861  Project::ConstProjectPtrVector path_exclusions;
    16731862  CmtSystem::cmt_string_vector selections;
    16741863  CmtSystem::cmt_string_vector exclusions;
     
    16771866  bool is_cmt = false;
    16781867  int first = 0;
    1679   int i;
    16801868  bool ignore_errors = false;
    16811869  bool all_packages = false;
    1682 
     1870  int depth (1);
    16831871  bool local = true;
    1684 
    1685   for (i = 0; i < ap.arguments.size (); i++)
     1872  bool global (false);
     1873
     1874  for (int i = 0; i < ap.arguments.size (); i++)
    16861875    {
    16871876      const cmt_string& w = ap.arguments[i];
     
    16991888            {
    17001889              local = false;
     1890              global = false;
    17011891
    17021892              cmt_string depth_str;
    1703               int depth_value = 0;
     1893              int depth_value;
    17041894                         
    17051895              w.substr (7, depth_str);
    1706               if ((sscanf (depth_str.c_str (), "%d", &depth_value) < 1) ||
    1707                   (depth_value < 1))
    1708                 {
     1896              int n = sscanf (depth_str.c_str (), "%d", &depth_value);
     1897              cmt_string msg;
     1898              switch (n)
     1899                {
     1900                case EOF:
     1901                  msg = "Cannot read `depth' value `";
     1902                  msg += depth_str;
     1903                  msg += cmt_string ("'");
     1904                  if (errno)
     1905                    msg += cmt_string (strerror (errno));
     1906                  CmtError::set (CmtError::system_error, msg);
     1907                  return;
     1908                  break;
     1909                case 0:
     1910                  msg = "Invalid `depth' value `";
     1911                  msg += depth_str;
     1912                  msg += cmt_string ("'");
     1913                  CmtError::set (CmtError::syntax_error, msg);
     1914                  return;
     1915                  break;
     1916                case 1:
     1917                  if (depth_value < -1)
     1918                    {
     1919                      char num[32]; sprintf (num, "%lu", -depth_value);
     1920                      msg = "Invalid `depth' value `-";
     1921                      msg += num;
     1922                      msg += cmt_string ("'");
     1923                      CmtError::set (CmtError::syntax_error, msg);
     1924                      return;
     1925                    }
     1926                  depth = depth_value;
     1927                  //cerr << "depth: " << depth << endl;
     1928                  break;
     1929                default:
     1930                  break;
     1931                }
     1932//               if ((sscanf (depth_str.c_str (), "%d", &depth_value) < 1) ||
     1933//                   (depth_value < 1))
     1934//                {
    17091935                  // Syntax error
    17101936                  //  We shall restrict to packages found within
     
    17121938                  //  If CMTPATH is empty, nothing is selected.
    17131939                  // depth=1 is equivalent to local
    1714                 }
    1715 
    1716               Project::fill_selection (depth_value, path_selections);
     1940//                }
     1941
     1942//            Project::fill_selection (depth_value, path_selections);
    17171943            }
    17181944          else if (w.substr (0, 9) == "-exclude=")
     
    17381964          else if (w.substr (0, 7) == "-global")
    17391965            {
    1740               path_selections.clear ();
    1741 
     1966              //path_selections.clear ();
     1967              global = true;
    17421968              local = false;
    17431969            }
     
    17451971            {
    17461972              local = true;
     1973              global = false;
    17471974            }
    17481975          else if (w.substr (0, 8) == "-select=")
     
    17872014    }
    17882015
    1789   if (local)
    1790     {
    1791       Project::fill_selection (1, path_selections);
     2016  const Project* p_cur (Project::get_current ());
     2017  if (global)
     2018    {
     2019      Project::fill_exclusion (path_exclusions);
     2020    }
     2021  else if (local)
     2022    {
     2023      if (p_cur)
     2024        Project::fill_selection (1, path_selections);
     2025      else
     2026        path_selections.push_back (0); // means that we want Use::current ()
     2027      //        path_selections.push_back ((Use::current ()).get_realpath ());
     2028    }
     2029  else
     2030    {
     2031      if (!p_cur
     2032          && depth != 0
     2033          && depth != -1)
     2034        path_selections.push_back (0); // means that we want Use::current ()
     2035//      path_selections.push_back ((Use::current ()).get_realpath ());
     2036      Project::fill_selection (depth, path_selections);
     2037      /*
     2038      cerr << "depth: " << depth << endl;
     2039      for (int j = 0; j < path_selections.size (); j++)
     2040        {
     2041          const Project* sp = path_selections[j];
     2042          cerr << "path_selections: " << (sp ? sp->get_cmtpath () : "current use") << endl;
     2043        }
     2044      */
    17922045    }
    17932046
     
    18002053  //if (command.substr (0, 3) == "cmt") is_cmt = true;
    18012054
    1802   cmt_string curuse = CmtSystem::pwd ();
     2055  //cmt_string curuse = CmtSystem::pwd ();
    18032056  if (all_packages)
    18042057    {
     
    18062059      PathScanner scanner;
    18072060      Project::scan_paths (scanner, selector);
     2061      return;
    18082062    }
    18092063  else
    18102064    {
    1811       for (i = Uses.size () - 1; i >= 0; i--)
     2065      for (int i = Uses.size () - 1; i >= 0; i--)
    18122066        {
    18132067          Use* use = Uses[i];
     
    18152069          if (use->discarded) continue;
    18162070          if (use->m_hidden) continue;
    1817 
    18182071          if (!use->located ())
    18192072            {
    1820               CmtMessage::warning ("package " + use->get_package_name ()
    1821                                    + " " + use->version + " " + use->path
    1822                                    + " not found");
    1823               /*
    1824               if (!Me.m_quiet)
    1825                 {
    1826                   cerr << "#CMT> package " << use->get_package_name () <<
    1827                     " " << use->version << " " << use->path <<
    1828                     " not found" <<
    1829                     endl;
    1830                 }
    1831               */
     2073              CmtMessage::warning
     2074                (CmtError::get_error_name (CmtError::package_not_found)
     2075                 + ": " + use->get_info ());
     2076              continue;
    18322077            }
    1833           else
    1834             {
    1835               if (use->get_package_name () != "CMT")
    1836                 {
    1837                   cmt_string& s = uses.add ();
    1838 
    1839                   use->get_full_path (s);
    1840 
    1841                   s += CmtSystem::file_separator ();
    1842                   if (use->style == mgr_style) s += "mgr";
    1843                   else s += "cmt";
    1844 
    1845                   cmt_string& v = versions.add ();
    1846                   v = use->version;
    1847 
    1848                   cmt_string& p = packages.add ();
    1849                   p = use->get_package_name ();
    1850                 }
    1851             }
    1852         }
     2078          if (use->get_package_name () == "CMT") continue;
     2079
     2080          cmt_string& s = uses.add ();
     2081          use->get_full_path (s);
     2082          switch (use->style)
     2083            {
     2084            case cmt_style:
     2085              s += CmtSystem::file_separator ();
     2086              s += "cmt";
     2087              break;
     2088            case mgr_style:
     2089              s += CmtSystem::file_separator ();
     2090              s += "mgr";
     2091              break;
     2092            default:
     2093              break;
     2094            }
     2095//                   if (use->style == mgr_style) s += "mgr";
     2096//                   else s += "cmt";
     2097
     2098          cmt_string& v = versions.add ();
     2099          v = use->version;
     2100         
     2101          cmt_string& p = packages.add ();
     2102          p = use->get_package_name ();
     2103         
     2104          int& use_index = use_indexes.add ();
     2105          use_index = i;
     2106        }
    18532107         
    18542108      {
     2109        Use* use = &(Use::current ());
     2110       
    18552111        cmt_string& s = uses.add ();
     2112        use->get_full_path (s);
     2113        switch (use->style)
     2114          {
     2115          case cmt_style:
     2116            s += CmtSystem::file_separator ();
     2117            s += "cmt";
     2118            break;
     2119          case mgr_style:
     2120            s += CmtSystem::file_separator ();
     2121            s += "mgr";
     2122            break;
     2123          default:
     2124            break;
     2125          }
     2126//         if (use->get_package_name ().find ("cmt_standalone") != cmt_string::npos)
     2127//           {
     2128//             s = CmtSystem::pwd ();
     2129//           }
     2130//         else
     2131//           {
     2132//             use->get_full_path (s);
     2133
     2134//             s += CmtSystem::file_separator ();
    18562135                 
    1857         Use* use = &(Use::current ());
    1858 
    1859         if (use->get_package_name ().find ("cmt_standalone") != cmt_string::npos)
    1860           {
    1861             s = CmtSystem::pwd ();
    1862           }
    1863         else
    1864           {
    1865             use->get_full_path (s);
    1866 
    1867             s += CmtSystem::file_separator ();
    1868                  
    1869             if (use->style == mgr_style) s += "mgr";
    1870             else s += "cmt";
    1871           }
    1872 
    1873         curuse = s;
     2136//             if (use->style == mgr_style) s += "mgr";
     2137//             else s += "cmt";
     2138//           }
     2139        //curuse = s;
    18742140
    18752141        cmt_string& v = versions.add ();
     
    18782144        cmt_string& p = packages.add ();
    18792145        p = use->get_package_name ();
     2146         
     2147        int& use_index = use_indexes.add ();
     2148        use_index = -1;
    18802149      }
    18812150    }
     
    18912160    CmtSystem::putenv ("CMTBCAST", "");
    18922161
    1893   for (i = 0; i < uses.size (); i++)
     2162  for (int i = 0; i < uses.size (); i++)
    18942163    {
    18952164      const cmt_string& s = uses[i];
    18962165      const cmt_string& v = versions[i];
    18972166      const cmt_string& p = packages[i];
     2167      const int use_index = use_indexes[i];
     2168
     2169      const Use* use = use_index >= 0 ? Uses[use_index] : &(Use::current ());
     2170      const Project* up = use->get_project ();
     2171
    18982172      cmt_string cmtpath;
    18992173
    19002174      bool ok = true;
    1901       bool selected = true;
     2175      bool selected = global ? true : false;
    19022176      bool excluded = false;
    19032177
    1904       /**
    1905          Ensure that the current package is not skipped
    1906          due to symlinks in the paths
    1907        */
    1908       //      if (path_selections.size () > 0)
    1909       if (path_selections.size () > 0 && s != curuse)
     2178      ok = selected;
     2179      if (path_selections.size () > 0)
    19102180        {
    19112181          selected = false;
    1912 
    19132182          for (int j = 0; j < path_selections.size (); j++)
    19142183            {
    1915               const cmt_string& sel = path_selections[j];
    1916              
    1917               if (s.find (sel) != cmt_string::npos)
    1918                 {
    1919                   cmtpath = sel;
    1920                   selected = true;
    1921                   break;
    1922                 }
    1923             }
    1924 
     2184              const Project* sp = path_selections[j];
     2185              if (sp)
     2186                {
     2187                  if (up)
     2188                    {
     2189                      if (up == sp)
     2190                        {
     2191                          cmtpath = sp->get_cmtpath ();
     2192                          selected = true;
     2193                          break;
     2194                        }
     2195                    }
     2196                  else
     2197                    {
     2198                      if (use->get_realpath ().find (sp->get_cmtpath_real ()) == 0)
     2199                        {
     2200                          cmtpath = sp->get_cmtpath ();
     2201                          selected = true;
     2202                          break;
     2203                        }
     2204                    }
     2205                }
     2206              else if (use == &(Use::current ()))
     2207                {
     2208                  // means that we want Use::current ()
     2209                  // cmtpath = sp->get_cmtpath ();
     2210                  if (up)
     2211                    cmtpath = up->get_cmtpath ();
     2212                  else
     2213                    cmtpath = "";
     2214                  selected = true;
     2215                  break;
     2216                }
     2217              // const cmt_string& sel = path_selections[j];
     2218              // if (s.find (sel) != cmt_string::npos)
     2219//                 {
     2220//                cmtpath = sel;
     2221//                   selected = true;
     2222//                   break;
     2223//                 }
     2224            }
    19252225          ok = selected;
    19262226        }
     2227      else if (up)
     2228        cmtpath = up->get_cmtpath ();
    19272229
    19282230      if (ok)
     
    19602262        }
    19612263
    1962 
    19632264      if (ok)
    19642265        {
     
    19742275                  break;
    19752276                }
     2277            }
     2278
     2279          if (excluded) ok = false;
     2280        }
     2281
     2282      if (ok)
     2283        {
     2284          excluded = false;
     2285          for (int j = 0; j < path_exclusions.size (); j++)
     2286            {
     2287              const Project* sp = path_exclusions[j];
     2288              if (up)
     2289                {
     2290                  if (up == sp)
     2291                    {
     2292                      excluded = true;
     2293                      break;
     2294                    }
     2295                }
     2296              else
     2297                {
     2298                  if (use->get_realpath ().find (sp->get_cmtpath_real ()) == 0)
     2299                    {
     2300                      excluded = true;
     2301                      break;
     2302                    }
     2303                }
    19762304            }
    19772305
     
    20212349        }
    20222350
     2351      /*
    20232352      if (cmtpath == "")
    20242353        {
     
    20262355          cmtpath = Project::find_in_cmt_paths (sel);
    20272356        }
     2357      */
    20282358
    20292359      cmt_string cmd = command;
     
    20412371      static const cmt_string empty_string;
    20422372      static const cmt_string fs = CmtSystem::file_separator ();
    2043       cmt_string offset = s;
    2044       offset.replace (cmtpath, empty_string);
    2045       if (offset[0] == CmtSystem::file_separator ())
    2046         {
    2047           offset.replace (fs, empty_string);
    2048         }
    2049       CmtSystem::dirname (offset, offset);
    2050 
    2051       cmt_string n;
    2052       CmtSystem::basename (offset, n);
    2053       if (n == p)
    2054         {
     2373      cmt_string offset;
     2374      if (cmtpath.size ())
     2375        {
     2376          offset = s;
     2377          offset.replace (cmtpath, empty_string);
     2378          if (offset[0] == CmtSystem::file_separator ())
     2379            {
     2380              offset.replace (fs, empty_string);
     2381            }
    20552382          CmtSystem::dirname (offset, offset);
     2383         
     2384          cmt_string n;
     2385          CmtSystem::basename (offset, n);
     2386          if (n == p)
     2387            {
     2388              CmtSystem::dirname (offset, offset);
     2389            }
     2390          else
     2391            {
     2392              CmtSystem::dirname (offset, offset);
     2393              CmtSystem::dirname (offset, offset);
     2394            }
    20562395        }
    20572396      else
    20582397        {
    2059           CmtSystem::dirname (offset, offset);
    2060           CmtSystem::dirname (offset, offset);
    2061         }
    2062 
     2398          offset = use->real_path;
     2399        }
    20632400      cmd.replace_all (offset_template, offset);
    20642401
     
    20672404    {
    20682405      cout << "#--------------------------------------------------------------" << endl;
    2069       cout << "# Now trying [" << cmd << "] in " << s << " (" << i+1 << "/" << uses.size ()
     2406      cout << "# " << p << " " << v << " " << offset << ": Now trying [" << cmd << "] in " << s << " (" << i+1 << "/" << uses.size ()
    20702407           << ")" << endl;
    20712408      cout << "#--------------------------------------------------------------" << endl;
     
    29043241    }
    29053242
    2906   static CmtSystem::cmt_string_vector tags;
     3243  //  static CmtSystem::cmt_string_vector tags;
    29073244
    29083245  if (action_build_constituents_config != get_action ())
    2909     CmtSystem::split (Me.m_extra_tags, " \t,", tags);
    2910 
    2911   for (int i = 0; i < tags.size (); i++)
    2912     {
    2913       const cmt_string& t = tags[i];
    2914 
    2915       tag = Tag::find (t);
    2916       if (tag == 0) continue;
    2917 
    2918       if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag))
    2919         {
    2920           CmtMessage::warning ("The tag " + t + " is not used in any tag expression. Please check spelling");
    2921           //      cerr << "#CMT> The tag " << t << " is not used in any tag expression. Please check spelling" << endl;
    2922         }
    2923     }
    2924 
    2925   Symbol::check_all_paths ();
     3246    {
     3247    //    CmtSystem::split (Me.m_extra_tags, " \t,", tags);
     3248
     3249    //  for (int i = 0; i < tags.size (); i++)
     3250      //    {
     3251      //      const cmt_string& t = tags[i];
     3252      for (int i = 0; i < Me.m_extra_tags.size (); i++)
     3253        {
     3254          const cmt_string& t = Me.m_extra_tags[i];
     3255          tag = Tag::find (t);
     3256          if (tag == 0) continue;
     3257          if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag))
     3258            {
     3259              CmtMessage::warning ("The tag " + t + " is not used in any tag expression. Please check spelling");
     3260            }
     3261        }
     3262      for (int i = 0; i < Me.m_tags.size (); i++)
     3263        {
     3264          const cmt_string& t = Me.m_tags[i];
     3265          tag = Tag::find (t);
     3266          if (tag == 0) continue;
     3267          if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag))
     3268            {
     3269              CmtMessage::warning ("The tag " + t + " is not used in any tag expression. Please check spelling");
     3270            }
     3271        }
     3272      for (int i = 0; i < Me.m_tags_add.size (); i++)
     3273        {
     3274          const cmt_string& t = Me.m_tags_add[i];
     3275          tag = Tag::find (t);
     3276          if (tag == 0) continue;
     3277          if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag))
     3278            {
     3279              CmtMessage::warning ("The tag " + t + " is not used in any tag expression. Please check spelling");
     3280            }
     3281        }
     3282    }
     3283
     3284  if (action_setup != get_action () ||
     3285      Requirements == ap.mode)
     3286    // PathBuilder::filter_path_value is called
     3287    // for each path in Symbol::print
     3288    Symbol::check_all_paths ();
    29263289
    29273290  env = CmtSystem::getenv ("CMTSITE");
     
    29403303    {
    29413304      CmtMessage::warning ("The CMTSITE value " + env + " is not used in any tag expression. Please check spelling");
    2942       //      cerr << "#CMT> The CMTSITE value " << env << " is not used in any tag expression. Please check spelling" << endl;
    29433305    }
    29443306
     
    43234685      break;
    43244686    case Requirements :
     4687      /*
    43254688      CmtSystem::cmt_string_vector flags;
    43264689      get_cmt_flags (flags);
    43274690      cout << "\n# CMTFLAGS: -without_cmt";
     4691      cout << " -without_projects" ;
    43284692      for (int i = 0; i < flags.size (); i++)
    43294693        {
     
    43324696          else if (flags[i] == "-with_cmt")
    43334697            cout << " -without_cmt";
     4698          else if (flags[i] == "-without_projects")
     4699            cout << " -with_projects";
     4700          else if (flags[i] == "-with_projects")
     4701            cout << " -without_projects";
    43344702          else
    43354703            cout << " " << flags[i];
    43364704        }
    43374705      cout << endl;
     4706      */
    43384707      break;
    4339     }
    4340   print (ap.mode);
     4708    default:
     4709      break;
     4710    }
     4711
     4712  ostringstream os;
     4713  ostringstream oh;
     4714  bool reset (false);
     4715  CmtSystem::cmt_string_vector flags;
     4716  cmt_string strip_path_flag;
     4717  bool strip_path (false);
     4718
     4719  bool strip_saved (get_strip_path ());
     4720  bool access_saved (Cmt::get_env_access ());
     4721
     4722  switch (ap.mode)
     4723    {
     4724    case Requirements :
     4725
     4726      get_cmt_flags (flags);
     4727      for (int i = 0; i < flags.size (); i++)
     4728        {
     4729          if (flags[i] == "-no_strip_path")
     4730            strip_path_flag = "-no_strip_path";
     4731          else if (flags[i] == "-strip_path")
     4732            strip_path_flag = "-strip_path";
     4733        }
     4734      if (strip_path_flag != "-no_strip_path" &&
     4735          !get_strip_path ())
     4736        reset = Symbol::set_strip_path (true);
     4737
     4738      if (get_strip_path () || reset)
     4739        strip_path = true;
     4740      else
     4741        strip_path = false;
     4742
     4743      Cmt::set_env_access (false);
     4744
     4745      print (ap.mode, os);
     4746
     4747      if (CmtError::get_last_error_code () == CmtError::warning &&
     4748          (get_strip_path () || reset))
     4749        {
     4750          reset = Symbol::set_strip_path (false);
     4751          if (reset)
     4752            {
     4753              strip_path = false;
     4754
     4755              CmtError::print ();
     4756              CmtError::clear ();
     4757
     4758              if (Cmt::get_debug ())
     4759                {
     4760                  cerr << "|Cmt::do_setup> Failure with:\n" << os.str ()
     4761                       << "|Cmt::do_setup> Trying again." << endl;
     4762                }
     4763
     4764              // Try again
     4765              os.str ("");
     4766              print (ap.mode, os);
     4767            }
     4768        }
     4769
     4770      if (reset) Symbol::set_strip_path (strip_saved);
     4771      Cmt::set_env_access (access_saved);
     4772
     4773      //get_cmt_flags (flags);
     4774      oh << "\n# CMTFLAGS:"
     4775        " -without_cmt"
     4776        " -without_projects"
     4777        //" -strip_path"
     4778        ;
     4779      for (int i = 0; i < flags.size (); i++)
     4780        {
     4781          if (flags[i] == "-without_cmt")
     4782            oh << " -with_cmt";
     4783          else if (flags[i] == "-with_cmt")
     4784            oh << " -without_cmt";
     4785          else if (flags[i] == "-without_projects")
     4786            oh << " -with_projects";
     4787          else if (flags[i] == "-with_projects")
     4788            oh << " -without_projects";
     4789          /*
     4790          else if (flags[i] == "-no_strip_path")
     4791            oh << " -strip_path";
     4792          else if (flags[i] == "-strip_path")
     4793            oh << " -no_strip_path";
     4794          */
     4795          else if (flags[i] == "-no_strip_path" ||
     4796                   flags[i] == "-strip_path")
     4797            continue;
     4798          else
     4799            oh << " " << flags[i];
     4800        }
     4801      //if (reset) oh << " -strip_path";
     4802      if (strip_path)
     4803        oh << " -no_strip_path";
     4804      else
     4805        oh << " -strip_path";
     4806      oh << endl;
     4807
     4808      cout << oh.str ();
     4809      cout << os.str ();
     4810
     4811      break;
     4812
     4813    default:
     4814
     4815      print (ap.mode);
     4816
     4817      break;
     4818    }
     4819
    43414820  switch (ap.mode)
    43424821    {
     
    44764955
    44774956  Use& use = Use::current();   
     4957  /*
    44784958  use.get_cmtpath_and_offset (cmtpath, offset);
    44794959
    44804960  Project* p = Project::find_by_cmtpath (cmtpath);
    4481 
    4482   cout << p->get_author () << endl;
     4961  */
     4962  if (const Project* p = use.get_project ())
     4963    cout << p->get_author () << endl;
    44834964}
    44844965
     
    45034984  ClientCollector collector (package, version);
    45044985
     4986  /*
    45054987  clear     ();
    45064988  //  configure ();
    45074989  configure (ap);
     4990  */
    45084991
    45094992  cout << "# ----------- Clients of " << package
     
    51645647
    51655648//----------------------------------------------------------
     5649/*
    51665650ActionType Cmt::get_action ()
    51675651{
    51685652  return (Me.m_action);
    51695653}
    5170 
     5654*/
    51715655/*
    51725656  const CmtSystem::cmt_string_vector& Cmt::get_cmt_path ()
     
    51855669  }
    51865670*/
    5187 
     5671 /*
    51885672const cmt_string& Cmt::get_cmt_home ()
    51895673{
     
    52055689  return (Me.m_current_dir);
    52065690}
    5207 
     5691*/
    52085692const cmt_string Cmt::get_current_dir_real ()
    52095693{
     
    52135697  return (Me.m_current_dir);
    52145698}
    5215 
     5699/*
    52165700const cmt_string& Cmt::get_current_package ()
    52175701{
    52185702  return (Me.m_current_package);
    52195703}
    5220 
     5704*/
    52215705const cmt_string& Cmt::get_current_path ()
    52225706{
     
    52335717  return (Me.m_current_offset);
    52345718}
    5235 
     5719/*
    52365720AccessMode Cmt::get_current_access ()
    52375721{
     
    52485732  return (Me.m_current_style);
    52495733}
    5250 
     5734*/
    52515735const cmt_string& Cmt::get_current_version ()
    52525736{
    52535737  return (Me.m_current_version);
    52545738}
    5255 
     5739/*
    52565740const cmt_string& Cmt::get_current_target ()
    52575741{
    52585742  return (Me.m_current_target);
    52595743}
    5260 
     5744*/
     5745/*
     5746const CmtSystem::cmt_string_vector& Cmt::get_tags_remove ()
     5747{
     5748  return (Me.m_tags_remove);
     5749}
     5750*/
     5751 /*
    52615752bool Cmt::get_debug ()
    52625753{
     
    52835774  return (Me.m_recursive);
    52845775}
    5285 
     5776 */
    52865777CmtScopeFilteringMode Cmt::get_scope_filtering_mode ()
    52875778{
     
    52975788
    52985789//----------------------------------------------------------
     5790/*
    52995791bool Cmt::get_all_sets_done ()
    53005792{
    53015793  return (Me.m_all_sets_done);
    53025794}
    5303 
     5795*/
    53045796//----------------------------------------------------------
    53055797void Cmt::get_cmt_flags (CmtSystem::cmt_string_vector& flags)
     
    54215913void Cmt::guess_current_project ()
    54225914{
     5915  if (!m_cmt_context.m_use_projects) return;
     5916
    54235917  Log;
    54245918
    54255919  log << "guess_current_project" << log_endl;
    54265920
    5427   cmt_string here = CmtSystem::pwd ();
     5921  //  cmt_string here = CmtSystem::pwd ();
    54285922
    54295923  Use& use = Use::current();
     
    54385932    //  if (Project::find_in_cmt_paths (Me.m_current_dir) == "")
    54395933    {
     5934      /*
    54405935      if (!CmtSystem::cd (current_path))
    54415936        {
     
    54445939          return;
    54455940        }
     5941      */
    54465942      cmt_string project_file = "cmt";
    54475943      project_file += CmtSystem::file_separator ();
    54485944      project_file += Project::get_project_file_name ();
    54495945
    5450       cmt_string pwd;
     5946      /*
     5947      cmt_string pwd (CmtSystem::pwd ());
     5948      cmt_string pwd_prev;
     5949      */
     5950      cmt_string dir_cur (current_path);
     5951      cmt_string dir_par;
     5952
     5953      cmt_string proj_file_cur;
    54515954
    54525955      for (;;)
    54535956        {
    5454           pwd = CmtSystem::pwd ();
     5957          /*
     5958          //      pwd = CmtSystem::pwd ();
    54555959          if (CmtSystem::test_file (project_file))
    54565960            {
     
    54625966              break;
    54635967            }
    5464 
    5465           log << "pwd=" << CmtSystem::pwd () << log_endl;
     5968          */
     5969          proj_file_cur = dir_cur;
     5970          proj_file_cur += CmtSystem::file_separator ();
     5971          proj_file_cur += project_file;
     5972          if (CmtSystem::test_file (proj_file_cur))
     5973            {
     5974              //this directory should become the first entry of the CMTPATH
     5975
     5976              IProjectFactory& factory = ProjectFactory::instance ();
     5977              factory.create_project ("", dir_cur, "CurrentProject", 0);
     5978
     5979              break;
     5980            }
     5981
     5982          /*
     5983          log << "pwd=" << pwd << log_endl;
    54665984         
    54675985          if (!CmtSystem::cd (".."))
     
    54715989            }
    54725990
    5473           if (CmtSystem::pwd () == pwd)
     5991          pwd_prev = pwd;
     5992          pwd = CmtSystem::pwd ();
     5993          if (pwd == pwd_prev)
     5994            //    if (CmtSystem::pwd () == pwd)
    54745995            {
    54755996              log << "Looks the same pwd..." << log_endl;
    54765997              break;
    54775998            }
    5478         }
    5479 
    5480       CmtSystem::cd (Me.m_current_dir);
    5481     }
     5999          */
     6000          log << "dir_cur=`" << dir_cur << "'" << log_endl;
     6001          CmtSystem::dirname (dir_cur, dir_par);
     6002          if (dir_par == dir_cur)
     6003            {
     6004              log << "Looks the same dir_cur..." << log_endl;
     6005              break;
     6006            }
     6007          dir_cur = dir_par;
     6008        }
     6009
     6010      //      CmtSystem::cd (Me.m_current_dir);
     6011    } // if (Project::find_in_cmt_paths (current_path) == "")
    54826012
    54836013  //cmt_string buffer = "path CMTPATH \n";
     
    54876017  //  Use& use = Use::current();
    54886018
     6019  bool autoconfigure_cmtpath_saved (Me.m_autoconfigure_cmtpath);
     6020  Me.m_autoconfigure_cmtpath = false;
    54896021  bool save_quiet = Me.m_quiet;
    54906022  Me.m_quiet = true;
     
    54936025
    54946026  Me.m_quiet = save_quiet;
    5495 
    5496   Me.m_autoconfigure_cmtpath = true;
    5497 
    5498   CmtSystem::cd (here);
     6027  Me.m_autoconfigure_cmtpath = autoconfigure_cmtpath_saved;
     6028  //  Me.m_autoconfigure_cmtpath = true;
     6029
     6030  //  CmtSystem::cd (Me.m_current_dir);
     6031  //CmtSystem::cd (here);
    54996032}
    55006033
     
    59666499              fprintf (f, "endif\n");
    59676500              fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
    5968               fprintf (f, "set cmt%stempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n", mangled_package.c_str ());
     6501              fprintf (f, "set cmt%stempfile=`${CMTROOT}/${CMTBIN}/cmt.exe -quiet build temporary_name`\n", mangled_package.c_str ());
    59696502              fprintf (f, "if $status != 0 then\n  set cmt%stempfile=/tmp/cmt.$$\nendif\n", mangled_package.c_str ());
    5970               //fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
    5971               fprintf (f, "${CMTROOT}/mgr/cmt %s -%s "
     6503              fprintf (f, "${CMTROOT}/${CMTBIN}/cmt.exe %s -%s "
    59726504                       "-pack=%s -version=%s -path=%s %s $* >${cmt%stempfile}\n",
    59736505                       action.c_str (),
     
    59806512              fprintf (f,
    59816513                       "if ( $status != 0 ) then\n"
    5982                        "  echo \"${CMTROOT}/mgr/cmt %s -%s "
     6514                       "  echo \"${CMTROOT}/${CMTBIN}/cmt.exe %s -%s "
    59836515                       "-pack=%s -version=%s -path=%s %s $* >${cmt%stempfile}\"\n"
    59846516                       "  set cmt%sstatus=2\n"
     
    60266558              fprintf (f, "fi\n");
    60276559              fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
    6028               fprintf (f, "cmt%stempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n", mangled_package.c_str ());
     6560              fprintf (f, "cmt%stempfile=`${CMTROOT}/${CMTBIN}/cmt.exe -quiet build temporary_name`\n", mangled_package.c_str ());
    60296561              fprintf (f, "if test ! $? = 0 ; then cmt%stempfile=/tmp/cmt.$$; fi\n", mangled_package.c_str ());
    6030               //fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
    6031               fprintf (f, "${CMTROOT}/mgr/cmt %s -%s "
     6562              fprintf (f, "${CMTROOT}/${CMTBIN}/cmt.exe %s -%s "
    60326563                       "-pack=%s -version=%s -path=%s %s $* >${cmt%stempfile}\n",
    60336564                       action.c_str (),
     
    60406571              fprintf (f,
    60416572                       "if test $? != 0 ; then\n"
    6042                        "  echo >&2 \"${CMTROOT}/mgr/cmt %s -%s "
     6573                       "  echo >&2 \"${CMTROOT}/${CMTBIN}/cmt.exe %s -%s "
    60436574                       "-pack=%s -version=%s -path=%s %s $* >${cmt%stempfile}\"\n"
    60446575                       "  cmt%sstatus=2\n"
     
    60746605          else if (mode[i] == Bat)
    60756606            {
    6076               //fprintf (f, "rem Setting %s %s in %%~d0%%~p0\n",
    60776607              fprintf (f, "rem %s %s %s in %%~d0%%~p0\n",
    60786608                       action.c_str (),
     
    64096939
    64106940  /**
    6411    * See reach_current_package for an explanation of this call
     6941   * See apply_globals for an explanation of this call
    64126942   */
    64136943  Pattern::apply_all_globals ();
     
    64446974  Me.m_action = action_none;
    64456975
    6446   restore_all_tags (0);
     6976  //  restore_all_tags (0);
    64476977
    64486978#ifdef WIN32
     
    64817011int Cmt::parser (int argc, char* argv[])
    64827012{
     7013  // save CMTFLAGS
     7014  cmt_string cmtflags (get_cmt_flags ());
     7015
     7016  clear ();
     7017  Me.initialize ();
     7018
    64837019  ArgParser ap (Me);
    64847020 
     
    64937029    }
    64947030
    6495   // save CMTFLAGS
    6496   cmt_string cmtflags (get_cmt_flags ());
    6497 
    6498   clear ();
     7031  //  clear ();
     7032
     7033  //  Me.clear ();
     7034
     7035  parse_arguments (ap);
     7036  // Copy ap.mode into cmt_context member/instance
     7037  set_print_mode (ap.mode);
    64997038
    65007039  //  configure ();
    6501   configure (ap);
    6502 
    6503   CmtError::clear ();
     7040  switch (Me.m_action)
     7041    {
     7042    case action_none :
     7043    case action_build_temporary_name :
     7044    case action_help :
     7045      break;
     7046    default:
     7047      configure (ap);
     7048      break;
     7049    }
     7050 
     7051  //  CmtError::clear ();
    65047052
    65057053  /*
    6506     Set private if positioned inside the package
     7054    Set DeveloperMode if positioned inside the package
    65077055    (which is detected since we were able to retreive the
    65087056    Version, Package and Path)
    65097057  */
    65107058
     7059  if (!Use::current().located ())
     7060  /*
    65117061  if ((Me.m_current_path.size () == 0) ||
    65127062      (Me.m_current_package.size () == 0) ||
    65137063      (Me.m_current_version.size () == 0))
     7064  */
    65147065    {
    65157066      Me.m_current_access = UserMode;
     
    65207071    }
    65217072 
    6522   parse_arguments (ap);
     7073  //  parse_arguments (ap);
    65237074 
    65247075  if (ap.help_action == action_help)
     
    68267377  switch (Me.m_action)
    68277378    {
    6828     case action_none :
     7379      //case action_none :
    68297380    case action_awk :
    68307381    case action_broadcast :
     
    69297480        Me.m_warnings = false;
    69307481        if (strlen (ap.extra_file.c_str ()) == 0)
    6931           reach_current_package ();
     7482          use_current_package ();
     7483        //        reach_current_package ();
    69327484        else
    69337485          use_extra_file (ap.extra_file);
     
    69357487        if (strlen (ap.extra_line.c_str ()) > 0)
    69367488          SyntaxParser::parse_requirements_text (ap.extra_line, "extra statement(s)", (Use*) 0);
     7489        apply_globals ();
    69377490        Me.m_warnings = w;
    6938         //if (strlen (ap.extra_line.c_str ()) > 0) SyntaxParser::parse_requirements_line (ap.extra_line, &(Use::current ()));
    69397491      }
    69407492      break;
     
    69527504  if (use != 0 && !use->discarded && !use->m_hidden && use->located ())
    69537505    uses.push_back (use);
    6954   uses.push_back (&(Use::current()));
     7506  use = &(Use::current());
     7507  if (use != 0 && !use->discarded && !use->m_hidden && use->located ())
     7508    uses.push_back (use);
     7509  //  uses.push_back (&(Use::current()));
    69557510  use = Use::find (CmtSystem::get_user_context_package ());
    69567511  if (use != 0 && !use->discarded && !use->m_hidden && use->located ())
     
    74247979 * joined with semi-colons to form one shell command.
    74257980 */
    7426 void Cmt::print (PrintMode mode)
     7981void Cmt::print (PrintMode mode, ostream& out)
    74277982{
    74287983  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
     
    74528007  //
    74538008
     8009  /*
    74548010  {
    74558011    CmtSystem::cmt_string_vector words;
     
    74778033      }
    74788034  }
    7479 
     8035  */
    74808036  if (mode == Requirements)
    74818037    {
     
    74878043          if (tag != 0)
    74888044            {
    7489               tag->show (true, cout, "apply_tag ");
     8045              tag->show (true, out, "apply_tag ");
    74908046            }
    74918047        }
     
    75088064          if (use.m_hidden) continue;
    75098065         
    7510           print_context (use, mode, tag);
    7511         }
    7512     }
    7513 
    7514   print_context (Use::current (), mode, tag);
     8066          print_context (use, mode, tag, out);
     8067        }
     8068    }
     8069
     8070  print_context (Use::current (), mode, tag, out);
    75158071
    75168072  if (Me.m_debug)
     
    75198075    }
    75208076
    7521   Symbol::all_print (mode);
     8077  Symbol::all_print (mode, out);
    75228078  // Script::all_print (mode);
    75238079
     
    75328088      break;
    75338089    default :
    7534   cout << endl;
     8090      out << endl;
    75358091      break;
    75368092    }
     
    76388194
    76398195//----------------------------------------------------------
    7640 void Cmt::print_context (Use& use, PrintMode mode, const cmt_string& tag)
     8196void Cmt::print_context (Use& use, PrintMode mode, const cmt_string& tag, ostream& out)
    76418197{
    76428198  if (use.get_package_name () == "cmt_standalone") return;
     
    76548210  switch (mode)
    76558211    {
     8212    case Xml :
    76568213    case Requirements :
    76578214      break;
     
    76708227      if (do_root)
    76718228        {
    7672           cout << "setenv " << prefix << "ROOT \"" <<
     8229          out << "setenv " << prefix << "ROOT \"" <<
    76738230            use.get_full_path () << "\"" << endl;
    76748231        }
     
    76768233      if (use.get_package_name () == "CMT")
    76778234        {
    7678           cout << "setenv CMTCONFIG " << system << endl;
     8235          out << "setenv CMTCONFIG " << system << endl;
    76798236        }
    76808237      else
     
    76828239          if (do_config)
    76838240            {
    7684               cout << "setenv " << prefix << "CONFIG \"" << tag << "\"" << endl;
     8241              out << "setenv " << prefix << "CONFIG \"" << tag << "\"" << endl;
    76858242            }
    76868243        }
     
    76908247      if (do_root)
    76918248        {
    7692           cout << prefix << "ROOT=\"" <<
     8249          out << prefix << "ROOT=\"" <<
    76938250            use.get_full_path () << "\"; export " <<
    76948251            prefix << "ROOT" << endl;
     
    76978254      if (use.get_package_name () == "CMT")
    76988255        {
    7699           cout << "CMTCONFIG=" << system << "; export CMTCONFIG" << endl;
     8256          out << "CMTCONFIG=" << system << "; export CMTCONFIG" << endl;
    77008257        }
    77018258      else
     
    77038260          if (do_config)
    77048261            {
    7705               cout << prefix << "CONFIG=\"" <<
     8262              out << prefix << "CONFIG=\"" <<
    77068263                tag << "\"; export " <<
    77078264                prefix << "CONFIG" << endl;
     
    77138270      if (do_root)
    77148271        {
    7715           cout << "set " << prefix << "ROOT=" <<
     8272          out << "set " << prefix << "ROOT=" <<
    77168273            CmtSystem::quote (use.get_full_path (), " \t") << endl;
    77178274        }
     
    77198276      if (use.get_package_name () == "CMT")
    77208277        {
    7721           cout << "set CMTCONFIG=" << system << endl;
     8278          out << "set CMTCONFIG=" << system << endl;
    77228279        }
    77238280      else
     
    77258282          if (do_config)
    77268283            {
    7727               cout << "set " << prefix << "CONFIG=" << CmtSystem::quote (tag, " \t") << endl;
     8284              out << "set " << prefix << "CONFIG=" << CmtSystem::quote (tag, " \t") << endl;
    77288285            }
    77298286        }
     
    77338290      if (do_root)
    77348291        {
    7735           cout << "<variable><name>" << prefix << "ROOT</name>"
    7736                << "<value>" << use.get_full_path () << "</value></variable>";
     8292          out << "<variable><name>" << prefix << "ROOT</name>"
     8293              << "<value>" << use.get_full_path () << "</value></variable>";
    77378294        }
    77388295
    77398296      if (use.get_package_name () == "CMT")
    77408297        {
    7741           cout << "<variable><name>CMTCONFIG</name>"
    7742                << "<value>" << system << "</value></variable>";
     8298          out << "<variable><name>CMTCONFIG</name>"
     8299              << "<value>" << system << "</value></variable>";
    77438300        }
    77448301      else
     
    77468303          if (do_config)
    77478304            {
    7748               cout << "<variable><name>" << prefix << "CONFIG</name>"
    7749                    << "<value>" << tag << "</value></variable>";
     8305              out << "<variable><name>" << prefix << "CONFIG</name>"
     8306                  << "<value>" << tag << "</value></variable>";
    77508307            }
    77518308        }
     
    77568313          use.get_package_name () != "CMT")
    77578314        {
    7758           cout << "set " << use.prefix << "ROOT " <<
     8315          out << "set " << use.prefix << "ROOT " <<
    77598316            CmtSystem::quote (use.get_full_path (), " \t") << endl;
    77608317
     
    77758332      if (use.get_package_name () == "CMT")
    77768333        {
    7777           cout << "set CMTCONFIG " << system << endl;
     8334          out << "set CMTCONFIG " << system << endl;
    77788335        }
    77798336      else
     
    77818338          if (do_config)
    77828339            {
    7783               cout << "set " << use.prefix << "CONFIG " << CmtSystem::quote (tag, " \t") << endl;
     8340              out << "set " << use.prefix << "CONFIG " << CmtSystem::quote (tag, " \t") << endl;
     8341             
     8342              cmt_string name (use.prefix + "CONFIG");
     8343              Symbol* symbol = Symbol::find (name);
     8344              if (symbol != 0)
     8345                {
     8346                  symbol->printed = true;
     8347                }
     8348              if (symbol == 0 || symbol->type != Symbol::SymbolMacro)
     8349                {
     8350                  CmtMessage::warning
     8351                    (CmtError::get_error_name (CmtError::symbol_not_found)
     8352                     + ": macro " + name);
     8353                }
    77848354            }
    77858355        }
     
    79398509
    79408510//----------------------------------------------------------
    7941 int Cmt::reach_current_package ()
     8511int Cmt::use_current_package ()
    79428512{
    79438513  Use& use = Use::current ();
     
    79468516  if (Me.m_debug)
    79478517    {
    7948       cout << "Cmt::reach_current_package> pwd = "
     8518      cout << "Cmt::use_current_package> pwd = "
    79498519           << CmtSystem::pwd ()
    79508520           << " path=" << Me.m_current_path
     
    79598529  if (Me.m_current_package == "cmt_standalone")
    79608530    {
    7961       if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
     8531      if ((Me.m_current_path != "") && (Me.m_current_path != Me.m_current_dir))
     8532//      if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
    79628533        {
    79638534          if (!CmtSystem::cd (Me.m_current_path))
    79648535            {
    79658536              CmtError::set (CmtError::package_not_found,
    7966                              "ReachCurrentPackage> Cannot reach the path directory");
     8537                             "Cannot reach the path directory: "
     8538                             + Me.m_current_path);
    79678539              return (0);
    79688540            }
     
    79758547
    79768548      Me.m_current_structuring_style = without_version_directory;
     8549      use.structuring_style = Me.m_current_structuring_style;
     8550      use.change_path (Me.m_current_path, Project::get_current ());
     8551      Me.m_current_access = DeveloperMode;
    79778552    }
    79788553  else if (Me.m_current_package != "")
    79798554    {
    7980       if (!use.move_to () && !use.move_to ("", true))
    7981         //      if (!use.move_to ())
    7982         {
    7983           CmtError::set (CmtError::package_not_found,
    7984                          "ReachCurrentPackage> Cannot reach the path directory");
    7985           return (0);
    7986         }
    7987 
    7988       Me.m_current_path = use.real_path;
     8555      if (!use.located ())
     8556        {
     8557          //      if (!use.move_to () && !use.move_to ("", true))
     8558            //      if (!use.move_to ())
     8559          if (!use.move_to ())
     8560            {
     8561              if (!CmtSystem::cd (Cmt::get_current_dir ()))
     8562                {
     8563                  CmtError::set (CmtError::file_access_error,
     8564                                 Cmt::get_current_dir ()
     8565                                 + " (use_current_package)");
     8566                  return 0;
     8567                }
     8568              if (!use.move_to ("", true))
     8569                {
     8570                  CmtError::set (CmtError::package_not_found, use.get_info ());
     8571                  return 0;
     8572                }
     8573            }
     8574         
     8575          Me.m_current_path = use.real_path;
     8576          Me.m_current_access = DeveloperMode;
     8577        }
    79898578    }
    79908579  else
     
    80248613             
    80258614              CmtError::set (CmtError::package_not_found,
    8026                              "ReachCurrentPackage> Cannot reach the mgr/cmt directory");
     8615                             "Cannot reach the mgr/cmt directory: "
     8616                             + use.get_info ());
    80278617              return (0);
    80288618            }
     
    80308620      else
    80318621        Me.m_current_style = none_style;
     8622
     8623      Me.m_current_access = DeveloperMode;
    80328624
    80338625      dir = CmtSystem::pwd ();
     
    80578649      use.style   = Me.m_current_style;
    80588650      use.structuring_style = Me.m_current_structuring_style;
    8059     }
    8060 
     8651
     8652      configure_current_dir ();
     8653      build_prefix (Me.m_current_package, Me.m_current_prefix);
     8654      build_config (Me.m_current_prefix, Me.m_current_config);
     8655    }
     8656
     8657  /*
    80618658  configure_current_dir ();
    80628659  build_prefix (Me.m_current_package, Me.m_current_prefix);
    80638660  build_config (Me.m_current_prefix, Me.m_current_config);
     8661  */
    80648662
    80658663  /*
     
    80678665  */
    80688666
    8069   if (Me.m_debug) cout << "reach_current_package0> current_tag=" << Me.m_current_tag << endl;
     8667  if (Me.m_debug) cout << "use_current_package0> current_tag=" << Me.m_current_tag << endl;
    80708668
    80718669  if (Me.m_current_tag == "")
     
    80788676          Tag* tag;
    80798677
    8080           tag = Tag::add (env, PriorityConfig, "reach current package", 0);
     8678          tag = Tag::add (env, PriorityConfig, "current package", 0);
    80818679          tag->mark (use.get_package_name ());
    80828680          //Me.m_current_tag = env;
    80838681
    8084           //if (!Me.m_quiet) cerr << "reach_current_package1> current_tag=" << Me.m_current_tag << endl;
     8682          //if (!Me.m_quiet) cerr << "use_current_package1> current_tag=" << Me.m_current_tag << endl;
    80858683
    80868684        }
     
    81008698  SyntaxParser::parse_requirements (dir, &use);
    81018699
    8102   if (Me.m_debug) cout << "reach_current_package2> current_tag=" << Me.m_current_tag << endl;
     8700  if (CmtError::has_pending_error ()) return 0;
     8701
     8702  if (Me.m_debug) cout << "use_current_package2> current_tag=" << Me.m_current_tag << endl;
     8703
     8704  return 1;
     8705}
     8706
     8707//----------------------------------------------------------
     8708int Cmt::use_extra_file (const cmt_string& file)
     8709{
     8710  if (!CmtSystem::test_file (file))
     8711    {
     8712      CmtError::set (CmtError::path_not_found, file);
     8713      return 0;
     8714    }
     8715
     8716  // (almost) Cmt::use_current_package ()
     8717  Use& use = Use::current ();
     8718  /*
     8719    Try to access the package.
     8720  */
     8721
     8722  if (Me.m_current_package == "cmt_standalone")
     8723    {
     8724      if ((Me.m_current_path != "") && (Me.m_current_path != Me.m_current_dir))
     8725//      if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
     8726        {
     8727          if (!CmtSystem::cd (Me.m_current_path))
     8728            {
     8729              CmtError::set (CmtError::package_not_found,
     8730                             "Cannot reach the path directory: "
     8731                             + Me.m_current_path);
     8732              return (0);
     8733            }
     8734        }
     8735      /*
     8736      if (!CmtSystem::test_file ("requirements"))
     8737        {
     8738          return (0);
     8739        }
     8740      */
     8741      Me.m_current_structuring_style = without_version_directory;
     8742      use.structuring_style = Me.m_current_structuring_style;
     8743      use.change_path (Me.m_current_path, Project::get_current ());
     8744      Me.m_current_access = DeveloperMode;
     8745    }
     8746  else if (Me.m_current_package != "")
     8747    {
     8748      if (!use.located ())
     8749        {
     8750          //      if (!use.move_to () && !use.move_to ("", true))
     8751            //      if (!use.move_to ())
     8752          if (!use.move_to ())
     8753            {
     8754              if (!CmtSystem::cd (Cmt::get_current_dir ()))
     8755                {
     8756                  CmtError::set (CmtError::file_access_error,
     8757                                 Cmt::get_current_dir ()
     8758                                 + " (use_extra_file)");
     8759                  return 0;
     8760                }
     8761              if (!use.move_to ("", true))
     8762                {
     8763                  CmtError::set (CmtError::package_not_found, use.get_info ());
     8764                  return 0;
     8765                }
     8766            }
     8767         
     8768          Me.m_current_path = use.real_path;
     8769          Me.m_current_access = DeveloperMode;
     8770        }
     8771    }
     8772  else
     8773    {
     8774      //
     8775      // The cmt command has been given without explicit search for
     8776      // a package. Thus it is expected that we are in the context of a
     8777      // true package.
     8778      //
     8779      //  This means that there should be a requirements file visible.
     8780      //
     8781      //  If this is not true, we'll make a try into ../cmt and then
     8782      // a last try into ../mgr
     8783      //
     8784
     8785      Me.m_current_access = DeveloperMode;
     8786      //...
     8787      configure_current_dir ();
     8788      build_prefix (Me.m_current_package, Me.m_current_prefix);
     8789      build_config (Me.m_current_prefix, Me.m_current_config);
     8790    }
     8791
     8792  /*
     8793  configure_current_dir ();
     8794  build_prefix (Me.m_current_package, Me.m_current_prefix);
     8795  build_config (Me.m_current_prefix, Me.m_current_config);
     8796  */
     8797
     8798  /*
     8799    Check Tag is always set up
     8800  */
     8801
     8802  if (Me.m_debug) cout << "use_extra_file0> current_tag=" << Me.m_current_tag << endl;
     8803
     8804  if (Me.m_current_tag == "")
     8805    {
     8806      cmt_string env;
     8807
     8808      env = CmtSystem::getenv (Me.m_current_config);
     8809      if (env != "")
     8810        {
     8811          Tag* tag;
     8812
     8813          tag = Tag::add (env, PriorityConfig, "current package", 0);
     8814          tag->mark (use.get_package_name ());
     8815          //Me.m_current_tag = env;
     8816
     8817          //if (!Me.m_quiet) cerr << "use_extra_file1> current_tag=" << Me.m_current_tag << endl;
     8818
     8819        }
     8820    }
     8821
     8822  if (Me.m_debug)
     8823    {
     8824      cout << "pwd = " << CmtSystem::pwd () << endl;
     8825    }
     8826
     8827  /*
     8828    Work on the requirements file.
     8829  */
     8830
     8831  SyntaxParser::parse_requirements (file, &use);
     8832
     8833  if (CmtError::has_pending_error ()) return 0;
     8834
     8835  if (Me.m_debug) cout << "use_extra_file2> current_tag=" << Me.m_current_tag << endl;
     8836  return 1;
     8837}
     8838
     8839//----------------------------------------------------------
     8840int Cmt::apply_globals ()
     8841{
    81038842
    81048843  /**
     
    81318870  Tag::restore_tree ();
    81328871
    8133   return (1);
    8134 }
    8135 
    8136 //----------------------------------------------------------
    8137 int Cmt::use_extra_file (const cmt_string& file)
    8138 {
    8139   if (!CmtSystem::test_file (file))
    8140     {
    8141       CmtError::set (CmtError::path_not_found, file);
    8142       return 0;
    8143     }
    8144 
    8145   // (almost) Cmt::reach_current_package ()
    8146   Use& use = Use::current ();
    8147   /*
    8148     Try to access the package.
    8149   */
    8150 
    8151   if (Me.m_current_package == "cmt_standalone")
    8152     {
    8153       if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
    8154         {
    8155           if (!CmtSystem::cd (Me.m_current_path))
    8156             {
    8157               CmtError::set (CmtError::package_not_found,
    8158                              "ReachCurrentPackage> Cannot reach the path directory");
    8159               return (0);
    8160             }
    8161         }
    8162       /*
    8163       if (!CmtSystem::test_file ("requirements"))
    8164         {
    8165           return (0);
    8166         }
    8167       */
    8168       Me.m_current_structuring_style = without_version_directory;
    8169     }
    8170   else if (Me.m_current_package != "")
    8171     {
    8172       if (!use.move_to () && !use.move_to ("", true))
    8173         //      if (!use.move_to ())
    8174         {
    8175           CmtError::set (CmtError::package_not_found,
    8176                          "ReachCurrentPackage> Cannot reach the path directory");
    8177           //          return -1;
    8178           return (0);
    8179         }
    8180 
    8181       Me.m_current_path = use.real_path;
    8182     }
    8183   else
    8184     {
    8185       //
    8186       // The cmt command has been given without explicit search for
    8187       // a package. Thus it is expected that we are in the context of a
    8188       // true package.
    8189       //
    8190       //  This means that there should be a requirements file visible.
    8191       //
    8192       //  If this is not true, we'll make a try into ../cmt and then
    8193       // a last try into ../mgr
    8194       //
    8195 
    8196       //...
    8197     }
    8198 
    8199   configure_current_dir ();
    8200   build_prefix (Me.m_current_package, Me.m_current_prefix);
    8201   build_config (Me.m_current_prefix, Me.m_current_config);
    8202 
    8203   /*
    8204     Check Tag is always set up
    8205   */
    8206 
    8207   if (Me.m_debug) cout << "use_extra_file0> current_tag=" << Me.m_current_tag << endl;
    8208 
    8209   if (Me.m_current_tag == "")
    8210     {
    8211       cmt_string env;
    8212 
    8213       env = CmtSystem::getenv (Me.m_current_config);
    8214       if (env != "")
    8215         {
    8216           Tag* tag;
    8217 
    8218           tag = Tag::add (env, PriorityConfig, "reach current package", 0);
    8219           tag->mark (use.get_package_name ());
    8220           //Me.m_current_tag = env;
    8221 
    8222           //if (!Me.m_quiet) cerr << "use_extra_file1> current_tag=" << Me.m_current_tag << endl;
    8223 
    8224         }
    8225     }
    8226 
    8227   if (Me.m_debug)
    8228     {
    8229       cout << "pwd = " << CmtSystem::pwd () << endl;
    8230     }
    8231 
    8232   /*
    8233     Work on the requirements file.
    8234   */
    8235 
    8236   SyntaxParser::parse_requirements (file, &use);
    8237 
    8238   if (Me.m_debug) cout << "use_extra_file2> current_tag=" << Me.m_current_tag << endl;
    8239 
    8240   /**
    8241    *   It would be useful to change this mechanism. Instead of
    8242    *  applying all global patterns at once to all use contexts, it
    8243    *  would be much better to apply it at the end of each
    8244    *  requirements file parsing, and only in the context the
    8245    *  appropriate Use.
    8246    *
    8247    *   This would avoid the current flaw which is that when a global
    8248    *  pattern specifies a "private" definition, it is actually
    8249    *  applied in the scope context of the Current Use and not in
    8250    *  each individual Use. Therefore the private is lost.
    8251    *
    8252    *   However, this induces problems since some pattern definitions
    8253    *  are done AFTER the use statements, which will NOT receive the
    8254    *  pattern aplications.
    8255    *
    8256    *   Therefore it is decided to leave this "bad" mechanism until
    8257    *  everybody is aware of this constraint.
    8258    *
    8259    *
    8260    */
    8261   Pattern::apply_all_globals ();
    8262 
    8263   /*
    8264     Select all possible tags
    8265   */
    8266 
    8267   Tag::restore_tree ();
    8268 
    8269   return (1);
     8872  if (CmtError::has_pending_error ()) return 0;
     8873
     8874  return 1;
    82708875}
    82718876
     
    967610281
    967710282//----------------------------------------------------------
     10283/*
    967810284void Cmt::set_current_access (AccessMode mode)
    967910285{
     
    969210298  Me.m_scope_filtering_mode = mode;
    969310299}
    9694 
     10300*/
    969510301//----------------------------------------------------------
    969610302void Cmt::set_standard_macros ()
     
    983610442  builder.fill_for_constituent_macros ();
    983710443}
    9838 
     10444/*
    983910445void Cmt::set_all_sets_done ()
    984010446{
     
    984610452  Me.m_all_sets_done = false;
    984710453}
    9848 
     10454*/
    984910455//----------------------------------------------------------
    985010456void Cmt::use_cmt ()
     
    990510511  if (CmtSystem::test_file (f))
    990610512    {
    9907       use->m_located = true;
    9908     }
    9909   SyntaxParser::parse_requirements (f, use);
     10513      use->style = none_style;
     10514      use->structuring_style = without_version_directory;
     10515
     10516      if (name == CmtSystem::get_home_package () ||
     10517          name == CmtSystem::get_user_context_package ())
     10518        {
     10519          const Project::ProjectPtrVector& Ordered = Project::ordered_projects ();
     10520          if (0 == Ordered.size ())
     10521            {
     10522              if (m_cmt_context.m_use_projects)
     10523                {
     10524                  CmtError::set(CmtError::configuration_error,
     10525                                "No such ordered project: " + use->get_info ());
     10526                  return;
     10527                }
     10528              else
     10529                {
     10530                  use->change_path (path);
     10531                }
     10532            }
     10533          else
     10534            {
     10535              if (name == CmtSystem::get_home_package ())
     10536                use->change_path (path, Ordered[Ordered.size () - 1]);
     10537              else if (name == CmtSystem::get_user_context_package ())
     10538                use->change_path (path, Ordered[0]);
     10539            }
     10540        }
     10541      else
     10542        {
     10543          CmtMessage::verbose
     10544            (CmtError::get_error_name (CmtError::configuration_error)
     10545             + ": Unknown special use: " + use->get_info ());
     10546          use->change_path (path);
     10547        }
     10548      //      use->m_located = true;
     10549      SyntaxParser::parse_requirements (f, use);
     10550    }
     10551  else
     10552    {
     10553      use->discard ();
     10554    }
    991010555
    991110556  Me.m_recursive = recursive_copy;
     
    992210567    {
    992310568      const cmt_string& s = v[i];
    9924       if (s == "") continue;
     10569      if (s.size () == 0) continue;
    992510570
    992610571      if (result.size () != 0) result += separator;
    992710572      //if (i > 0) result += separator;
    9928       result += v[i];
     10573      result += s;
    992910574    }
    993010575}
Note: See TracChangeset for help on using the changeset viewer.