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

See C.L. 515

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.