Changeset 656


Ignore:
Timestamp:
Dec 4, 2013, 10:57:15 AM (10 years ago)
Author:
rybkin
Message:

See C.L. 515

Location:
CMT/HEAD
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/ChangeLog

    r655 r656  
     12013-12-03    <rybkin@lal.in2p3.fr> 515
     2
     3        * source/cmt_symbol.h: In class SymbolValueList function print, class
     4        Symbol functions all_print, print introduce optional argument of type
     5        ostream reference, in class Symbol, declare static functions std_env_vars,
     6        set_path_strip
     7        * source/cmt_symbol.cxx: In class PathBuilder, introduce and implement
     8        functions filter_path_value, get/set_path_strip, constructor with
     9        path_strip argument and member m_path_strip to indicate whether to strip
     10        paths of non-existent directories, in unnamed namespace, introduce cache
     11        of command outputs for use in functions resolve_value,
     12        resolve_value_for_macros, suppress_OS_delimiters, in class Symbol function
     13        create, create PathBuilder instance with configured value of path_strip,
     14        in class Symbol, implement static functions std_env_vars, set_path_strip,
     15        control access to environment in functions resolve_value, class Symbol
     16        functions all_set, get_env_value, class SetBuilder function build, class
     17        PathBuilder function build, systematically use class PathBuilder function
     18        filter_path_value in class Symbol functions all_set, check_all_paths,
     19        print, in class PathBuilder function build, in class SymbolValueList
     20        function print, modify helper function find_path_entry so as not to access
     21        file system and return index of entry found, in class PathBuilder function
     22        build, make use of signature to enhance implementation of path_append /
     23        prepend commands, drop redundant cleaning of repeating path separators, in
     24        class SymbolValueList function print, implement enhanced cached
     25        requirements file generation, i.e., resolve sets for macros if possible,
     26        resolve paths fully if possible, so as to strip path of non-existent
     27        directories, implement use of argument of type ostream reference
     28        * source/cmt_use.cxx: In class Use function fill_standard_macros, generate
     29        CONFIG macros, if CONFIG environment variables are relevant, in setup
     30        Requirements mode
     31        * source/cmt_error.cxx: Cosmetic modifications to error messages
     32        * source/cmt_commands.h: In class ArgParser, declare functions
     33        option_with(out)_projects, option(_no)_path_strip
     34        * source/cmt_commands.cxx: In class ArgParser, implement introduced
     35        functions
     36        * source/cmt.h: In class CmtContext, introduce member m_use_projects to
     37        indicate whether to parse project files, member m_env_access to indicate
     38        whether symbols values can be taken from environment, member m_print_mode
     39        to hold corresponding value from class ArgParser instance, member
     40        m_path_strip to indicate whether to strip paths of non-existent
     41        directories, in class Cmt functions print, print_context introduce optional
     42        argument of type ostream reference, declare and implement inline functions
     43        get/set_env_access, get/set_print_mode, get_path_strip
     44        * source/cmt_parser.cxx: In class Cmt function configure_cmt_path, do not
     45        create projects if m_use_projects is false, in function do_broadcast, set
     46        cmtpath for all uses so as to fill in templates correctly, in function
     47        do_check_configuration, do not run class Symbol function check_all_paths
     48        for setup unless in Requirements mode (since paths checks are done in class
     49        Symbol function print), in function do_setup, implement procedure of cached
     50        requirements file generation, i.e., do not access environment to set
     51        symbols values and, by default, strip paths of non-existent directories if
     52        possible, in function guess_current_project, return if projects are not
     53        used, do not change m_autoconfigure_cmtpath value, in functions print,
     54        print_context, implement use of argument of type ostream reference, in
     55        function print_context, in Requirements mode, generate CONFIG sets if
     56        CONFIG environment variables are relevant, in function
     57        use_special_requirements, handle case when projects are not used
     58        * mgr/requirements: Associate CMTr25 tag with HEAD, append CMT to PATH as
     59        in CMT setup scripts
     60       
    1612013-11-13    <rybkin@lal.in2p3.fr> 514
    262
     
    41101        system tags handling to make all initially known tags available while
    42102        reading project files, implement get_tags_remove function, in parser
    43         function initialise static xCmtContext instance at very beginning
     103        function initialise static CmtContext instance at very beginning
    44104        * source/cmt.h: In class Cmt, declare get_tags_remove function
    45105       
  • CMT/HEAD/mgr/requirements

    r628 r656  
    66tag CMTr16 CMTr14
    77tag CMTr18 CMTr16
    8 tag CMTr0  CMTr18
     8tag CMTr0  CMTr25
    99
    1010#
     
    125125             WIN32     "CMT\v"
    126126
    127 path_prepend PATH      "${CMTROOT}/${CMTBIN}" \
     127path_append PATH      "${CMTROOT}/${CMTBIN}" \
    128128             WIN32     "%CMTROOT%\%CMTBIN%"
    129129
  • CMT/HEAD/source/cmt.h

    r654 r656  
    3535  cmt_string m_cmt_version;
    3636  bool m_use_cmt;
     37  bool m_use_projects;
    3738 
    3839  cmt_string m_current_dir;
     
    7475
    7576  bool m_autoconfigure_cmtpath;
     77
     78  bool m_env_access;
     79  PrintMode m_print_mode;
     80  bool m_path_strip;
    7681
    7782private:
     
    271276  static int parser (const cmt_string& command_line);
    272277  static int parser (int argc, char* argv[]);
    273   static void print (PrintMode mode);
     278  static void print (PrintMode mode, ostream& out = cout);
     279  //static void print (PrintMode mode);
    274280  static void print_clean (PrintMode mode);
    275   static void print_context (Use& use, PrintMode mode, const cmt_string& tag);
     281  static void print_context (Use& use, PrintMode mode, const cmt_string& tag, ostream& out = cout);
     282  //static void print_context (Use& use, PrintMode mode, const cmt_string& tag);
    276283  static void print_macros (PrintMode mode, const cmt_string& pattern = "",
    277284                            ostream& out = cout);
     
    302309                                cmt_string& result);
    303310
     311  static inline const bool& get_env_access ();
     312  static inline void set_env_access (const bool& access);
     313  static inline const PrintMode& get_print_mode ();
     314  static inline void set_print_mode (const PrintMode& mode);
     315  static inline const bool& get_path_strip ();
     316
    304317private:
    305318  static CmtContext& m_cmt_context;
     
    425438}
    426439
     440inline const bool& Cmt::get_env_access ()
     441{
     442  return m_cmt_context.m_env_access;
     443}
     444
     445inline void Cmt::set_env_access (const bool& access)
     446{
     447  m_cmt_context.m_env_access = access;
     448}
     449
     450inline const PrintMode& Cmt::get_print_mode ()
     451{
     452  return m_cmt_context.m_print_mode;
     453}
     454
     455inline void Cmt::set_print_mode (const PrintMode& mode)
     456{
     457  m_cmt_context.m_print_mode = mode;
     458}
     459
     460inline const bool& Cmt::get_path_strip ()
     461{
     462  return m_cmt_context.m_path_strip;
     463}
    427464//----------------------------------------------------------
    428465
  • CMT/HEAD/source/cmt_commands.cxx

    r652 r656  
    256256  pv.push_back (&ArgParser::option_no_cleanup); i++;
    257257
     258  parsers.add ("-no_path_s", i);
     259  parsers.add ("-no_path_st", i);
     260  parsers.add ("-no_path_str", i);
     261  parsers.add ("-no_path_stri", i);
     262  parsers.add ("-no_path_strip", i);
     263  pv.push_back (&ArgParser::option_no_path_strip); i++;
     264
    258265  parsers.add ("-pac", i);
    259266  parsers.add ("-pack", i);
     
    263270  parsers.add ("-path", i);
    264271  pv.push_back (&ArgParser::option_path); i++;
     272
     273  parsers.add ("-path_s", i);
     274  parsers.add ("-path_st", i);
     275  parsers.add ("-path_str", i);
     276  parsers.add ("-path_stri", i);
     277  parsers.add ("-path_strip", i);
     278  pv.push_back (&ArgParser::option_path_strip); i++;
    265279
    266280  parsers.add ("-pr", i);
     
    346360  parsers.add ("-without_cmt", i);
    347361  pv.push_back (&ArgParser::option_without_cmt); i++;
     362
     363  parsers.add ("-with_p", i);
     364  parsers.add ("-with_pr", i);
     365  parsers.add ("-with_pro", i);
     366  parsers.add ("-with_proj", i);
     367  parsers.add ("-with_proje", i);
     368  parsers.add ("-with_projec", i);
     369  parsers.add ("-with_project", i);
     370  parsers.add ("-with_projects", i);
     371  pv.push_back (&ArgParser::option_with_projects); i++;
     372
     373  parsers.add ("-without_p", i);
     374  parsers.add ("-without_pr", i);
     375  parsers.add ("-without_pro", i);
     376  parsers.add ("-without_proj", i);
     377  parsers.add ("-without_proje", i);
     378  parsers.add ("-without_projec", i);
     379  parsers.add ("-without_project", i);
     380  parsers.add ("-without_projects", i);
     381  pv.push_back (&ArgParser::option_without_projects); i++;
    348382
    349383  parsers.add ("-warn", i);
     
    20222056}
    20232057
     2058void ArgParser::option_no_path_strip ()
     2059{
     2060  cmt.m_path_strip = false;
     2061  if (!Cmt::add_cmt_flag ("-no_path_strip"))
     2062    CmtMessage::error ("Cannot add flag `-no_path_strip'");
     2063}
     2064
     2065void ArgParser::option_path_strip ()
     2066{
     2067  cmt.m_path_strip = true;
     2068  if (!Cmt::add_cmt_flag ("-path_strip"))
     2069    CmtMessage::error ("Cannot add flag `-path_strip'");
     2070}
     2071
    20242072void ArgParser::option_tag ()
    20252073{
     
    23232371  if (!Cmt::add_cmt_flag ("-without_cmt"))
    23242372    CmtMessage::error ("Cannot add flag `-without_cmt'");
     2373}
     2374
     2375void ArgParser::option_with_projects ()
     2376{
     2377  cmt.m_use_projects = true;
     2378  if (!Cmt::add_cmt_flag ("-with_projects"))
     2379    CmtMessage::error ("Cannot add flag `-with_projects'");
     2380}
     2381
     2382void ArgParser::option_without_projects ()
     2383{
     2384  cmt.m_use_projects = false;
     2385  if (!Cmt::add_cmt_flag ("-without_projects"))
     2386    CmtMessage::error ("Cannot add flag `-without_projects'");
    23252387}
    23262388
  • CMT/HEAD/source/cmt_commands.h

    r561 r656  
    8383  void option_with_cmt ();
    8484  void option_without_cmt ();
     85  void option_with_projects ();
     86  void option_without_projects ();
    8587  void option_with_version_directory ();
    8688  void option_without_version_directory ();
    8789  void option_no_cleanup ();
     90  void option_no_path_strip ();
     91  void option_path_strip ();
    8892  void option_private ();
    8993  void option_public ();
  • CMT/HEAD/source/cmt_error.cxx

    r598 r656  
    1818  {
    1919    error_names.add() = "ok";
    20     error_names.add() = "Warning";
     20    error_names.add() = "warning";
    2121    error_names.add() = "symbol not found";
    2222    error_names.add() = "pattern not found";
     
    159159
    160160  result = get_error_name (e.get_code ());
    161   result += " : ";
     161  result += ": ";
    162162  result += e.get_text ();
    163163
  • CMT/HEAD/source/cmt_parser.cxx

    r655 r656  
    6868  m_cmt_version    = "";
    6969  m_use_cmt        = true;
     70  m_use_projects   = true;
    7071
    7172  m_current_dir     = "";
     
    109110
    110111  m_autoconfigure_cmtpath = false;
     112
     113  m_env_access = true;
     114  m_print_mode = Csh;
     115  m_path_strip = false;
    111116}
    112117//----------------------------------------------------------
     
    627632  Me.m_autoconfigure_cmtpath = true;
    628633  configure_cmt_path (0);
    629   Me.m_autoconfigure_cmtpath = false;
     634  //  Me.m_autoconfigure_cmtpath = false;
    630635
    631636  Me.m_quiet = save_quiet;
     
    710715{
    711716  if (!Me.m_autoconfigure_cmtpath) return;
     717
     718  if (!m_cmt_context.m_use_projects) return;
    712719
    713720  cmt_string s;
     
    21152122          ok = selected;
    21162123        }
     2124      else if (up)
     2125        cmtpath = up->get_cmtpath ();
    21172126
    21182127      if (ok)
     
    31703179    }
    31713180
    3172   Symbol::check_all_paths ();
     3181  if (action_setup != get_action () ||
     3182      Requirements == ap.mode)
     3183    // PathBuilder::filter_path_value is called
     3184    // for each path in Symbol::print
     3185    Symbol::check_all_paths ();
    31733186
    31743187  env = CmtSystem::getenv ("CMTSITE");
     
    45694582      break;
    45704583    case Requirements :
     4584      /*
    45714585      CmtSystem::cmt_string_vector flags;
    45724586      get_cmt_flags (flags);
    45734587      cout << "\n# CMTFLAGS: -without_cmt";
     4588      cout << " -without_projects" ;
    45744589      for (int i = 0; i < flags.size (); i++)
    45754590        {
     
    45784593          else if (flags[i] == "-with_cmt")
    45794594            cout << " -without_cmt";
     4595          else if (flags[i] == "-without_projects")
     4596            cout << " -with_projects";
     4597          else if (flags[i] == "-with_projects")
     4598            cout << " -without_projects";
    45804599          else
    45814600            cout << " " << flags[i];
    45824601        }
    45834602      cout << endl;
     4603      */
    45844604      break;
    4585     }
    4586   print (ap.mode);
     4605    default:
     4606      break;
     4607    }
     4608
     4609  ostringstream os;
     4610  ostringstream oh;
     4611  bool reset (false);
     4612  CmtSystem::cmt_string_vector flags;
     4613  cmt_string path_strip_flag;
     4614  bool path_strip (false);
     4615
     4616  bool strip_saved (get_path_strip ());
     4617  bool access_saved (Cmt::get_env_access ());
     4618
     4619  switch (ap.mode)
     4620    {
     4621    case Requirements :
     4622
     4623      get_cmt_flags (flags);
     4624      for (int i = 0; i < flags.size (); i++)
     4625        {
     4626          if (flags[i] == "-no_path_strip")
     4627            path_strip_flag = "-no_path_strip";
     4628          else if (flags[i] == "-path_strip")
     4629            path_strip_flag = "-path_strip";
     4630        }
     4631      if (path_strip_flag != "-no_path_strip" &&
     4632          !get_path_strip ())
     4633        reset = Symbol::set_path_strip (true);
     4634
     4635      if (get_path_strip () || reset)
     4636        path_strip = true;
     4637      else
     4638        path_strip = false;
     4639
     4640      Cmt::set_env_access (false);
     4641
     4642      print (ap.mode, os);
     4643
     4644      if (CmtError::get_last_error_code () == CmtError::warning &&
     4645          (get_path_strip () || reset))
     4646        {
     4647          reset = Symbol::set_path_strip (false);
     4648          if (reset)
     4649            {
     4650              path_strip = false;
     4651
     4652              CmtError::print ();
     4653              CmtError::clear ();
     4654
     4655              if (Cmt::get_debug ())
     4656                {
     4657                  cerr << "|Cmt::do_setup> Failure with:\n" << os.str ()
     4658                       << "|Cmt::do_setup> Trying again." << endl;
     4659                }
     4660
     4661              // Try again
     4662              os.str ("");
     4663              print (ap.mode, os);
     4664            }
     4665        }
     4666
     4667      if (reset) Symbol::set_path_strip (strip_saved);
     4668      Cmt::set_env_access (access_saved);
     4669
     4670      //get_cmt_flags (flags);
     4671      oh << "\n# CMTFLAGS:"
     4672        " -without_cmt"
     4673        " -without_projects"
     4674        //" -path_strip"
     4675        ;
     4676      for (int i = 0; i < flags.size (); i++)
     4677        {
     4678          if (flags[i] == "-without_cmt")
     4679            oh << " -with_cmt";
     4680          else if (flags[i] == "-with_cmt")
     4681            oh << " -without_cmt";
     4682          else if (flags[i] == "-without_projects")
     4683            oh << " -with_projects";
     4684          else if (flags[i] == "-with_projects")
     4685            oh << " -without_projects";
     4686          /*
     4687          else if (flags[i] == "-no_path_strip")
     4688            oh << " -path_strip";
     4689          else if (flags[i] == "-path_strip")
     4690            oh << " -no_path_strip";
     4691          */
     4692          else if (flags[i] == "-no_path_strip" ||
     4693                   flags[i] == "-path_strip")
     4694            continue;
     4695          else
     4696            oh << " " << flags[i];
     4697        }
     4698      //if (reset) oh << " -path_strip";
     4699      if (path_strip)
     4700        oh << " -no_path_strip";
     4701      else
     4702        oh << " -path_strip";
     4703      oh << endl;
     4704
     4705      cout << oh.str ();
     4706      cout << os.str ();
     4707
     4708      break;
     4709
     4710    default:
     4711
     4712      print (ap.mode);
     4713
     4714      break;
     4715    }
     4716
    45874717  switch (ap.mode)
    45884718    {
     
    56805810void Cmt::guess_current_project ()
    56815811{
     5812  if (!m_cmt_context.m_use_projects) return;
     5813
    56825814  Log;
    56835815
     
    57825914  //  Use& use = Use::current();
    57835915
     5916  bool autoconfigure_cmtpath_saved (Me.m_autoconfigure_cmtpath);
     5917  Me.m_autoconfigure_cmtpath = false;
    57845918  bool save_quiet = Me.m_quiet;
    57855919  Me.m_quiet = true;
     
    57885922
    57895923  Me.m_quiet = save_quiet;
    5790 
    5791   Me.m_autoconfigure_cmtpath = true;
     5924  Me.m_autoconfigure_cmtpath = autoconfigure_cmtpath_saved;
     5925  //  Me.m_autoconfigure_cmtpath = true;
    57925926
    57935927  //  CmtSystem::cd (Me.m_current_dir);
     
    67976931
    67986932  parse_arguments (ap);
     6933  // Copy ap.mode into cmt_context member/instance
     6934  set_print_mode (ap.mode);
    67996935
    68006936  //  configure ();
     
    77417877 * joined with semi-colons to form one shell command.
    77427878 */
    7743 void Cmt::print (PrintMode mode)
     7879void Cmt::print (PrintMode mode, ostream& out)
    77447880{
    77457881  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
     
    78057941          if (tag != 0)
    78067942            {
    7807               tag->show (true, cout, "apply_tag ");
     7943              tag->show (true, out, "apply_tag ");
    78087944            }
    78097945        }
     
    78267962          if (use.m_hidden) continue;
    78277963         
    7828           print_context (use, mode, tag);
    7829         }
    7830     }
    7831 
    7832   print_context (Use::current (), mode, tag);
     7964          print_context (use, mode, tag, out);
     7965        }
     7966    }
     7967
     7968  print_context (Use::current (), mode, tag, out);
    78337969
    78347970  if (Me.m_debug)
     
    78377973    }
    78387974
    7839   Symbol::all_print (mode);
     7975  Symbol::all_print (mode, out);
    78407976  // Script::all_print (mode);
    78417977
     
    78507986      break;
    78517987    default :
    7852   cout << endl;
     7988      out << endl;
    78537989      break;
    78547990    }
     
    79568092
    79578093//----------------------------------------------------------
    7958 void Cmt::print_context (Use& use, PrintMode mode, const cmt_string& tag)
     8094void Cmt::print_context (Use& use, PrintMode mode, const cmt_string& tag, ostream& out)
    79598095{
    79608096  if (use.get_package_name () == "cmt_standalone") return;
     
    79888124      if (do_root)
    79898125        {
    7990           cout << "setenv " << prefix << "ROOT \"" <<
     8126          out << "setenv " << prefix << "ROOT \"" <<
    79918127            use.get_full_path () << "\"" << endl;
    79928128        }
     
    79948130      if (use.get_package_name () == "CMT")
    79958131        {
    7996           cout << "setenv CMTCONFIG " << system << endl;
     8132          out << "setenv CMTCONFIG " << system << endl;
    79978133        }
    79988134      else
     
    80008136          if (do_config)
    80018137            {
    8002               cout << "setenv " << prefix << "CONFIG \"" << tag << "\"" << endl;
     8138              out << "setenv " << prefix << "CONFIG \"" << tag << "\"" << endl;
    80038139            }
    80048140        }
     
    80088144      if (do_root)
    80098145        {
    8010           cout << prefix << "ROOT=\"" <<
     8146          out << prefix << "ROOT=\"" <<
    80118147            use.get_full_path () << "\"; export " <<
    80128148            prefix << "ROOT" << endl;
     
    80158151      if (use.get_package_name () == "CMT")
    80168152        {
    8017           cout << "CMTCONFIG=" << system << "; export CMTCONFIG" << endl;
     8153          out << "CMTCONFIG=" << system << "; export CMTCONFIG" << endl;
    80188154        }
    80198155      else
     
    80218157          if (do_config)
    80228158            {
    8023               cout << prefix << "CONFIG=\"" <<
     8159              out << prefix << "CONFIG=\"" <<
    80248160                tag << "\"; export " <<
    80258161                prefix << "CONFIG" << endl;
     
    80318167      if (do_root)
    80328168        {
    8033           cout << "set " << prefix << "ROOT=" <<
     8169          out << "set " << prefix << "ROOT=" <<
    80348170            CmtSystem::quote (use.get_full_path (), " \t") << endl;
    80358171        }
     
    80378173      if (use.get_package_name () == "CMT")
    80388174        {
    8039           cout << "set CMTCONFIG=" << system << endl;
     8175          out << "set CMTCONFIG=" << system << endl;
    80408176        }
    80418177      else
     
    80438179          if (do_config)
    80448180            {
    8045               cout << "set " << prefix << "CONFIG=" << CmtSystem::quote (tag, " \t") << endl;
     8181              out << "set " << prefix << "CONFIG=" << CmtSystem::quote (tag, " \t") << endl;
    80468182            }
    80478183        }
     
    80518187      if (do_root)
    80528188        {
    8053           cout << "<variable><name>" << prefix << "ROOT</name>"
    8054                << "<value>" << use.get_full_path () << "</value></variable>";
     8189          out << "<variable><name>" << prefix << "ROOT</name>"
     8190              << "<value>" << use.get_full_path () << "</value></variable>";
    80558191        }
    80568192
    80578193      if (use.get_package_name () == "CMT")
    80588194        {
    8059           cout << "<variable><name>CMTCONFIG</name>"
    8060                << "<value>" << system << "</value></variable>";
     8195          out << "<variable><name>CMTCONFIG</name>"
     8196              << "<value>" << system << "</value></variable>";
    80618197        }
    80628198      else
     
    80648200          if (do_config)
    80658201            {
    8066               cout << "<variable><name>" << prefix << "CONFIG</name>"
    8067                    << "<value>" << tag << "</value></variable>";
     8202              out << "<variable><name>" << prefix << "CONFIG</name>"
     8203                  << "<value>" << tag << "</value></variable>";
    80688204            }
    80698205        }
     
    80748210          use.get_package_name () != "CMT")
    80758211        {
    8076           cout << "set " << use.prefix << "ROOT " <<
     8212          out << "set " << use.prefix << "ROOT " <<
    80778213            CmtSystem::quote (use.get_full_path (), " \t") << endl;
    80788214
     
    80938229      if (use.get_package_name () == "CMT")
    80948230        {
    8095           cout << "set CMTCONFIG " << system << endl;
     8231          out << "set CMTCONFIG " << system << endl;
    80968232        }
    80978233      else
     
    80998235          if (do_config)
    81008236            {
    8101               cout << "set " << use.prefix << "CONFIG " << CmtSystem::quote (tag, " \t") << endl;
     8237              out << "set " << use.prefix << "CONFIG " << CmtSystem::quote (tag, " \t") << endl;
     8238             
     8239              cmt_string name (use.prefix + "CONFIG");
     8240              Symbol* symbol = Symbol::find (name);
     8241              if (symbol != 0)
     8242                {
     8243                  symbol->printed = true;
     8244                }
     8245              if (symbol == 0 || symbol->type != Symbol::SymbolMacro)
     8246                {
     8247                  CmtMessage::warning
     8248                    (CmtError::get_error_name (CmtError::symbol_not_found)
     8249                     + ": macro " + name);
     8250                }
    81028251            }
    81038252        }
     
    1033310482          if (0 == Ordered.size ())
    1033410483            {
    10335               CmtError::set(CmtError::configuration_error,
    10336                             "No ordered project: " + use->get_info ());
    10337               return;
     10484              if (m_cmt_context.m_use_projects)
     10485                {
     10486                  CmtError::set(CmtError::configuration_error,
     10487                                "No such ordered project: " + use->get_info ());
     10488                  return;
     10489                }
     10490              else
     10491                {
     10492                  use->change_path (path);
     10493                }
    1033810494            }
    10339           if (name == CmtSystem::get_home_package ())
    10340             use->change_path (path, Ordered[Ordered.size () - 1]);
    10341           else if (name == CmtSystem::get_user_context_package ())
    10342             use->change_path (path, Ordered[0]);
     10495          else
     10496            {
     10497              if (name == CmtSystem::get_home_package ())
     10498                use->change_path (path, Ordered[Ordered.size () - 1]);
     10499              else if (name == CmtSystem::get_user_context_package ())
     10500                use->change_path (path, Ordered[0]);
     10501            }
    1034310502        }
    1034410503      else
     
    1037010529    {
    1037110530      const cmt_string& s = v[i];
    10372       if (s == "") continue;
     10531      if (s.size () == 0) continue;
    1037310532
    1037410533      if (result.size () != 0) result += separator;
    1037510534      //if (i > 0) result += separator;
    10376       result += v[i];
     10535      result += s;
    1037710536    }
    1037810537}
  • CMT/HEAD/source/cmt_symbol.cxx

    r652 r656  
    1515#include "cmt_database.h"
    1616#include "cmt_log.h"
     17#include "cmt_error.h"
    1718
    1819// Global inhibitor of any display
     
    4243  const cmt_string clean (const Symbol& symbol,
    4344                          const cmt_string& tag_name = "");
     45
     46  void filter_path_value (const Symbol& symbol,
     47                          cmt_string& value,
     48                          const cmt_string& tag_name = "") const;
     49  void filter_path_value (const Symbol& symbol,
     50                          CmtSystem::cmt_string_vector& value,
     51                          const cmt_string& tag_name = "") const;
     52  inline const bool& get_path_strip () const;
     53  inline void set_path_strip (const bool& path_strip);
     54
     55  PathBuilder ();
     56  PathBuilder (bool path_strip);
     57
     58private:
     59  bool m_path_strip;
    4460};
    4561//-------------------------------------------------------------
     
    248264}
    249265
     266//
     267// Global cache
     268//
     269namespace
     270{
     271  cmt_vmap <cmt_string, cmt_string> cmdoutputs;
     272}
    250273/**
    251274
     
    285308  int start = 0;
    286309
     310  //  static cmt_vmap <cmt_string, cmt_string> cmdoutputs;
     311
    287312  for (;;)
    288313    {
     
    337362            // to be applied. The output of the command is then substituted
    338363
     364          Symbol::all_set ();
     365
    339366          cmt_string result;
    340 
    341           Symbol::all_set ();
    342           CmtSystem::execute (command, result);
    343          
    344           /*
    345           int pos;
    346           pos = result.find ('\n');
    347           if (pos != cmt_string::npos) result.erase (pos);
    348           pos = result.find ('\r');
    349           if (pos != cmt_string::npos) result.erase (pos);
    350           */         
    351           process_cmd_output (result);
    352 
    353           if (Cmt::get_debug ())
    354             {
    355               cout << "resolve_value: Executing [" << command << "] to expand a symbol value =>["
    356                    << result << "]" << endl;
    357             }
    358          
     367          const cmt_string * presult;
     368          if (!(presult = cmdoutputs.find (command)))
     369            {
     370              CmtSystem::execute (command, result);
     371             
     372              process_cmd_output (result);
     373              cmdoutputs.add (command, result);
     374              if (Cmt::get_debug ())
     375                {
     376                  cout << "resolve_value: Executing [" << command << "] to expand a symbol value =>["
     377                       << result << "]" << endl;
     378                }
     379            }
     380          else
     381            {
     382              result = *presult;
     383              if (Cmt::get_debug ())
     384                {
     385                  cout << "resolve_value: Found in cache [" << command << "] to expand a symbol value =>["
     386                       << result << "]" << endl;
     387                }
     388            }
     389
    359390          text.replace_all (pattern, result);
    360391
     
    378409          else
    379410            {
     411              if (Cmt::get_env_access () ||
     412                  Symbol::std_env_vars ().has (symbol_name))
     413                {
    380414                // Symbol not found. Look for env. variable
    381415              cmt_string value = CmtSystem::getenv (symbol_name);
    382              
    383416                // When the env. variable is not defined, the replacement is empty
    384417                // thus all $(xxx) ${xxx} %xxx% patterns are always filtered away.
    385418              text.replace_all (pattern, value);
    386419             
     420                  if (Cmt::get_debug ())
     421                    {
     422                      cerr << "resolve_value: getenv (" << symbol_name
     423                           << ") => " << value << endl;
     424                    }
    387425                // The substitution will restart from the same place
    388426                // allowing for recursive replacements
    389427              start = begin;
     428                }
     429              else
     430                {
     431                  if (Cmt::get_debug ())
     432                    {
     433                      cerr << "resolve_value: getenv (" << symbol_name
     434                           << ") denied" << endl;
     435                    }
     436                  CmtError::set (CmtError::warning,
     437                                 "getenv (" + symbol_name + ") denied");
     438                  return;
     439                }
    390440            }
    391441        }
     
    484534            // to be applied. The output of the command is substituted
    485535
     536          Symbol::all_set ();
     537
    486538          cmt_string result;
    487 
    488           Symbol::all_set ();
    489           CmtSystem::execute (command, result);
    490          
    491           /*
    492           int pos;
    493           pos = result.find ('\n');
    494           if (pos != cmt_string::npos) result.erase (pos);
    495           pos = result.find ('\r');
    496           if (pos != cmt_string::npos) result.erase (pos);
    497           */
    498           process_cmd_output (result);
    499          
    500           if (Cmt::get_debug ())
    501             {
    502               cout << "   Executing [" << command << "] to expand a macro value =>["
    503                    << result << "]" << endl;
    504             }
    505          
     539          const cmt_string * presult;
     540          if (!(presult = cmdoutputs.find (command)))
     541            {
     542              CmtSystem::execute (command, result);
     543             
     544              process_cmd_output (result);
     545              cmdoutputs.add (command, result);
     546              if (Cmt::get_debug ())
     547                {
     548                  cout << "resolve_value_for_macros: Executing [" << command << "] to expand a symbol value =>["
     549                       << result << "]" << endl;
     550                }
     551            }
     552          else
     553            {
     554              result = *presult;
     555              if (Cmt::get_debug ())
     556                {
     557                  cout << "resolve_value_for_macros: Found in cache [" << command << "] to expand a symbol value =>["
     558                       << result << "]" << endl;
     559                }
     560            }
     561
    506562          text.replace_all (pattern, result);
    507563
     
    621677            // to be applied. The output of the command is substituted
    622678
     679          Symbol::all_set ();
     680
    623681          cmt_string result;
    624 
    625           Symbol::all_set ();
    626           CmtSystem::execute (command, result);
    627          
    628           /*
    629           int pos;
    630           pos = result.find ('\n');
    631           if (pos != cmt_string::npos) result.erase (pos);
    632           pos = result.find ('\r');
    633           if (pos != cmt_string::npos) result.erase (pos);
    634           */         
    635           process_cmd_output (result);
    636          
    637           if (Cmt::get_debug ())
    638             {
    639               cout << "   Executing [" << command << "] to expand a macro value =>["
    640                    << result << "]" << endl;
    641             }
    642          
     682          const cmt_string * presult;
     683          if (!(presult = cmdoutputs.find (command)))
     684            {
     685              CmtSystem::execute (command, result);
     686             
     687              process_cmd_output (result);
     688              cmdoutputs.add (command, result);
     689              if (Cmt::get_debug ())
     690                {
     691                  cout << "suppress_OS_delimiters: Executing [" << command << "] to expand a symbol value =>["
     692                       << result << "]" << endl;
     693                }
     694            }
     695          else
     696            {
     697              result = *presult;
     698              if (Cmt::get_debug ())
     699                {
     700                  cout << "suppress_OS_delimiters: Found in cache [" << command << "] to expand a symbol value =>["
     701                       << result << "]" << endl;
     702                }
     703            }
     704
    643705          text.replace_all (pattern, result);
    644706
     
    692754{
    693755  static SetBuilder Set;
    694   static PathBuilder Path;
     756  static PathBuilder Path (Cmt::get_path_strip ());
     757  //static PathBuilder Path;
    695758  static MacroBuilder Macro;
    696759  static ScriptBuilder Script;
     
    913976}
    914977
     978//-------------------------------------------------------------
     979Symbol::SymbolMap& Symbol::std_env_vars ()
     980{
     981  static SymbolMap env_vars;
     982  static Symbol std_sym;
     983  static bool initialized (false);
     984  if (!initialized)
     985    {
     986      env_vars.add ("SITEROOT", std_sym);
     987      env_vars.add ("CMTCONFIG", std_sym);
     988      env_vars.add ("CMTBIN", std_sym);
     989      env_vars.add ("CMTPATH", std_sym);
     990      env_vars.add ("CMTHEADVERSION", std_sym);
     991      env_vars.add ("CMTPROJECTPATH", std_sym);
     992      env_vars.add ("CMTSITE", std_sym);
     993      env_vars.add ("CMTEXTRATAGS", std_sym);
     994      env_vars.add ("CMTSTRUCTURINGSTYLE", std_sym);
     995      env_vars.add ("CMTHOME", std_sym);
     996      env_vars.add ("CMTUSERCONTEXT", std_sym);
     997      initialized = true;
     998    }
     999  return env_vars;
     1000}
     1001
    9151002/**
    9161003   Filter out faulty items of a path-like symbol value
     
    11681255
    11691256//-------------------------------------------------------------
     1257bool Symbol::set_path_strip (const bool& path_strip)
     1258{
     1259  // searching for a path symbol
     1260  for (int number = 0; number < Symbol::symbol_number (); number++)
     1261    {
     1262      Symbol& symbol = Symbol::symbol (number);
     1263     
     1264      if (symbol.type == Symbol::SymbolPath)
     1265        {
     1266          static_cast<PathBuilder*> (symbol.builder)->set_path_strip (path_strip);
     1267          return true;
     1268        }
     1269    }
     1270
     1271  return false;
     1272}
     1273
     1274//-------------------------------------------------------------
    11701275int Symbol::is_selected (const cmt_string& name)
    11711276{
     
    14221527  cmt_string value;
    14231528
     1529  if (Cmt::get_env_access ())
     1530    {
    14241531  for (number = 0; number < Symbol::symbol_number (); number++)
    14251532    {
     
    14331540          Symbol::expand (value);
    14341541
     1542          if (Cmt::get_debug ())
     1543            {
     1544              cerr << "Symbol::all_set (set)> " << symbol.name << " = " << value << endl;
     1545            }
     1546
    14351547          CmtSystem::putenv (symbol.name, value);
    14361548        }
     1549    }
    14371550    }
    14381551
     
    15001613  }
    15011614
     1615  static PathBuilder* pb (0);
     1616
     1617  if (Cmt::get_env_access ())
     1618    {
    15021619  for (number = 0; number < Symbol::symbol_number (); number++)
    15031620    {
     
    15101627        {
    15111628          Symbol::expand (value);
    1512           filter_path_value (symbol.name, value);
     1629          if (!pb)
     1630            pb = static_cast<PathBuilder*> (symbol.builder);
     1631          pb->filter_path_value (symbol, value);
     1632          //filter_path_value (symbol.name, value);
    15131633
    15141634#ifdef WIN32
     
    15181638          if (Cmt::get_debug ())
    15191639            {
    1520               cerr << "Symbol::all_set-2> " << symbol.name << " = " << value << endl;
     1640              cerr << "Symbol::all_set (path)> " << symbol.name << " = " << value << endl;
    15211641            }
    15221642
     
    15241644        }
    15251645    }
     1646    }
    15261647
    15271648  running = false;
     
    15291650
    15301651//-------------------------------------------------------------
    1531 void Symbol::all_print (PrintMode mode)
     1652void Symbol::all_print (PrintMode mode, ostream& out)
     1653//void Symbol::all_print (PrintMode mode)
    15321654{
    15331655  static SymbolVector& Symbols = symbols ();
     
    15501672              (symbol.type == SymbolMacro))
    15511673            {
    1552               if (symbol.print_macro (mode))
     1674              if (symbol.print_macro (mode, out))
    15531675                {
    15541676                  //              cout << endl;
     
    15671689              (symbol.type == SymbolPath))
    15681690            {
    1569               if (symbol.print (mode))
     1691              if (symbol.print (mode, out))
    15701692                {
    15711693                  if (mode == Bat)
    15721694                    {
    1573                       cout << endl;
     1695                      out << endl;
    15741696                    }
    15751697                  else if (mode == Xml)
     
    15791701                  else
    15801702                    {
    1581                       cout << endl;
     1703                      out << endl;
    15821704                    }
    15831705                }
     
    15931715  static SymbolVector& Symbols = symbols ();
    15941716
     1717  static PathBuilder* pb (0);
     1718
    15951719  int number;
    15961720
     
    16081732          expand (temp);
    16091733
    1610           Symbol::filter_path_value (symbol.name, temp);
     1734          if (!pb)
     1735            pb = static_cast<PathBuilder*> (symbol.builder);
     1736          pb->filter_path_value (symbol, temp);
     1737          //Symbol::filter_path_value (symbol.name, temp);
    16111738        }
    16121739    }
     
    17621889
    17631890//-------------------------------------------------------------
    1764 int Symbol::print (PrintMode mode)
    1765 {
     1891int Symbol::print (PrintMode mode, ostream& out)
     1892{
     1893  static PathBuilder* pb (0);
     1894
    17661895  int result = 0;
    17671896
     
    17721901    {
    17731902      expand (temp);
    1774       Symbol::filter_path_value (name, temp);
     1903      //Symbol::filter_path_value (name, temp);
     1904      if (!pb)
     1905        pb = static_cast<PathBuilder*> (builder);
     1906      pb->filter_path_value (*this, temp);
    17751907    }
    17761908
     
    17851917          {
    17861918            case Csh :
    1787               if (empty) cout << "unsetenv " << _name;
    1788               else cout << "setenv " << _name << " \"" << temp << "\"";
    1789               //else cout << "setenv " << name << " " << CmtSystem::quote (temp, " \t");
     1919              if (empty) out << "unsetenv " << _name;
     1920              else out << "setenv " << _name << " \"" << temp << "\"";
     1921              //else out << "setenv " << name << " " << CmtSystem::quote (temp, " \t");
    17901922
    17911923              result = 1;
    17921924              break;
    17931925            case Sh :
    1794               if (empty) cout << "[ -z ${" << _name << "+CMT} ] || unset " << _name;
    1795               //              if (empty) cout << "unset " << _name;
    1796               else cout << _name << "=\"" << temp << "\"; export " << _name;
    1797               //else cout << name << "=" << CmtSystem::quote (temp, " \t") << "; export " << name;
     1926              if (empty) out << "[ -z ${" << _name << "+CMT} ] || unset " << _name;
     1927              //              if (empty) out << "unset " << _name;
     1928              else out << _name << "=\"" << temp << "\"; export " << _name;
     1929              //else out << name << "=" << CmtSystem::quote (temp, " \t") << "; export " << name;
    17981930
    17991931              result = 1;
     
    18011933            case Bat :
    18021934              temp.replace_all ("/", "\\");
    1803               cout << "set " << _name << "=" << CmtSystem::quote (temp, " \t");
    1804               //cout << "set " << name << "=" << temp;
     1935              out << "set " << _name << "=" << CmtSystem::quote (temp, " \t");
     1936              //out << "set " << name << "=" << temp;
    18051937              result = 1;
    18061938              break;
    18071939            case Xml :
    1808               cout << "<variable><name>" << _name << "</name>"
     1940              out << "<variable><name>" << _name << "</name>"
    18091941                   << "<value>" << temp << "</value></variable>";
    18101942              result = 1;
     
    18161948          {
    18171949            case Csh :
    1818               cout << "alias " << name <<
     1950              out << "alias " << name <<
    18191951                " \"" << temp << "\"";
    18201952              //CmtSystem::quote (temp, " \t");
     
    18221954              break;
    18231955            case Sh :
    1824               cout << "alias " << name <<
     1956              out << "alias " << name <<
    18251957                "=\"" << temp << "\"";
    18261958              //"=" << CmtSystem::quote (temp, " \t");
     
    18281960              break;
    18291961            case Bat :
    1830               cout << "set " << name <<
     1962              out << "set " << name <<
    18311963                "=" << CmtSystem::quote (temp, " \t");
    18321964              //"=" << temp;
     
    18341966              break;
    18351967            case Xml :
    1836               cout << "<alias><name>" << name << "</name>"
     1968              out << "<alias><name>" << name << "</name>"
    18371969                   << "<value>" << temp << "</value></alias>";
    18381970              result = 1;
     
    18521984              {
    18531985                case Csh :
    1854                   cout << "if ( -f " << CmtSystem::quote (name, " \t") << ".csh ) then" << endl;
    1855                   cout << "  source " << CmtSystem::quote (name, " \t") << ".csh" << endl;
    1856                   cout <<
     1986                  out << "if ( -f " << CmtSystem::quote (name, " \t") << ".csh ) then" << endl;
     1987                  out << "  source " << CmtSystem::quote (name, " \t") << ".csh" << endl;
     1988                  out <<
    18571989                    "if ( $status != 0 ) then\n"
    18581990                    "    set cmtsetupstatus=1\n"
    18591991                    "endif\n";
    1860                   cout << "endif" << endl;
     1992                  out << "endif" << endl;
    18611993                  result = 1;
    18621994                  break;
    18631995                case Sh :
    1864                   cout << "if test -f " << CmtSystem::quote (name, " \t") << ".sh; then" << endl;
    1865                   cout << "  . " << CmtSystem::quote (name, " \t") << ".sh" << endl;
    1866                   cout <<
     1996                  out << "if test -f " << CmtSystem::quote (name, " \t") << ".sh; then" << endl;
     1997                  out << "  . " << CmtSystem::quote (name, " \t") << ".sh" << endl;
     1998                  out <<
    18671999                    "if test $? != 0; then\n"
    18682000                    "    cmtsetupstatus=1\n"
    18692001                    "fi\n";
    1870                   cout << "fi" << endl;
     2002                  out << "fi" << endl;
    18712003                  result = 1;
    18722004                  break;
    18732005                case Bat :
    1874                   cout << "call " << CmtSystem::quote (name, " \t");
     2006                  out << "call " << CmtSystem::quote (name, " \t");
    18752007                  result = 1;
    18762008                  break;
    18772009                case Xml :
    1878                   cout << "<script>" << name << "</script>";
     2010                  out << "<script>" << name << "</script>";
    18792011                  result = 1;
    18802012                  break;
     
    21242256      SymbolValue& value = value_list.values[selected];
    21252257
    2126       result += value_list.print (symbol, value, first_definition);
     2258      result += value_list.print (symbol, value, first_definition, out);
    21272259    }
    21282260
     
    22022334            else if (temp == "")
    22032335              {
    2204                 temp = CmtSystem::getenv (symbol.name);
     2336                if (Cmt::get_env_access () ||
     2337                    Symbol::std_env_vars ().has (symbol.name))
     2338                  {
     2339                    temp = CmtSystem::getenv (symbol.name);
     2340                    if (Cmt::get_debug ())
     2341                      {
     2342                        cerr << "SetBuilder::build> getenv (" << symbol.name
     2343                             << ") => " << temp << endl;
     2344                      }
     2345                  }
     2346                else
     2347                  {
     2348                    if (Cmt::get_debug ())
     2349                      {
     2350                        cerr << "SetBuilder::build> getenv (" << symbol.name
     2351                             << ") denied" << endl;
     2352                      }
     2353                    CmtError::set (CmtError::warning,
     2354                                   "getenv (" + symbol.name + ") denied");
     2355                    return "";
     2356                  }
    22052357              }
    22062358
     
    22632415}
    22642416
     2417namespace
     2418{
     2419int find_path_entry (const CmtSystem::cmt_string_vector& items, const cmt_string& value)
     2420{
     2421  //  if (value.size () == 0) return true;
     2422 
     2423  static cmt_vmap <cmt_string, cmt_string> realpaths;
     2424
     2425  cmt_string rvalue;
     2426  const cmt_string * prvalue;
     2427
     2428  if (!(prvalue = realpaths.find (value)))
     2429    {
     2430      // if (!CmtSystem::realpath_ (value, rvalue))
     2431      //{
     2432          rvalue = value;
     2433          CmtSystem::compress_path (rvalue);
     2434      //}
     2435      prvalue = &rvalue;
     2436      realpaths.add (value, rvalue);
     2437      //      cerr << "realpaths.add: " << value << " , " << rvalue << endl;
     2438    }
     2439
     2440  for (int i = 0; i < items.size (); i++)
     2441    {
     2442      const cmt_string& item = items[i];
     2443      if (item.size () == 0) continue;
     2444      cmt_string ritem;
     2445      const cmt_string * pritem;
     2446
     2447      if (!(pritem = realpaths.find (item)))
     2448        {
     2449          //if (!CmtSystem::realpath_ (item, ritem))
     2450          //{
     2451              ritem = item;
     2452              CmtSystem::compress_path (ritem);
     2453          //}
     2454          pritem = &ritem;
     2455          realpaths.add (item, ritem);
     2456          //  cerr << "realpaths.add: " << item << " , " << ritem << endl;
     2457        }
     2458      if (*pritem == *prvalue)
     2459        {
     2460          return i;
     2461        }
     2462    }
     2463
     2464  return -1;
     2465}
     2466
     2467}
     2468/*
    22652469static bool find_path_entry (const CmtSystem::cmt_string_vector& items, const cmt_string& value)
     2470{
     2471  if (value.size () == 0) return true;
     2472
     2473  static cmt_vmap <cmt_string, cmt_string> realpaths;
     2474
     2475  cmt_string rvalue;
     2476  const cmt_string * prvalue;
     2477
     2478  if (!(prvalue = realpaths.find (value)))
     2479    {
     2480      // if (!CmtSystem::realpath_ (value, rvalue))
     2481      //{
     2482          rvalue = value;
     2483          CmtSystem::compress_path (rvalue);
     2484      //}
     2485      prvalue = &rvalue;
     2486      realpaths.add (value, rvalue);
     2487      //      cerr << "realpaths.add: " << value << " , " << rvalue << endl;
     2488    }
     2489
     2490  for (int i = 0; i < items.size (); i++)
     2491    {
     2492      const cmt_string& item = items[i];
     2493      if (item.size () == 0) continue;
     2494      cmt_string ritem;
     2495      const cmt_string * pritem;
     2496
     2497      if (!(pritem = realpaths.find (item)))
     2498        {
     2499          //if (!CmtSystem::realpath_ (item, ritem))
     2500          //{
     2501              ritem = item;
     2502              CmtSystem::compress_path (ritem);
     2503          //}
     2504          pritem = &ritem;
     2505          realpaths.add (item, ritem);
     2506          //  cerr << "realpaths.add: " << item << " , " << ritem << endl;
     2507        }
     2508      if (*pritem == *prvalue)
     2509        {
     2510          return true;
     2511        }
     2512    }
     2513
     2514  return false;
     2515}
     2516*/
     2517/*
     2518static bool find_path_entry (const cmt_string& paths, const cmt_string& value)
    22662519{
    22672520  static const cmt_string path_separator = CmtSystem::path_separator ();
    22682521  static cmt_vmap <cmt_string, cmt_string> realpaths;
    2269 
    2270   if (value.size () == 0) return true;
    22712522
    22722523  cmt_string rvalue;
     
    22852536    }
    22862537
    2287   //  CmtSystem::cmt_string_vector items;
    2288   //  CmtSystem::split (paths, path_separator, items);
     2538  CmtSystem::cmt_string_vector items;
     2539  CmtSystem::split (paths, path_separator, items);
    22892540
    22902541  bool found = false;
     
    22932544    {
    22942545      const cmt_string& item = items[i];
    2295       if (item.size () == 0) continue;
    22962546      cmt_string ritem;
    22972547      const cmt_string * pritem;
     
    23172567  return (found);
    23182568}
    2319 
    2320 static bool find_path_entry (const cmt_string& paths, const cmt_string& value)
    2321 {
    2322   static const cmt_string path_separator = CmtSystem::path_separator ();
    2323   static cmt_vmap <cmt_string, cmt_string> realpaths;
    2324 
    2325   cmt_string rvalue;
    2326   const cmt_string * prvalue;
    2327 
    2328   if (!(prvalue = realpaths.find (value)))
    2329     {
    2330       if (!CmtSystem::realpath_ (value, rvalue))
    2331         {
    2332           rvalue = value;
    2333           CmtSystem::compress_path (rvalue);
    2334         }
    2335       prvalue = &rvalue;
    2336       realpaths.add (value, rvalue);
    2337       //      cerr << "realpaths.add: " << value << " , " << rvalue << endl;
    2338     }
    2339 
    2340   CmtSystem::cmt_string_vector items;
    2341   CmtSystem::split (paths, path_separator, items);
    2342 
    2343   bool found = false;
    2344 
    2345   for (int i = 0; i < items.size (); i++)
    2346     {
    2347       const cmt_string& item = items[i];
    2348       cmt_string ritem;
    2349       const cmt_string * pritem;
    2350 
    2351       if (!(pritem = realpaths.find (item)))
    2352         {
    2353           if (!CmtSystem::realpath_ (item, ritem))
    2354             {
    2355               ritem = item;
    2356               CmtSystem::compress_path (ritem);
    2357             }
    2358           pritem = &ritem;
    2359           realpaths.add (item, ritem);
    2360           //  cerr << "realpaths.add: " << item << " , " << ritem << endl;
    2361         }
    2362       if (*pritem == *prvalue)
    2363         {
    2364           found = true;
    2365           break;
    2366         }
    2367     }
    2368 
    2369   return (found);
     2569*/
     2570//-------------------------------------------------------------
     2571PathBuilder::PathBuilder ()
     2572  : m_path_strip (false)
     2573{
     2574}
     2575
     2576//-------------------------------------------------------------
     2577PathBuilder::PathBuilder (bool path_strip)
     2578{
     2579  PathBuilder ();
     2580  m_path_strip = path_strip;
    23702581}
    23712582
     
    24012612  level++;
    24022613
     2614                if (Cmt::get_env_access () ||
     2615                    Symbol::std_env_vars ().has (symbol.name))
     2616                  {
     2617  //temp = CmtSystem::getenv (symbol.name);
    24032618  CmtSystem::split (CmtSystem::getenv (symbol.name), path_separator, temp_vector);
    2404   //temp = CmtSystem::getenv (symbol.name);
     2619  filter_path_value (symbol, temp_vector);
     2620                    if (Cmt::get_debug ())
     2621                      {
     2622                        cmt_string temp_txt;
     2623                        Cmt::vector_to_string (temp_vector, path_separator, temp_txt);
     2624                        cerr << "PathBuilder::build> getenv (" << symbol.name
     2625                             << ") => " << temp_txt << endl;
     2626                      }
     2627                  }
     2628                else
     2629                  {
     2630                    if (Cmt::get_debug ())
     2631                      {
     2632                        cerr << "PathBuilder::build> getenv (" << symbol.name
     2633                             << ") denied" << endl;
     2634                      }
     2635                    CmtError::set (CmtError::warning,
     2636                                   "getenv (" + symbol.name + ") denied");
     2637                    return "";
     2638                  }
    24052639
    24062640  bool first_definition = true;
     
    24422676                CmtSystem::split (new_value, path_separator, temp_vector);
    24432677                //temp = new_value;
     2678                filter_path_value (symbol, temp_vector);
    24442679              }
    24452680
     
    24512686                CmtSystem::split (new_value, path_separator, new_value_vector);
    24522687                for (int i = 0; i < new_value_vector.size (); i++)
    2453                   if (!find_path_entry (temp_vector, new_value_vector[i]))
    2454                     //if (!find_path_entry (temp, new_value))
    2455                     {
    2456                       temp_vector.push_back (new_value_vector[i]);
    2457                       /*
    2458                         if (temp != "") temp += path_separator;
    2459                        
    2460                         temp += new_value;
    2461                       */
    2462                     }
     2688                  {
     2689                    if (new_value_vector[i].size () == 0) continue;
     2690                    int j = find_path_entry (temp_vector, new_value_vector[i]);
     2691                    if (j < 0)
     2692                      {
     2693                        temp_vector.push_back (new_value_vector[i]);
     2694                      }
     2695                    else if (j < temp_vector.size () - 1)
     2696                      {
     2697                        temp_vector [j] = "";
     2698                        temp_vector.push_back (new_value_vector[i]);
     2699                      }
     2700                  }
    24632701              }
    24642702                 
     
    24732711                for (int i = temp_vector.size () - 1; i > n - 1; i--)
    24742712                  temp_vector [i] = temp_vector [i - n];
     2713                for (int i = 0; i < n; i++)
     2714                  temp_vector [i] = "";
    24752715                for (int i = 0; i < new_value_vector.size (); i++)
    2476                   if (!find_path_entry (temp_vector, new_value_vector[i]))
    2477                     //if (!find_path_entry (temp, new_value))
    2478                     {
    2479                       temp_vector [i] = new_value_vector[i];
    2480                       /*
    2481                         previous_temp = temp;
    2482                         temp = new_value;
    2483                         if (previous_temp != "") temp += path_separator;
    2484                         temp += previous_temp;
    2485                       */
    2486                     }
    2487                   else
    2488                     temp_vector [i] = "";
     2716                  {
     2717                    if (new_value_vector[i].size () == 0) continue;
     2718                    int j = find_path_entry (temp_vector, new_value_vector[i]);
     2719                    if (j < 0)
     2720                      {
     2721                        temp_vector [i] = new_value_vector[i];
     2722                      }
     2723                    else if (j >= n)
     2724                      {
     2725                        temp_vector [i] = new_value_vector[i];
     2726                        temp_vector [j] = "";
     2727                      }
     2728                  }
    24892729              }
    24902730           
     
    26142854
    26152855  level--;
    2616 
     2856  /*
    26172857  for (;;)
    26182858    {
     
    26372877  temp.replace_all ("::", ":");
    26382878  temp.replace_all (";;", ";");
    2639  
     2879  */
    26402880  return (temp);
    26412881}
     
    27673007 
    27683008  return (temp);
     3009}
     3010
     3011//-------------------------------------------------------------
     3012void PathBuilder::filter_path_value (const Symbol& symbol,
     3013                                     CmtSystem::cmt_string_vector& value,
     3014                                     const cmt_string& /* tag_name */) const
     3015{
     3016  static cmt_regexp reg ("[$%`]");
     3017
     3018  cmt_vector<int> path (value.size ());
     3019  int n (0);
     3020
     3021  for (int j = 0; j < value.size (); j++)
     3022    {
     3023      const cmt_string& v = value[j];
     3024      bool exists (false); 
     3025      for (int i = 0; i < j; i++)
     3026        {
     3027          if (value[i] == v)
     3028            {
     3029              exists = true;
     3030              break;
     3031            }
     3032        }                 
     3033      if (!exists)
     3034        {
     3035          if (m_path_strip)
     3036            {
     3037              if (!reg.match (v))
     3038                {
     3039                  if (!CmtSystem::test_directory (v))
     3040                    {
     3041                      CmtMessage::verbose ("Non-existent directory " + v + " in " + symbol.name + " skipped");
     3042                      continue;
     3043                    }
     3044                }
     3045              else
     3046                {
     3047                  if (CmtMessage::active (Verbose))
     3048                    {
     3049                      CmtMessage::warning ("Unresolved directory name " + v + " in " + symbol.name);
     3050                    }
     3051                }
     3052            }
     3053          else
     3054            {
     3055              if (CmtMessage::active (Verbose))
     3056                if (!reg.match (v) &&
     3057                    !CmtSystem::test_directory (v))
     3058                  {
     3059                    CmtMessage::warning ("Non-existent directory " + v + " in " + symbol.name);
     3060                  }
     3061            }
     3062          path[n++] = j;
     3063        }
     3064    }
     3065
     3066  for (int i = 0; i < n; i++)
     3067    if (i != path[i]) value[i] = value[path[i]];
     3068 
     3069  value.resize (n);
     3070}
     3071
     3072//-------------------------------------------------------------
     3073void PathBuilder::filter_path_value (const Symbol& symbol,
     3074                                     cmt_string& value,
     3075                                     const cmt_string& tag_name) const
     3076{
     3077  static cmt_string ps (CmtSystem::path_separator ());
     3078  CmtSystem::cmt_string_vector paths;
     3079
     3080  CmtSystem::split (value, ps, paths);
     3081  filter_path_value (symbol, paths, tag_name);
     3082  Cmt::vector_to_string (paths, ps, value);
     3083}
     3084
     3085//-------------------------------------------------------------
     3086inline const bool& PathBuilder::get_path_strip () const
     3087{
     3088  return m_path_strip;
     3089}
     3090
     3091//-------------------------------------------------------------
     3092inline void PathBuilder::set_path_strip (const bool& path_strip)
     3093{
     3094  m_path_strip = path_strip;
    27693095}
    27703096
     
    32753601int SymbolValueList::print (const Symbol& symbol,
    32763602                            const SymbolValue& value,
    3277                             bool& first_definition) const
     3603                            bool& first_definition,
     3604                            ostream& out) const
    32783605{
    32793606  int result (0);
    3280 
    3281   //if (use->get_package_name () == "CMT") return result;
    32823607
    32833608  cmt_string discarded_text;
    32843609  cmt_string define_text;
    32853610  ActionType action = Cmt::get_action ();
     3611
     3612  static PathBuilder* pb (0);
     3613  cmt_string rvalue (value.text);
    32863614
    32873615  switch (command_type)
     
    33063634      case CommandMacroRemoveAllRegexp :
    33073635        //case CommandAction :
    3308         if (value.text == "") return result;
     3636        if (value.text.size () == 0) return result;
     3637        break;
     3638    }
     3639
     3640  CmtError::code code (CmtError::ok);
     3641  cmt_string msg, n;
     3642  int exec_err (0);
     3643
     3644  switch (command_type)
     3645    {
     3646      case CommandSet :
     3647      case CommandSetAppend :
     3648      case CommandSetPrepend :
     3649      case CommandSetRemove :
     3650      case CommandSetRemoveRegexp :
     3651
     3652        if (CmtError::has_pending_error ())
     3653          {
     3654            code = CmtError::get_last_error_code ();
     3655            msg = CmtError::get_last_error ();
     3656            exec_err = CmtError::get_last_execution_error ();
     3657            n = CmtError::get_error_name (code);
     3658            CmtError::clear ();
     3659          }
     3660        resolve_value_for_macros (rvalue);
     3661        if (CmtError::get_last_error_code () != CmtError::warning)
     3662          {
     3663            if (CmtError::has_pending_error ())
     3664              {
     3665                CmtError::print ();
     3666                CmtError::clear ();
     3667              }
     3668            if (CmtError::ok != code)
     3669              {
     3670                // restore error occurred before value expansion
     3671                CmtError::set (code,
     3672                               (msg.replace (n + ": ", cmt_string ("")), msg),
     3673                               exec_err);
     3674              }
     3675            if (CommandSet != command_type &&
     3676                rvalue.size () == 0)
     3677              return result;
     3678          }
     3679        else
     3680          {
     3681            if (CmtMessage::active (Verbose))
     3682              CmtError::print ();
     3683            CmtError::clear ();
     3684            if (CmtError::ok != code)
     3685              {
     3686                // restore error occurred before value expansion
     3687                CmtError::set (code,
     3688                               (msg.replace (n + ": ", cmt_string ("")), msg),
     3689                               exec_err);
     3690              }
     3691            // Ignore the error, keep the value unresolved
     3692            rvalue = value.text;
     3693          }
     3694
     3695        break;
     3696
     3697        //case CommandAlias :
     3698      case CommandPath :
     3699      case CommandPathAppend :
     3700      case CommandPathPrepend :
     3701      case CommandPathRemove :
     3702      case CommandPathRemoveRegexp :
     3703        //case CommandMacroPrepend :
     3704        //case CommandMacro :
     3705        //case CommandMacroAppend :
     3706        //case CommandMacroRemove :
     3707        //case CommandMacroRemoveRegexp :
     3708        //case CommandMacroRemoveAll :
     3709        //case CommandMacroRemoveAllRegexp :
     3710        //case CommandAction :
     3711
     3712        if (!pb)
     3713          pb = static_cast<PathBuilder*> (symbol.builder);
     3714        if (pb->get_path_strip ())
     3715          {
     3716            /*
     3717            CmtError::code code (CmtError::ok);
     3718            cmt_string msg, n;
     3719            int exec_err (0);
     3720            */
     3721            if (CmtError::has_pending_error ())
     3722              {
     3723                code = CmtError::get_last_error_code ();
     3724                msg = CmtError::get_last_error ();
     3725                exec_err = CmtError::get_last_execution_error ();
     3726                n = CmtError::get_error_name (code);
     3727                CmtError::clear ();
     3728              }
     3729            resolve_value (rvalue);
     3730            if (CmtError::get_last_error_code () != CmtError::warning)
     3731              {
     3732                if (CmtError::has_pending_error ())
     3733                  {
     3734                    CmtError::print ();
     3735                    CmtError::clear ();
     3736                  }
     3737                if (CmtError::ok != code)
     3738                  {
     3739                    // restore error occurred before value expansion
     3740                    CmtError::set (code,
     3741                                   (msg.replace (n + ": ", cmt_string ("")), msg),
     3742                                   exec_err);
     3743                  }
     3744                if (CommandPath != command_type &&
     3745                    rvalue.size () == 0)
     3746                  return result;
     3747              }
     3748            else
     3749              {
     3750                if (CommandPathRemove == command_type ||
     3751                    CommandPathRemoveRegexp == command_type)
     3752                  {
     3753                    // This means that the value is not resolved via symbols
     3754                    // and, possibly, standard environment variables and
     3755                    //   * either has no effect on the path at all,
     3756                    //     or
     3757                    //   * there should be similar contribution from
     3758                    //     and, hence, we should get the same error with
     3759                    //     CommandPath, CommandPathAppend, or CommandPathPrepend
     3760                    //  Either way, we can ignore this error.
     3761
     3762                    if (CmtMessage::active (Verbose))
     3763                      CmtError::print ();
     3764                    CmtError::clear ();
     3765                    if (CmtError::ok != code)
     3766                      {
     3767                        // restore error occurred before value expansion
     3768                        CmtError::set (code,
     3769                                       (msg.replace (n + ": ", cmt_string ("")), msg),
     3770                                       exec_err);
     3771                      }
     3772                  }
     3773                else if (CmtError::ok != code)
     3774                  {
     3775                    // print error occurred before value expansion
     3776                    CmtMessage::error (msg);
     3777                  }
     3778                // We keep CmtError::warning to indicate that
     3779                // we could not resolve path
     3780                // (without referencing the environment)
     3781                // and strip path of non-existent directories
     3782                //
     3783                rvalue = value.text;
     3784              }
     3785          }
     3786        else // (!pb->get_path_strip ())
     3787          {
     3788            if (CmtError::has_pending_error ())
     3789              {
     3790                code = CmtError::get_last_error_code ();
     3791                msg = CmtError::get_last_error ();
     3792                exec_err = CmtError::get_last_execution_error ();
     3793                n = CmtError::get_error_name (code);
     3794                CmtError::clear ();
     3795              }
     3796            resolve_value_for_macros (rvalue);
     3797            if (CmtError::get_last_error_code () != CmtError::warning)
     3798              {
     3799                if (CmtError::has_pending_error ())
     3800                  {
     3801                    CmtError::print ();
     3802                    CmtError::clear ();
     3803                  }
     3804                if (CmtError::ok != code)
     3805                  {
     3806                    // restore error occurred before value expansion
     3807                    CmtError::set (code,
     3808                                   (msg.replace (n + ": ", cmt_string ("")), msg),
     3809                                   exec_err);
     3810                  }
     3811                if (CommandPath != command_type &&
     3812                    rvalue.size () == 0)
     3813                  return result;
     3814              }
     3815            else
     3816              {
     3817                if (CmtMessage::active (Verbose))
     3818                  CmtError::print ();
     3819                CmtError::clear ();
     3820                if (CmtError::ok != code)
     3821                  {
     3822                    // restore error occurred before value expansion
     3823                    CmtError::set (code,
     3824                                   (msg.replace (n + ": ", cmt_string ("")), msg),
     3825                                   exec_err);
     3826                  }
     3827                // Ignore the error, keep the value unresolved
     3828                rvalue = value.text;
     3829              }
     3830          }
     3831
    33093832        break;
    33103833    }
     
    33173840
    33183841  if (CmtMessage::active (Verbose))
    3319     cout << "# Package " << (use != 0 ? use->get_package_name () + " " + use->version : "");
    3320   /*
    3321   if (use != 0)
    3322     {
    3323       cout << use->get_package_name () << " " << use->version;
    3324     }
    3325   */
     3842    out << "# Package " << (use ? use->get_package_name () + " " + use->version : "");
    33263843
    33273844  switch (command_type)
     
    33293846      case CommandSet :
    33303847        if (CmtMessage::active (Verbose))
    3331           cout << " " << define_text << " set " << symbol.name << " as " << endl;
    3332         //        cout << " " << define_text << " set " << symbol.name << " as ";
    3333         cout << "set " << symbol.name;
     3848          out << " " << define_text << " set " << symbol.name << " as " << endl;
     3849        //        out << " " << define_text << " set " << symbol.name << " as ";
     3850        out << "set " << symbol.name;
    33343851        first_definition = false;
    33353852        result = 1;
     
    33373854      case CommandSetAppend :
    33383855        if (CmtMessage::active (Verbose))
    3339           cout << " appends to set " << symbol.name << " : " << endl;
    3340         //        cout << " appends to set " << symbol.name << " : ";
    3341         cout << "set_append " << symbol.name;
     3856          out << " appends to set " << symbol.name << " : " << endl;
     3857        //        out << " appends to set " << symbol.name << " : ";
     3858        out << "set_append " << symbol.name;
    33423859        result = 1;
    33433860        break;
    33443861      case CommandSetPrepend :
    33453862        if (CmtMessage::active (Verbose))
    3346           cout << " prepends to set " << symbol.name << " : " << endl;
    3347         //        cout << " prepends to set " << symbol.name << " : ";
    3348         cout << "set_prepend " << symbol.name;
     3863          out << " prepends to set " << symbol.name << " : " << endl;
     3864        //        out << " prepends to set " << symbol.name << " : ";
     3865        out << "set_prepend " << symbol.name;
    33493866        result = 1;
    33503867        break;
    33513868      case CommandSetRemove :
    33523869        if (CmtMessage::active (Verbose))
    3353           cout << " removes from set " << symbol.name << " : " << endl;
    3354         //        cout << " removes from set " << symbol.name << " : ";
    3355         cout << "set_remove " << symbol.name;
     3870          out << " removes from set " << symbol.name << " : " << endl;
     3871        //        out << " removes from set " << symbol.name << " : ";
     3872        out << "set_remove " << symbol.name;
    33563873        result = 1;
    33573874        break;
    33583875      case CommandSetRemoveRegexp :
    33593876        if (CmtMessage::active (Verbose))
    3360           cout << " removes RE from set " << symbol.name << " : " << endl;
    3361         //        cout << " removes RE from set " << symbol.name << " : ";
    3362         cout << "set_remove_regexp " << symbol.name;
     3877          out << " removes RE from set " << symbol.name << " : " << endl;
     3878        //        out << " removes RE from set " << symbol.name << " : ";
     3879        out << "set_remove_regexp " << symbol.name;
    33633880        result = 1;
    33643881        break;
    33653882      case CommandAlias :
    33663883        if (CmtMessage::active (Verbose))
    3367           cout << " " << define_text << " alias " << symbol.name << endl;
    3368         //        cout << " " << define_text << " alias " << symbol.name << " as ";
    3369         cout << "alias " << symbol.name;
     3884          out << " " << define_text << " alias " << symbol.name << endl;
     3885        //        out << " " << define_text << " alias " << symbol.name << " as ";
     3886        out << "alias " << symbol.name;
    33703887        first_definition = false;
    33713888        result = 1;
    33723889        break;
    3373       case CommandPath :
     3890    case CommandPath :
    33743891        if (CmtMessage::active (Verbose))
    3375           cout << " " << define_text << " path " << symbol.name << endl;
    3376         //        cout << " " << define_text << " path " << symbol.name << " as ";
    3377         cout << "path " << symbol.name;
     3892          out << " " << define_text << " path " << symbol.name << endl;
     3893        //        out << " " << define_text << " path " << symbol.name << " as ";
     3894        pb->filter_path_value (symbol, rvalue);
     3895
     3896        if (Cmt::get_debug ())
     3897          {
     3898            cerr << "|SymbolValueList::print> path " << symbol.name
     3899                 << " " << value.text << " => " << rvalue << endl;
     3900          }
     3901
     3902        out << "path " << symbol.name;
    33783903        first_definition = false;
    33793904        result = 1;
     
    33813906      case CommandPathAppend :
    33823907        if (CmtMessage::active (Verbose))
    3383           cout << " appends to path " << symbol.name << endl;
    3384         //        cout << " appends to path " << symbol.name << " : ";
    3385         cout << "path_append " << symbol.name;
     3908          out << " appends to path " << symbol.name << endl;
     3909        //        out << " appends to path " << symbol.name << " : ";
     3910        pb->filter_path_value (symbol, rvalue);
     3911
     3912        if (Cmt::get_debug ())
     3913          {
     3914            cerr << "|SymbolValueList::print> path_append " << symbol.name
     3915                 << " " << value.text << " => " << rvalue << endl;
     3916          }
     3917
     3918        if (rvalue.size () == 0) return result;
     3919        out << "path_append " << symbol.name;
    33863920        result = 1;
    33873921        break;
    33883922      case CommandPathPrepend :
    33893923        if (CmtMessage::active (Verbose))
    3390           cout << " prepends to path " << symbol.name << " : " << endl;
    3391         //        cout << " prepends to path " << symbol.name << " : ";
    3392         cout << "path_prepend " << symbol.name;
     3924          out << " prepends to path " << symbol.name << " : " << endl;
     3925        //        out << " prepends to path " << symbol.name << " : ";
     3926        pb->filter_path_value (symbol, rvalue);
     3927
     3928        if (Cmt::get_debug ())
     3929          {
     3930            cerr << "|SymbolValueList::print> path_prepend " << symbol.name
     3931                 << " " << value.text << " => " << rvalue << endl;
     3932          }
     3933
     3934        if (rvalue.size () == 0) return result;
     3935        out << "path_prepend " << symbol.name;
    33933936        result = 1;
    33943937        break;
    33953938      case CommandPathRemove :
    33963939        if (CmtMessage::active (Verbose))
    3397           cout << " removes from path " << symbol.name << " : " << endl;
    3398         //        cout << " removes from path " << symbol.name << " : ";
    3399         cout << "path_remove " << symbol.name;
     3940          out << " removes from path " << symbol.name << " : " << endl;
     3941        //        out << " removes from path " << symbol.name << " : ";
     3942
     3943        if (Cmt::get_debug ())
     3944          {
     3945            cerr << "|SymbolValueList::print> path_remove " << symbol.name
     3946                 << " " << value.text << " => " << rvalue << endl;
     3947          }
     3948
     3949        out << "path_remove " << symbol.name;
    34003950        result = 1;
    34013951        break;
    34023952      case CommandPathRemoveRegexp :
    34033953        if (CmtMessage::active (Verbose))
    3404           cout << " removes RE from path " << symbol.name << " : " << endl;
    3405         //        cout << " removes RE from path " << symbol.name << " : ";
    3406         cout << "path_remove_regexp " << symbol.name;
     3954          out << " removes RE from path " << symbol.name << " : " << endl;
     3955        //        out << " removes RE from path " << symbol.name << " : ";
     3956
     3957        if (Cmt::get_debug ())
     3958          {
     3959            cerr << "|SymbolValueList::print> path_remove_regexp " << symbol.name
     3960                 << " " << value.text << " => " << rvalue << endl;
     3961          }
     3962
     3963        out << "path_remove_regexp " << symbol.name;
    34073964        result = 1;
    34083965        break;
    34093966      case CommandMacro :
    34103967        if (CmtMessage::active (Verbose))
    3411           cout << " " << define_text << " macro " << symbol.name << " as " << endl;
    3412         //        cout << " " << define_text << " macro " << symbol.name << " as ";
    3413         cout << "macro " << symbol.name;
     3968          out << " " << define_text << " macro " << symbol.name << " as " << endl;
     3969        //        out << " " << define_text << " macro " << symbol.name << " as ";
     3970        out << "macro " << symbol.name;
    34143971        result = 1;
    34153972        break;
    34163973      case CommandMacroPrepend :
    34173974        if (CmtMessage::active (Verbose))
    3418           cout << " prepends to macro " << symbol.name << " : " << endl;
    3419         //        cout << " prepends to macro " << symbol.name << " : ";
    3420         cout << "macro_prepend " << symbol.name;
     3975          out << " prepends to macro " << symbol.name << " : " << endl;
     3976        //        out << " prepends to macro " << symbol.name << " : ";
     3977        out << "macro_prepend " << symbol.name;
    34213978        result = 1;
    34223979        break;
    34233980      case CommandMacroAppend :
    34243981        if (CmtMessage::active (Verbose))
    3425           cout << " appends to macro " << symbol.name << " : " << endl;
    3426         //        cout << " appends to macro " << symbol.name << " : ";
    3427         cout << "macro_append " << symbol.name;
     3982          out << " appends to macro " << symbol.name << " : " << endl;
     3983        //        out << " appends to macro " << symbol.name << " : ";
     3984        out << "macro_append " << symbol.name;
    34283985        result = 1;
    34293986        break;
    34303987      case CommandMacroRemove :
    34313988        if (CmtMessage::active (Verbose))
    3432           cout << " remove from macro " << symbol.name << " : " << endl;
    3433         //        cout << " remove from macro " << symbol.name << " : ";
    3434         cout << "macro_remove " << symbol.name;
     3989          out << " remove from macro " << symbol.name << " : " << endl;
     3990        //        out << " remove from macro " << symbol.name << " : ";
     3991        out << "macro_remove " << symbol.name;
    34353992        result = 1;
    34363993        break;
    34373994      case CommandMacroRemoveRegexp :
    34383995        if (CmtMessage::active (Verbose))
    3439           cout << " remove RE from macro " << symbol.name << " : " << endl;
    3440         //        cout << " remove RE from macro " << symbol.name << " : ";
    3441         cout << "macro_remove_regexp " << symbol.name;
     3996          out << " remove RE from macro " << symbol.name << " : " << endl;
     3997        //        out << " remove RE from macro " << symbol.name << " : ";
     3998        out << "macro_remove_regexp " << symbol.name;
    34423999        result = 1;
    34434000        break;
    34444001      case CommandMacroRemoveAll :
    34454002        if (CmtMessage::active (Verbose))
    3446           cout << " remove all from macro " << symbol.name << " : " << endl;
    3447         //        cout << " remove all from macro " << symbol.name << " : ";
    3448         cout << "macro_remove_all " << symbol.name;
     4003          out << " remove all from macro " << symbol.name << " : " << endl;
     4004        //        out << " remove all from macro " << symbol.name << " : ";
     4005        out << "macro_remove_all " << symbol.name;
    34494006        result = 1;
    34504007        break;
    34514008      case CommandMacroRemoveAllRegexp :
    34524009        if (CmtMessage::active (Verbose))
    3453           cout << " remove all RE from macro " << symbol.name << " : " << endl;
    3454         //        cout << " remove all RE from macro " << symbol.name << " : ";
    3455         cout << "macro_remove_all_regexp " << symbol.name;
     4010          out << " remove all RE from macro " << symbol.name << " : " << endl;
     4011        //        out << " remove all RE from macro " << symbol.name << " : ";
     4012        out << "macro_remove_all_regexp " << symbol.name;
    34564013        result = 1;
    34574014        break;
    34584015      case CommandSetupScript :
    34594016        if (CmtMessage::active (Verbose))
    3460           cout << " " << define_text << " setup script " << symbol.name << endl;
    3461         //       cout << " " << define_text << " action " << symbol.name << " as ";
    3462         cout << "setup_script" /* << symbol.name */;
     4017          out << " " << define_text << " setup script " << symbol.name << endl;
     4018        //       out << " " << define_text << " action " << symbol.name << " as ";
     4019        out << "setup_script" /* << symbol.name */;
    34634020        first_definition = false;
    34644021        result = 1;
     
    34664023        /*
    34674024      case CommandAction :
    3468         cout << " " << define_text << " action " << symbol.name << " as ";
     4025        out << " " << define_text << " action " << symbol.name << " as ";
    34694026        first_definition = false;
    34704027        break;
     
    34724029    }
    34734030
    3474   cout << " " << CmtSystem::quote (value.text, " \t");
    3475   //  cout << "'" << value.text << "'";
     4031  out << " " << CmtSystem::quote (rvalue, " \t");
     4032  //  out << " " << CmtSystem::quote (value.text, " \t");
     4033  //  out << "'" << value.text << "'";
    34764034         
    34774035  /*
     
    34814039      (selected_tag == Tag::get_default ()))
    34824040    {
    3483       cout << " for default tag";
     4041      out << " for default tag";
    34844042    }
    34854043  else
    34864044    {
    3487       cout << " for tag '" << selected_tag->get_name () << "'";
     4045      out << " for tag '" << selected_tag->get_name () << "'";
    34884046    }
    34894047  */
    34904048
    3491   cout << endl;
    3492   //  cout << discarded_text << endl;
     4049  out << endl;
     4050  //  out << discarded_text << endl;
    34934051  return result;
    34944052}
     
    35474105  else
    35484106    {
     4107                if (Cmt::get_env_access () ||
     4108                    Symbol::std_env_vars ().has (name))
     4109                  {
    35494110      s = CmtSystem::getenv (name);
     4111                    if (Cmt::get_debug ())
     4112                      {
     4113                        cerr << "Symbol::get_env_value> getenv (" << name
     4114                             << ") => " << s << endl;
     4115                      }
     4116                  }
     4117                else
     4118                  {
     4119                    if (Cmt::get_debug ())
     4120                      {
     4121                        cerr << "Symbol::get_env_value> getenv (" << name
     4122                             << ") denied" << endl;
     4123                      }
     4124                    CmtError::set (CmtError::warning,
     4125                                   "getenv (" + name + ") denied");
     4126                    return (s);
     4127                  }
    35504128    }
    35514129
  • CMT/HEAD/source/cmt_symbol.h

    r588 r656  
    3434  int select_last () const;
    3535  void show (const Symbol& symbol, const SymbolValue& value, bool& first_definition) const;
    36   int print (const Symbol& symbol, const SymbolValue& value, bool& first_definition) const;
     36  int print (const Symbol& symbol, const SymbolValue& value, bool& first_definition, ostream& out = cout) const;
    3737
    3838  CommandType command_type;
     
    8989
    9090  static void all_set ();
    91   static void all_print (PrintMode mode);
     91  static void all_print (PrintMode mode, ostream& out = cout);
     92  //static void all_print (PrintMode mode);
    9293  static void all_print_clean (PrintMode mode);
    9394  static void check_all_paths ();
     
    9697  static SymbolVector& symbols ();
    9798  static SymbolMap& symbol_map ();
     99  static SymbolMap& std_env_vars ();
    98100  static Symbol& symbol (int index);
    99101  static void clear_all ();
     
    107109
    108110  static bool get_inhibit_display ();
     111  static bool set_path_strip (const bool& path_strip);
    109112
    110113public:
     
    118121
    119122  int print_clean (PrintMode mode);
    120   int print (PrintMode mode);
     123  int print (PrintMode mode, ostream& out = cout);
     124  //int print (PrintMode mode);
    121125  cmt_string build_macro_value (bool display_it = false) const;
    122126  int print_macro (PrintMode mode, ostream& out = cout) const;
  • CMT/HEAD/source/cmt_use.cxx

    r655 r656  
    19341934    {
    19351935      cout << "|Use::change_path> path: " << new_path
    1936            << ": project: " << (project ? project->get_cmtpath () : "0")
    1937            << ": " << get_info () << endl;
     1936           << " project: " << (project ? project->get_cmtpath () : "0")
     1937           << " use: " << get_info () << endl;
    19381938    }
    19391939
     
    19781978    {
    19791979      cout << "<Use::change_path| real_path: " << real_path
    1980            << ": m_project: " << (m_project ? m_project->get_cmtpath () : "0")
    1981            << ": " << get_info () << endl;
     1980           << " m_project: " << (m_project ? m_project->get_cmtpath () : "0")
     1981           << " use: " << get_info () << endl;
    19821982    }
    19831983}
     
    37703770    }
    37713771
     3772  if (action_setup == Cmt::get_action () &&
     3773      Requirements == Cmt::get_print_mode ())
     3774    {
     3775      //cerr << "|Use::fill_standard_macros> Checking for " << prefix << "CONFIG" << endl;
     3776      if (!discarded &&
     3777          get_package_name () != "cmt_standalone" &&
     3778          get_strategy ("SetupConfig"))
     3779        {
     3780          buffer += "macro ";
     3781          buffer += prefix;
     3782          buffer += "CONFIG";
     3783          buffer += " \"";
     3784          buffer += CmtSystem::get_cmt_config ();
     3785          buffer += "\"";
     3786          buffer += "\n";
     3787        }
     3788    }
     3789
    37723790  buffer += "macro ";
    37733791  buffer += prefix;
Note: See TracChangeset for help on using the changeset viewer.