Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

cmt_parser.cxx

Go to the documentation of this file.
00001 //-----------------------------------------------------------
00002 // Copyright Christian Arnault LAL-Orsay CNRS
00003 // arnault@lal.in2p3.fr
00004 // See the complete license in cmt_license.txt "http://www.cecill.info". 
00005 //-----------------------------------------------------------
00006 
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <ctype.h>
00011 
00012 //----------------------------------------------------------
00013 
00014 #include "cmt_parser.h"
00015 #include "cmt_version.h"
00016 
00017 #include "cmt_database.h"
00018 #include "cmt_include.h"
00019 #include "cmt_script.h"
00020 #include "cmt_generator.h"
00021 #include "cmt_system.h"
00022 #include "cmt.h"
00023 #include "cmt_error.h"
00024 #include "cmt_cvs.h"
00025 #include "cmt_lock.h"
00026 #include "cmt_triggers.h"
00027 #include "cmt_model.h"
00028 #include "cmt_awk.h"
00029 #include "cmt_syntax.h"
00030 #include "cmt_install_area.h"
00031 #include "cmt_cmtpath_pattern.h"
00032 #include "cmt_sequence.h"
00033 #include "cmt_map.h"
00034 #include "cmt_project.h"
00035 #include "cmt_log.h"
00036 #include "cmt_commands.h"
00037 
00038 //----------------------------------------------------------
00039 //
00040 //  Static object definitions for the CmtContext class.
00041 //
00042 
00043 static CmtContext Me;
00044 
00045 CmtContext::CmtContext ()
00046 {
00047   clear ();
00048 }
00049 
00050 CmtContext::~CmtContext ()
00051 {
00052 }
00053 
00054 void CmtContext::clear ()
00055 {
00056   m_action         = action_none;
00057   m_build_nmake    = false;
00058   m_cmt_config     = "";
00059   //m_cmt_path.clear ();
00060   //m_cmt_path_pwds.clear ();
00061   //m_cmt_path_sources.clear ();
00062   m_cmt_root       = "";
00063   m_cmt_version    = "";
00064   m_current_dir     = "";
00065   m_current_package = "";
00066   m_current_config  = "";
00067   m_current_path    = "";
00068   m_current_prefix  = "";
00069   m_current_cmtpath = "";
00070   m_current_offset  = "";
00071 
00072   m_current_access   = DeveloperMode;
00073 
00074   m_current_tag      = "";
00075   m_current_target   = "";
00076   m_current_version  = "";
00077   m_default_path     = "";
00078   m_quiet            = false;
00079   m_recursive        = false;
00080 
00081   m_scope_filtering_mode = default_filtering_mode;
00082   m_simulation       = false;
00083 
00084   m_standard_macros_done = false;
00085   m_current_access = UserMode;
00086   m_current_style = cmt_style;
00087   m_current_structuring_style = with_version_directory;
00088   m_all_sets_done = false;
00089   m_autoconfigure_cmtpath = false;
00090   m_debug = false;
00091   if (getenv ("CMTDEBUG") != 0) m_debug = true;
00092 }
00093 
00094 //----------------------------------------------------------
00095 
00096 
00097 //----------------------------------------------------------
00098 //
00099 //   Utility classes
00100 //
00101 //----------------------------------------------------------
00102 
00107 class PackageViewer : public PathScanner::actor
00108 {
00109 public:
00110   void run (const cmt_string& package,
00111             const cmt_string& version,
00112             const cmt_string& path);
00113 };
00114 
00115 
00120 class PackageSelector : public PathScanner::actor
00121 {
00122 public:
00123   PackageSelector (CmtSystem::cmt_string_vector& uses);
00124   void run (const cmt_string& package,
00125             const cmt_string& version,
00126             const cmt_string& path);
00127 private:
00128   CmtSystem::cmt_string_vector& m_uses;
00129 };
00130 
00131 
00132 
00137 class ClientCollector : public PathScanner::actor
00138 {
00139 public:
00140   ClientCollector (const cmt_string& package,
00141                    const cmt_string& version);
00142   void run (const cmt_string& package,
00143             const cmt_string& version,
00144             const cmt_string& path);
00145   int count ();
00146 
00147 private:
00148   const cmt_string& m_package;
00149   const cmt_string& m_version;
00150   int m_count;
00151 };
00152 
00153 
00154 //----------------------------------------------------------
00155 static bool get_strategy (const cmt_string& name, Use& use = Use::current())
00156 {
00157   static cmt_string cmtpath;
00158   static cmt_string offset;
00159 
00160   use.get_cmtpath_and_offset (cmtpath, offset);
00161 
00162   Project* p = Project::find_by_cmtpath (cmtpath);
00163 
00164   bool strategy;
00165 
00166   if (p == 0) strategy = StrategyMgr::get_default_strategy (name);
00167   else strategy = p->get_strategy (name);
00168 
00169   return (strategy);
00170 }
00171 
00172 //----------------------------------------------------------
00173 void PackageViewer::run (const cmt_string& package,
00174                          const cmt_string& version,
00175                          const cmt_string& path)
00176 {
00177   cout << package << " " << version << " " << path << endl;
00178 }
00179 
00180 //----------------------------------------------------------
00181 PackageSelector::PackageSelector (CmtSystem::cmt_string_vector& uses) : m_uses(uses)
00182 {
00183 }
00184 
00185 //----------------------------------------------------------
00186 void PackageSelector::run (const cmt_string& package,
00187                            const cmt_string& version,
00188                            const cmt_string& path)
00189 {
00190   //
00191   // this might be called on a package with no version directory.
00192   // then simply the version argument is empty.
00193   // 
00194 
00195   cmt_string r = CmtSystem::file_separator ();
00196   r += "requirements";
00197 
00198   cmt_string temp;
00199 
00200   if (version == "")
00201     {
00202       temp = path;
00203       //temp += CmtSystem::file_separator ();
00204       //temp += package;
00205       temp += CmtSystem::file_separator ();
00206       temp += "cmt";
00207       temp += r;
00208       
00209       if (!CmtSystem::test_file (temp)) return;
00210     }
00211   else
00212     {
00213       temp = path;
00214       //temp += CmtSystem::file_separator ();
00215       //temp += package;
00216       temp += CmtSystem::file_separator ();
00217       temp += version;
00218       temp += CmtSystem::file_separator ();
00219       temp += "cmt";
00220       temp += r;
00221       
00222       if (!CmtSystem::test_file (temp))
00223         {
00224           temp = path;
00225           //temp += CmtSystem::file_separator ();
00226           //temp += package;
00227           temp += CmtSystem::file_separator ();
00228           temp += version;
00229           temp += CmtSystem::file_separator ();
00230           temp += "mgr";
00231           temp += r;
00232           
00233           if (!CmtSystem::test_file (temp))
00234             {
00235               return;
00236             }
00237         }
00238     }
00239 
00240   temp.replace (r.c_str(), "");
00241   cmt_string& use = m_uses.add ();
00242   use = temp;
00243 }
00244 
00245 //----------------------------------------------------------
00246 ClientCollector::ClientCollector (const cmt_string& package,
00247                                   const cmt_string& version) :
00248   m_package (package), m_version (version), m_count (0)
00249 {
00250 }
00251 
00252 //----------------------------------------------------------
00253 void ClientCollector::run (const cmt_string& package,
00254                            const cmt_string& version,
00255                            const cmt_string& path)
00256 {
00257   cmt_string dir = path;
00258   dir += CmtSystem::file_separator ();
00259   dir += package;
00260   dir += CmtSystem::file_separator ();
00261   if (version != "")
00262     {
00263       dir += version;
00264       dir += CmtSystem::file_separator ();
00265     }
00266 
00267   cmt_string req;
00268 
00269   req = dir;
00270   req += "cmt";
00271   req += CmtSystem::file_separator ();
00272   req += "requirements";
00273 
00274   cmt_string requirements;
00275   cmt_string line;
00276   CmtSystem::cmt_string_vector words;
00277 
00278   if (CmtSystem::test_file (req))
00279     {
00280       requirements.read (req);
00281     }
00282   else
00283     {
00284       req = dir;
00285       req += "mgr";
00286       req += CmtSystem::file_separator ();
00287       req += "requirements";
00288       if (CmtSystem::test_file (req))
00289         {
00290           requirements.read (req);
00291         }
00292     }
00293 
00294   if (requirements != "")
00295     {
00296       int pos = 0;
00297       int max_pos = requirements.size ();
00298 
00299       while (pos < max_pos)
00300         {
00301           int cr = requirements.find (pos, "\r\n");
00302           int nl = requirements.find (pos, '\n');
00303           int first = nl;
00304           int length = 1;
00305                 
00306           if (cr != cmt_string::npos)
00307             {
00308               if (nl == cmt_string::npos)
00309                 {
00310                   first = cr;
00311                   length = 2;
00312                 }
00313               else
00314                 {
00315                   first = (nl < cr) ? nl : cr;
00316                   length = (nl < cr) ? 1 : 2;
00317                 }
00318             }
00319                 
00320           if (first == cmt_string::npos)
00321             {
00322               requirements.substr (pos, line);
00323               pos = max_pos;
00324             }
00325           else if (first > pos)
00326             {
00327               requirements.substr (pos, first - pos, line);
00328               pos = first + length;
00329             }
00330           else
00331             {
00332               line.erase (0);
00333               pos += length;
00334             }
00335 
00336           CmtSystem::split (line, " \t", words);
00337 
00338           if ((words.size () > 2) && (words[0] == "use")) 
00339             {
00340               if ((words[1] == m_package) && 
00341                   ((words[2] == m_version) || (m_version == "")))
00342                 {
00343                   cout << "# " << package << " " << version << " " << path;
00344                   if (m_version == "")
00345                     {
00346                       cout << " (use version " << words[2] << ")";
00347                     }
00348                   cout << endl;
00349                   m_count++;
00350                 }
00351             }
00352         }
00353     }
00354 }
00355 
00356 //----------------------------------------------------------
00357 int ClientCollector::count ()
00358 {
00359   return (m_count);
00360 }
00361 
00362 
00363 
00364 
00365 //----------------------------------------------------------
00366 //
00367 //   The Cmt methods
00368 //
00369 //----------------------------------------------------------
00370 
00371 
00372 
00376 void Cmt::build_config (const cmt_string& prefix,
00377                         cmt_string& config)
00378 {
00379   /*
00380     Building the config from <prefix> 
00381   */
00382 
00383   config = prefix;
00384   config += "CONFIG";
00385 }
00386 
00387 //----------------------------------------------------------
00388 void Cmt::build_makefile (const cmt_string& target)
00389 {
00390   Constituent* constituent = 0;
00391 
00392   if (target.size () > 0)
00393     {
00394       /*
00395         Do genmake for one specific target.
00396       */
00397       constituent = Constituent::find (target);
00398       if (constituent != 0)
00399         {
00400           constituent->build_makefile (Me.m_simulation);
00401         }
00402     }
00403   else
00404     {
00405       /*
00406         Do genmake for all possible targets.
00407       */
00408       Constituent::build_all_makefiles (Me.m_simulation);
00409     }
00410 }
00411 
00412 //----------------------------------------------------------
00413 void Cmt::build_msdev_file (const cmt_string& target)
00414 {
00415   Constituent* constituent = 0;
00416 
00417   set_standard_macros ();
00418 
00419   if (target != "")
00420     {
00421       /*
00422         Do genmsdev for one specific target.
00423       */
00424       constituent = Constituent::find (target);
00425       if (constituent != 0)
00426         {
00427           constituent->build_msdev_file (Me.m_simulation);
00428         }
00429     }
00430   else
00431     {
00432       /*
00433         Do genmsdev for all possible targets.
00434       */
00435       Constituent::build_all_msdev_files (Me.m_simulation);
00436     }
00437 }
00438 
00442 void Cmt::build_vsnet_file (const cmt_string& target)        
00443 {                                                            
00444   Constituent* constituent = 0;                              
00445                                                              
00446   set_standard_macros ();                                    
00447                                                              
00448   if (target != "")                                          
00449     {                                                        
00450       /*                                                     
00451         Do genvsnet for one specific target.                 
00452       */                                                     
00453       constituent = Constituent::find (target);              
00454       if (constituent != 0)                                  
00455         {                                                    
00456           constituent->build_vsnet_file (Me.m_simulation);        
00457         }                                                    
00458     }                                                        
00459   else                                                       
00460     {                                                        
00461       /*                                                     
00462         Do genvsnet for all possible targets.                
00463       */                                                     
00464       Constituent::build_all_vsnet_files (Me.m_simulation);       
00465     }                                                        
00466 }                                                            
00467 
00468 //----------------------------------------------------------
00469 bool Cmt::build_nmake ()
00470 {
00471   return (Me.m_build_nmake);
00472 }
00473 
00474 //----------------------------------------------------------
00475 void Cmt::build_OS9_makefile (const cmt_string& target)
00476 {
00477   build_makefile (target);
00478 }
00479 
00483 void Cmt::build_prefix (const cmt_string& package, cmt_string& prefix)
00484 {
00485   int pos;
00486   char c;
00487 
00488   /*
00489     Building the prefix from <package> 
00490   */
00491 
00492   prefix = package;
00493 
00494   for (pos = 0; pos < package.size (); pos++)
00495     {
00496       c = package[pos];
00497       prefix[pos] = toupper (c);
00498     }
00499 }
00500 
00501 //----------------------------------------------------------
00502 void Cmt::clear ()
00503 {
00504   Me.clear ();
00505 
00506   Database::clear ();
00507   Include::clear_all ();
00508   Script::clear_all ();
00509   CmtError::clear ();
00510 }
00511 
00512 //----------------------------------------------------------
00513 void Cmt::configure ()
00514 {
00515   Log;
00516   static bool configured = false;
00517 
00518   if (configured) return;
00519 
00520   Me.clear ();
00521 
00522   log << "configure_default_path" << log_endl;
00523   configure_default_path ();
00524   log << "configure_version_tag" << log_endl;
00525   configure_version_tag ();
00526   log << "configure_uname_tag" << log_endl;
00527   configure_uname_tag ();
00528   log << "configure_hosttype_tag" << log_endl;
00529   configure_hosttype_tag ();
00530   log << "configure_config_tag" << log_endl;
00531   configure_config_tag ();
00532   log << "configure_site_tag" << log_endl;
00533   configure_site_tag (0);
00534   log << "configure_home" << log_endl;
00535   // CMTHOME, CMTUSERCONTEXT and CMTPATH
00536   configure_home (0);
00537   log << "configure_current_dir" << log_endl;
00538 
00539 
00540   Me.m_autoconfigure_cmtpath = true;
00541   configure_cmt_path (0);
00542   Me.m_autoconfigure_cmtpath = false;
00543 
00544 
00545   configure_current_dir ();
00546 
00547   log << "configure_current_package" << log_endl;
00548   configure_current_package ();
00549   log << "configure_current_structuring_style" << log_endl;
00550   configure_current_structuring_style ();
00551 
00552   Use& use = Use::current();
00553 
00554   use.set (Me.m_current_package,
00555            Me.m_current_version,
00556            Me.m_current_path,
00557            "",
00558            "");
00559 
00560   use.style = Me.m_current_style;
00561 
00562   use.change_path (Me.m_current_path);
00563 
00564   guess_current_project ();
00565 
00566   if (CmtError::has_pending_error ()) 
00567     {
00568       Me.m_configure_error = CmtError::get_last_error ();
00569     }
00570 }
00571 
00572 //----------------------------------------------------------
00573 void Cmt::configure_cmt_path (Use* use)
00574 {
00575   if (!Me.m_autoconfigure_cmtpath) return;
00576 
00577   cmt_string s;
00578 
00579   Symbol* symbol = Symbol::find ("CMTPATH");
00580   if (symbol != 0)
00581     {
00582       bool show_set_hidden = false;
00583 
00584       if (Me.m_action == action_show_set)
00585         {
00586           show_set_hidden = true;
00587           Me.m_action = action_none;
00588         }
00589 
00590       s = symbol->build_macro_value ();
00591       Symbol::expand (s);
00592 
00593       if (show_set_hidden)
00594         {
00595           show_set_hidden = false;
00596           Me.m_action = action_show_set;
00597         }
00598     }
00599   else
00600     {
00601       s = CmtSystem::getenv ("CMTPATH");
00602     }
00603 
00604   IProjectFactory& factory = ProjectFactory::instance ();
00605   factory.reset ();
00606 
00607   CmtSystem::get_cmt_paths (factory, s, Me.m_cmt_user_context, Me.m_cmt_home);
00608 }
00609 
00610 //----------------------------------------------------------
00611 void Cmt::configure_config_tag ()
00612 {
00613   Me.m_cmt_config = CmtSystem::get_cmt_config ();
00614   if (Me.m_cmt_config != "")
00615     {
00616       Tag* tag;
00617 
00618       tag = Tag::add (Me.m_cmt_config, PriorityConfig, "CMTCONFIG", 0);
00619       tag->mark ();
00620     }
00621 }
00622 
00623 //----------------------------------------------------------
00624 void Cmt::configure_current_cmtpath ()
00625 {
00626   Use& current_use = Use::current ();
00627 
00628   Me.m_current_cmtpath = "";
00629   Me.m_current_offset = "";
00630 
00631   Me.m_current_cmtpath = Project::find_in_cmt_paths (current_use.path);
00632 
00633   if (Me.m_current_cmtpath != "")
00634     {
00635       static const cmt_string empty_string;
00636       static const cmt_string fs = CmtSystem::file_separator ();
00637 
00638       Me.m_current_offset = current_use.path;
00639 
00646       Me.m_current_offset.replace (Me.m_current_cmtpath, empty_string);
00647       if (Me.m_current_offset[0] == CmtSystem::file_separator ())
00648         {
00649           // Just in case there is a part left after removing the cmtpath entry
00650           
00651           Me.m_current_offset.replace (fs, empty_string);
00652         }
00653     }
00654 }
00655 
00656 class CmtMountFilterParser : public FAwk
00657 {
00658 public:
00659 
00660   CmtMountFilterParser ()
00661   {
00662     reset ();
00663   }
00664 
00665   void reset ()
00666   {
00667     m_current_dir = CmtSystem::pwd ();
00668     m_done = false;
00669     m_prefix = "";
00670   }
00671 
00672   bool is_done () const
00673   {
00674     return (m_done);
00675   }
00676 
00677   const cmt_string& get_current_dir () const
00678   {
00679     return (m_current_dir);
00680   }
00681 
00682   void set_prefix (const cmt_string& prefix)
00683   {
00684     m_prefix = prefix;
00685   }
00686 
00687   void filter (const cmt_string& line)
00688   {
00689     //cout << "line=" << line << endl;
00690 
00691     if (m_done) 
00692       {
00693         stop ();
00694         return;
00695       }
00696 
00697     CmtSystem::cmt_string_vector words;
00698 
00699     CmtSystem::split (line, " \t", words);
00700 
00701     int requested = 2;
00702 
00703     if (m_prefix != "")
00704       {
00705         requested++;
00706       }
00707 
00708     if (words.size () < requested) return;
00709 
00710     int n = 0;
00711 
00712     if (m_prefix != "")
00713       {
00714         if (words[n] != m_prefix) return;
00715         n++;
00716       }
00717 
00718     cmt_string& path_name = words[n];
00719     cmt_string& replacement = words[n+1];
00720     
00721     if (m_current_dir.find (path_name) != cmt_string::npos)
00722       {
00723         m_current_dir.replace (path_name, replacement);
00724         m_done = true;
00725         stop ();
00726       }
00727   }
00728 
00729 private:
00730   bool m_done;
00731   cmt_string m_prefix;
00732   cmt_string m_current_dir;
00733 };
00734 
00735 //----------------------------------------------------------
00736 void Cmt::configure_current_dir ()
00737 {
00738   cmt_string file_name;
00739 
00740   /*
00741     Building current_dir :
00742 
00743     o we first get the physical value (using getwd)
00744     o then this value is possibly filtered using the
00745     cmt_mount_filter file.
00746   */
00747 
00748   CmtMountFilterParser mount_filter;
00749 
00755   file_name = Me.m_default_path;
00756   if (file_name != "")
00757     {
00758       file_name += CmtSystem::file_separator ();
00759       file_name += "CMT";
00760       file_name += CmtSystem::file_separator ();
00761       file_name += Me.m_cmt_version;
00762       file_name += CmtSystem::file_separator ();
00763       file_name += "mgr";
00764       file_name += CmtSystem::file_separator ();
00765     }
00766 
00767   file_name += "cmt_mount_filter";
00768 
00769   mount_filter.run (file_name);
00770 
00776   mount_filter.set_prefix ("mount_filter");
00777 
00778   mount_filter.run (".cmtrc");
00779 
00785   if (CmtSystem::get_home_directory (file_name))
00786     {
00787       file_name += CmtSystem::file_separator ();
00788       file_name += ".cmtrc";
00789       mount_filter.run (file_name);
00790     }
00791 
00792   Me.m_current_dir = mount_filter.get_current_dir ();
00793 }
00794 
00795 //----------------------------------------------------------
00796 void Cmt::configure_current_package ()
00797 {
00798   /*
00799     Build current_package and current_prefix.
00800 
00801     This is only possible if we are within the cmt/mgr branch of a
00802     standard directory tree (i.e. <package>/<version>/cmt or mgr)
00803   */
00804 
00805   cmt_string req = "..";
00806   req += CmtSystem::file_separator ();
00807   req += "cmt";
00808   req += CmtSystem::file_separator ();
00809   req += "requirements";
00810 
00811   if (CmtSystem::test_file (req))
00812     {
00813       Me.m_current_style = cmt_style;
00814     }
00815   else
00816     {
00817       cmt_string req = "..";
00818       req += CmtSystem::file_separator ();
00819       req += "mgr";
00820       req += CmtSystem::file_separator ();
00821       req += "requirements";
00822 
00823       if (CmtSystem::test_file (req))
00824         {
00825           Me.m_current_style = mgr_style;
00826         }
00827       else
00828         {
00829           // This package is probably a standalone one
00830           Me.m_current_style = none_style;
00831         }
00832     }
00833 
00834 
00835   if (Me.m_current_style != none_style)
00836     {
00837       //
00838       //  Here there is a ../cmt or ../mgr branch in front of us
00839       //  and there is a requirements file there
00840       //
00841 
00842       cmt_string up_dir;
00843       cmt_string up_branch;
00844 
00845       CmtSystem::dirname (Me.m_current_dir, up_dir);
00846       CmtSystem::basename (up_dir, up_branch);
00847 
00848       cmt_string version_file = "..";
00849       version_file += CmtSystem::file_separator ();
00850       version_file += "cmt";
00851       version_file += CmtSystem::file_separator ();
00852       version_file += "version.cmt";
00853 
00854       if (CmtSystem::test_file (version_file))
00855         {
00856           // 
00857           // There is an explicit version descriptor. This one takes precedence
00858           // and forces the structuring style to no directory
00859           //
00860 
00861           Me.m_current_package = up_branch;
00862           CmtSystem::dirname (up_dir, Me.m_current_path);
00863 
00864           if (Me.m_current_version.read (version_file))
00865             {
00866               int pos;
00867 
00868               pos = Me.m_current_version.find ('\n');
00869               if (pos != cmt_string::npos) Me.m_current_version.erase (pos);
00870               pos = Me.m_current_version.find ('\r');
00871               if (pos != cmt_string::npos) Me.m_current_version.erase (pos);
00872             }
00873           else
00874             {
00875               Me.m_current_version = "v*";
00876             }
00877 
00878           if (Me.m_debug)
00879             {
00880               cout << "Cmt::configure_current_package>" << endl
00881                    << " m_current_package " << Me.m_current_package << endl
00882                    << " m_current_version " << Me.m_current_version << endl
00883                    << " m_current_dir " << Me.m_current_dir << endl
00884                    << " pwd " << CmtSystem::pwd ()
00885                    << endl;
00886             }
00887 
00888           Me.m_current_style = no_version_style;
00889         }
00890       else if (CmtSystem::is_version_directory (up_branch))
00891         {
00892           // The up branch IS a version directory.
00893 
00894           Me.m_current_version = up_branch;
00895           CmtSystem::dirname (up_dir, up_dir);
00896           CmtSystem::basename (up_dir, Me.m_current_package);
00897           CmtSystem::dirname (up_dir, Me.m_current_path);
00898         }
00899       else
00900         {
00901           // No version descriptor
00902           // No version directory. The version is defaulted to v*
00903  
00904           CmtSystem::basename (up_dir, Me.m_current_package);
00905           Me.m_current_version = "v*";
00906           CmtSystem::dirname (up_dir, Me.m_current_path);
00907 
00908           Me.m_current_style = no_version_style;
00909         }
00910 
00911       build_prefix (Me.m_current_package, Me.m_current_prefix);
00912       build_config (Me.m_current_prefix, Me.m_current_config);
00913     }
00914   else
00915     {
00916       Me.m_current_package = "cmt_standalone";
00917       Me.m_current_version = "";
00918       Me.m_current_path = Me.m_current_dir;
00919       build_prefix (Me.m_current_package, Me.m_current_prefix);
00920       build_config (Me.m_current_prefix, Me.m_current_config);
00921       Me.m_current_style = none_style;
00922     }
00923 
00924   //cout << "configure_current_package> current style=" << Me.m_current_style << endl;
00925 }
00926 
00927 //----------------------------------------------------------
00928 void Cmt::configure_current_structuring_style ()
00929 {
00930   cmt_string s;
00931 
00932   s = CmtSystem::getenv ("CMTSTRUCTURINGSTYLE");
00933   if (s == "without_version_directory")
00934     {
00935       Me.m_current_structuring_style = without_version_directory;
00936     }
00937 }
00938 
00939 //----------------------------------------------------------
00940 void Cmt::configure_default_path ()
00941 {
00942   Me.m_default_path = CmtSystem::get_cmt_root ();
00943   CmtSystem::get_cmt_version (Me.m_cmt_version);
00944   Me.m_cmt_root = Me.m_default_path;
00945   Me.m_cmt_root += CmtSystem::file_separator ();
00946   Me.m_cmt_root += "CMT";
00947   Me.m_cmt_root += CmtSystem::file_separator ();
00948   Me.m_cmt_root += Me.m_cmt_version;
00949 }
00950 
00951 //----------------------------------------------------------
00952 void Cmt::configure_home (Use* use)
00953 {
00954   Me.m_cmt_home = "";
00955 
00956   Symbol* symbol = Symbol::find ("CMTHOME");
00957   if (symbol != 0)
00958     {
00959       Me.m_cmt_home = symbol->build_macro_value ();
00960       Symbol::expand (Me.m_cmt_home);
00961     }
00962   else if (CmtSystem::testenv ("CMTHOME"))
00963     {
00964       Me.m_cmt_home = CmtSystem::getenv ("CMTHOME");
00965     }
00966 
00967   if ((Me.m_cmt_home != "") && !CmtSystem::test_directory (Me.m_cmt_home))
00968     {
00969       Me.m_cmt_home = "";
00970     }
00971 
00972   configure_user_context (0);
00973 }
00974 
00975 //----------------------------------------------------------
00976 void Cmt::configure_user_context (Use* use)
00977 {
00978   Me.m_cmt_user_context = "";
00979 
00980   Symbol* symbol = Symbol::find ("CMTUSERCONTEXT");
00981   if (symbol != 0)
00982     {
00983       Me.m_cmt_user_context = symbol->build_macro_value ();
00984       Symbol::expand (Me.m_cmt_user_context);
00985     }
00986   else if (CmtSystem::testenv ("CMTUSERCONTEXT"))
00987     {
00988       Me.m_cmt_user_context = CmtSystem::getenv ("CMTUSERCONTEXT");
00989     }
00990 
00991   if ((Me.m_cmt_user_context != "") && !CmtSystem::test_directory (Me.m_cmt_user_context))
00992     {
00993       Me.m_cmt_user_context = "";
00994     }
00995 
00996   if (Me.m_debug) cout << "configure_user_context> user_context=" << Me.m_cmt_user_context << endl;
00997 
00998   configure_cmt_path (0);
00999 }
01000 
01001 //----------------------------------------------------------
01002 void Cmt::configure_hosttype_tag ()
01003 {
01004   cmt_string hosttype;
01005 
01006   CmtSystem::get_hosttype (hosttype);
01007 
01008   if (hosttype != "")
01009     {
01010       Tag* tag;
01011 
01012       tag = Tag::add (hosttype, PriorityUname, "HOSTTYPE", 0);
01013       tag->mark ();
01014     }
01015 }
01016 
01017 //----------------------------------------------------------
01018 void Cmt::configure_site_tag (Use* use)
01019 {
01020   Symbol* symbol = Symbol::find ("CMTSITE");
01021   if (symbol != 0)
01022     {
01023       Me.m_cmt_site = symbol->build_macro_value ();
01024       Symbol::expand (Me.m_cmt_site);
01025     }
01026   else
01027     {
01028       Me.m_cmt_site = CmtSystem::get_cmt_site ();
01029     }
01030 
01031   if (Me.m_cmt_site != "")
01032     {
01033       cmt_string s = "CMTSITE";
01034 
01035       if (use != 0)
01036         {
01037           s += " in ";
01038         }
01039 
01040       Tag* tag;
01041 
01042       tag = Tag::add (Me.m_cmt_site, PrioritySite, s, use);
01043       tag->mark ();
01044     }
01045 }
01046 
01047 //----------------------------------------------------------
01048 void Cmt::restore_all_tags (Use* use)
01049 {
01050     //cerr << "restore_all_tags" << endl;
01051 
01052   Cmt::configure_tags (use);
01053 
01054     /*
01055       Then get existing extra tags
01056      */
01057 
01058   if (CmtSystem::testenv ("CMTEXTRATAGS"))
01059     {
01060       cmt_string s = "CMTEXTRATAGS";
01061 
01062       if (use != 0)
01063         {
01064           s += " in ";
01065         }
01066 
01067       Tag* tag;
01068       CmtSystem::cmt_string_vector words;
01069       
01070       cmt_string tags = CmtSystem::getenv ("CMTEXTRATAGS");
01071       
01072       CmtSystem::split (tags, " \t,", words);
01073 
01074       Me.m_extra_tags = ",";
01075       
01076       for (int i = 0; i < words.size (); i++)
01077         {
01078           const cmt_string& a = words[i];
01079 
01080           Me.m_extra_tags += a;
01081           Me.m_extra_tags += ",";
01082           
01083           tag = Tag::add (a, PriorityUserTag, s, use);
01084           
01085           tag->mark ();
01086         }
01087     }
01088 }
01089 
01090 //----------------------------------------------------------
01091 void Cmt::configure_tags (Use* use)
01092 {
01093   cmt_string config_tag;
01094 
01095   Log;
01096 
01097   //if (Me.m_debug) cout << "configure_tags0> current_tag=" << Me.m_current_tag << endl;
01098 
01099   log << "current_tag=" << Me.m_current_tag << log_endl;
01100 
01101   Symbol* symbol = Symbol::find ("CMTCONFIG");
01102   if (symbol != 0)
01103     {
01104       bool show_set_hidden = false;
01105 
01106       if (Me.m_action == action_show_set)
01107         {
01108           show_set_hidden = true;
01109           Me.m_action = action_none;
01110         }
01111 
01112       config_tag = symbol->build_macro_value ();
01113       Symbol::expand (config_tag);
01114 
01115       if (show_set_hidden)
01116         {
01117           show_set_hidden = false;
01118           Me.m_action = action_show_set;
01119         }
01120     }
01121   else if (CmtSystem::testenv ("CMTCONFIG"))
01122     {
01123       config_tag = CmtSystem::getenv ("CMTCONFIG");
01124     }
01125   else if (CmtSystem::testenv ("CMTBIN"))
01126     {
01127       config_tag = CmtSystem::getenv ("CMTBIN");
01128     }
01129 
01130   if (config_tag == "")
01131     {
01132       CmtSystem::get_uname (config_tag);
01133     }
01134 
01135   //if (Me.m_debug) cout << "configure_tags> current_tag=" << Me.m_current_tag << endl;
01136   log << "current_tag=" << Me.m_current_tag << log_endl;
01137 
01138   cmt_string s = "CMTCONFIG";
01139 
01140   if (use != 0)
01141     {
01142       s += " in ";
01143     }
01144 
01145   Tag* tag;
01146 
01147   tag = Tag::add (config_tag, PriorityConfig, s, use);
01148   tag->mark ();
01149 
01150     //Me.m_current_tag = config_tag;
01151 }
01152 
01153 //----------------------------------------------------------
01154 void Cmt::configure_uname_tag ()
01155 {
01156   cmt_string uname;
01157 
01158   CmtSystem::get_uname (uname);
01159 
01160   if (uname != "")
01161     {
01162       Tag* tag;
01163 
01164       tag = Tag::add (uname, PriorityUname, "uname", 0);
01165       tag->mark ();
01166     }
01167 }
01168 
01169 //----------------------------------------------------------
01170 void Cmt::configure_version_tag ()
01171 {
01172   int v = 0;
01173   int r = 0;
01174   int p = 0;
01175 
01176   CmtSystem::is_version_directory (CMTVERSION, v, r, p);
01177 
01178   Tag* tag;
01179 
01180   static char temp[80];
01181 
01182   sprintf (temp, "CMTv%d", v);
01183 
01184   tag = Tag::add (temp, PriorityVersion, "CMTVERSION", 0);
01185   tag->mark ();
01186 
01187   sprintf (temp, "CMTr%d", r);
01188 
01189   tag = Tag::add (temp, PriorityVersion, "CMTVERSION", 0);
01190   tag->mark ();
01191 
01192   sprintf (temp, "CMTp%d", p);
01193 
01194   tag = Tag::add (temp, PriorityVersion, "CMTVERSION", 0);
01195   tag->mark ();
01196 
01197 }
01198 
01199 //----------------------------------------------------------
01200 //
01201 //   Actions
01202 //
01203 //----------------------------------------------------------
01204 
01205 class AwkActor : public Awk
01206 {
01207 public:
01208 
01209   void filter (const cmt_string& line)
01210       {
01211         cout << line << endl;
01212       }
01213 };
01214 
01215 //----------------------------------------------------------
01216 void Cmt::do_awk (const ArgParser& ap)
01217 {
01218   if (ap.arguments.size () < 1)
01219     {
01220       cerr << "#CMT> cmt awk <file> <pattern>" << endl;
01221       return;
01222     }
01223 
01224   const cmt_string& file = ap.arguments[0];
01225   const cmt_string& pattern = ap.arguments[1];
01226   cmt_string text;
01227 
01228   text.read (file);
01229 
01230   static AwkActor a;
01231 
01232   cmt_regexp exp (pattern);
01233 
01234   a.run (text, exp);
01235 }
01236 
01237 //----------------------------------------------------------
01238 void Cmt::do_broadcast (const ArgParser& ap)
01239 {
01240   Use::UsePtrVector& Uses = Use::get_ordered_uses ();
01241 
01242   CmtSystem::cmt_string_vector uses;
01243   CmtSystem::cmt_string_vector packages;
01244   CmtSystem::cmt_string_vector versions;
01245   CmtSystem::cmt_string_vector path_selections;
01246   CmtSystem::cmt_string_vector selections;
01247   CmtSystem::cmt_string_vector exclusions;
01248   cmt_string begin;
01249   cmt_string command;
01250   bool is_cmt = false;
01251   int first = 0;
01252   int i;
01253   bool ignore_errors = false;
01254   bool all_packages = false;
01255 
01256   bool local = true;
01257 
01258   for (i = 0; i < ap.arguments.size (); i++)
01259     {
01260       const cmt_string& w = ap.arguments[i];
01261 
01262       //cerr << "broadcast: arg=[" << w << "]" << endl;
01263 
01264       if (command == "")
01265         {
01266           if (w.substr (0, 13) == "-all_packages")
01267             {
01268               local = false;
01269               all_packages = true;
01270             }
01271           else if (w.substr (0, 7) == "-depth=")
01272             {
01273               local = false;
01274 
01275               cmt_string depth_str;
01276               int depth_value = 0;
01277                           
01278               w.substr (7, depth_str);
01279               if ((sscanf (depth_str.c_str (), "%d", &depth_value) < 1) ||
01280                   (depth_value < 1))
01281                 {
01282                   // Syntax error
01283                   //  We shall restrict to packages found within 
01284                   // the <depth_value> first elements of CMTPATH.
01285                   //  If CMTPATH is empty, nothing is selected.
01286                   // depth=1 is equivalent to local
01287                 }
01288 
01289               Project::fill_selection (depth_value, path_selections);
01290             }
01291           else if (w.substr (0, 9) == "-exclude=")
01292             {
01293               cmt_string exclusion;
01294 
01295               w.substr (9, exclusion);
01296 
01297               int size = exclusion.size ();
01298               
01299               if (size >= 2)
01300                 {
01301                   if (((exclusion[0] == '"') && (exclusion[size - 1] == '"')) ||
01302                       ((exclusion[0] == '\'') && (exclusion[size - 1] == '\'')))
01303                     {
01304                       exclusion.erase (size - 1);
01305                       exclusion.erase (0, 1);
01306                     }
01307 
01308                   CmtSystem::split (exclusion, " \t", exclusions);
01309                 }
01310             }
01311           else if (w.substr (0, 7) == "-global")
01312             {
01313               path_selections.clear ();
01314 
01315               local = false;
01316             }
01317           else if (w.substr (0, 6) == "-local")
01318             {
01319               local = true;
01320             }
01321           else if (w.substr (0, 8) == "-select=")
01322             {
01323               cmt_string selection;
01324 
01325               w.substr (8, selection);
01326 
01327               //cerr << "Select=[" << selection << "]" << endl;
01328 
01329               int size = selection.size ();
01330               
01331               if (size >= 2)
01332                 {
01333                   if (((selection[0] == '"') && (selection[size - 1] == '"')) ||
01334                       ((selection[0] == '\'') && (selection[size - 1] == '\'')))
01335                     {
01336                       selection.erase (size - 1);
01337                       selection.erase (0, 1);
01338                     }
01339                 }
01340 
01341               CmtSystem::split (selection, " \t", selections);
01342 
01343               //cerr << "Selections.size () = " << selections.size () << endl;
01344             }
01345           else if (w.substr (0, 7) == "-begin=")
01346             {
01347               w.substr (7, begin);
01348             }
01349           else
01350             {
01351               command = w;
01352             }
01353         }
01354       else
01355         {
01356           command += " ";
01357           command += w;
01358         }
01359 
01360     }
01361 
01362   if (local)
01363     {
01364       Project::fill_selection (1, path_selections);
01365     }
01366 
01367   if (command[0] == '-')
01368     {
01369       ignore_errors = true;
01370       command.erase (0, 1);
01371     }
01372 
01373   //if (command.substr (0, 3) == "cmt") is_cmt = true;
01374 
01375   if (all_packages)
01376     {
01377       PackageSelector selector (uses);
01378       PathScanner scanner;
01379       Project::scan_paths (scanner, selector);
01380     }
01381   else
01382     {
01383       for (i = Uses.size () - 1; i >= 0; i--)
01384         {
01385           Use* use = Uses[i];
01386                   
01387           if (use->discarded) continue;
01388 
01389           if (!use->located ())
01390             {
01391               if (!Me.m_quiet)
01392                 {
01393                   cerr << "#CMT> package " << use->get_package_name () <<
01394                       " " << use->version << " " << use->path <<
01395                       " not found" <<
01396                       endl;
01397                 }
01398             }
01399           else
01400             {
01401               if (use->get_package_name () != "CMT")
01402                 {
01403                   cmt_string& s = uses.add ();
01404 
01405                   use->get_full_path (s);
01406 
01407                   s += CmtSystem::file_separator ();
01408                   if (use->style == mgr_style) s += "mgr";
01409                   else s += "cmt";
01410 
01411                   cmt_string& v = versions.add ();
01412                   v = use->version;
01413 
01414                   cmt_string& p = packages.add ();
01415                   p = use->get_package_name ();
01416 
01417                   //cout << ">>> adding " << s << " to selection" << endl;
01418                 }
01419             }
01420         }
01421           
01422       {
01423         cmt_string& s = uses.add ();
01424                   
01425         Use* use = &(Use::current ());
01426 
01427         if (use->get_package_name ().find ("cmt_standalone") != cmt_string::npos)
01428           {
01429             s = CmtSystem::pwd ();
01430           }
01431         else
01432           {
01433             use->get_full_path (s);
01434 
01435             s += CmtSystem::file_separator ();
01436                   
01437             if (use->style == mgr_style) s += "mgr";
01438             else s += "cmt";
01439           }
01440 
01441         cmt_string& v = versions.add ();
01442         v = use->version;
01443 
01444         cmt_string& p = packages.add ();
01445         p = use->get_package_name ();
01446 
01447         //cout << ">>> adding current " << s << " to selection" << endl;
01448       }
01449     }
01450 
01451   bool started = false;
01452 
01453   if (begin == "") started = true;
01454 
01455   Cmt::reset_all_sets_done ();
01456   Symbol::all_set ();
01457 
01458   for (i = 0; i < uses.size (); i++)
01459     {
01460       const cmt_string& s = uses[i];
01461       const cmt_string& v = versions[i];
01462       const cmt_string& p = packages[i];
01463       cmt_string cmtpath;
01464 
01465       bool ok = true;
01466       bool selected = true;
01467       bool excluded = false;
01468 
01469       if (path_selections.size () > 0)
01470         {
01471           selected = false;
01472 
01473           for (int j = 0; j < path_selections.size (); j++)
01474             {
01475               const cmt_string& sel = path_selections[j];
01476               
01477               if (s.find (sel) != cmt_string::npos) 
01478                 {
01479                   cmtpath = sel;
01480                   selected = true;
01481                   break;
01482                 }
01483             }
01484 
01485           ok = selected;
01486         }
01487 
01488       if (ok)
01489         {
01490           if (selections.size () > 0)
01491             {
01492               selected = false;
01493               
01494               for (int j = 0; j < selections.size (); j++)
01495                 {
01496                   const cmt_string& sel = selections[j];
01497                   
01498                   if (s.find (sel) != cmt_string::npos) 
01499                     {
01500                       selected = true;
01501                       break;
01502                     }
01503                 }
01504               
01505               ok = selected;
01506             }
01507         }
01508 
01509       if (ok && !started)
01510         {
01511           if (s.find (begin) != cmt_string::npos)
01512             {
01513               started = true;
01514               ok = true;
01515             }
01516           else
01517             {
01518               ok = false;
01519             }
01520         }
01521 
01522 
01523       if (ok)
01524         {
01525           excluded = false;
01526 
01527           for (int j = 0; j < exclusions.size (); j++)
01528             {
01529               const cmt_string& exc = exclusions[j];
01530               
01531               if (s.find (exc) != cmt_string::npos) 
01532                 {
01533                   excluded = true;
01534                   break;
01535                 }
01536             }
01537 
01538           if (excluded) ok = false;
01539         }
01540 
01541       if (!ok) 
01542         {
01543           continue;
01544         }
01545 
01546 
01547 
01548       if (!CmtSystem::cd (s))
01549         {
01550           if (s.find ("cmt_standalone") != cmt_string::npos)
01551             {
01552               cerr << "#CMT> Currently not in a CMT package" << endl;
01553             }
01554           else
01555             {
01556               cerr << "#CMT> Cannot move to the package in " << s << " (" << i+1 << "/" 
01557                    << uses.size () << ")"<< endl;
01558             }
01559 
01560           if (!ignore_errors) break;
01561 
01562           continue;
01563         }
01564 
01565       if (CmtLock::check () == CmtLock::locked_by_another_user)
01566         {
01567           cerr << "#CMT> Ignore locked package in " << s << " (" << i+1 << "/" 
01568                << uses.size () << ")" << endl;
01569           continue;
01570         }
01571 
01572       if (cmtpath == "")
01573         {
01574           cmt_string sel = CmtSystem::pwd ();
01575           cmtpath = Project::find_in_cmt_paths (sel);
01576         }
01577 
01578       cmt_string cmd = command;
01579       static const cmt_string version_template = "<version>";
01580       cmd.replace_all (version_template, v);
01581 
01582       static const cmt_string package_template = "<package>";
01583       cmd.replace_all (package_template, p);
01584 
01585       static const cmt_string cmtpath_template = "<package_cmtpath>";
01586       cmd.replace_all (cmtpath_template, cmtpath);
01587 
01588       static const cmt_string offset_template = "<package_offset>";
01589 
01590       static const cmt_string empty_string;
01591       static const cmt_string fs = CmtSystem::file_separator ();
01592       cmt_string offset = s;
01593       offset.replace (cmtpath, empty_string);
01594       if (offset[0] == CmtSystem::file_separator ())
01595         {
01596           offset.replace (fs, empty_string);
01597         }
01598       CmtSystem::dirname (offset, offset);
01599 
01600       cmt_string n;
01601       CmtSystem::basename (offset, n);
01602       if (n == p)
01603         {
01604           CmtSystem::dirname (offset, offset);
01605         }
01606       else
01607         {
01608           CmtSystem::dirname (offset, offset);
01609           CmtSystem::dirname (offset, offset);
01610         }
01611 
01612       cmd.replace_all (offset_template, offset);
01613 
01614 
01615       cout << "#--------------------------------------------------------------" << endl;
01616       cout << "# Now trying [" << cmd << "] in " << s << " (" << i+1 << "/" << uses.size () 
01617            << ")" << endl;
01618       cout << "#--------------------------------------------------------------" << endl;
01619 
01620       if (is_cmt)
01621         {
01622           //
01623           //  There is a bug in the recursive use of the parser. Macros are not set correctly.
01624           //  Thus the recursive optimization is now discarded.
01625           //
01626           if (parser (cmd) != 0)
01627             {
01628               CmtError::set (CmtError::execution_error, cmd);
01629               break;
01630             }
01631         }
01632       else
01633         {
01634           int status = CmtSystem::execute (cmd);
01635 
01636           //cerr << "do_broadcast> status=" << status << " ignore_errors=" << ignore_errors << endl;
01637 
01638           if ((status != 0) && !ignore_errors)
01639               //if ((status != 0) && !ignore_errors)
01640             {
01641               if (status != 2) CmtError::set (CmtError::execution_error, cmd);
01642               break;
01643             }
01644         }
01645     }
01646 }
01647 
01648 //----------------------------------------------------------
01649 void Cmt::do_build_constituent_makefile (const ArgParser& ap)
01650 {
01651   if (CmtLock::check () == CmtLock::locked_by_another_user)
01652     {
01653       CmtError::set (CmtError::conflicting_lock, "build_constituent_makefile>");
01654       return;
01655     }
01656   if (ap.arguments.size () > 0) 
01657     {
01658       set_standard_macros ();
01659       Generator::build_constituent_makefile (ap.arguments[0]);
01660     }
01661 }
01662 
01663 //----------------------------------------------------------
01664 void Cmt::do_build_constituents_makefile (const ArgParser& ap)
01665 {
01666   if (CmtLock::check () == CmtLock::locked_by_another_user)
01667     {
01668       CmtError::set (CmtError::conflicting_lock, "build_constituents_makefile>");
01669       return;
01670     }
01671   set_standard_macros ();
01672 
01673   Generator::build_constituents_makefile (Me.m_current_package, ap.arguments);
01674 }
01675 
01676 //----------------------------------------------------------
01677 void Cmt::do_build_dependencies (const ArgParser& ap,
01678                                  int argc,
01679                                  char* argv[])
01680 {
01681   if (CmtLock::check () == CmtLock::locked_by_another_user)
01682     {
01683       CmtError::set (CmtError::conflicting_lock, "build_dependencies>");
01684       return;
01685     }
01686   if (ap.arguments.size () > 0)
01687     {
01688       set_standard_macros ();
01689 
01690       Generator::build_dependencies (ap.arguments);
01691     }
01692 }
01693 
01694 //----------------------------------------------------------
01695 void Cmt::do_build_library_links (const ArgParser& ap)
01696 {
01697   cmt_string cmtinstallarea = "";
01698   cmt_string tag = "";
01699   cmt_string shlibsuffix;
01700   cmt_string symlinkcmd;
01701 
01702   if (CmtLock::check () == CmtLock::locked_by_another_user)
01703     {
01704       CmtError::set (CmtError::conflicting_lock, "build_library_links>");
01705       return;
01706     }
01707 
01708   set_standard_macros ();
01709 
01710   Use::UsePtrVector& Uses = Use::get_ordered_uses ();
01711   Use& current_use = Use::current ();
01712   int i;
01713 
01714   {
01715     Symbol* macro = Symbol::find ("shlibsuffix");
01716     if (macro == 0) return;
01717     shlibsuffix = macro->build_macro_value ();
01718     Symbol::expand (shlibsuffix);
01719   }
01720 
01721   {
01722     Symbol* macro = Symbol::find ("library_install_command");
01723     if (macro != 0)
01724       {
01725         symlinkcmd = macro->build_macro_value ();
01726         Symbol::expand (symlinkcmd);
01727       }
01728   }
01729 
01730   if (get_strategy ("InstallArea"))
01731     {
01732       const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
01733 
01734       //cout << "#IA2>" << endl;
01735       
01736       cmt_string s1 = ia_mgr.get_installarea ();
01737 
01738       {
01739         Symbol* symbol = Symbol::find ("CMTINSTALLAREA");
01740         if (symbol != 0)
01741           {
01742             s1 = symbol->build_macro_value ();
01743             Symbol::expand (s1);
01744           }
01745       }
01746 
01747       cmtinstallarea = s1;
01748                   
01749       cmt_string s2;
01750 
01751       {
01752         Symbol* macro = Symbol::find ("tag");
01753         if (macro != 0)
01754           {
01755             s2 = macro->build_macro_value ();
01756             Symbol::expand (s2);
01757           }
01758       }
01759 
01760       tag = s2;
01761 
01762       cmt_string s = s1;
01763       s += CmtSystem::file_separator ();
01764       s += s2;
01765       s += CmtSystem::file_separator ();
01766       s += "lib";
01767 
01768       CmtSystem::mkdir (s);
01769     }
01770 
01771   current_use.build_library_links (cmtinstallarea, tag, shlibsuffix, symlinkcmd);
01772 
01773   for (i = 0; i < Uses.size (); i++)
01774     {
01775       Use* use = Uses[i];
01776 
01777       if (use == 0) continue;
01778       if (use->discarded) continue;
01779 
01780       if (use->get_package_name () == "CMT") continue;
01781       if (use->get_package_name () == current_use.get_package_name ()) continue;
01782 
01783       use->build_library_links (cmtinstallarea, tag, shlibsuffix, symlinkcmd);
01784     }
01785 }
01786 
01787 //----------------------------------------------------------
01788 void Cmt::do_build_make_setup (const ArgParser& ap)
01789 {
01790   if (CmtLock::check () == CmtLock::locked_by_another_user)
01791     {
01792       CmtError::set (CmtError::conflicting_lock, "build_make_setup>");
01793       return;
01794     }
01795   set_standard_macros ();
01796   Generator::build_make_setup (Me.m_current_package);
01797 }
01798 
01799 //----------------------------------------------------------
01800 void Cmt::do_build_msdev (const ArgParser& ap)
01801 {
01802   if (CmtLock::check () == CmtLock::locked_by_another_user)
01803     {
01804       CmtError::set (CmtError::conflicting_lock, "build_msdev>");
01805       return;
01806     }
01807 
01808   if (true)
01809     {
01810       set_standard_macros ();
01811       if (ap.arguments.size () > 0) build_msdev_file (ap.arguments[0]);
01812       else build_msdev_file ("");
01813     }
01814 }
01815 
01816 void Cmt::do_build_CMT_pacman (const ArgParser& ap)
01817 {
01818   cmt_string pacman_file;
01819 
01820   pacman_file = Me.m_cmt_root;
01821   pacman_file += CmtSystem::file_separator ();
01822   pacman_file += "mgr";
01823   pacman_file += CmtSystem::file_separator ();
01824   pacman_file += "CMT.pacman";
01825 
01826   cmt_string pacman;
01827   cmt_string pattern = "<version>";
01828   cmt_string replacement = CMTVERSION;
01829 
01830   pacman.read (pacman_file);
01831 
01832   pacman.replace_all (pattern, replacement);
01833 
01834   cout << pacman << endl;
01835 }
01836 
01837 // Visual Studio.net Support                                                 
01838 //----------------------------------------------------------                 
01839 void Cmt::do_build_vsnet (const ArgParser& ap)     
01840 {                                                                            
01841   if (CmtLock::check () == CmtLock::locked_by_another_user)                  
01842     {                                                                        
01843       CmtError::set (CmtError::conflicting_lock, "build_vsnet>");            
01844       return;                                                                
01845     }                                                                        
01846                                                                              
01847   if (true)                                                                  
01848     {                                                                        
01849       set_standard_macros ();                                                
01850       if (ap.arguments.size () > 0) build_vsnet_file (ap.arguments[0]);            
01851       else build_vsnet_file ("");                                            
01852     }                                                                        
01853 }                                                                            
01854 
01855 //----------------------------------------------------------
01856 void Cmt::do_build_os9_makefile (const ArgParser& ap)
01857 {
01858   if (CmtLock::check () == CmtLock::locked_by_another_user)
01859     {
01860       CmtError::set (CmtError::conflicting_lock, "build_os9_makefile>");
01861       return;
01862     }
01863 
01864   if (ap.arguments.size () > 0) 
01865     {
01866       set_standard_macros ();
01867       build_OS9_makefile (ap.arguments[0]);
01868     }
01869 }
01870 
01871 //----------------------------------------------------------
01872 void Cmt::do_build_prototype (const ArgParser& ap)
01873 {
01874   if (CmtLock::check () == CmtLock::locked_by_another_user)
01875     {
01876       CmtError::set (CmtError::conflicting_lock, "build_prototype>");
01877       return;
01878     }
01879 
01880   if (ap.arguments.size () > 0) 
01881     {
01882       set_standard_macros ();
01883       Generator::build_prototype (ap.arguments[0]);
01884     }
01885 }
01886 
01887 //----------------------------------------------------------
01888 void Cmt::do_build_readme (const ArgParser& ap)
01889 {
01890   if (CmtLock::check () == CmtLock::locked_by_another_user)
01891     {
01892       CmtError::set (CmtError::conflicting_lock, "build_readme>");
01893       return;
01894     }
01895 
01896   set_standard_macros ();
01897   Generator::build_readme (ap.arguments);
01898 }
01899 
01900 //----------------------------------------------------------
01901 void Cmt::do_build_tag_makefile (const ArgParser& ap)
01902 {
01903   if (CmtLock::check () == CmtLock::locked_by_another_user)
01904     {
01905       CmtError::set (CmtError::conflicting_lock, "build_tag_makefile>");
01906       return;
01907     }
01908 
01909   print_macros (Make);
01910 }
01911 
01912 //----------------------------------------------------------
01913 void Cmt::do_build_temporary_name (const ArgParser& ap)
01914 {
01915   cmt_string name = CmtSystem::get_temporary_name ();
01916   cout << name << endl;
01917 }
01918 
01919 //----------------------------------------------------------
01920 void Cmt::do_build_triggers (const ArgParser& ap)
01921 {
01922   if (CmtLock::check () == CmtLock::locked_by_another_user)
01923     {
01924       CmtError::set (CmtError::conflicting_lock, "build_tag_makefile>");
01925       return;
01926     }
01927 
01928   if (ap.arguments.size () > 0) 
01929     {
01930       set_standard_macros ();
01931       TriggerGenerator::run (ap.arguments[0]);
01932     }
01933 }
01934 
01935 //----------------------------------------------------------
01936 void Cmt::do_build_windefs (const ArgParser& ap)
01937 {
01938   if (CmtLock::check () == CmtLock::locked_by_another_user)
01939     {
01940       CmtError::set (CmtError::conflicting_lock, "build_windefs>");
01941       return;
01942     }
01943 
01944   if (ap.arguments.size () > 0) 
01945     {
01946       set_standard_macros ();
01947       Generator::build_windefs (ap.arguments[0]);
01948     }
01949 }
01950 
01951 //----------------------------------------------------------
01952 void Cmt::do_check_configuration (const ArgParser& ap)
01953 {
01954   cmt_string env;
01955   Tag* tag;
01956 
01957   static CmtSystem::cmt_string_vector tags;
01958 
01959   CmtSystem::split (Me.m_extra_tags, " \t,", tags);
01960 
01961   for (int i = 0; i < tags.size (); i++)
01962     {
01963       const cmt_string& t = tags[i];
01964 
01965       tag = Tag::find (t);
01966       if (tag == 0) continue;
01967 
01968       if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag)) 
01969         {
01970           cerr << "#CMT> The tag " << t << " is not used in any tag expression. Please check spelling" << endl;
01971         }
01972     }
01973 
01974   env = CmtSystem::getenv ("CMTSITE");
01975   if (env == "") 
01976     {
01977       return;
01978     }
01979 
01980   tag = Tag::find (env);
01981   if (tag == 0) 
01982     {
01983       return;
01984     }
01985 
01986   if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag)) 
01987     {
01988       cerr << "#CMT> The CMTSITE value " << env << " is not used in any tag expression. Please check spelling" << endl;
01989     }
01990 }
01991 
01992 //----------------------------------------------------------
01993 void Cmt::do_check_files (const ArgParser& ap)
01994 {
01995   if (ap.arguments.size () >= 2) 
01996     {
01997       cmt_string first_file = ap.arguments[0];
01998       cmt_string second_file = ap.arguments[1];
01999           
02000       if (first_file == "") return;
02001       if (second_file == "") return;
02002           
02003       CmtSystem::compare_and_update_files (first_file, second_file);
02004     }
02005 }
02006 
02007 //----------------------------------------------------------
02008 void Cmt::do_check_version (const ArgParser& ap)
02009 {
02010   if (ap.arguments.size () > 0)
02011     {
02012       cmt_string name = ap.arguments[0];
02013           
02014       if (name == "") return;
02015       int v = 0;
02016       int r = 0;
02017       int p = 0;
02018           
02019       bool ok = CmtSystem::is_version_directory (name, v, r, p);
02020           
02021       if (ok)
02022         {
02023           cout << "# " << name << " is version " << v << " release " << r << " patch " << p << endl;
02024         }
02025       else
02026         {
02027           cout << "# " << name << " is not a version tag" << endl;
02028         }
02029     }
02030 }
02031 
02032 //----------------------------------------------------------
02033 void Cmt::do_checkout (const ArgParser& ap)
02034 {
02035   Cvs::checkout (ap.arguments);
02036 }
02037 
02038 //----------------------------------------------------------
02039 void Cmt::do_cleanup (const ArgParser& ap)
02040 {
02041   print_clean (ap.mode);
02042 }
02043 
02044 //----------------------------------------------------------
02045 void Cmt::do_config (const ArgParser& ap)
02046 {
02047   if (CmtLock::check () == CmtLock::locked_by_another_user)
02048     {
02049       CmtError::set (CmtError::conflicting_lock, "config>");
02050       return;
02051     }
02052 
02053     //Use::UsePtrVector& Uses = Use::get_ordered_uses ();
02054 
02055   if (Me.m_debug)
02056     {
02057       cout << "Cmt::do_config> " << endl;
02058       cout << "pwd " << CmtSystem::pwd () << endl;
02059       cout << "current_dir " << Me.m_current_dir << endl;
02060       cout << "default_path " << Me.m_default_path << endl;
02061       cout << "cmt config " <<
02062           Me.m_current_package << " " <<
02063           Me.m_current_version << " " <<
02064           Me.m_current_path << endl;
02065     }
02066 
02067   if (Me.m_current_package == "CMT") return;
02068   if (Me.m_current_package == "methods") return;
02069 
02070   cmt_string branch;
02071 
02072   CmtSystem::basename (Me.m_current_dir, branch);
02073 
02074   if ((branch != "mgr") && (branch != "cmt"))
02075     {
02076 
02077         //
02078         // Here we are in a standalone package (ie completely unstructured)
02079         //
02080 
02081       if (CmtSystem::test_file ("requirements"))
02082         {
02083           cout << "------------------------------------------" << endl;
02084           cout << "Configuring environment for standalone package." << endl;
02085           cout << "CMT version " << Me.m_cmt_version << "." << endl;
02086           cout << "System is " << Me.m_cmt_config << endl;
02087           cout << "------------------------------------------" << endl;
02088 
02089           install_test_setup_scripts ();
02090           install_test_cleanup_scripts ();
02091 
02092           Generator::build_default_makefile ();
02093         }
02094       else
02095         {
02096           cout << "==============================================" << endl;
02097           cout << "cmt config must be operated either upon "
02098             "an existing package" << endl;
02099           cout << " (ie. when a requirements file already exists)" << endl;
02100           cout << "   > cd ..." << endl;
02101           cout << "   > cmt config" << endl;
02102           cout << "or to create a new package" << endl;
02103           cout << "   > cmt config <package> <version> [<path>]" << endl;
02104           cout << "==============================================" << endl;
02105         }
02106 
02107       return;
02108     }
02109 
02110   configure_current_package ();
02111 
02112   Generator::build_default_makefile ();
02113 
02114   CmtSystem::cmt_string_vector makes;
02115   cmt_regexp expression ("[.]n?make(sav)?$");
02116 
02117   CmtSystem::scan_dir (".", expression, makes);
02118 
02119   if (makes.size () > 0)
02120     {
02121       cout << "Removing all previous make fragments from " << branch << endl;
02122 
02123       for (int i = 0; i < makes.size (); i++)
02124         {
02125           const cmt_string& s = makes[i];
02126           CmtSystem::remove_file (s);
02127         }
02128     }
02129 
02130   CmtSystem::cd ("..");
02131 
02132   CmtSystem::scan_dir (Me.m_cmt_config, expression, makes); 
02133     
02134   if (makes.size () > 0) 
02135     {
02136       cout << "Removing all previous make fragments from "
02137            << Me.m_cmt_config << endl; 
02138 
02139       for (int i = 0; i < makes.size (); i++) 
02140         { 
02141           const cmt_string& s = makes[i]; 
02142           CmtSystem::remove_file (s); 
02143         }    
02144     } 
02145 
02146   /*
02147   // cout << "Try a cleanup of the installation area " << endl;
02148 
02149     //
02150     //  Try a cleanup of the installation area
02151     //
02152   if (get_strategy ("InstallArea"))
02153     {
02154       CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
02155 
02156       //cout << "#IA3>" << endl;
02157 
02158       if (get_strategy ("SetupCleanup"))
02159         {
02160           ia_mgr.config ();
02161         }
02162     }
02163   */
02164 
02165   CmtSystem::cd (branch); 
02166 
02167   Use& use = Use::current ();
02168 
02169   use.set (Me.m_current_package,
02170            Me.m_current_version,
02171            Me.m_current_path,
02172            "",
02173            "");
02174 
02175   use.change_path (Me.m_current_path);
02176   use.style     = Me.m_current_style;
02177 
02178   //cout << "do_config> current style=" << Me.m_current_style << endl;
02179 
02180   Me.m_quiet = true;
02181 
02182   if (!reach_current_package ())
02183     {
02184       cout << "Cannot read the requirements file" << endl;
02185       return;
02186     }
02187 
02188   install_setup_scripts ();
02189   install_cleanup_scripts ();
02190 
02191   CmtSystem::cd ("..");
02192 
02193   Branch::BranchVector& branches = Branch::branches ();
02194 
02195   int i;
02196 
02197   for (i = 0; i < branches.size (); i++)
02198     {
02199       const Branch& branch = branches[i];
02200       const cmt_string& branch_name = branch.name ();
02201 
02202       if (!CmtSystem::test_directory (branch_name))
02203         {
02204           if (!CmtSystem::mkdir (branch_name))
02205             {
02206               cout << "Cannot create the " << branch_name <<" branch" << endl;
02207             }
02208           else
02209             {
02210               cout << "Installing the " << branch_name << " directory" << endl;
02211             }
02212         }
02213       else
02214         {
02215           cout << branch_name << " directory already installed" << endl;
02216         }
02217     }
02218 }
02219 
02220 //----------------------------------------------------------
02221 void Cmt::do_create (const ArgParser& ap)
02222 {
02223   if (ap.arguments.size () < 2) return;
02224 
02225   const cmt_string& package = ap.arguments[0];
02226   const cmt_string& version = ap.arguments[1];
02227   cmt_string offset;
02228   if (ap.arguments.size () >= 3) offset = ap.arguments[2];
02229 
02230   if (Me.m_debug)
02231     {
02232       cout << "do_create>Me.m_current_package=" << Me.m_current_package << endl;
02233       cout << "do_create>package=" << package << endl;
02234     }
02235 
02236     //if (Me.m_current_package == "CMT") return;
02237     //if (Me.m_current_package == "methods") return;
02238 
02239   cmt_string the_path;
02240 
02241   the_path = CmtSystem::pwd ();
02242 
02243   if (offset != "")
02244     {
02245       if (!CmtSystem::absolute_path (offset))
02246         {
02247           // offset is really a relative offset
02248           the_path += CmtSystem::file_separator ();
02249           the_path += offset;
02250         }
02251       else // absolute path
02252         {
02253           the_path = offset;
02254         }
02255     }
02256 
02257   CmtSystem::compress_path (the_path);
02258 
02259   // Now 'the_path' contains the complete path where the package will be created
02260 
02261   cout << "------------------------------------------" << endl;
02262   cout << "Configuring environment for package " << package <<
02263     " version " << version << "." << endl;
02264   cout << "CMT version " << Me.m_cmt_version << "." << endl;
02265   cout << "Root set to " << the_path << "." << endl;
02266   cout << "System is " << Me.m_cmt_config << endl;
02267   cout << "------------------------------------------" << endl;
02268 
02269   if (!CmtSystem::test_directory (the_path))
02270     {
02271       if (!CmtSystem::mkdir (the_path))
02272         {
02273           cout << "Cannot create the path directory" << endl;
02274           return;
02275         }
02276       else
02277         {
02278           cout << "Installing the path directory" << endl;
02279         }
02280     }
02281 
02282   CmtSystem::cd (the_path);
02283 
02284   if (!CmtSystem::test_directory (package))
02285     {
02286       if (!CmtSystem::mkdir (package))
02287         {
02288           cout << "Cannot create the package directory" << endl;
02289           return;
02290         }
02291       else
02292         {
02293           cout << "Installing the package directory" << endl;
02294         }
02295     }
02296   else
02297     {
02298       cout << "Package directory already installed" << endl;
02299     }
02300 
02301   CmtSystem::cd (package);
02302 
02303   if (Me.m_current_structuring_style == with_version_directory)
02304     {
02305       if (!CmtSystem::test_directory (version))
02306         {
02307           if (!CmtSystem::mkdir (version))
02308             {
02309               cout << "Cannot create the version directory" << endl;
02310               return;
02311             }
02312           else
02313             {
02314               cout << "Installing the version directory" << endl;
02315             }
02316         }
02317       else
02318         {
02319           cout << "Version directory already installed" << endl;
02320         }
02321 
02322       CmtSystem::cd (version);
02323     }
02324   else
02325     {
02326       cout << "Version directory will not be created due to structuring style" << endl;
02327     }
02328 
02329   if (!CmtSystem::test_directory ("cmt"))
02330     {
02331       if (!CmtSystem::test_directory ("mgr"))
02332         {
02333           if (!CmtSystem::mkdir ("cmt"))
02334             {
02335               cout << "Cannot create the cmt directory" << endl;
02336               return;
02337             }
02338           else
02339             {
02340               if (Me.m_current_structuring_style == with_version_directory)
02341                 {
02342                   Me.m_current_style = cmt_style;
02343                 }
02344               else
02345                 {
02346                   Me.m_current_style = no_version_style;
02347                 }
02348 
02349               cout << "Installing the cmt directory" << endl;
02350             }
02351         }
02352       else
02353         {
02354           if (Me.m_current_structuring_style == with_version_directory)
02355             {
02356               Me.m_current_style = mgr_style;
02357             }
02358           else
02359             {
02360               Me.m_current_style = no_version_style;
02361             }
02362           
02363           cout << "Mgr directory already installed" << endl;
02364         }
02365     }
02366   else
02367     {
02368       if (Me.m_current_structuring_style == with_version_directory)
02369         {
02370           Me.m_current_style = cmt_style;
02371         }
02372       else
02373         {
02374           Me.m_current_style = no_version_style;
02375         }
02376 
02377       cout << "Cmt directory already installed" << endl;
02378     }
02379 
02380   if (!CmtSystem::test_directory ("src"))
02381     {
02382       if (!CmtSystem::mkdir ("src"))
02383         {
02384           cout << "Cannot create the src directory" << endl;
02385           return;
02386         }
02387       else
02388         {
02389           cout << "Installing the src directory" << endl;
02390         }
02391     }
02392   else
02393     {
02394       cout << "src directory already installed" << endl;
02395     }
02396 
02397   switch (Me.m_current_style)
02398     {
02399     case cmt_style:
02400     case no_version_style:
02401       CmtSystem::cd ("cmt");
02402       break;
02403     case mgr_style:
02404       CmtSystem::cd ("mgr");
02405       break;
02406     }
02407 
02408   Generator::build_default_makefile ();
02409 
02410   if (!CmtSystem::test_file ("requirements"))
02411     {
02412       // create an empty requirement file.
02413       ofstream f ("requirements");
02414       if (f)
02415         {
02416           f << "package " << package << endl;
02417           f << endl;
02418           f.close ();
02419         }
02420     }
02421 
02422   if (Me.m_current_structuring_style == without_version_directory)
02423     {
02424       ofstream f ("version.cmt");
02425       if (f)
02426         {
02427           f << version << endl;
02428           f.close ();
02429         }
02430     }
02431 
02432   Me.m_current_package = package;
02433   Me.m_current_version = version;
02434   Me.m_current_path    = the_path;
02435   Me.m_current_dir     = CmtSystem::pwd ();
02436 
02437   do_config (ap);
02438 }
02439 
02440 //----------------------------------------------------------
02441 void Cmt::do_create_project (const ArgParser& ap)
02442 {
02443   if (ap.arguments.size () < 1) return;
02444 
02445   const cmt_string& project = ap.arguments[0];
02446   const cmt_string& release = ap.arguments[1];
02447   cmt_string path;
02448 
02449   if (ap.arguments.size () >= 3)
02450     {
02451       path = ap.arguments[2];
02452     }
02453 
02454   Project::create (project, release, path);
02455 }
02456 
02457 //----------------------------------------------------------
02458 void Cmt::do_cvsbranches (const ArgParser& ap)
02459 {
02460   Cvs::branches (ap.arguments[0]);
02461 }
02462 
02463 //----------------------------------------------------------
02464 void Cmt::do_cvssubpackages (const ArgParser& ap)
02465 {
02466   Cvs::subpackages (ap.arguments[0]);
02467 }
02468 
02469 //----------------------------------------------------------
02470 void Cmt::do_cvssubprojects (const ArgParser& ap)
02471 {
02472   Cvs::subprojects (ap.arguments[0]);
02473 }
02474 
02475 //----------------------------------------------------------
02476 void Cmt::do_cvstags (const ArgParser& ap)
02477 {
02478   Cvs::tags (ap.arguments);
02479 }
02480 
02481 //----------------------------------------------------------
02482 void Cmt::do_do (const ArgParser& ap)
02483 {
02484   if (ap.arguments.size () > 0) 
02485     {
02486       set_standard_macros ();
02487       Cmt::reset_all_sets_done ();
02488       Symbol::all_set ();
02489       Generator::build_default_makefile ();
02490 
02491       Symbol* symbol = Symbol::find (ap.arguments[0]);
02492 
02493       if (symbol == 0)
02494         {
02495           Me.m_action = action_show_action_names;
02496           /*
02497           if (!Me.m_quiet)
02498             {
02499               cerr << "Existing actions:" << endl;
02500               print_symbol_names (ap.mode);
02501             }
02502           */
02503           CmtError::set (CmtError::unknown_command, ap.arguments[0]);
02504           return;
02505         }
02506 
02507       /*
02508         We convert extra arguments into the standard macro cmt_args 
02509       */
02510 
02511       cmt_string args;
02512 
02513       for (int i = 1; i < ap.arguments.size (); i++)
02514         {
02515           cmt_string s = ap.arguments[i];
02516           if (i > 1) args += " ";
02517           args += s;
02518         }
02519 
02520       cmt_string r = "macro cmt_args \"";
02521       r += args;
02522       r += "\"";
02523 
02524       Use* current_use = &(Use::current ());
02525       
02526       SyntaxParser::parse_requirements_line (r, current_use);
02527 
02528       cmt_string cmd = symbol->build_macro_value ();
02529       Symbol::expand (cmd);
02530 
02531       cout << "Execute action " << ap.arguments[0] << " => " << cmd << endl;
02532 
02533       CmtSystem::execute (cmd);
02534     }
02535 }
02536 
02537 //----------------------------------------------------------
02538 void Cmt::do_expand_model (const ArgParser& ap)
02539 {
02540   set_standard_macros ();
02541 
02542   if ((ap.arguments[0] == "-strict") && (ap.arguments.size () > 1))
02543     {
02544       CmtModel::strict_expand (ap.arguments[1]);
02545     }
02546   else if ((ap.arguments[0] == "-test") && (ap.arguments.size () > 2))
02547     {
02548       CmtModel::test_regexp (ap.arguments[1], ap.arguments[2]);
02549     }
02550   else if (ap.arguments.size () > 0)
02551     {
02552       CmtModel::expand (ap.arguments[0]);
02553     }
02554 }
02555 
02566 void Cmt::do_filter (const ArgParser& ap)
02567 {
02568   if (ap.arguments.size () < 2) return;
02569 
02570   cmt_string& input = ap.arguments[0];
02571   cmt_string& output = ap.arguments[1];
02572 
02573   if (!CmtSystem::test_file (input))
02574     {
02575       cerr << "#CMT> File " << input << " not found" << endl;
02576       return;
02577     }
02578 
02579   cmt_string text;
02580 
02581   text.read (input);
02582 
02583   set_standard_macros ();
02584 
02585   Symbol::expand (text);
02586 
02587   FILE* file = fopen (output, "wb");
02588   if (file == NULL)
02589     {
02590       cerr << "#CMT> Cannot write filtered file " << output << endl;
02591     }
02592   else
02593     {
02594       text.write (file);
02595       fclose (file);
02596     }
02597 }
02598 
02599 //----------------------------------------------------------
02600 void Cmt::do_help (const ArgParser& ap)
02601 {
02602   //cerr << "ap.help_action=" << ap.help_action << " Me.m_action=" << Me.m_action << endl;
02603   if (Me.m_action == action_none)
02604     {
02605       CommandHelp::show_all ();
02606     }
02607   else
02608     {
02609       CommandHelp::show (Me.m_action);
02610     }
02611 }
02612 
02613 //----------------------------------------------------------
02614 void Cmt::do_lock (const ArgParser& ap)
02615 {
02616   const cmt_string& package = Me.m_current_package;
02617   const cmt_string& version = Me.m_current_version;
02618   const cmt_string& path    = Me.m_current_path;
02619 
02620   //(unsused) Use& use = Use::current();
02621 
02622   cout << "try to lock package " << package << " in " << CmtSystem::pwd () << endl;
02623 
02624   set_standard_macros ();
02625 
02626   CmtLock::status status = CmtLock::lock ();
02627 }
02628 
02629 //----------------------------------------------------------
02630 void Cmt::do_remove (const ArgParser& ap)
02631 {
02632   const cmt_string& package = Me.m_current_package;
02633   const cmt_string& version = Me.m_current_version;
02634   const cmt_string& path    = Me.m_current_path;
02635 
02636     //Use::UsePtrVector& Uses = Use::get_ordered_uses ();
02637 
02638   if (Me.m_current_package == "CMT") return;
02639   if (Me.m_current_package == "methods") return;
02640 
02641   cmt_string the_path;
02642 
02643   //the_path = Me.m_default_path;
02644   the_path = CmtSystem::pwd ();
02645 
02646   if (path != "")
02647     {
02648       if (!CmtSystem::absolute_path (path))
02649         {
02650           // path is just a suffix
02651           the_path += CmtSystem::file_separator ();
02652           the_path += path;
02653         }
02654       else // absolute path
02655         {
02656           the_path = path;
02657         }
02658     }
02659 
02660   CmtSystem::compress_path (the_path);
02661 
02662   cout << "------------------------------------------" << endl;
02663   cout << "Removing package " << package <<
02664     " version " << version << "." << endl;
02665   cout << "CMT version " << Me.m_cmt_version << "." << endl;
02666   cout << "Root set to " << the_path << "." << endl;
02667   cout << "System is " << Me.m_cmt_config << endl;
02668   cout << "------------------------------------------" << endl;
02669 
02670   the_path += CmtSystem::file_separator ();
02671   the_path += package;
02672 
02673   if (!CmtSystem::cd (the_path))
02674     {
02675       cout << "Path " << the_path << " not reachable" << endl;
02676       return;
02677     }
02678 
02679   if (CmtSystem::test_directory (version))
02680     {
02681       if (CmtSystem::remove_directory (version))
02682         {
02683           cout << "Version " << version << " has been removed from " << the_path << endl;
02684           CmtSystem::cmt_string_vector contents;
02685           CmtSystem::scan_dir (".", contents);
02686           if (contents.size () == 0)
02687             {
02688               CmtSystem::cd ("..");
02689               if (CmtSystem::remove_directory (package))
02690                 {
02691                   cout << "Package " << package << " has no more versions. Thus it has been removed."<< endl;
02692                 }
02693             }
02694         }
02695       else
02696         {
02697           cout << "Impossible to remove version " << version << " from " << the_path << endl;
02698         }
02699     }
02700   else if (CmtSystem::test_directory ("cmt"))
02701     {
02702       CmtSystem::cd ("cmt");
02703 
02704       cmt_string v;
02705 
02706       v.read ("version.cmt");
02707       if (v == version)
02708         {
02709           CmtSystem::cd ("..");
02710           if (!CmtSystem::remove_directory ("cmt"))
02711             {
02712               cout << "Unstructured version " << version
02713                    << " has been removed from " << the_path << endl;
02714             }
02715           else
02716             {
02717               cout << "Impossible to remove unstructured version " << version
02718                    << " from " << the_path << endl;
02719             }
02720         }
02721       else
02722         {
02723           cout << "Version " << version << " not found" << endl;
02724         }
02725     }
02726   else
02727     {
02728       cout << "Version " << version << " not found" << endl;
02729     }
02730 }
02731 
02732 //----------------------------------------------------------
02733 void Cmt::do_remove_library_links (const ArgParser& ap)
02734 {
02735   if (CmtLock::check () == CmtLock::locked_by_another_user)
02736     {
02737       CmtError::set (CmtError::conflicting_lock, "remove_library_links>");
02738       return;
02739     }
02740 
02741   set_standard_macros ();
02742 
02743   Use::UsePtrVector& Uses = Use::get_ordered_uses ();
02744   Use& current_use = Use::current ();
02745   int i;
02746   cmt_string shlibsuffix;
02747   cmt_string symunlink;
02748 
02749   {
02750     Symbol* macro = Symbol::find ("shlibsuffix");
02751     if (macro == 0) return;
02752     shlibsuffix = macro->build_macro_value ();
02753     Symbol::expand (shlibsuffix);
02754   }
02755 
02756   {
02757     Symbol* macro = Symbol::find ("symunlink");
02758     if (macro == 0) return;
02759     symunlink = macro->build_macro_value ();
02760     Symbol::expand (symunlink);
02761   }
02762 
02763   for (i = 0; i < Uses.size (); i++)
02764     {
02765       Use* use = Uses[i];
02766 
02767       if (use->discarded) continue;
02768 
02769       if (!use->located ())
02770         {
02771           if (!Me.m_quiet)
02772             {
02773               cerr << "#CMT> package " << use->get_package_name () <<
02774                   " " << use->version << " " << use->path << 
02775                   " not found" <<
02776                   endl;
02777             }
02778         }
02779       else
02780         {
02781           if (use->get_package_name () == "CMT") continue;
02782           if (use->get_package_name () == current_use.get_package_name ()) continue;
02783 
02784           cmt_string s;
02785 
02786           s = use->get_package_name ();
02787           s += "_libraries";
02788 
02789           Symbol* libraries_macro = Symbol::find (s);
02790 
02791           if (libraries_macro == 0) continue;
02792 
02793           cmt_string libraries = libraries_macro->build_macro_value ();
02794           Symbol::expand (libraries);
02795 
02796           static CmtSystem::cmt_string_vector values;
02797 
02798           CmtSystem::split (libraries, " \t", values);
02799 
02800           for (int j = 0; j < values.size (); j++)
02801             {
02802               const cmt_string& library = values[j];
02803 
02804               static cmt_string libname;
02805               static cmt_string name;
02806 
02807               // Is it a simple name or a complete path?
02808 
02809               libname = library;
02810               Symbol::expand (libname);
02811 
02812               if (CmtSystem::absolute_path (libname))
02813                 {
02819                   cmt_string suffix;
02820                   CmtSystem::basename (library, name);
02821                 }
02822               else
02823                 {
02831                   name = "lib";
02832                   name += libname;
02833                   name += ".";
02834                   name += shlibsuffix;
02835                 }
02836 
02837               Symbol::expand (libname);
02838 
02839               if (get_strategy ("InstallArea"))
02840                 {
02841                   const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
02842 
02843                   //cout << "#IA4>" << endl;
02844 
02845                   cmt_string s1 = ia_mgr.get_installarea ();
02846 
02847                   {
02848                     Symbol* symbol = Symbol::find ("CMTINSTALLAREA");
02849                     if (symbol != 0)
02850                       {
02851                         s1 = symbol->build_macro_value ();
02852                         Symbol::expand (s1);
02853                       }
02854                   }
02855                   
02856                   cmt_string s2;
02857 
02858                   {
02859                     Symbol* macro = Symbol::find ("tag");
02860                     if (macro != 0)
02861                       {
02862                         s2 = macro->build_macro_value ();
02863                         Symbol::expand (s2);
02864                       }
02865                   }
02866 
02867                     // Now deleting the reference file
02868 
02869                   s = symunlink;
02870                   s += " ";
02871                   s += s1;
02872                   s += CmtSystem::file_separator ();
02873                   s += s2;
02874                   s += CmtSystem::file_separator ();
02875                   s += "lib";
02876                   s += CmtSystem::file_separator ();
02877                   s += name;
02878                   s += ".cmtref";
02879                   s += " ";
02880                   s += s1;
02881                   s += CmtSystem::file_separator ();
02882                   s += s2;
02883                   s += CmtSystem::file_separator ();
02884                   s += "lib";
02885                   s += CmtSystem::file_separator ();
02886                   s += name;
02887                 }
02888               else
02889                 {
02890                   s = symunlink;
02891                   s += " ../$(";
02892                   s += current_use.get_package_name ();
02893                   s += "_tag)/";
02894                   s += name;
02895                 }
02896 
02897               Symbol::expand (s);
02898 
02899               if (!Me.m_quiet) cout << s << endl;
02900               int status = CmtSystem::execute (s);
02901 
02902               if (status != 0)
02903                 {
02904                   if (status != 2) CmtError::set (CmtError::execution_error, s);
02905 
02906                   cerr << "#CMT> Cannot remove the symbolic link " << s << endl;
02907 
02908                   break;
02909                 }
02910             }
02911         }
02912     }
02913 }
02914 
02915 //----------------------------------------------------------
02916 void Cmt::do_run (const ArgParser& ap)
02917 {
02918   if (ap.arguments.size () > 0) 
02919     {
02920       set_standard_macros ();
02921       Cmt::reset_all_sets_done ();
02922       Symbol::all_set ();
02923 
02924       cmt_string cmd;
02925 
02926       for (int i = 0; i < ap.arguments.size (); i++)
02927         {
02928           cmd += ap.arguments[i];
02929           cmd += " ";
02930         }
02931 
02932       CmtSystem::execute (cmd);
02933     }
02934 }
02935 
02936 //----------------------------------------------------------
02937 void Cmt::do_run_sequence (const ArgParser& ap)
02938 {
02939   if (ap.arguments.size () == 0) cerr << "#CMT> run_sequence: no sequence specified" << endl;
02940 
02941   SequenceRunner runner;
02942 
02943   cout << "# cmt run_sequence: sequence " << ap.arguments[0] << endl;
02944 
02945   runner.run (ap.arguments[0]);
02946 }
02947 
02948 //----------------------------------------------------------
02949 void Cmt::do_set_version (const ArgParser& ap)
02950 {
02951   if (ap.arguments.size () == 0) cerr << "#CMT> set version: no version specified" << endl;
02952 
02953   const cmt_string& version = ap.arguments[0];
02954 
02955   int v, r, p;
02956 
02957   if (!CmtSystem::is_version_directory (version, v, r, p))
02958     {
02959       cerr << "#CMT> set version " << version << " is not a correct version syntax" << endl;
02960       return;
02961     }
02962 
02963   if ((v == -1) || (r == -1) || (p == -1))
02964     {
02965       cerr << "#CMT> set version " << version
02966            << " You cannot use wild card to set a version" << endl;
02967       return;
02968     }
02969 
02970   // We want to install the version.cmt file
02971 
02972   // We first check we are in a cmt branch
02973   cmt_string h = CmtSystem::pwd ();
02974   cmt_string branch;
02975   CmtSystem::basename (h, branch);
02976 
02977   if (branch != "cmt")
02978     {
02979       cerr << "#CMT> set version " << version << " must be applied in a cmt directory" 
02980            << endl;
02981       return;
02982     }
02983 
02984   CmtSystem::dirname (h, h);
02985   CmtSystem::basename (h, branch);
02986 
02987   if (branch == version)
02988     {
02989       cerr << "#CMT> set version " << version << " is already available as a version directory" 
02990            << endl;
02991       return;
02992     }
02993 
02994   cout << "Writing version file : " << version << endl;
02995 
02996   version.write ("version.cmt");
02997 }
02998 
02999 //----------------------------------------------------------
03000 void Cmt::do_set_versions (const ArgParser& ap)
03001 {
03002   CmtSystem::cmt_string_vector args;
03003 
03004   args = ap.arguments;
03005   {
03006     cmt_string& s = args.add ();
03007     s = "cmt";
03008   }
03009   {
03010     cmt_string& s = args.add ();
03011     s = "set";
03012   }
03013   {
03014     cmt_string& s = args.add ();
03015     s = "version";
03016   }
03017   {
03018     cmt_string& s = args.add ();
03019     s = "<version>";
03020   }
03021 
03022   Me.m_action = action_broadcast;
03023 
03024   do_broadcast (ap);
03025 }
03026 
03027 //----------------------------------------------------------
03028 void Cmt::do_setup (const ArgParser& ap)
03029 {
03030 
03031   do_check_configuration (ap);
03032 
03033   print (ap.mode);
03034 
03035     //
03036     //  Try a cleanup of the installation area
03037     //
03038   if (get_strategy ("InstallArea"))
03039     {
03040       CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
03041 
03042       //cout << "#IA5>" << endl;
03043 
03044       ia_mgr.setup ();
03045 
03046       /*
03047       if (get_strategy ("SetupCleanup"))
03048         {
03049           const cmt_string& installarea = ia_mgr.get_installarea ();
03050 
03051           if (installarea != "")
03052             {
03053               cmt_string q;
03054               
03055               switch (mode)
03056                 {
03057                 case Sh :
03058                 case Csh :
03059                   q = "\'";
03060                   break;
03061                 default :
03062                   break;
03063                 }
03064               
03065               if (!Me.m_quiet)
03066                 {
03067                   cout << "echo "  << q 
03068                        << "# Doing cleanup in the installation area " << installarea 
03069                        << q << endl;
03070                 }
03071             }
03072 
03073           ia_mgr.config ();
03074         }
03075       */
03076     }
03077 }
03078 
03079 //----------------------------------------------------------
03080 void Cmt::do_show_action (const ArgParser& ap)
03081 {
03082   cmt_string target;
03083 
03084   if (ap.arguments.size () > 0) target = ap.arguments[0];
03085 
03086   Symbol* symbol;
03087 
03088   set_standard_macros ();
03089 
03090   symbol = Symbol::find (target);
03091 
03092   if (symbol == 0) 
03093     {
03094       cmt_string t = " ";
03095       t += target;
03096       t += " is not defined ";
03097 
03098       CmtError::set (CmtError::symbol_not_found, t);
03099 
03100       return;
03101     }
03102   else
03103     {
03104       cmt_string t = target;
03105       t += " is a ";
03106 
03107       if ((Me.m_action == action_show_action) ||
03108           (Me.m_action == action_show_action_value))
03109         {
03110           if (symbol->type != Symbol::SymbolAction)
03111             {
03112               if (symbol->type == Symbol::SymbolMacro)
03113                 {
03114                   t += "macro";
03115                 }
03116               else if (symbol->type == Symbol::SymbolSet)
03117                 {
03118                   t += "set";
03119                 }
03120               else if (symbol->type == Symbol::SymbolPath)
03121                 {
03122                   t += "path";
03123                 }
03124               else if (symbol->type == Symbol::SymbolAlias)
03125                 {
03126                   t += "alias";
03127                 }
03128 
03129               CmtError::set (CmtError::warning, t);
03130             }
03131         }
03132     }
03133 
03134   if (symbol->value_lists.size () < 1) return;
03135 
03136   symbol->show_macro (ap.mode);
03137 }
03138 
03139 //----------------------------------------------------------
03140 void Cmt::do_show_action_names (const ArgParser& ap)
03141 {
03142   if (ap.arguments.size () > 0)
03143     {
03144       const cmt_string& pattern = ap.arguments[0];
03145       print_symbol_names (ap.mode, pattern);
03146     }
03147   else
03148     {
03149       print_symbol_names (ap.mode);
03150     }
03151 }
03152 
03153 //----------------------------------------------------------
03154 void Cmt::do_show_action_value (const ArgParser& ap)
03155 {
03156   do_show_macro (ap);
03157 }
03158 
03159 //----------------------------------------------------------
03160 void Cmt::do_show_actions (const ArgParser& ap)
03161 {
03162   if (ap.arguments.size () > 0)
03163     {
03164       const cmt_string& pattern = ap.arguments[0];
03165       print_macros (ap.mode, pattern);
03166     }
03167   else
03168     {
03169       print_macros (ap.mode);
03170     }
03171 }
03172 
03173 //----------------------------------------------------------
03174 void Cmt::do_show_all_tags (const ArgParser& /*ap*/)
03175 {
03176   Tag::TagPtrVector tags = Tag::tags ();
03177   int index;
03178 
03179   set_standard_macros ();
03180 
03181   for (index = 0; index < tags.size (); index++)
03182     {
03183       const Tag* tag = tags[index];
03184       if (tag != 0)
03185         {
03186           tag->show_definition (true);
03187         }
03188     }
03189 }
03190 
03191 //----------------------------------------------------------
03192 void Cmt::do_show_applied_patterns (const ArgParser& /*ap*/)
03193 {
03194   Pattern::show_all_applied_patterns ();
03195 }
03196 
03197 //----------------------------------------------------------
03198 void Cmt::do_show_author (const ArgParser& /*ap*/)
03199 {
03200   Use& use = Use::current();
03201 
03202   cout << use.author << endl;
03203 }
03204 
03205 //----------------------------------------------------------
03206 void Cmt::do_show_branches (const ArgParser& ap)
03207 {
03208   Branch::print_all (ap.mode);
03209 }
03210 
03211 //----------------------------------------------------------
03212 void Cmt::do_show_clients (const ArgParser& ap)
03213 {
03214   cmt_string package;
03215   cmt_string version;
03216   cmt_string path_name;
03217 
03218   if (ap.arguments.size () >= 1) package = ap.arguments[0];
03219   if (ap.arguments.size () >= 2) version = ap.arguments[1];
03220   if (ap.arguments.size () >= 3) path_name = ap.arguments[2];
03221 
03222   PathScanner scanner;
03223   ClientCollector collector (package, version);
03224 
03225   clear ();
03226   configure ();
03227 
03228   cout << "# ----------- Clients of " << package <<
03229     " " << version <<
03230     " " << path_name <<
03231     endl;
03232 
03233   if (path_name == "")
03234     {
03235       Project::scan_paths (scanner, collector);
03236     }
03237   else
03238     {
03239       scanner.scan_path (path_name, collector);
03240     }
03241   cout << "# ----------- " << collector.count () << " clients found." << endl;
03242 }
03243 
03244 //----------------------------------------------------------
03245 void Cmt::do_show_cmtpath_patterns (const ArgParser& /*ap*/)
03246 {
03247   set_standard_macros ();
03248   CmtPathPattern::show_all ();
03249 }
03250 
03251 //----------------------------------------------------------
03252 void Cmt::do_show_constituent (const ArgParser& ap)
03253 {
03254   if (ap.arguments.size () > 0) 
03255     {
03256       set_standard_macros ();
03257 
03258       Constituent* c = Constituent::find (ap.arguments[0]);
03259       if (c != 0)
03260         {
03261           c->show ();
03262         }
03263     }
03264 }
03265 
03266 //----------------------------------------------------------
03267 void Cmt::do_show_constituent_names (const ArgParser& /*ap*/)
03268 {
03269   set_standard_macros ();
03270   Constituent::show_names ();
03271 }
03272 
03273 //----------------------------------------------------------
03274 void Cmt::do_show_constituents (const ArgParser& /*ap*/)
03275 {
03276   set_standard_macros ();
03277   Constituent::show_all ();
03278 }
03279 
03280 //----------------------------------------------------------
03281 void Cmt::do_show_cycles (const ArgParser& /*ap*/)
03282 {
03283   set_standard_macros ();
03284   Use& use = Use::current();
03285 
03286   use.show_cycles ();
03287 }
03288 
03289 //----------------------------------------------------------
03290 void Cmt::do_show_fragment (const ArgParser& ap)
03291 {
03292   if (ap.arguments.size () > 0) Fragment::show (ap.arguments[0]);
03293 }
03294 
03295 //----------------------------------------------------------
03296 void Cmt::do_show_fragments (const ArgParser& /*ap*/)
03297 {
03298   Fragment::show_all ();
03299 }
03300 
03301 //----------------------------------------------------------
03302 void Cmt::do_show_groups (const ArgParser& /*ap*/)
03303 {
03304   Group::show_all ();
03305 }
03306 
03307 //----------------------------------------------------------
03308 void Cmt::do_show_include_dirs (const ArgParser& /*ap*/)
03309 {
03310   cmt_string temp;
03311 
03312   Use& use = Use::current();
03313 
03314   set_standard_macros ();
03315 
03316   if (use.include_path == "")
03317     {
03318       temp += "$(src) ";
03319     }
03320   else if (use.include_path != "none")
03321     {
03322       temp += use.include_path;
03323       temp += " ";
03324     }
03325 
03326   for (int include_number = 0;
03327        include_number < use.includes.size ();
03328        include_number++)
03329     {
03330       Include& incl = use.includes[include_number];
03331       
03332       temp += incl.name;
03333       temp += " ";
03334     }
03335 
03336   cout << temp << endl;
03337 }
03338 
03339 //----------------------------------------------------------
03340 void Cmt::do_show_language (const ArgParser& ap)
03341 {
03342   if (ap.arguments.size () > 0) 
03343     {
03344       set_standard_macros ();
03345       Language::show (ap.arguments[0]);
03346     }
03347 }
03348 
03349 //----------------------------------------------------------
03350 void Cmt::do_show_languages (const ArgParser& /*ap*/)
03351 {
03352   set_standard_macros ();
03353   Language::show_all ();
03354 }
03355 
03356 //----------------------------------------------------------
03357 void Cmt::do_show_macro (const ArgParser& ap)
03358 {
03359   cmt_string target;
03360 
03361   if (ap.arguments.size () > 0) target = ap.arguments[0];
03362 
03363   Symbol* symbol;
03364 
03365   set_standard_macros ();
03366 
03367   symbol = Symbol::find (target);
03368 
03369   if (symbol == 0) 
03370     {
03371       cmt_string t = " ";
03372       t += target;
03373       t += " is not defined ";
03374 
03375       CmtError::set (CmtError::symbol_not_found, t);
03376 
03377       return;
03378     }
03379   else
03380     {
03381       cmt_string t = target;
03382       t += " is a ";
03383 
03384       if ((Me.m_action == action_show_macro) ||
03385           (Me.m_action == action_show_macro_value))
03386         {
03387           if (symbol->type != Symbol::SymbolMacro)
03388             {
03389               if (symbol->type == Symbol::SymbolAction)
03390                 {
03391                   t += "action";
03392                 }
03393               else if (symbol->type == Symbol::SymbolSet)
03394                 {
03395                   t += "set";
03396                 }
03397               else if (symbol->type == Symbol::SymbolPath)
03398                 {
03399                   t += "path";
03400                 }
03401               else if (symbol->type == Symbol::SymbolAlias)
03402                 {
03403                   t += "alias";
03404                 }
03405 
03406               CmtError::set (CmtError::warning, t);
03407             }
03408         }
03409       else if ((Me.m_action == action_show_set) ||
03410                (Me.m_action == action_show_set_value))
03411         {
03412           if ((symbol->type != Symbol::SymbolSet) &&
03413               (symbol->type != Symbol::SymbolPath) &&
03414               (symbol->type != Symbol::SymbolAction) &&
03415               (symbol->type != Symbol::SymbolAlias))
03416             {
03417               t += "macro";
03418 
03419               CmtError::set (CmtError::warning, t);
03420             }
03421         }
03422     }
03423 
03424   if (symbol->value_lists.size () < 1) return;
03425 
03426   symbol->show_macro (ap.mode);
03427 }
03428 
03429 //----------------------------------------------------------
03430 void Cmt::do_show_macro_names (const ArgParser& ap)
03431 {
03432   if (ap.arguments.size () > 0)
03433     {
03434       const cmt_string& pattern = ap.arguments[0];
03435       print_symbol_names (ap.mode, pattern);
03436     }
03437   else
03438     {
03439       print_symbol_names (ap.mode);
03440     }
03441 }
03442 
03443 //----------------------------------------------------------
03444 void Cmt::do_show_macro_value (const ArgParser& ap)
03445 {
03446   do_show_macro (ap);
03447 }
03448 
03449 //----------------------------------------------------------
03450 void Cmt::do_show_macros (const ArgParser& ap)
03451 {
03452   if (ap.arguments.size () > 0)
03453     {
03454       const cmt_string& pattern = ap.arguments[0];
03455       print_macros (ap.mode, pattern);
03456     }
03457   else
03458     {
03459       print_macros (ap.mode);
03460     }
03461 }
03462 
03463 //----------------------------------------------------------
03464 void Cmt::do_show_manager (const ArgParser& /*ap*/)
03465 {
03466   Use& use = Use::current();
03467 
03468   cout << use.manager << endl;
03469 }
03470 
03471 //----------------------------------------------------------
03472 void Cmt::do_show_packages (const ArgParser& ap)
03473 {
03474   cmt_string path_name;
03475 
03476   if (ap.arguments.size () > 0) path_name = ap.arguments[0];
03477 
03478   PathScanner scanner;
03479   PackageViewer viewer;
03480 
03481   if (path_name == "")
03482     {
03483       Project::scan_paths (scanner, viewer);
03484     }
03485   else
03486     {
03487       scanner.scan_path (path_name, viewer);
03488     }
03489 }
03490 
03491 //----------------------------------------------------------
03492 void Cmt::do_show_path (const ArgParser& /*ap*/)
03493 {
03494   Project::show_paths ();
03495 }
03496 
03497 //----------------------------------------------------------
03498 void Cmt::do_show_pattern (const ArgParser& ap)
03499 {
03500   cmt_string name;
03501   if (ap.arguments.size () > 0) name = ap.arguments[0];
03502   Pattern::show (name);
03503 }
03504 
03505 //----------------------------------------------------------
03506 void Cmt::do_show_pattern_names (const ArgParser& /*ap*/)
03507 {
03508   Pattern::show_all_names ();
03509 }
03510 
03511 //----------------------------------------------------------
03512 void Cmt::do_show_patterns (const ArgParser& /*ap*/)
03513 {
03514   Pattern::show_all ();
03515 }
03516 
03517 //----------------------------------------------------------
03518 void Cmt::do_show_projects (const ArgParser& /*ap*/)
03519 {
03520   Project::show_all ();
03521 }
03522 
03523 //----------------------------------------------------------
03524 void Cmt::do_show_pwd (const ArgParser& /*ap*/)
03525 {
03526   cout << Me.m_current_dir << endl;
03527 }
03528 
03529 //----------------------------------------------------------
03530 void Cmt::do_show_setup (const ArgParser& ap)
03531 {
03532   cout << "----------> uses" << endl;
03533   do_show_uses (ap);
03534 
03535   cout << "----------> tags" << endl;
03536   do_show_tags (ap);
03537 
03538   cout << "----------> CMTPATH" << endl;
03539   do_show_path (ap);
03540 }
03541 
03542 //----------------------------------------------------------
03543 void Cmt::do_show_set (const ArgParser& ap)
03544 {
03545   do_show_macro (ap);
03546 }
03547 
03548 //----------------------------------------------------------
03549 void Cmt::do_show_set_names (const ArgParser& ap)
03550 {
03551   if (ap.arguments.size () > 0)
03552     {
03553       const cmt_string& pattern = ap.arguments[0];
03554       print_symbol_names (ap.mode, pattern);
03555     }
03556   else
03557     {
03558       print_symbol_names (ap.mode);
03559     }
03560 }
03561 
03562 //----------------------------------------------------------
03563 void Cmt::do_show_set_value (const ArgParser& ap)
03564 {
03565   do_show_macro (ap);
03566 }
03567 
03568 //----------------------------------------------------------
03569 void Cmt::do_show_sets (const ArgParser& ap)
03570 {
03571   if (ap.arguments.size () > 0)
03572     {
03573       const cmt_string& pattern = ap.arguments[0];
03574       print_macros (ap.mode, pattern);
03575     }
03576   else
03577     {
03578       print_macros (ap.mode);
03579     }
03580 }
03581 
03582 //----------------------------------------------------------
03583 void Cmt::do_show_strategies (const ArgParser& /*ap*/)
03584 {
03585   Project::show_specified_strategies_for_all ();
03586 
03587   Project* p = Project::get_current ();
03588 
03589   /*
03590     if (p != 0) p->show ();
03591     else cout << "No current project" << endl;
03592   */
03593 
03594   cout << "Structuring style : ";
03595 
03596   switch (Me.m_current_structuring_style)
03597     {
03598     case without_version_directory:
03599       cout << "without_version_directory";
03600       break;
03601     case with_version_directory:
03602       cout << "with_version_directory";
03603       break;
03604     }
03605 
03606   cout << endl;
03607 
03608   cout << "Build strategy    : ";
03609 
03610   if (get_strategy ("BuildPrototypes"))
03611     {
03612       cout << "prototypes";
03613     }
03614   else
03615     {
03616       cout << "no_prototypes";
03617     }
03618   
03619   if (get_strategy ("InstallArea"))
03620     {
03621       cout << " with_installarea";
03622     }
03623   else
03624     {
03625       cout << " without_installarea";
03626     }
03627   
03628   cout << endl;
03629 
03630   cout << "Setup strategy    : ";
03631   
03632   if (get_strategy ("SetupConfig"))
03633     {
03634       cout << "config";
03635     }
03636   else
03637     {
03638       cout << "no_config";
03639     }
03640   
03641   if (get_strategy ("SetupRoot"))
03642     {
03643       cout << " root";
03644     }
03645   else
03646     {
03647       cout << " no_root";
03648     }
03649   
03650   if (get_strategy ("SetupCleanup"))
03651     {
03652       cout << " cleanup";
03653     }
03654   else
03655     {
03656       cout << " no_cleanup";
03657     }
03658   
03659   cout << endl;
03660 }
03661 
03662 //----------------------------------------------------------
03663 void Cmt::do_show_tags (const ArgParser& /*ap*/)
03664 {
03665   Tag::TagPtrVector tags = Tag::tags ();
03666   int index;
03667 
03668   set_standard_macros ();
03669 
03670   for (index = 0; index < tags.size (); index++)
03671     {
03672       const Tag* tag = tags[index];
03673       if (tag != 0)
03674         {
03675           tag->show (Me.m_quiet);
03676         }
03677     }
03678 }
03679 
03680 //----------------------------------------------------------
03681 void Cmt::do_show_use_paths (const ArgParser& ap)
03682 {
03683   const cmt_string& to_name = ap.arguments[0];
03684 
03685   Use* current = &(Use::current());
03686 
03687   current->get_all_clients (to_name);
03688 }
03689 
03690 //----------------------------------------------------------
03691 void Cmt::do_show_uses (const ArgParser& /*ap*/)
03692 {
03693   Use::show_all ();
03694 }
03695 
03696 //----------------------------------------------------------
03697 void Cmt::do_show_version (const ArgParser& /*ap*/)
03698 {
03699   cout << Me.m_current_version << endl;
03700 }
03701 
03702 //----------------------------------------------------------
03703 void Cmt::do_show_versions (const ArgParser& ap)
03704 {
03705   cmt_string package_name;
03706 
03707   if (ap.arguments.size () > 0) package_name = ap.arguments[0];
03708 
03709   PathScanner scanner;
03710 
03711   Project::scan_paths_for_package (scanner, package_name);
03712 }
03713 
03714 //----------------------------------------------------------
03715 void Cmt::do_show_system (const ArgParser& /*ap*/)
03716 {
03717   cout << CmtSystem::get_cmt_config () << endl;
03718 }
03719 
03720 //----------------------------------------------------------
03721 void Cmt::do_unlock (const ArgParser& /*ap*/)
03722 {
03723   const cmt_string& package = Me.m_current_package;
03724   const cmt_string& version = Me.m_current_version;
03725   const cmt_string& path    = Me.m_current_path;
03726 
03727   // (unused??) Use& use = Use::current();
03728 
03729   cout << "try to unlock package " << package << " in " << CmtSystem::pwd () << endl;
03730 
03731   set_standard_macros ();
03732 
03733   CmtLock::status status = CmtLock::unlock ();
03734 }
03735 
03736 //----------------------------------------------------------
03737 void Cmt::do_version (const ArgParser& /*ap*/)
03738 {
03739   cout << CMTVERSION << endl;
03740 }
03741 
03742 
03743 
03744 //----------------------------------------------------------
03745 ActionType Cmt::get_action ()
03746 {
03747   return (Me.m_action);
03748 }
03749 
03750 /*
03751 const CmtSystem::cmt_string_vector& Cmt::get_cmt_path ()
03752 {
03753   return (Me.m_cmt_path);
03754 }
03755 
03756 const CmtSystem::cmt_string_vector& Cmt::get_cmt_path_pwds ()
03757 {
03758   return (Me.m_cmt_path_pwds);
03759 }
03760 
03761 const CmtSystem::cmt_string_vector& Cmt::get_cmt_path_sources ()
03762 {
03763   return (Me.m_cmt_path_sources);
03764 }
03765 */
03766 
03767 const cmt_string& Cmt::get_cmt_home ()
03768 {
03769   return (Me.m_cmt_home);
03770 }
03771 
03772 const cmt_string& Cmt::get_cmt_user_context ()
03773 {
03774   return (Me.m_cmt_user_context);
03775 }
03776 
03777 const cmt_string& Cmt::get_cmt_version ()
03778 {
03779   return (Me.m_cmt_version);
03780 }
03781 
03782 const cmt_string& Cmt::get_current_dir ()
03783 {
03784   return (Me.m_current_dir);
03785 }
03786 
03787 const cmt_string& Cmt::get_current_package ()
03788 {
03789   return (Me.m_current_package);
03790 }
03791 
03792 const cmt_string& Cmt::get_current_cmtpath ()
03793 {
03794   return (Me.m_current_cmtpath);
03795 }
03796 
03797 const cmt_string& Cmt::get_current_offset ()
03798 {
03799   return (Me.m_current_offset);
03800 }
03801 
03802 AccessMode Cmt::get_current_access ()
03803 {
03804   return (Me.m_current_access);
03805 }
03806 
03807 CmtStructuringStyle Cmt::get_current_structuring_style ()
03808 {
03809   return (Me.m_current_structuring_style);
03810 }
03811 
03812 CmtDirStyle Cmt::get_current_style ()
03813 {
03814   return (Me.m_current_style);
03815 }
03816 
03817 const cmt_string& Cmt::get_current_version ()
03818 {
03819   return (Me.m_current_version);
03820 }
03821 
03822 const cmt_string& Cmt::get_current_target ()
03823 {
03824   return (Me.m_current_target);
03825 }
03826 
03827 bool Cmt::get_debug ()
03828 {
03829   return (Me.m_debug);
03830 }
03831 
03832 bool Cmt::get_quiet ()
03833 {
03834   return (Me.m_quiet);
03835 }
03836 
03837 bool Cmt::get_recursive ()
03838 {
03839   return (Me.m_recursive);
03840 }
03841 
03842 CmtScopeFilteringMode Cmt::get_scope_filtering_mode ()
03843 {
03844   if (Me.m_scope_filtering_mode == default_filtering_mode)
03845     {
03846       return (block_private_uses);
03847     }
03848   else
03849     {
03850       return (Me.m_scope_filtering_mode);
03851     }
03852 }
03853 
03854 //----------------------------------------------------------
03855 bool Cmt::get_all_sets_done ()
03856 {
03857   return (Me.m_all_sets_done);
03858 }
03859 
03881 void Cmt::guess_current_project ()
03882 {
03883   Log;
03884 
03885   log << "guess_current_project" << log_endl;
03886 
03887   if (Project::find_in_cmt_paths (Me.m_current_dir) == "")
03888     {
03889       cmt_string project_file = "cmt";
03890       project_file += CmtSystem::file_separator ();
03891       project_file += Project::get_project_file_name ();
03892 
03893       cmt_string pwd;
03894 
03895       for (;;)
03896         {
03897           pwd = CmtSystem::pwd ();
03898           if (CmtSystem::test_file (project_file))
03899             {
03900               //this directory should become the first entry of the CMTPATH
03901 
03902               IProjectFactory& factory = ProjectFactory::instance ();
03903               factory.create_project ("", pwd, "CurrentProject", 0);
03904 
03905               /*
03906               cmt_string temp = "path_prepend CMTPATH \"";
03907               temp += pwd;
03908               temp += "\"";
03909               
03910               Use& use = Use::current();
03911 
03912               SyntaxParser::parse_requirements_line (temp, &use);
03913               */
03914 
03915               break;
03916             }
03917 
03918           log << "pwd=" << CmtSystem::pwd () << log_endl;
03919           
03920           if (!CmtSystem::cd (".."))
03921             {
03922               break;
03923             }
03924           if (CmtSystem::pwd () == pwd)
03925             {
03926               break;
03927             }
03928         }
03929       CmtSystem::cd (Me.m_current_dir);
03930     }
03931 
03932   //cmt_string buffer = "path CMTPATH \n";
03933   cmt_string buffer;
03934   Project::fill_cmtpaths (buffer);
03935   //cerr << "buffer = " << buffer << endl;
03936   Use& use = Use::current();
03937   bool save_quiet = Me.m_quiet;
03938   Me.m_quiet = true;
03939   SyntaxParser::parse_requirements_text (buffer, "", &use);
03940   Me.m_quiet = save_quiet;
03941 
03942   Me.m_autoconfigure_cmtpath = true;
03943 }
03944 
03945 //----------------------------------------------------------
03946 const cmt_string& Cmt::filter_dir (const cmt_string& dir)
03947 {
03948   static cmt_string newdir;
03949 
03950   CmtSystem::compress_path (dir, newdir);
03951 
03952   return (newdir);
03953 }
03954 
03955 //----------------------------------------------------------
03956 static void dos_script_prefix (FILE* f, 
03957                                const cmt_string& cmt_root, 
03958                                const cmt_string& package, 
03959                                const cmt_string& version, 
03960                                const cmt_string& path, 
03961                                const cmt_string& action, 
03962                                const cmt_string& option = "")
03963 {
03964   cmt_string no_device = path;
03965 
03966   if (CmtSystem::absolute_path (path)) 
03967     {
03968       if (path[1] == ':')
03969         {
03970           no_device = path.substr (2);
03971         }
03972     }
03973 
03974   if (package == "cmt_standalone")
03975     {
03976       no_device = "";
03977     }
03978   else
03979     {
03980       no_device = "..\\..\\..";
03981       if (Cmt::get_current_style () == no_version_style)
03982         {
03983           no_device = "..\\..";
03984         }
03985     }
03986 
03987 
03988   fprintf (f, "@echo off\n");
03989   fprintf (f, "if NOT DEFINED CMTROOT set CMTROOT=%s& set PATH=%%CMTROOT%%\\%%CMTBIN%%;%%PATH%%& set CMTBIN=VisualC& if not defined CMTCONFIG set CMTCONFIG=%%CMTBIN%%\n", cmt_root.c_str ());
03990   fprintf (f, "\n");
03991   fprintf (f, "set cmttempfile=\"%%TEMP%%\\tmpsetup.bat\"\n");
03992   fprintf (f, "%%CMTROOT%%\\%%CMTBIN%%\\cmt.exe %s -bat "
03993            " -pack=%s -version=%s -path=%%~d0%%~p0%s "
03994            " %s "
03995            "%%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >%%cmttempfile%%\n",
03996            action.c_str (),
03997            package.c_str (),
03998            version.c_str (),
03999            no_device.c_str (),
04000            option.c_str ());
04001   fprintf (f, "if exist %%cmttempfile%% call %%cmttempfile%%\n");
04002   fprintf (f, "if exist %%cmttempfile%% del %%cmttempfile%%\n");
04003   fprintf (f, "set cmttempfile=\n");
04004 }
04005 
04006 //----------------------------------------------------------
04007 void Cmt::install_cleanup_scripts ()
04008 {
04009 #ifdef WIN32
04010   static const int modes = 1;
04011   static const cmt_string suffix[1]   = {"bat"};
04012   static const PrintMode  mode[1]     = {Bat};
04013 #else
04014   static const int modes = 2;
04015   static const cmt_string suffix[2]   = {"csh", "sh"};
04016   static const PrintMode  mode[2]     = {Csh, Sh};
04017 #endif
04018 
04019   cout << "Creating cleanup scripts." << endl;
04020 
04021   cmt_string temp;
04022   int i;
04023 
04024   cmt_string version = Me.m_current_version;
04025   if (version == "v*") version = "";
04026 
04027   for (i = 0; i < modes; i++)
04028     {
04029       cmt_string file_name = "cleanup";
04030       file_name += ".";
04031       file_name += suffix[i];
04032       file_name += ".";
04033       file_name += "new";
04034 
04035       FILE* f = fopen (file_name.c_str (), "wb");
04036       if (f != NULL)
04037         {
04038           if (mode[i] == Csh)
04039             {
04040               fprintf (f, "if ( $?CMTROOT == 0 ) then\n");
04041               fprintf (f, "  setenv CMTROOT %s\n", Me.m_cmt_root.c_str ());
04042               fprintf (f, "endif\n");
04043               fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
04044               fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
04045               fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
04046               fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s "
04047                        "-pack=%s -version=%s -path=%s $* >${tempfile}; "
04048                        "source ${tempfile}\n",
04049                        suffix[i].c_str (),
04050                        Me.m_current_package.c_str (),
04051                        version.c_str (),
04052                        Me.m_current_path.c_str ());
04053               fprintf (f, "/bin/rm -f ${tempfile}\n");
04054             }
04055           else if (mode[i] == Sh)
04056             {
04057               fprintf (f, "if test \"${CMTROOT}\" = \"\"; then\n");
04058               fprintf (f, "  CMTROOT=%s; export CMTROOT\n", Me.m_cmt_root.c_str ());
04059               fprintf (f, "fi\n");
04060               fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
04061               fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
04062               fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
04063               fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s "
04064                        "-pack=%s -version=%s -path=%s $* >${tempfile}; "
04065                        ". ${tempfile}\n",
04066                        suffix[i].c_str (),
04067                        Me.m_current_package.c_str (),
04068                        version.c_str (),
04069                        Me.m_current_path.c_str ());
04070               fprintf (f, "/bin/rm -f ${tempfile}\n");
04071             }
04072           else if (mode[i] == Bat)
04073             {
04074               dos_script_prefix (f, Me.m_cmt_root, 
04075                                  Me.m_current_package, version, Me.m_current_path,
04076                                  "cleanup");
04077             }
04078 
04079           fprintf (f, "\n");
04080 
04081           fclose (f);
04082 
04083           cmt_string old_file_name = "cleanup";
04084           old_file_name += ".";
04085           old_file_name += suffix[i];
04086 
04087           CmtSystem::compare_and_update_files (file_name, old_file_name);
04088         }
04089     }
04090 }
04091 
04092 //----------------------------------------------------------
04093 void Cmt::install_setup_scripts ()
04094 {
04095 #ifdef WIN32
04096   static const int modes = 1;
04097   static const cmt_string suffix[1]   = {"bat"};
04098   static const PrintMode  mode[1]     = {Bat};
04099 #else
04100   static const int modes = 2;
04101   static const cmt_string suffix[2]   = {"csh", "sh"};
04102   static const PrintMode  mode[2]     = {Csh, Sh};
04103 #endif
04104 
04105   cout << "Creating setup scripts." << endl;
04106 
04107   
04108   cmt_string no_cleanup_opt;
04109 
04110   if (get_strategy ("SetupCleanup"))
04111     {
04112       no_cleanup_opt = " -no_cleanup";
04113     }
04114 
04115   cmt_string temp;
04116   int i;
04117 
04118   cmt_string version = Me.m_current_version;
04119   if (version == "v*") version = "";
04120 
04121   for (i = 0; i < modes; i++)
04122     {
04123       cmt_string file_name = "setup";
04124       file_name += ".";
04125       file_name += suffix[i];
04126       file_name += ".";
04127       file_name += "new";
04128 
04129       FILE* f = fopen (file_name.c_str (), "wb");
04130       if (f != NULL)
04131         {
04132           if (mode[i] == Csh)
04133             {
04134               fprintf (f, "# echo \"Setting %s %s in %s\"\n",
04135                        Me.m_current_package.c_str (),
04136                        version.c_str (),
04137                        Me.m_current_path.c_str ());
04138               fprintf (f, "\n");
04139 
04140               fprintf (f, "if ( $?CMTROOT == 0 ) then\n");
04141               fprintf (f, "  setenv CMTROOT %s\n", Me.m_cmt_root.c_str ());
04142               fprintf (f, "endif\n");
04143               fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
04144               fprintf (f, "\n");
04145               fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
04146               fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
04147               fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
04148                        "-pack=%s -version=%s -path=%s %s $* >${tempfile}; "
04149                        "source ${tempfile}\n",
04150                        suffix[i].c_str (),
04151                        Me.m_current_package.c_str (),
04152                        version.c_str (),
04153                        Me.m_current_path.c_str (),
04154                        no_cleanup_opt.c_str ());
04155               fprintf (f, "/bin/rm -f ${tempfile}\n");
04156             }
04157           else if (mode[i] == Sh)
04158             {
04159               fprintf (f, "# echo \"Setting %s %s in %s\"\n",
04160                        Me.m_current_package.c_str (),
04161                        version.c_str (),
04162                        Me.m_current_path.c_str ());
04163               fprintf (f, "\n");
04164 
04165               fprintf (f, "if test \"${CMTROOT}\" = \"\"; then\n");
04166               fprintf (f, "  CMTROOT=%s; export CMTROOT\n", Me.m_cmt_root.c_str ());
04167               fprintf (f, "fi\n");
04168               fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
04169               fprintf (f, "\n");
04170               fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
04171               fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
04172               fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
04173                        "-pack=%s -version=%s -path=%s %s $* >${tempfile}; "
04174                        ". ${tempfile}\n",
04175                        suffix[i].c_str (),
04176                        Me.m_current_package.c_str (),
04177                        version.c_str (),
04178                        Me.m_current_path.c_str (),
04179                        no_cleanup_opt.c_str ());
04180               fprintf (f, "/bin/rm -f ${tempfile}\n");
04181             }
04182           else if (mode[i] == Bat)
04183             {
04184               fprintf (f, "rem Setting %s %s in %%~d0%%~p0\n",
04185                        Me.m_current_package.c_str (),
04186                        version.c_str ());
04187               dos_script_prefix (f, Me.m_cmt_root, 
04188                                  Me.m_current_package, version, Me.m_current_path,
04189                                  "setup", no_cleanup_opt);
04190             }
04191 
04192           fprintf (f, "\n");
04193 
04194           fclose (f);
04195 
04196           cmt_string old_file_name = "setup";
04197           old_file_name += ".";
04198           old_file_name += suffix[i];
04199 
04200           CmtSystem::compare_and_update_files (file_name, old_file_name);
04201         }
04202     }
04203 }
04204 
04205 //----------------------------------------------------------
04206 void Cmt::install_test_cleanup_scripts ()
04207 {
04208 #ifdef WIN32
04209   static const int modes = 1;
04210   static const cmt_string suffix[1]   = {"bat"};
04211   static const PrintMode  mode[1]     = {Bat};
04212 #else
04213   static const int modes = 2;
04214   static const cmt_string suffix[2]   = {"csh", "sh"};
04215   static const PrintMode  mode[2]     = {Csh, Sh};
04216 #endif
04217 
04218   cout << "Creating cleanup scripts." << endl;
04219 
04220   cmt_string temp;
04221   int i;
04222 
04223   cmt_string version = Me.m_current_version;
04224   if (version == "v*") version = "";
04225 
04226   for (i = 0; i < modes; i++)
04227     {
04228       cmt_string file_name = "cleanup";
04229       file_name += ".";
04230       file_name += suffix[i];
04231       file_name += ".";
04232       file_name += "new";
04233 
04234       FILE* f = fopen (file_name.c_str (), "wb");
04235       if (f != NULL)
04236         {
04237           if (mode[i] == Csh)
04238             {
04239               fprintf (f, "if ( $?CMTROOT == 0 ) then\n");
04240               fprintf (f, "  setenv CMTROOT %s\n", Me.m_cmt_root.c_str ());
04241               fprintf (f, "endif\n");
04242               fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
04243               fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
04244               fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
04245               fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}; "
04246                        "source ${tempfile}\n",
04247                        suffix[i].c_str (),
04248                        Me.m_current_path.c_str ());
04249               fprintf (f, "/bin/rm -f ${tempfile}\n");
04250             }
04251           else if (mode[i] == Sh)
04252             {
04253               fprintf (f, "if test \"${CMTROOT}\" = \"\"; then\n");
04254               fprintf (f, "  CMTROOT=%s; export CMTROOT\n", Me.m_cmt_root.c_str ());
04255               fprintf (f, "fi\n");
04256               fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
04257               fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
04258               fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
04259               fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}; "
04260                        ". ${tempfile}\n",
04261                        suffix[i].c_str (),
04262                        Me.m_current_path.c_str ());
04263               fprintf (f, "/bin/rm -f ${tempfile}\n");
04264             }
04265           else
04266             {
04267               dos_script_prefix (f, Me.m_cmt_root, 
04268                                  "cmt_standalone", "", Me.m_current_path, 
04269                                  "cleanup");
04270             }
04271 
04272           fprintf (f, "\n");
04273 
04274           fclose (f);
04275 
04276           cmt_string old_file_name = "cleanup";
04277           old_file_name += ".";
04278           old_file_name += suffix[i];
04279 
04280           CmtSystem::compare_and_update_files (file_name, old_file_name);
04281         }
04282     }
04283 }
04284 
04285 //----------------------------------------------------------
04286 void Cmt::install_test_setup_scripts ()
04287 {
04288 #ifdef WIN32
04289   static const int modes = 1;
04290   static const cmt_string suffix[1]   = {"bat"};
04291   static const PrintMode  mode[1]     = {Bat};
04292 #else
04293   static const int modes = 2;
04294   static const cmt_string suffix[2]   = {"csh", "sh"};
04295   static const PrintMode  mode[2]     = {Csh, Sh};
04296 #endif
04297 
04298   cout << "Creating setup scripts." << endl;
04299 
04300   cmt_string no_cleanup_opt;
04301 
04302   if (get_strategy ("SetupCleanup"))
04303     {
04304       no_cleanup_opt = " -no_cleanup";
04305     }
04306 
04307   cmt_string temp;
04308   int i;
04309 
04310   for (i = 0; i < modes; i++)
04311     {
04312       cmt_string file_name = "setup";
04313       file_name += ".";
04314       file_name += suffix[i];
04315       file_name += ".";
04316       file_name += "new";
04317 
04318       FILE* f = fopen (file_name.c_str (), "wb");
04319       if (f != NULL)
04320         {
04321           if (mode[i] == Csh)
04322             {
04323               fprintf (f, "# echo \"Setting standalone package\"\n");
04324               fprintf (f, "\n");
04325 
04326               fprintf (f, "if ( $?CMTROOT == 0 ) then\n");
04327               fprintf (f, "  setenv CMTROOT %s\n", Me.m_cmt_root.c_str ());
04328               fprintf (f, "endif\n");
04329               fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
04330               fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
04331               fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
04332               fprintf (f, "${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}; "
04333                        "source ${tempfile}\n",
04334                        suffix[i].c_str (),
04335                        Me.m_current_path.c_str (),
04336                        no_cleanup_opt.c_str ());
04337               fprintf (f, "/bin/rm -f ${tempfile}\n");
04338             }
04339           else if (mode[i] == Sh)
04340             {
04341               fprintf (f, "# echo \"Setting standalone package\"\n");
04342               fprintf (f, "\n");
04343 
04344               fprintf (f, "if test \"${CMTROOT}\" = \"\"; then\n");
04345               fprintf (f, "  CMTROOT=%s; export CMTROOT\n", Me.m_cmt_root.c_str ());
04346               fprintf (f, "fi\n");
04347               fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
04348               fprintf (f, "\n");
04349               fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
04350               fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
04351               fprintf (f, "${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}; "
04352                        ". ${tempfile}\n",
04353                        suffix[i].c_str (),
04354                        Me.m_current_path.c_str (),
04355                        no_cleanup_opt.c_str ());
04356               fprintf (f, "/bin/rm -f ${tempfile}\n");
04357             }
04358           else
04359             {
04360               fprintf (f, "rem Setting standalone package\n");
04361               dos_script_prefix (f, Me.m_cmt_root, 
04362                                  "cmt_standalone", "", Me.m_current_path, 
04363                                  "setup", no_cleanup_opt);
04364             }
04365 
04366           fprintf (f, "\n");
04367 
04368           fclose (f);
04369 
04370           cmt_string old_file_name = "setup";
04371           old_file_name += ".";
04372           old_file_name += suffix[i];
04373 
04374           CmtSystem::compare_and_update_files (file_name, old_file_name);
04375         }
04376     }
04377 }
04378 
04384 bool Cmt::load (const cmt_string& path,
04385                 const cmt_string& package,
04386                 const cmt_string& version,
04387                 const cmt_string& tag_name)
04388 {
04389   clear ();
04390   configure ();
04391 
04392   Me.m_action  = action_load;
04393   Me.m_recursive = true;
04394 
04395   if (((package != "") && (version != "")) || (Me.m_current_package == ""))
04396     {
04397       //
04398       //  Here we want to connect to a new package, or to the current package
04399       //  but with another tag.
04400       //
04401       //   the 'package' argument may include a directory offset. Thus 'path'
04402       //  is only expected to hold the base directory.
04403       //
04404       cmt_string offset;
04405       cmt_string package_name;
04406       
04407       CmtSystem::dirname (package, offset);
04408       CmtSystem::basename (package, package_name);
04409       
04410       if (offset != "")
04411         {
04412           Me.m_current_path = path;
04413           Me.m_current_path += CmtSystem::file_separator ();
04414           Me.m_current_path += offset;
04415         }
04416       else
04417         {
04418           Me.m_current_path = path;
04419         }
04420       
04421       Me.m_current_package = package_name;
04422       Me.m_current_version = version;
04423     }
04424 
04425   if (tag_name != "")
04426     {
04427       Tag* tag;
04428 
04429       Tag::unmark_all ();
04430       configure_version_tag ();
04431       configure_site_tag (0);
04432       configure_uname_tag ();
04433       configure_hosttype_tag ();
04434 
04435       Me.m_current_tag = tag_name;
04436 
04437       //if (!Me.m_quiet) cerr << "load1> current_tag=" << Me.m_current_tag << endl;
04438 
04439       tag = Tag::add (tag_name, PriorityTag, "load", 0);
04440       tag->mark ();
04441     }
04442 
04443   /*
04444     Set to developer mode if positioned into the package
04445     (which is detected since we were able to retreive the
04446     Version, Package and Path)
04447   */
04448 
04449   if ((Me.m_current_path == "") ||
04450       (Me.m_current_package == "") ||
04451       (Me.m_current_version == ""))
04452     {
04453       Me.m_current_access = UserMode;
04454     }
04455   else
04456     {
04457       Me.m_current_access = DeveloperMode;
04458     }
04459 
04460   use_cmt ();
04461 
04462   cmt_string dir;
04463 
04464   /*
04465     Try to access the package.
04466   */
04467 
04468   if (Me.m_current_path != "")
04469     {
04470       dir = Me.m_current_path;
04471     }
04472   else
04473     {
04474       dir = Me.m_default_path;
04475     }
04476 
04477   if (!CmtSystem::cd (Me.m_current_path))
04478     {
04479       if (!Me.m_quiet)
04480         {
04481           cerr << "#CMT> Cannot reach the directory " <<
04482             Me.m_current_path << endl;
04483         }
04484       CmtError::set (CmtError::package_not_found, "Load> Cannot reach the path directory");
04485       CmtSystem::cd (Me.m_current_dir);
04486 
04487       return (false);
04488     }
04489 
04490   dir += CmtSystem::file_separator ();
04491   dir += Me.m_current_package;
04492 
04493   if (!CmtSystem::cd (Me.m_current_package))
04494     {
04495       if (!Me.m_quiet)
04496         {
04497           cerr << "#CMT::load> Cannot reach the package " <<
04498             Me.m_current_package << endl;
04499         }
04500       CmtError::set (CmtError::package_not_found, "Load> Cannot reach the package directory");
04501       CmtSystem::cd (Me.m_current_dir);
04502 
04503       return (false);
04504     }
04505 
04506   dir += CmtSystem::file_separator ();
04507   dir += Me.m_current_version;
04508 
04509   Me.m_current_style = none_style;
04510 
04511   if (!CmtSystem::cd (Me.m_current_version))
04512     {
04513       if (!CmtSystem::test_directory ("cmt"))
04514         {
04515           if (!Me.m_quiet)
04516             {
04517               cerr << "#CMT> Cannot reach the version " <<
04518                 Me.m_current_version << endl;
04519             }
04520           CmtError::set (CmtError::package_not_found, "Load> Cannot reach the version directory");
04521           CmtSystem::cd (Me.m_current_dir);
04522 
04523           return (false);
04524         }
04525       else
04526         {
04527           Me.m_current_style = no_version_style;
04528         }
04529     }
04530 
04531   if (CmtSystem::cd ("cmt"))
04532     {
04533       dir += CmtSystem::file_separator ();
04534       dir += "cmt";
04535       if (Me.m_current_style == none_style) Me.m_current_style = cmt_style;
04536     }
04537   else
04538     {
04539       /*
04540         if (!Me.m_quiet)
04541         {
04542         cerr << "Cannot reach the cmt branch" << endl;
04543         }
04544       */
04545 
04546       if (CmtSystem::cd ("mgr"))
04547         {
04548           dir += CmtSystem::file_separator ();
04549           dir += "mgr";
04550           if (Me.m_current_style == none_style) Me.m_current_style = mgr_style;
04551         }
04552       else
04553         {
04554           if (!Me.m_quiet)
04555             {
04556               cerr << "#CMT> Cannot reach the mgr branch" << endl;
04557             }
04558 
04559           CmtError::set (CmtError::package_not_found,
04560                          "Load> Cannot reach the mgr/cmt directory");
04561           CmtSystem::cd (Me.m_current_dir);
04562 
04563           return (false);
04564         }
04565     }
04566 
04567   /*
04568     Check Tag is always set up
04569   */
04570 
04571   if (Me.m_current_tag == "")
04572     {
04573       char* env;
04574 
04575       env = getenv (Me.m_current_config.c_str ());
04576       if (env != 0)
04577         {
04578           Tag* tag;
04579 
04580           tag = Tag::add (env, PriorityConfig, "load", 0);
04581           tag->mark ();
04582           Me.m_current_tag = env;
04583 
04584           //if (!Me.m_quiet) cerr << "load2> current_tag=" << Me.m_current_tag << endl;
04585 
04586         }
04587       else
04588         {
04589           Me.m_current_tag = Me.m_cmt_config;
04590 
04591           //if (!Me.m_quiet) cerr << "load3> current_tag=" << Me.m_current_tag << endl;
04592 
04593         }
04594     }
04595 
04596   if (Me.m_debug)
04597     {
04598       cout << "pwd = " << CmtSystem::pwd () << endl;
04599     }
04600 
04601   configure_current_dir ();
04602   build_prefix (Me.m_current_package, Me.m_current_prefix);
04603   build_config (Me.m_current_prefix, Me.m_current_config);
04604 
04605   Use* use = &(Use::current());
04606   use->path    = Me.m_current_path;
04607   use->set_package_name (Me.m_current_package);
04608   use->version = Me.m_current_version;
04609   use->prefix  = Me.m_current_prefix;
04610   use->done    = false;
04611   use->style   = Me.m_current_style;
04612 
04613   /*
04614     Work on the requirements file.
04615   */
04616 
04617   dir += CmtSystem::file_separator ();
04618   dir += "requirements";
04619   SyntaxParser::parse_requirements (dir, use);
04620 
04621   if (CmtError::has_pending_error ()) return (false);
04622 
04626   Pattern::apply_all_globals ();
04627 
04628   /*
04629     Select all possible tags
04630   */
04631 
04632   Tag::restore_tree ();
04633 
04634   return (true);
04635 }
04636 
04637 //----------------------------------------------------------
04638 bool Cmt::need_prototypes ()
04639 {
04640   if (get_strategy ("BuildPrototypes")) return (true);
04641   else return (false);
04642 }
04643 
04644 //----------------------------------------------------------
04645 void Cmt::parse_arguments (ArgParser& ap)
04646 {
04647   /*
04648     Decoding arguments.
04649 
04650     While decoding all arguments, no requirements analysis should
04651     occur. Every new option, or parameter should be saved and
04652     used later at actual analysis time.
04653   */
04654 
04655   Me.m_action = action_none;
04656 
04657   restore_all_tags (0);
04658 
04659 #ifdef WIN32
04660   Me.m_build_nmake = true;
04661 #endif
04662 
04663   ap.parse ();
04664 }
04665 
04666 //----------------------------------------------------------
04667 int Cmt::parser (const cmt_string& command_line)
04668 {
04669   CmtSystem::cmt_string_vector v;
04670 
04671   CmtSystem::split (command_line, " \t", v);
04672 
04673   int argc = v.size ();
04674 
04675   char** argv = (char**) malloc ((argc + 1) * sizeof (char*));
04676 
04677   int i;
04678   for (i = 0; i < argc; i++)
04679     {
04680       argv[i] = (char*) v[i].c_str ();
04681     }
04682   argv[argc] = 0;
04683 
04684   int status = parser (argc, argv);
04685 
04686   free (argv);
04687 
04688   return (status);
04689 }
04690 
04691 //----------------------------------------------------------
04692 int Cmt::parser (int argc, char* argv[])
04693 {
04694   ArgParser ap (Me);
04695 
04696   ap.argc = argc;
04697   ap.argv = argv;
04698 
04699   if (argc <= 1)
04700     {
04701       do_help (ap);
04702       exit (0);
04703     }
04704 
04705   clear ();
04706   configure ();
04707 
04708   CmtError::clear ();
04709 
04710   /*
04711     Set private if positioned inside the package
04712     (which is detected since we were able to retreive the
04713     Version, Package and Path)
04714   */
04715 
04716   if ((Me.m_current_path.size () == 0) ||
04717       (Me.m_current_package.size () == 0) ||
04718       (Me.m_current_version.size () == 0))
04719     {
04720       Me.m_current_access = UserMode;
04721     }
04722   else
04723     {
04724       Me.m_current_access = DeveloperMode;
04725     }
04726 
04727   parse_arguments (ap);
04728 
04729   if (Me.m_debug)
04730     {
04731       cout << "After parse_argument> pack=" << Me.m_current_package
04732            << " Me.m_current_tag=" << Me.m_current_tag
04733            << " cwd=" << CmtSystem::pwd () 
04734            << " mode=" << Me.m_current_access
04735            << endl;
04736     }
04737 
04738   if (Me.m_configure_error != "")
04739     {
04740       if (!Me.m_quiet) cerr << "#CMT> Error: " << Me.m_configure_error << endl;
04741       return (CmtError::execution_error);
04742     }
04743 
04744   if (CmtError::has_pending_error ())
04745     {
04746       int code = CmtError::get_last_error_code ();
04747       if (!Me.m_quiet) CmtError::print ();
04748       clear ();
04749 
04750       return (code);
04751     }
04752 
04753   /*
04754     Now actual requirements analysis can take place.
04755 
04756     Extra lines or files are analysed first.
04757   */
04758 
04759   if (strlen (ap.extra_file.c_str ()) > 0) SyntaxParser::parse_requirements (ap.extra_file, (Use*) 0);
04760   if (strlen (ap.extra_line.c_str ()) > 0) SyntaxParser::parse_requirements_line (ap.extra_line, (Use*) 0);
04761 
04762   //
04763   //  For some of the actions, the CMT package must be automatically
04764   //  included
04765   //
04766 
04767   if (Me.m_debug) cout << "parser1> current_tag=" << Me.m_current_tag << endl;
04768 
04769   if (ap.help_action == action_help)
04770     {
04771       do_help (ap);
04772       return (0);
04773     }
04774 
04775   switch (Me.m_action)
04776     {
04777       // case action_none :
04778     case action_awk :
04779     case action_broadcast :
04780     case action_build_constituent_makefile :
04781     case action_build_constituents_makefile :
04782     case action_build_dependencies :
04783     case action_build_library_links :
04784     case action_build_make_setup :
04785     case action_build_msdev :
04786     case action_build_CMT_pacman :
04787     case action_build_vsnet :     
04788     case action_build_os9_makefile :
04789       // case action_build_prototype :
04790     case action_build_readme :
04791     case action_build_tag_makefile :
04792       // case action_build_temporary_name :
04793     case action_build_triggers :
04794     case action_build_windefs :
04795     case action_check_configuration :
04796       // case action_check_files :
04797       // case action_check_version :
04798     case action_checkout :
04799     case action_cleanup :
04800     case action_config :
04801     case action_create :
04802       // case action_create_project :
04803     case action_cvsbranches :
04804     case action_cvssubpackages :
04805     case action_cvssubprojects :
04806     case action_cvstags :
04807     case action_do :
04808     case action_expand_model :
04809     case action_filter :
04810       // case action_help :
04811     case action_load :
04812     case action_lock :
04813     case action_remove :
04814     case action_remove_library_links :
04815     case action_run :
04816     case action_run_sequence :
04817     case action_set_version :
04818     case action_set_versions :
04819     case action_setup :
04820     case action_show_action :
04821     case action_show_action_names :
04822     case action_show_action_value :
04823     case action_show_actions :
04824     case action_show_all_tags :
04825     case action_show_applied_patterns :
04826       // case action_show_author :
04827       // case action_show_branches :
04828       // case action_show_clients :
04829     case action_show_cmtpath_patterns :
04830     case action_show_constituent :
04831     case action_show_constituent_names :
04832     case action_show_constituents :
04833     case action_show_cycles :
04834     case action_show_fragment :
04835     case action_show_fragments :
04836     case action_show_groups :
04837     case action_show_include_dirs :
04838     case action_show_language :
04839     case action_show_languages :
04840     case action_show_macro :
04841     case action_show_macro_names :
04842     case action_show_macro_value :
04843     case action_show_macros :
04844       // case action_show_manager :
04845     case action_show_packages :
04846     case action_show_path :
04847     case action_show_pattern :
04848     case action_show_pattern_names :
04849     case action_show_patterns :
04850     case action_show_projects :
04851       // case action_show_pwd :
04852     case action_show_setup :
04853     case action_show_set :
04854     case action_show_set_names :
04855     case action_show_set_value :
04856     case action_show_sets :
04857     case action_show_strategies :
04858     case action_show_tags :
04859     case action_show_use_paths :
04860     case action_show_uses :
04861     case action_show_version :
04862       // case action_show_versions :
04863       // case action_system :
04864     case action_unlock :
04865     case action_version :
04866       use_cmt ();
04867         //
04868         // Now parse the requirements file stored in ${CMTHOME}
04869         //
04870       
04871       use_home_requirements ();
04872 
04873       break;
04874     default:
04875       break;
04876     }
04877 
04878   if (Me.m_debug) cout << "parser2> current_tag=" << Me.m_current_tag << endl;
04879 
04880   //
04881   // Setting up recursive actions
04882   //
04883 
04884   switch (Me.m_action)
04885     {
04886       // case action_none :
04887     case action_awk :
04888     case action_broadcast :
04889     case action_build_constituent_makefile :
04890     case action_build_constituents_makefile :
04891     case action_build_dependencies :
04892     case action_build_library_links :
04893     case action_build_make_setup :
04894     case action_build_msdev :
04895     case action_build_CMT_pacman :
04896     case action_build_vsnet :     
04897     case action_build_os9_makefile :
04898       // case action_build_prototype :
04899     case action_build_readme :
04900     case action_build_tag_makefile :
04901       // case action_build_temporary_name :
04902     case action_build_triggers :
04903     case action_build_windefs :
04904     case action_check_configuration :
04905       // case action_check_files :
04906       // case action_check_version :
04907       // case action_checkout :
04908     case action_cleanup :
04909     case action_config :
04910       // case action_create :
04911       // case action_create_project :
04912       // case action_cvsbranches :
04913       // case action_cvssubpackages :
04914       // case action_cvssubprojects :
04915       // case action_cvstags :
04916     case action_do :
04917     case action_expand_model :
04918     case action_filter :
04919       // case action_help :
04920     case action_load :
04921       // case action_lock :
04922       // case action_remove :
04923     case action_remove_library_links :
04924     case action_run :
04925     case action_run_sequence :
04926       // case action_set_version :
04927     case action_set_versions :
04928     case action_setup :
04929     case action_show_action :
04930     case action_show_action_names :
04931     case action_show_action_value :
04932     case action_show_actions :
04933     case action_show_all_tags :
04934     case action_show_applied_patterns :
04935       // case action_show_author :
04936       // case action_show_branches :
04937       // case action_show_clients :
04938     case action_show_cmtpath_patterns :
04939     case action_show_constituent :
04940     case action_show_constituent_names :
04941     case action_show_constituents :
04942     case action_show_cycles :
04943     case action_show_fragment :
04944     case action_show_fragments :
04945     case action_show_groups :
04946     case action_show_include_dirs :
04947     case action_show_language :
04948     case action_show_languages :
04949     case action_show_macro :
04950     case action_show_macro_names :
04951     case action_show_macro_value :
04952     case action_show_macros :
04953       // case action_show_manager :
04954     case action_show_packages :
04955     case action_show_path :
04956     case action_show_pattern :
04957     case action_show_pattern_names :
04958     case action_show_patterns :
04959     case action_show_projects :
04960       // case action_show_pwd :
04961     case action_show_setup :
04962     case action_show_set :
04963     case action_show_set_names :
04964     case action_show_set_value :
04965     case action_show_sets :
04966     case action_show_strategies :
04967     case action_show_tags :
04968     case action_show_use_paths :
04969     case action_show_uses :
04970       // case action_show_version :
04971       // case action_show_versions :
04972       // case action_system :
04973       // case action_unlock :
04974       // case action_version :
04975       Me.m_recursive = true;
04976       break;
04977     default:
04978       Me.m_recursive = false;
04979       break;
04980     }
04981 
04982   //
04983   //  Actions for which the context of the package is checked,
04984   //  and the requirements file is analysed.
04985   //
04986 
04987   switch (Me.m_action)
04988     {
04989     case action_none :
04990     case action_awk :
04991     case action_broadcast :
04992     case action_build_constituent_makefile :
04993     case action_build_constituents_makefile :
04994     case action_build_dependencies :
04995     case action_build_library_links :
04996     case action_build_make_setup :
04997     case action_build_msdev :
04998     case action_build_CMT_pacman :
04999     case action_build_vsnet :     
05000     case action_build_os9_makefile :
05001       // case action_build_prototype :
05002     case action_build_readme :
05003     case action_build_tag_makefile :
05004       // case action_build_temporary_name :
05005     case action_build_triggers :
05006     case action_build_windefs :
05007     case action_check_configuration :
05008       // case action_check_files :
05009       // case action_check_version :
05010       // case action_checkout :
05011     case action_cleanup :
05012     case action_config :
05013       // case action_create :
05014       // case action_create_project :
05015       // case action_cvsbranches :
05016       // case action_cvssubpackages :
05017       // case action_cvssubprojects :
05018       // case action_cvstags :
05019     case action_do :
05020     case action_expand_model :
05021     case action_filter :
05022       // case action_help :
05023     case action_load :
05024     case action_lock :
05025       // case action_remove :
05026     case action_remove_library_links :
05027     case action_run :
05028       // case action_run_sequence :
05029       // case action_set_version :
05030     case action_set_versions :
05031     case action_setup :
05032     case action_show_action :
05033     case action_show_action_names :
05034     case action_show_action_value :
05035     case action_show_actions :
05036     case action_show_all_tags :
05037     case action_show_applied_patterns :
05038     case action_show_author :
05039     case action_show_branches :
05040       // case action_show_clients :
05041     case action_show_cmtpath_patterns :
05042     case action_show_constituent :
05043     case action_show_constituent_names :
05044     case action_show_constituents :
05045     case action_show_cycles :
05046     case action_show_fragment :
05047     case action_show_fragments :
05048     case action_show_groups :
05049     case action_show_include_dirs :
05050     case action_show_language :
05051     case action_show_languages :
05052     case action_show_macro :
05053     case action_show_macro_names :
05054     case action_show_macro_value :
05055     case action_show_macros :
05056     case action_show_manager :
05057     case action_show_packages :
05058     case action_show_path :
05059     case action_show_pattern :
05060     case action_show_pattern_names :
05061     case action_show_patterns :
05062     case action_show_projects :
05063     case action_show_pwd :
05064     case action_show_setup :
05065     case action_show_set :
05066     case action_show_set_names :
05067     case action_show_set_value :
05068     case action_show_sets :
05069     case action_show_strategies :
05070     case action_show_tags :
05071     case action_show_use_paths :
05072     case action_show_uses :
05073     case action_show_version :
05074       // case action_show_versions :
05075       // case action_system :
05076     case action_unlock :
05077       // case action_version :
05078       reach_current_package ();
05079       use_user_context_requirements ();
05080       break;
05081     default:
05082       break;
05083     }
05084 
05085   if (Me.m_debug) cout << "parser3> current_tag=" << Me.m_current_tag << endl;
05086 
05087   //
05088   // Perform some actions even if there is an error
05089   //
05090 
05091   if (CmtError::has_pending_error ())
05092     {
05093       int code = CmtError::get_last_error_code ();
05094       if (!Me.m_quiet) CmtError::print ();
05095 
05096       switch (Me.m_action)
05097         {
05098           // case action_none :
05099           // case action_awk :
05100           // case action_broadcast :
05101         case action_build_constituent_makefile :
05102         case action_build_constituents_makefile :
05103         case action_build_dependencies :
05104         case action_build_library_links :
05105         case action_build_make_setup :
05106         case action_build_msdev :
05107         case action_build_CMT_pacman :
05108         case action_build_vsnet :     
05109         case action_build_os9_makefile :
05110         case action_build_prototype :
05111         case action_build_readme :
05112         case action_build_tag_makefile :
05113           // case action_build_temporary_name :
05114         case action_build_triggers :
05115         case action_build_windefs :
05116         case action_check_configuration :
05117           // case action_check_files :
05118           // case action_check_version :
05119           // case action_checkout :
05120         case action_cleanup :
05121           // case action_config :
05122           // case action_create :
05123           // case action_create_project :
05124           // case action_cvsbranches :
05125           // case action_cvssubpackages :
05126           // case action_cvssubprojects :
05127           // case action_cvstags :
05128           // case action_do :
05129           // case action_expand_model :
05130           // case action_filter :
05131           // case action_help :
05132         case action_load :
05133         case action_lock :
05134         case action_remove :
05135         case action_remove_library_links :
05136           // case action_run :
05137         case action_run_sequence :
05138           // case action_set_version :
05139           // case action_set_versions :
05140         case action_setup :
05141           // case action_show_action :
05142           // case action_show_action_names :
05143           // case action_show_action_value :
05144           // case action_show_actions :
05145           // case action_show_all_tags :
05146           // case action_show_applied_patterns :
05147           // case action_show_author :
05148           // case action_show_branches :
05149           // case action_show_clients :
05150           // case action_show_cmtpath_patterns :
05151           // case action_show_constituent :
05152           // case action_show_constituent_names :
05153           // case action_show_constituents :
05154           // case action_show_cycles :
05155           // case action_show_fragment :
05156           // case action_show_fragments :
05157           // case action_show_groups :
05158           // case action_show_include_dirs :
05159           // case action_show_language :
05160           // case action_show_languages :
05161           // case action_show_macro :
05162           // case action_show_macro_names :
05163           // case action_show_macro_value :
05164           // case action_show_macros :
05165           // case action_show_manager :
05166           // case action_show_packages :
05167           // case action_show_path :
05168           // case action_show_pattern :
05169           // case action_show_pattern_names :
05170           // case action_show_patterns :
05171           // case action_show_projects :
05172           // case action_show_pwd :
05173           // case action_show_setup :
05174           // case action_show_set :
05175           // case action_show_set_names :
05176           // case action_show_set_value :
05177           // case action_show_sets :
05178           // case action_show_strategies :
05179           // case action_show_tags :
05180           // case action_show_use_paths :
05181           // case action_show_uses :
05182           // case action_show_version :
05183           // case action_show_versions :
05184           // case action_system :
05185         case action_unlock :
05186           // case action_version :
05187           clear ();
05188           return (code);
05189         default:
05190           CmtError::clear ();
05191           break;
05192         }
05193     }
05194 
05195   //
05196   // Perform actions
05197   //
05198 
05199   if (!Me.m_simulation)
05200     {
05201       switch (Me.m_action)
05202         {
05203         case action_none :
05204           //CmtError::set (CmtError::syntax_error, "ParseArguments> ");
05205           break;
05206         case action_awk :
05207           do_awk (ap);
05208       break;
05209         case action_broadcast :
05210           do_broadcast (ap);
05211           break;
05212         case action_build_constituent_makefile :
05213           do_build_constituent_makefile (ap);
05214           break;
05215         case action_build_constituents_makefile :
05216           do_build_constituents_makefile (ap);
05217           break;
05218         case action_build_dependencies :
05219           do_build_dependencies (ap, argc, argv);
05220           break;
05221         case action_build_library_links :
05222           do_build_library_links (ap);
05223           break;
05224         case action_build_make_setup :
05225           do_build_make_setup (ap);
05226           break;
05227         case action_build_msdev :
05228           do_build_msdev (ap);
05229           break;
05230         case action_build_CMT_pacman :
05231           do_build_CMT_pacman (ap);
05232           break;
05233         case action_build_vsnet :     
05234           do_build_vsnet (ap);
05235           break;
05236         case action_build_os9_makefile :
05237           do_build_os9_makefile (ap);
05238           break;
05239         case action_build_prototype :
05240           do_build_prototype (ap);
05241           break;
05242         case action_build_readme :
05243           do_build_readme (ap);
05244           break;
05245         case action_build_tag_makefile :
05246           do_build_tag_makefile (ap);
05247           break;
05248         case action_build_temporary_name :
05249           do_build_temporary_name (ap);
05250           break;
05251         case action_build_triggers :
05252           do_build_triggers (ap);
05253           break;
05254         case action_build_windefs :
05255           do_build_windefs (ap);
05256           break;
05257         case action_check_configuration :
05258           do_check_configuration (ap);
05259           break;
05260         case action_check_files :
05261           do_check_files (ap);
05262           break;
05263         case action_check_version :
05264           do_check_version (ap);
05265           break;
05266         case action_checkout :
05267           do_checkout (ap);
05268           break;
05269         case action_cleanup :
05270           do_cleanup (ap);
05271           break;
05272         case action_config :
05273           do_config (ap);
05274           break;
05275         case action_create :
05276           do_create (ap);
05277           break;
05278         case action_create_project :
05279           do_create_project (ap);
05280           break;
05281         case action_cvsbranches :
05282           do_cvsbranches (ap);
05283           break;
05284         case action_cvssubpackages :
05285           do_cvssubpackages (ap);
05286           break;
05287         case action_cvssubprojects :
05288           do_cvssubprojects (ap);
05289           break;
05290         case action_cvstags :
05291           do_cvstags (ap);
05292           break;
05293         case action_do :
05294           do_do (ap);
05295           break;
05296         case action_expand_model :
05297           do_expand_model (ap);
05298           break;
05299         case action_filter :
05300           do_filter (ap);
05301           break;
05302         case action_help :
05303           do_help (ap);
05304           break;
05305         case action_load :
05306           cerr << "#CMT> action not implemented" << endl;
05307           break;
05308         case action_lock :
05309           do_lock (ap);
05310           break;
05311         case action_remove :
05312           do_remove (ap);
05313           break;
05314         case action_remove_library_links :
05315           do_remove_library_links (ap);
05316           break;
05317         case action_run :
05318           do_run (ap);
05319           break;
05320         case action_run_sequence :
05321           do_run_sequence (ap);
05322           break;
05323         case action_set_version :
05324           do_set_version (ap);
05325           break;
05326         case action_set_versions :
05327           do_set_versions (ap);
05328           break;
05329         case action_setup :
05330           do_setup (ap);
05331           break;
05332         case action_show_action :
05333           do_show_action (ap);
05334           break;
05335         case action_show_action_names :
05336           do_show_action_names (ap);
05337           break;
05338         case action_show_action_value :
05339           do_show_action_value (ap);
05340           break;
05341         case action_show_actions :
05342           do_show_actions (ap);
05343           break;
05344         case action_show_all_tags :
05345           do_show_all_tags (ap);
05346           break;
05347         case action_show_applied_patterns :
05348           do_show_applied_patterns (ap);
05349           break;
05350         case action_show_author :
05351           do_show_author (ap);
05352           break;
05353         case action_show_branches :
05354           do_show_branches (ap);
05355           break;
05356         case action_show_clients :
05357           do_show_clients (ap);
05358           break;
05359         case action_show_cmtpath_patterns :
05360           do_show_cmtpath_patterns (ap);
05361           break;
05362         case action_show_constituent :
05363           do_show_constituent (ap);
05364           break;
05365         case action_show_constituent_names :
05366           do_show_constituent_names (ap);
05367           break;
05368         case action_show_constituents :
05369           do_show_constituents (ap);
05370           break;
05371         case action_show_cycles :
05372           do_show_cycles (ap);
05373           break;
05374         case action_show_fragment :
05375           do_show_fragment (ap);
05376           break;
05377         case action_show_fragments :
05378           do_show_fragments (ap);
05379           break;
05380         case action_show_groups :
05381           do_show_groups (ap);
05382           break;
05383         case action_show_include_dirs :
05384           do_show_include_dirs (ap);
05385           break;
05386         case action_show_language :
05387           do_show_language (ap);
05388           break;
05389         case action_show_languages :
05390           do_show_languages (ap);
05391           break;
05392         case action_show_macro :
05393           do_show_macro (ap);
05394           break;
05395         case action_show_macro_names :
05396           do_show_macro_names (ap);
05397           break;
05398         case action_show_macro_value :
05399           do_show_macro_value (ap);
05400           break;
05401         case action_show_macros :
05402           do_show_macros (ap);
05403           break;
05404         case action_show_manager :
05405           do_show_manager (ap);
05406           break;
05407         case action_show_packages :
05408           do_show_packages (ap);
05409           break;
05410         case action_show_path :
05411           do_show_path (ap);
05412           break;
05413         case action_show_pattern :
05414           do_show_pattern (ap);
05415           break;
05416         case action_show_pattern_names :
05417           do_show_pattern_names (ap);
05418           break;
05419         case action_show_patterns :
05420           do_show_patterns (ap);
05421           break;
05422         case action_show_projects :
05423           do_show_projects (ap);
05424           break;
05425         case action_show_pwd :
05426           do_show_pwd (ap);
05427           break;
05428         case action_show_setup :
05429           do_show_setup (ap);
05430           break;
05431         case action_show_set :
05432           do_show_set (ap);
05433           break;
05434         case action_show_set_names :
05435           do_show_set_names (ap);
05436           break;
05437         case action_show_set_value :
05438           do_show_set_value (ap);
05439           break;
05440         case action_show_sets :
05441           do_show_sets (ap);
05442           break;
05443         case action_show_strategies :
05444           do_show_strategies (ap);
05445           break;
05446         case action_show_tags :
05447           do_show_tags (ap);
05448           break;
05449         case action_show_use_paths :
05450           do_show_use_paths (ap);
05451           break;
05452         case action_show_uses :
05453           do_show_uses (ap);
05454           break;
05455         case action_show_version :
05456           do_show_version (ap);
05457           break;
05458         case action_show_versions :
05459           do_show_versions (ap);
05460           break;
05461         case action_system :
05462           do_show_system (ap);
05463           break;
05464         case action_unlock :
05465           do_unlock (ap);
05466           break;
05467         case action_version :
05468           do_version (ap);
05469           break;
05470         default:
05471           CmtError::set (CmtError::syntax_error, "ParseArguments>");
05472           break;
05473         }
05474     }
05475 
05476   if (CmtError::has_pending_error ())
05477     {
05478       int code = CmtError::get_last_error_code ();
05479       if (!Me.m_quiet) CmtError::print ();
05480       clear ();
05481       return (code);
05482     }
05483   else
05484     {
05485       clear ();
05486       return (0);
05487     }
05488 }
05489 
05490 
05495 void Cmt::print (PrintMode mode)
05496 {
05497   Use::UsePtrVector& Uses = Use::get_ordered_uses ();
05498   Use& current_use = Use::current ();
05499 
05500   cmt_string tag;
05501 
05502   set_standard_macros ();
05503 
05504     //cerr << "# current_tag=" << Me.m_current_tag << endl;
05505     //cerr << "# current_config=" << Me.m_current_config << endl;
05506 
05507   if (Me.m_current_tag == "")
05508     {
05509       if (mode == Bat) tag = "%CMTCONFIG%";
05510       else tag = "${CMTCONFIG}";
05511     }
05512   else
05513     {
05514       tag = Me.m_current_tag;
05515     }
05516 
05517     //
05518     //  Now check if all extra tags are still valid. Some of them
05519     //  may be discarded du to some conflict with highest priority
05520     //  tags, or with exclude statements
05521     //
05522 
05523   {
05524     CmtSystem::cmt_string_vector words;
05525       
05526     cmt_string tags;
05527 
05528     tags = Me.m_extra_tags;
05529       
05530     CmtSystem::split (tags, " \t,", words);
05531 
05532     Me.m_extra_tags = ",";
05533       
05534     for (int i = 0; i < words.size (); i++)
05535       {
05536         Tag* tag;
05537         const cmt_string& a = words[i];
05538 
05539         tag = Tag::find (a);
05540 
05541         if ((tag != 0) && (tag->is_selected ()))
05542           {
05543             Me.m_extra_tags += a;
05544             Me.m_extra_tags += ",";
05545           }
05546       }
05547   }
05548 
05549   if (Me.m_debug)
05550     {
05551       cout << "Before all print contexts" << endl;
05552     }
05553 
05554   if (Uses.size () > 0)
05555     {
05556       int number;
05557 
05558       for (number = 0; number < Uses.size (); number++)
05559         {
05560           Use& use = *(Uses[number]);
05561 
05562           if (use.discarded) continue;
05563 
05564           print_context (use, mode, tag);
05565         }
05566     }
05567 
05568   print_context (Use::current (), mode, tag);
05569 
05570   if (Me.m_debug)
05571     {
05572       cout << "After all print contexts" << endl;
05573     }
05574 
05575   Symbol::all_print (mode);
05576   // Script::all_print (mode);
05577 
05578   if (Me.m_debug)
05579     {
05580       cout << "After all print" << endl;
05581     }
05582 
05583   cout << endl;
05584 }
05585 
05586 
05591 void Cmt::print_clean (PrintMode mode)
05592 {
05593   Use::UsePtrVector& Uses = Use::get_ordered_uses ();
05594 
05595   set_standard_macros ();
05596 
05597   Script::all_print_clean (mode);
05598   Symbol::all_print_clean (mode);
05599 
05600   switch (mode)
05601     {
05602     case Csh :
05603       if (Me.m_current_package != "CMT")
05604         {
05605           cout << "unsetenv " << Me.m_current_prefix << "ROOT" << endl;
05606           cout << "unsetenv " << Me.m_current_prefix << "CONFIG" << endl;
05607         }
05608       break;
05609     case Sh :
05610       if (Me.m_current_package != "CMT")
05611         {
05612           cout << "unset " << Me.m_current_prefix << "ROOT" << endl;
05613           cout << "unset " << Me.m_current_prefix << "CONFIG" << endl;
05614         }
05615       break;
05616     case Bat :
05617       if (Me.m_current_package != "CMT")
05618         {
05619           cout << "set " << Me.m_current_prefix << "ROOT=" << endl;
05620           cout << "set " << Me.m_current_prefix << "CONFIG=" << endl;
05621         }
05622       break;
05623     }
05624 
05625   if (Uses.size () > 0)
05626     {
05627       int number;
05628 
05629       for (number = 0; number < Uses.size (); number++)
05630         {
05631           Use* use = Uses[number];
05632 
05633           if (use->discarded) continue;
05634 
05635           Package* p = use->get_package ();
05636           if (p->is_cmt ()) continue;
05637 
05638           switch (mode)
05639             {
05640             case Csh :
05641               cout << "unsetenv " << use->prefix << "ROOT" << endl;
05642               cout << "unsetenv " << use->prefix << "CONFIG" << endl;
05643               break;
05644             case Sh :
05645               cout << "unset " << use->prefix << "ROOT" << endl;
05646               cout << "unset " << use->prefix << "CONFIG" << endl;
05647               break;
05648             case Bat :
05649               cout << "set " << use->prefix << "ROOT=" << endl;
05650               cout << "set " << use->prefix << "CONFIG" << endl;
05651               break;
05652             }
05653         }
05654     }
05655 
05656   switch (mode)
05657     {
05658     case Csh :
05659       cout << "unsetenv CMTEXTRATAGS" << endl;
05660       break;
05661     case Sh :
05662       cout << "unset CMTEXTRATAGS" << endl;
05663       break;
05664     case Bat :
05665       cout << "set CMTEXTRATAGS=" << endl;
05666       break;
05667     }
05668 
05669   cout << endl;
05670 }
05671 
05672 //----------------------------------------------------------
05673 void Cmt::print_context (Use& use, PrintMode mode, const cmt_string& tag)
05674 {
05675   if (use.get_package_name () == "cmt_standalone") return;
05676 
05677   cmt_string fs = CmtSystem::file_separator ();
05678 
05679   use.real_path.replace_all (CmtSystem::file_separator (), fs);
05680 
05681   cmt_string system = CmtSystem::get_cmt_config ();
05682 
05683   bool do_config = get_strategy ("SetupConfig");
05684   bool do_root = get_strategy ("SetupRoot");
05685 
05686   switch (mode)
05687     {
05688     case Csh :
05689       if (do_root)
05690         {
05691           cout << "setenv " << use.prefix << "ROOT \"" <<
05692             use.get_full_path () << "\"" << endl;
05693         }
05694 
05695       if (use.get_package_name () == "CMT")
05696         {
05697           cout << "setenv CMTCONFIG " << system << endl;
05698         }
05699       else
05700         {
05701           if (do_config)
05702             {
05703               cout << "setenv " << use.prefix << "CONFIG \"" << tag << "\"" << endl;
05704             }
05705         }
05706         
05707       break;
05708     case Sh :
05709       if (do_root)
05710         {
05711           cout << use.prefix << "ROOT=\"" <<
05712             use.get_full_path () << "\"; export " <<
05713             use.prefix << "ROOT" << endl;
05714         }
05715 
05716       if (use.get_package_name () == "CMT")
05717         {
05718           cout << "CMTCONFIG=" << system << "; export CMTCONFIG" << endl;
05719         }
05720       else
05721         {
05722           if (do_config)
05723             {
05724               cout << use.prefix << "CONFIG=\"" <<
05725                 tag << "\"; export " <<
05726                 use.prefix << "CONFIG" << endl;
05727             }
05728         }
05729         
05730       break;
05731     case Bat :
05732       if (do_root)
05733         {
05734           cout << "set " << use.prefix << "ROOT=" <<
05735             use.get_full_path () << endl;
05736         }
05737 
05738       if (use.get_package_name () == "CMT")
05739         {
05740           cout << "set CMTCONFIG=" << system << endl;
05741         }
05742       else
05743         {
05744           if (do_config)
05745             {
05746               cout << "set " << use.prefix << "CONFIG=" << tag << endl;
05747             }
05748         }
05749         
05750       break;
05751     }
05752 }
05753 
05761 void Cmt::print_symbol_names (PrintMode mode, const cmt_string& pattern)
05762 {
05763   int number;
05764 
05765   set_standard_macros ();
05766 
05767   cmt_regexp expression (pattern);
05768 
05769   bool has_pattern = (pattern != "");
05770 
05771   for (number = 0; number < Symbol::symbol_number (); number++)
05772     {
05773       Symbol& symbol = Symbol::symbol (number);
05774 
05775       if (has_pattern)
05776        {
05777          if (!expression.match (symbol.name)) continue;
05778        }
05779 
05780       if (Me.m_action == action_show_macro_names)
05781         {
05782           // Only keep macros.
05783           if ((symbol.type == Symbol::SymbolSet) ||
05784               (symbol.type == Symbol::SymbolAlias) ||
05785               (symbol.type == Symbol::SymbolPath) ||
05786               (symbol.type == Symbol::SymbolAction)) continue;
05787         }
05788       else if (Me.m_action == action_show_set_names)
05789         {
05790           // Exclude macros.
05791           if ((symbol.type == Symbol::SymbolMacro) ||
05792               (symbol.type == Symbol::SymbolAction)) continue;
05793         }
05794       else if (Me.m_action == action_show_action_names)
05795         {
05796           // Exclude macros.
05797           if (symbol.type != Symbol::SymbolAction) continue;
05798         }
05799 
05800       cout << symbol.name << endl;
05801     }
05802 }
05803 
05811 void Cmt::print_macros (PrintMode mode, const cmt_string& pattern)
05812 {
05813   int number;
05814 
05815   set_standard_macros ();
05816 
05817   cmt_regexp expression (pattern);
05818 
05819   bool has_pattern = (pattern != "");
05820 
05821   for (number = 0; number < Symbol::symbol_number (); number++)
05822     {
05823       Symbol& symbol = Symbol::symbol (number);
05824 
05825       if (has_pattern)
05826         {
05827           if (!expression.match (symbol.name)) continue;
05828         }
05829 
05830       if (Me.m_action == action_show_macros)
05831         {
05832           // Only keep macros.
05833           if ((symbol.type == Symbol::SymbolSet) ||
05834               (symbol.type == Symbol::SymbolAlias) ||
05835               (symbol.type == Symbol::SymbolPath) ||
05836               (symbol.type == Symbol::SymbolAction)) continue;
05837         }
05838       else if (Me.m_action == action_show_sets)
05839         {
05840           // Exclude macros.
05841           if ((symbol.type == Symbol::SymbolMacro) ||
05842               (symbol.type == Symbol::SymbolAction)) continue;
05843         }
05844       else if (Me.m_action == action_build_tag_makefile)
05845         {
05846           // Exclude scripts and actions
05847           if ((symbol.type == Symbol::SymbolSetupScript) ||
05848               (symbol.type == Symbol::SymbolCleanupScript) ||
05849               (symbol.type == Symbol::SymbolAction)) continue;
05850         }
05851       else if (Me.m_action == action_show_actions)
05852         {
05853           if (symbol.type != Symbol::SymbolAction) continue;
05854         }
05855 
05856       if (symbol.value_lists.size () < 1) continue;
05857 
05858       symbol.show_macro (mode);
05859     }
05860 }
05861 
05862 //----------------------------------------------------------
05863 void Cmt::print_tabs (int tabs)
05864 {
05865   while (tabs > 0)
05866     {
05867       cout << "  ";
05868       tabs--;
05869     }
05870 }
05871 
05872 //----------------------------------------------------------
05873 int Cmt::reach_current_package ()
05874 {
05875   Use& use = Use::current ();
05876   cmt_string dir;
05877 
05878   if (Me.m_debug)
05879     {
05880       cout << "Cmt::reach_current_package> pwd = " 
05881            << CmtSystem::pwd () 
05882            << " path=" << Me.m_current_path
05883            << " package=" << Me.m_current_package
05884            << endl;
05885     }
05886 
05887   /*
05888     Try to access the package.
05889   */
05890 
05891   if (Me.m_current_package == "cmt_standalone")
05892     {
05893       if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
05894         {
05895           if (!CmtSystem::cd (Me.m_current_path))
05896             {
05897               CmtError::set (CmtError::package_not_found,
05898                              "ReachCurrentPackage> Cannot reach the path directory");
05899               return (0);
05900             }
05901         }
05902 
05903       if (!CmtSystem::test_file ("requirements"))
05904         {
05905             /*
05906           if (!Me.m_quiet)
05907             {
05908               cout << "#CMT> Cannot reach the requirements file" << endl;
05909             }
05910               
05911           CmtError::set (CmtError::package_not_found,
05912                          "ReachCurrentPackage> Cannot reach the requirements file");
05913             */
05914           return (0);
05915         }
05916     }
05917   else if (Me.m_current_package != "")
05918     {
05919       if (!use.move_to ())
05920         {
05921           CmtError::set (CmtError::package_not_found,
05922                          "ReachCurrentPackage> Cannot reach the path directory");
05923           return (0);
05924         }
05925 
05926       Me.m_current_path = use.real_path;
05927     }
05928   else
05929     {
05930       //
05931       // The cmt command has been given without explicit search for 
05932       // a package. Thus it is expected that we are in the context of a
05933       // true package.
05934       //
05935       //  This means that there should be a requirements file visible.
05936       //
05937       //  If this is not true, we'll make a try into ../cmt and then
05938       // a last try into ../mgr
05939       //
05940 
05941       if (!CmtSystem::test_file ("requirements"))
05942         {
05943           if (CmtSystem::cd ("../cmt") && 
05944               CmtSystem::test_file ("requirements"))
05945             {
05946               Me.m_current_style = cmt_style;
05947             }
05948           else if (CmtSystem::cd ("../mgr") && 
05949                    CmtSystem::test_file ("requirements"))
05950             {
05951               Me.m_current_style = mgr_style;
05952             }
05953           else
05954             {
05955               if (!Me.m_quiet)
05956                 {
05957                   cerr << "#CMT> Cannot reach the mgr branch" << endl;
05958                 }
05959               
05960               CmtError::set (CmtError::package_not_found,
05961                              "ReachCurrentPackage> Cannot reach the mgr/cmt directory");
05962               return (0);
05963             }
05964         }
05965 
05966       dir = CmtSystem::pwd ();
05967 
05968       CmtSystem::dirname (dir, Me.m_current_path);
05969       CmtSystem::basename (Me.m_current_path, Me.m_current_version);
05970 
05971       if (CmtSystem::is_version_directory (Me.m_current_version))
05972         {
05973           CmtSystem::dirname (Me.m_current_path, Me.m_current_path);
05974           CmtSystem::basename (Me.m_current_path, Me.m_current_package);
05975           CmtSystem::dirname (Me.m_current_path, Me.m_current_path);
05976         }
05977       else
05978         {
05979           Me.m_current_package = Me.m_current_version;
05980           Me.m_current_version = "";
05981           CmtSystem::dirname (Me.m_current_path, Me.m_current_path);
05982 
05983           Me.m_current_style = no_version_style;
05984         }
05985 
05986       use.set_package_name (Me.m_current_package);
05987       use.version = Me.m_current_version;
05988       use.path    = Me.m_current_path;
05989       use.style   = Me.m_current_style;
05990     }
05991 
05992   configure_current_dir ();
05993   build_prefix (Me.m_current_package, Me.m_current_prefix);
05994   build_config (Me.m_current_prefix, Me.m_current_config);
05995 
05996   /*
05997     Check Tag is always set up
05998   */
05999 
06000   if (Me.m_debug) cout << "reach_current_package0> current_tag=" << Me.m_current_tag << endl;
06001 
06002   if (Me.m_current_tag == "")
06003     {
06004       cmt_string env;
06005 
06006       env = CmtSystem::getenv (Me.m_current_config);
06007       if (env != "")
06008         {
06009           Tag* tag;
06010 
06011           tag = Tag::add (env, PriorityConfig, "reach current package", 0);
06012           tag->mark ();
06013             //Me.m_current_tag = env;
06014 
06015           //if (!Me.m_quiet) cerr << "reach_current_package1> current_tag=" << Me.m_current_tag << endl;
06016 
06017         }
06018     }
06019 
06020   if (Me.m_debug)
06021     {
06022       cout << "pwd = " << CmtSystem::pwd () << endl;
06023     }
06024 
06025   /*
06026     Work on the requirements file.
06027   */
06028 
06029   if (dir != "") dir += CmtSystem::file_separator ();
06030   dir += "requirements";
06031   SyntaxParser::parse_requirements (dir, &use);
06032 
06033   if (Me.m_debug) cout << "reach_current_package2> current_tag=" << Me.m_current_tag << endl;
06034 
06056   Pattern::apply_all_globals ();
06057 
06058   /*
06059     Select all possible tags
06060   */
06061 
06062   Tag::restore_tree ();
06063 
06064   return (1);
06065 }
06066 
06067 static cmt_string get_best_form (const CmtSystem::cmt_string_vector& pwd,
06068                                  const cmt_string& path)
06069 {
06070   static cmt_string fs = CmtSystem::file_separator ();
06071   cmt_string result;
06072 
06073     /*
06074     //if (CmtSystem::getenv ("CMTTESTPREFIX") != "")
06075     {
06076     */
06077 
06078     //
06079     //  If there is a common prefix between
06080     //  use->real_path and pwd
06081     //  we have 
06082     //  use->real_path = /<prefix>/aaa
06083     //  pwd            = /<prefix>/bbb
06084     //
06085     //  Then use->real_path may be expressed as:
06086     //  ../..../../aaa
06087     //   where ../..../../ moves up to /<prefix>
06088     //
06089     //   Then we try to find the shortest between
06090     //
06091     //     /<prefix> and ../..../..
06092     //
06093   cmt_string a = path;
06094   
06095   CmtSystem::cmt_string_vector va;
06096   
06097   va.clear ();
06098   
06099   CmtSystem::split (a, fs, va);
06100   
06101   int m = va.size ();
06102   if (pwd.size () < m) m = pwd.size ();
06103   
06104   int i;
06105   
06106     //cout << "Package " << use->get_package_name () << endl;
06107   
06108   for (i = 0; i < m; i++)
06109     {
06110       const cmt_string& fa = va[i];
06111       const cmt_string& fb = pwd[i];
06112       
06113         //cout << "  fa=" << fa << " fb=" << fb << endl;
06114       
06115       if (fa != fb) break;
06116     }
06117   
06118   cmt_string ups = "";
06119   
06120   if (i > 0)
06121     {
06122         // We have the prefix.
06123         // if we count what remains from pwd, then 
06124         // we have the number of ../ required to 
06125         // move to /<prefix>
06126       int j;
06127       
06128       for (j = i; j < pwd.size (); j++)
06129         {
06130           if (j > i) ups += fs;
06131           ups += "..";
06132         }
06133 
06134       for (j = i; j < va.size (); j++)
06135         {
06136           ups += fs;
06137           ups += va[j];
06138         }
06139     }
06140   
06141     //
06142     // Here ups contains the ../..../../aaa form
06143     // for the use->real_path or is empty when there
06144     // were no common prefix.
06145     //
06146   
06147     //if (ups != "")
06148   if ((ups != "") &&
06149       (ups.size () < path.size ()))
06150     {
06151       result = ups;
06152     }
06153   else
06154     {
06155       result = path;
06156     }
06157 
06158   return (result);
06159 }
06160 
06165 class StandardMacroBuilder
06166 {
06167 public:
06168 
06172   void fill_for_CMTVERSION ()
06173   {
06174     buffer = "macro CMTVERSION \"";
06175     buffer += CMTVERSION;
06176     buffer += "\"";
06177     apply ();
06178   }
06179 
06180   StandardMacroBuilder (const cmt_string& tag,
06181                         const cmt_string& package,
06182                         const cmt_string& version,
06183                         const cmt_string& prefix,
06184                         CmtDirStyle style)
06185   {
06186     fs = CmtSystem::file_separator ();
06187     buffer = "";
06188     pwd = CmtSystem::pwd ();
06189     CmtSystem::split (pwd, fs, vb);
06190     current_use = &(Use::current ());
06191     current_tag = tag;
06192     current_package = package;
06193     current_version = version;
06194     current_prefix = prefix;
06195     current_style = style;
06196   }
06197 
06198   void apply ()
06199   {
06200     SyntaxParser::parse_requirements_line (buffer, current_use);
06201     buffer = "";
06202   }
06203 
06207   void fill_for_tag ()
06208   {
06209     static bool tag_debug = CmtSystem::testenv ("TAGDEBUG");
06210 
06211     if (!Symbol::is_selected ("tag"))
06212       {
06213         if (tag_debug) cerr << "set_standard_macro2.1> current_tag=" << current_tag << endl;
06214 
06215         if (current_tag == "")
06216           {
06217             buffer = "macro tag \"$(CMTCONFIG)\"";
06218           }
06219         else
06220           {
06221             buffer = "macro tag \"";
06222             buffer += current_tag;
06223             buffer += "\"";
06224           }
06225         
06226         if (tag_debug) cerr << " define tag: " << buffer << endl;
06227         
06228         apply ();
06229       }
06230   }
06231 
06235   void fill_for_package (const cmt_string& current_dir)
06236   {
06237     buffer = "macro package \"";
06238     buffer += current_package;
06239     buffer += "\"";
06240     apply ();
06241 
06242     buffer = "macro version \"";
06243     buffer += current_version;
06244     buffer += "\"";
06245     apply ();
06246 
06247     if (!Symbol::is_selected ("PACKAGE_ROOT"))
06248       {
06249         buffer = "macro PACKAGE_ROOT \"$(";
06250         buffer += current_prefix;
06251         buffer += "ROOT";
06252         buffer += ")\"";
06253 
06254         apply ();
06255       }
06256   }
06257 
06278   void fill_for_branches ()
06279   {
06284     if (current_style == none_style)
06285       {
06286         buffer = "macro srcdir \".";
06287         buffer += "\"";
06288         apply ();
06289 
06290         buffer = "macro src \".";
06291         buffer += fs;
06292         buffer += "\"";
06293         apply ();
06294 
06295         buffer = "macro inc \".";
06296         buffer += fs;
06297         buffer += "\"";
06298         apply ();
06299 
06300         buffer = "macro mgr \".";
06301         buffer += fs;
06302         buffer += "\"";
06303         apply ();
06304 
06305         buffer = "macro bin \".";
06306         buffer += fs;
06307         buffer += "\"";
06308         apply ();
06309 
06310         buffer = "macro javabin \".";
06311         buffer += fs;
06312         buffer += "\"";
06313         apply ();
06314 
06315         buffer = "macro doc \".";
06316         buffer += fs;
06317         buffer += "\"";
06318         apply ();
06319       }
06320     else
06321       {
06322         if (!Symbol::is_selected ("srcdir"))
06323           {
06324             buffer = "macro srcdir \"..";
06325             buffer += fs;
06326             buffer += "src";
06327             buffer += "\"";
06328             apply ();
06329           }
06330         
06331         if (!Symbol::is_selected ("src"))
06332           {
06333             buffer = "macro src \"..";
06334             buffer += fs;
06335             buffer += "src";
06336             buffer += fs;
06337             buffer += "\"";
06338             apply ();
06339           }
06340         
06341         if (!Symbol::is_selected ("inc"))
06342           {
06343             buffer = "macro inc \"..";
06344             buffer += fs;
06345             buffer += "src";
06346             buffer += fs;
06347             buffer += "\"";
06348             apply ();
06349           }
06350         
06351         if (!Symbol::is_selected ("doc"))
06352           {
06353             buffer = "macro doc \"..";
06354             buffer += fs;
06355             buffer += "doc";
06356             buffer += fs;
06357             buffer += "\"";
06358             apply ();
06359           }
06360         
06361         if (!Symbol::is_selected ("bin"))
06362           {
06363             cmt_string package_tag = current_package;
06364             package_tag += "_tag";
06365 
06366             buffer = "macro bin \"..";
06367             buffer += fs;
06368             buffer += "$(";
06369             buffer += package_tag;
06370             buffer += ")";
06371             buffer += fs;
06372             buffer += "\"";
06373             apply ();
06374           }
06375 
06376         if (!Symbol::is_selected ("javabin"))
06377           {
06378             buffer = "macro javabin \"..";
06379             buffer += fs;
06380             buffer += "classes";
06381             buffer += fs;
06382             buffer += "\"";
06383             apply ();
06384           }
06385         
06386         if (current_style == mgr_style)
06387           {
06388             buffer = "macro mgrdir \"mgr\"";
06389             apply ();
06390 
06391             buffer = "macro mgr \"..";
06392             buffer += fs;
06393             buffer += "mgr";
06394             buffer += fs;
06395             buffer += "\"";
06396             apply ();
06397           }
06398         else
06399           {
06400             buffer = "macro mgrdir \"cmt\"";
06401             apply ();
06402 
06403             buffer = "macro mgr \"..";
06404             buffer += fs;
06405             buffer += "cmt";
06406             buffer += fs;
06407             buffer += "\"";
06408             apply ();
06409           }
06410 
06411         Cmt::configure_current_cmtpath ();
06412       }
06413   }
06414 
06418   void fill_for_project ()
06419   {
06420     if (current_style == none_style) return;
06421 
06422     cmt_string project_name;
06423     Project* project = Project::get_current ();
06424     if (project != 0)
06425       {
06426         project_name = project->get_name ();
06427       }
06428 
06429     buffer = "macro project \"";
06430     buffer += project_name;
06431     buffer += "\"";
06432     apply ();
06433   }
06434 
06438   void fill_for_use_requirements ()
06439   {
06440     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06441 
06442     if (Uses.size () == 0) return;
06443 
06444     if (!Symbol::is_selected ("use_requirements"))
06445       {
06446         buffer  = "macro use_requirements \"";
06447         buffer += "requirements ";
06448         
06449         for (int number = 0; number < Uses.size (); number++)
06450           {
06451             Use* use = Uses[number];
06452             
06453             if (use->discarded) continue;
06454             
06455             if (use->located ())
06456               {
06457                 buffer += "$(";
06458                 buffer += use->prefix;
06459                 buffer += "ROOT)";
06460                 buffer += fs;
06461                 
06462                 if (use->style == mgr_style) buffer += "mgr";
06463                 else buffer += "cmt";
06464                 
06465                 buffer += fs;
06466                 buffer += "requirements ";
06467               }
06468           }
06469         
06470         buffer += "\"";
06471         
06472         apply ();
06473       }
06474   }
06475 
06479   void fill_for_use_includes ()
06480   {
06481     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06482 
06483     if (Uses.size () == 0) return;
06484 
06485     if (!Symbol::is_selected ("use_includes"))
06486       {
06487         buffer = "macro_append use_includes \' ";
06488         
06489         for (int number = 0; number < Uses.size (); number++)
06490           {
06491             Use* use = Uses[number];
06492             
06493             if (use->discarded) continue;
06494 
06495             Package* p = use->get_package ();
06496             if (p->is_cmt ()) continue;
06497 
06498             if (Cmt::get_debug ())
06499               {
06500                 cout << "fill use_includes for " << use->get_package_name () 
06501                      << " discarded=" << use->discarded
06502                      << " auto_imports=" << use->auto_imports << endl;
06503               }
06504             
06505             if (use->auto_imports == Off) continue;
06506             
06507             use->fill_includes_macro (buffer);
06508           }
06509         
06510         buffer += "\'";
06511         
06512         apply ();
06513       }
06514   }
06515 
06519   void fill_for_use_fincludes ()
06520   {
06521     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06522 
06523     if (Uses.size () == 0) return;
06524 
06525     if (!Symbol::is_selected ("use_fincludes"))
06526       {
06527         buffer = "macro_append use_fincludes \" $(use_includes)\"";
06528         apply ();
06529       }
06530   }
06531 
06535   void fill_for_use_stamps ()
06536   {
06537     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06538 
06539     if (Uses.size () == 0) return;
06540 
06541     if (!Symbol::is_selected ("use_stamps"))
06542       {
06543         buffer = "macro use_stamps \"";
06544         (Use::current()).fill_macro (buffer, "stamps");
06545         
06546         for (int number = 0; number < Uses.size (); number++)
06547           {
06548             Use* use = Uses[number];
06549             
06550             if (use->discarded) continue;
06551 
06552             Package* p = use->get_package ();
06553             if (p->is_cmt ()) continue;
06554             
06555             use->fill_macro (buffer, "stamps");
06556           }
06557         
06558         buffer += "\"";
06559         
06560         apply ();
06561       }
06562   }
06563 
06567   void fill_for_use_cflags ()
06568   {
06569     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06570 
06571     if (Uses.size () == 0) return;
06572 
06573     if (!Symbol::is_selected ("use_cflags"))
06574       {
06575         Use::fill_macro_all (buffer, "cflags");
06576         apply ();
06577       }
06578   }
06579 
06583   void fill_for_use_pp_cflags ()
06584   {
06585     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06586 
06587     if (Uses.size () == 0) return;
06588 
06589     if (!Symbol::is_selected ("use_pp_cflags"))
06590       {
06591         Use::fill_macro_all (buffer, "pp_cflags");
06592         apply ();
06593       }
06594   }
06595 
06599   void fill_for_use_cppflags ()
06600   {
06601     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06602 
06603     if (Uses.size () == 0) return;
06604 
06605     if (!Symbol::is_selected ("use_cppflags"))
06606       {
06607         Use::fill_macro_all (buffer, "cppflags");
06608         apply ();
06609       }
06610   }
06611 
06615   void fill_for_use_pp_cppflags ()
06616   {
06617     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06618 
06619     if (Uses.size () == 0) return;
06620 
06621     if (!Symbol::is_selected ("use_pp_cppflags"))
06622       {
06623         Use::fill_macro_all (buffer, "pp_cppflags");
06624         apply ();
06625       }
06626   }
06627 
06631   void fill_for_use_fflags ()
06632   {
06633     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06634 
06635     if (Uses.size () == 0) return;
06636 
06637     if (!Symbol::is_selected ("use_fflags"))
06638       {
06639         Use::fill_macro_all (buffer, "fflags");
06640         apply ();
06641       }
06642   }
06643 
06647   void fill_for_use_pp_fflags ()
06648   {
06649     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06650 
06651     if (Uses.size () == 0) return;
06652 
06653     if (!Symbol::is_selected ("use_pp_fflags"))
06654       {
06655         Use::fill_macro_all (buffer, "pp_fflags");
06656         apply ();
06657       }
06658   }
06659 
06663   void fill_for_use_linkopts ()
06664   {
06665     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06666 
06667     if (Uses.size () == 0) return;
06668 
06669     if (!Symbol::is_selected ("use_linkopts"))
06670       {
06671         Use::fill_macro_all (buffer, "linkopts");
06672         apply ();
06673       }
06674   }
06675 
06679   void fill_for_use_libraries ()
06680   {
06681     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06682 
06683     if (Uses.size () == 0) return;
06684 
06685     if (!Symbol::is_selected ("use_libraries"))
06686       {
06687         buffer  = "macro use_libraries \"";
06688 
06689         for (int number = 0; number < Uses.size (); number++)
06690           {
06691             Use* use = Uses[number];
06692             
06693             if (use->discarded) continue;
06694             
06695             Package* p = use->get_package ();
06696             if (p->is_cmt ()) continue;
06697 
06698             use->fill_macro (buffer, "libraries");
06699           }
06700         
06701         buffer += "\"";
06702         
06703         apply ();
06704       }
06705   }
06706 
06710   void fill_for_includes ()
06711   {
06712     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06713 
06714     if (Uses.size () == 0) return;
06715 
06716     if (!Symbol::is_selected ("includes"))
06717       {
06718         buffer = "macro_append includes \' ";
06719 
06720         Use& use = Use::current();
06721 
06722         if (use.include_path == "")
06723           {
06724             buffer += "$(ppcmd)\"$(srcdir)\" ";
06725           }
06726         else if (use.include_path != "none")
06727           {
06728             buffer += "$(ppcmd)\"";
06729             buffer += use.include_path;
06730             buffer += "\" ";
06731           }
06732         
06733         for (int include_number = 0;
06734              include_number < use.includes.size ();
06735              include_number++)
06736           {
06737             Include& incl = use.includes[include_number];
06738             
06739             buffer += "$(ppcmd)\"";
06740             buffer += incl.name;
06741             buffer += "\" ";
06742           }
06743         
06744         buffer += "$(use_includes)\'";
06745         
06746         apply ();
06747       }
06748   }
06749 
06753   void fill_for_fincludes ()
06754   {
06755     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06756 
06757     if (Uses.size () == 0) return;
06758 
06759     if (!Symbol::is_selected ("fincludes"))
06760       {
06761         buffer = "macro_append fincludes \" $(includes)\"";
06762         apply ();
06763       }
06764   }
06765 
06783   void fill_for_all_constituents ()
06784   {
06786     Constituent::parse_all ();
06787 
06788     Use::UsePtrVector& Uses = Use::get_ordered_uses ();
06789 
06790     const Constituent::ConstituentVector& constituents =
06791       Constituent::constituents ();
06792 
06793   
06795 
06796     cmt_vector<bool> base_auto_imports_states;
06797 
06798     base_auto_imports_states.resize (Uses.size ());
06799 
06800     int number;
06801 
06802     for (number = 0; number < Uses.size (); number++)
06803       {
06804         Use* use = Uses[number];
06805         base_auto_imports_states[number] = (use->auto_imports != Off);
06806       }
06807 
06809 
06810     for (number = 0; number < constituents.size (); number++)
06811       {
06812         const Constituent& constituent = constituents[number];
06813 
06814         if (Cmt::get_debug ())
06815           {
06816             cout << "Checking " << constituent.name  << " against imports requests" << endl;
06817           }
06818 
06819         Use::UsePtrVector imports;
06820         int i;
06821 
06839         if (constituent.type == Document) continue;
06840         if (constituent.imports.size () == 0) 
06841           {
06842             buffer = "macro_append ";
06843             buffer += constituent.name;
06844             buffer += "_use_linkopts ";
06845             buffer += " \" ";
06846        
06847             current_use->fill_macro (buffer, "linkopts");
06848        
06849             for (i = 0; i < Uses.size (); i++)
06850               {
06851                 if (base_auto_imports_states[i])
06852                   {
06853                     Use* u = Uses[i];
06854                
06855                     if (u->discarded) continue;
06856 
06857                     Package* p = u->get_package ();
06858                     if (p->is_cmt ()) continue;
06859                     
06860                     u->fill_macro (buffer, "linkopts");
06861                   }
06862               }
06863             buffer += "\"";
06864             apply ();
06865 
06866           /*
06867             buffer = "macro_append ";
06868             buffer += constituent.name;
06869             buffer += "_use_linkopts ";
06870 
06871             buffer += " \" $(use_linkopts)\"";
06872             apply ();
06873             */
06874 
06875             continue;
06876           }
06877 
06883         cmt_vector<bool> auto_imports_states (base_auto_imports_states);
06884 
06885         for (i = 0; i < constituent.imports.size (); i++)
06886           {
06887             const cmt_string& import = constituent.imports[i];
06888             
06889             //
06890             // Resolve the imported uses
06891             //
06892 
06893             int use_index = Use::find_index (import, "", "");
06894 
06895             if (use_index >= 0)
06896               {
06897                 Use* u = Uses[use_index];
06898             
06899                 if (u->discarded) continue;
06900 
06901                 if (Cmt::get_debug ())
06902                   {
06903                     cout << constituent.name  << " needs imports " << import << " "
06904                          << use_index << " " 
06905                          << u->get_package()->get_name() << endl;
06906                   }
06907 
06908                 Package* p = u->get_package ();
06909                 if (p->is_cmt ()) continue;
06910 
06911                 if (u->auto_imports != Off) continue;
06912 
06913                 Use::set_auto_imports_state (use_index, auto_imports_states);
06914               }
06915           }
06916 
06917         if (Cmt::get_debug ())
06918           {
06919             cout << constituent.name  << " has imports " << endl;
06920           }
06921 
06922 
06927         for (i = 0; i < base_auto_imports_states.size (); i++)
06928           {
06929             if (auto_imports_states[i] != base_auto_imports_states[i])
06930               {
06931                 Use* u = Uses[i];
06932 
06933                 if (u->discarded) continue;
06934 
06935                 Package* p = u->get_package ();
06936                 if (p->is_cmt ()) continue;
06937 
06938                 if (Cmt::get_debug ())
06939                   {
06940                     cout << constituent.name  << " has import " << p->get_name () << endl;
06941                   }
06942 
06943                 if (u->auto_imports != Off) continue;
06944 
06945                 imports.push_back (u);
06946               }
06947           }
06948         
06949         if (imports.size () == 0) continue;
06950 
06951         cmt_string prefix;
06952             
06953         //
06954         // Documents are not considered 
06955         //
06956         switch (constituent.type)
06957           {
06958           case Application:
06959             prefix = "app_";
06960             break;
06961           case Library:
06962             prefix = "lib_";
06963             break;
06964           }
06965             
06966         buffer = "macro_append ";
06967         buffer += prefix;
06968         buffer += constituent.name;
06969         buffer += "_cflags ";
06970         buffer += " \' ";
06971         for (i = 0; i < imports.size (); i++)
06972           {
06973             Use* u = imports[i];
06974             
06975             u->fill_includes_macro (buffer);
06976             u->fill_macro (buffer, "cflags");
06977           }
06978         buffer += "\'";
06979         apply ();
06980         
06981         buffer = "macro_append ";
06982         buffer += prefix;
06983         buffer += constituent.name;
06984         buffer += "_pp_cflags ";
06985         buffer += " \" ";
06986         for (i = 0; i < imports.size (); i++)
06987           {
06988             Use* u = imports[i];
06989             
06990             u->fill_macro (buffer, "pp_cflags");
06991           }
06992         buffer += "\"";
06993         apply ();
06994         
06995         buffer = "macro_append ";
06996         buffer += prefix;
06997         buffer += constituent.name;
06998         buffer += "_cppflags ";
06999         buffer += " \' ";
07000         for (i = 0; i < imports.size (); i++)
07001           {
07002             Use* u = imports[i];
07003             
07004             u->fill_includes_macro (buffer);
07005             u->fill_macro (buffer, "cppflags");
07006           }
07007         buffer += "\'";
07008         apply ();
07009         
07010         buffer = "macro_append ";
07011         buffer += prefix;
07012         buffer += constituent.name;
07013         buffer += "_pp_cppflags ";
07014         buffer += " \" ";
07015         for (i = 0; i < imports.size (); i++)
07016           {
07017             Use* u = imports[i];
07018             
07019             u->fill_macro (buffer, "pp_cppflags");
07020           }
07021         buffer += "\"";
07022         apply ();
07023         
07024         buffer = "macro_append ";
07025         buffer += prefix;
07026         buffer += constituent.name;
07027         buffer += "_fflags ";
07028         buffer += " \' ";
07029         for (i = 0; i < imports.size (); i++)
07030           {
07031             Use* u = imports[i];
07032             
07033             u->fill_includes_macro (buffer);
07034             u->fill_macro (buffer, "fflags");
07035           }
07036         buffer += "\'";
07037         apply ();
07038         
07039         buffer = "macro_append ";
07040         buffer += prefix;
07041         buffer += constituent.name;
07042         buffer += "_pp_fflags ";
07043         buffer += " \" ";
07044         for (i = 0; i < imports.size (); i++)
07045           {
07046             Use* u = imports[i];
07047             
07048             u->fill_macro (buffer, "pp_fflags");
07049           }
07050         buffer += "\"";
07051         apply ();
07052         
07060        buffer = "macro_append ";
07061        buffer += constituent.name;
07062        buffer += "linkopts ";
07063        buffer += " \" ";
07064        for (i = 0; i < imports.size (); i++)
07065          {
07066            Use* u = imports[i];
07067            
07068            u->fill_macro (buffer, "linkopts");
07069          }
07070        buffer += "\"";
07071        apply ();
07072        
07080         buffer = "macro_append ";
07081         buffer += constituent.name;
07082         buffer += "_use_linkopts ";
07083         buffer += " \" ";
07084         
07085         current_use->fill_macro (buffer, "linkopts");
07086         
07087         for (i = 0; i < Uses.size (); i++)
07088           {
07089             if (auto_imports_states[i])
07090               {
07091                 Use* u = Uses[i];
07092                 
07093                 if (u->discarded) continue;
07094                 
07095                 Package* p = u->get_package ();
07096                 if (p->is_cmt ()) continue;
07097 
07098                 u->fill_macro (buffer, "linkopts");
07099               }
07100           }
07101         buffer += "\"";
07102         apply ();
07103 
07104         //==== GLAST addition for vs.net ==========
07105         buffer = "macro ";
07106         buffer += constituent.name;
07107         buffer += "_GUID \"{88BF15AB-5A2D-4bea-B64F-02752C2A1F4F}\" ";
07108         apply ();
07109       }
07110   }
07111 
07115   void fill_for_constituent_macros ()
07116   {
07117     int number;
07118     cmt_string temp;
07119 
07120     const Constituent::ConstituentVector& constituents = Constituent::constituents ();
07121   
07122     if (!Symbol::is_selected ("constituents"))
07123       {
07124         temp = "macro_append constituents \" ";
07125         
07126         for (number = 0; number < constituents.size (); number++)
07127           {
07128             const Constituent& constituent = constituents[number];
07129             
07130             if (constituent.group == 0)
07131               {
07132                 temp += constituent.name;
07133                 temp += " ";
07134               }
07135           }
07136         
07137         temp += "\"";
07138         
07139         SyntaxParser::parse_requirements_line (temp, current_use);
07140       }
07141     
07142     SyntaxParser::parse_requirements_line ("macro_append all_constituents \" $(constituents)\"", 
07143                                            current_use);
07144     
07145     if (!Symbol::is_selected ("constituentsclean"))
07146       {
07147         temp = "macro_append constituentsclean \" ";
07148         
07149         for (number = constituents.size () - 1; number >= 0 ; number--)
07150           {
07151             const Constituent& constituent = constituents[number];
07152             
07153             if (constituent.group == 0)
07154               {
07155                 temp += constituent.name;
07156                 temp += "clean ";
07157               }
07158           }
07159         
07160         temp += "\"";
07161         
07162         SyntaxParser::parse_requirements_line (temp, current_use);
07163       }
07164     
07165     SyntaxParser::parse_requirements_line ("macro_append all_constituentsclean \" $(constituentsclean)\"", 
07166                                            current_use);
07167     
07168     const Group::GroupVector& groups = Group::groups ();
07169     
07170     for (number = 0; number < groups.size (); number++)
07171       {
07172         const Group& group = groups[number];
07173         
07174         temp = "macro_append ";
07175         temp += group.name ();
07176         temp += "_constituents \" ";
07177         
07178         int i;
07179         
07180         for (i = 0; i < constituents.size (); i++)
07181           {
07182             const Constituent& constituent = constituents[i];
07183             
07184             if ((constituent.group != 0) && 
07185                 (group.name () == constituent.group->name ()))
07186               {
07187                 temp += constituent.name;
07188                 temp += " ";
07189               }
07190           }
07191         
07192         temp += "\"";
07193         
07194         SyntaxParser::parse_requirements_line (temp, current_use);
07195         
07196         temp = "macro_append ";
07197         temp += group.name ();
07198         temp += "_constituentsclean \" ";
07199         
07200         for (i = constituents.size () - 1; i >= 0 ; i--)
07201           {
07202             const Constituent& constituent = constituents[i];
07203             
07204             if ((constituent.group != 0) && 
07205                 (group.name () == constituent.group->name ()))
07206               {
07207                 temp += constituent.name;
07208                 temp += "clean ";
07209               }
07210           }
07211         
07212         temp += "\"";
07213         
07214         SyntaxParser::parse_requirements_line (temp, current_use);
07215     }
07216   }
07217 
07221   void fill_for_install_area ()
07222   {
07223     CmtPathPattern::apply_all ();
07224 
07225     if (get_strategy ("InstallArea"))
07226       {
07227         CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
07228 
07229         //cout << "#IA7>" << endl;
07230         
07231         ia_mgr.setup ();
07232       }
07233   }
07234 
07239   void fill_for_current_package (const cmt_string& current_dir)
07240   {
07241     fill_for_tag ();
07242     fill_for_package (current_dir);
07243   }
07244 
07245 private:
07246   cmt_string fs;
07247   cmt_string buffer;
07248   CmtSystem::cmt_string_vector vb;
07249   cmt_string pwd;
07250   Use* current_use;
07251   cmt_string current_tag; 
07252   cmt_string current_package; 
07253   cmt_string current_version; 
07254   cmt_string current_prefix; 
07255   CmtDirStyle current_style;
07256 };
07257 
07258 //----------------------------------------------------------
07259 void Cmt::set_current_access (AccessMode mode)
07260 {
07261   Me.m_current_access = mode;
07262 }
07263 
07264 //----------------------------------------------------------
07265 void Cmt::set_scope_filtering_mode (CmtScopeFilteringMode mode)
07266 {
07267   Me.m_scope_filtering_mode = mode;
07268 }
07269 
07270 //----------------------------------------------------------
07271 void Cmt::set_standard_macros ()
07272 {
07273   if (Me.m_standard_macros_done) return;
07274 
07275   Me.m_standard_macros_done = true;
07276 
07277   Use::UsePtrVector& Uses = Use::get_ordered_uses ();
07278   Use& current_use = Use::current ();
07279 
07280   cmt_string fs = CmtSystem::file_separator ();
07281 
07282   cmt_string pwd = CmtSystem::pwd ();
07283 
07284   if (CmtSystem::test_file ("../cmt/requirements")) Me.m_current_style = cmt_style;
07285   else if (CmtSystem::test_file ("../mgr/requirements")) Me.m_current_style = mgr_style;
07286   else Me.m_current_style = none_style;
07287 
07288   {
07289     cmt_string v;
07290     CmtSystem::dirname (pwd, v);
07291     CmtSystem::basename (v, v);
07292     if (!CmtSystem::is_version_directory (v))
07293       {
07294         Me.m_current_style = no_version_style;
07295       }
07296   }
07297 
07298   // Prepare computation of the best form for relative path from current directory
07299   // to package directories.
07300   CmtSystem::cmt_string_vector vb;
07301   CmtSystem::split (pwd, fs, vb);
07302 
07303 
07308   bool tag_debug = CmtSystem::testenv ("TAGDEBUG");
07309 
07310   if (tag_debug) cerr << "set_standard_macro0> current_tag=" << Me.m_current_tag << endl;
07311 
07312   if (Me.m_current_tag != "")
07313     {
07314         // this is when some -tag= argument was used.
07315       if (tag_debug) cerr << "set_standard_macro0.1> current_tag=" << Me.m_current_tag << endl;
07316     }
07317   else if (Symbol::is_selected ("CMTCONFIG"))
07318     {
07319         // This is when CMTCONFIG has been set from some requirements file
07320       Symbol* macro = Symbol::find ("CMTCONFIG");
07321       if (macro != 0)
07322         {
07323           Me.m_current_tag = macro->build_macro_value ();
07324           if (tag_debug) cerr << "set_standard_macro1> current_tag=" << Me.m_current_tag << endl;
07325         }
07326     }
07327   else
07328     {
07329         // this is when no -tag= argument was used.
07330       if (tag_debug) cerr << "set_standard_macro(before2)> current_tag=" << Me.m_current_tag << endl;
07331       if (current_use.get_package_name () == "CMT")
07332         {
07333           Me.m_current_tag = CmtSystem::getenv ("CMTBIN");
07334         }
07335       else
07336         {
07337           Me.m_current_tag = CmtSystem::getenv ("CMTCONFIG");
07338         }
07339 
07340       if (tag_debug) cerr << "set_standard_macro2> current_tag=" << Me.m_current_tag << endl;
07341     }
07342 
07343   if (Me.m_debug)
07344     {
07345       cout << "set_standard_macro3>" << endl;
07346     }
07347 
07348   StandardMacroBuilder builder (Me.m_current_tag,
07349                                 Me.m_current_package,
07350                                 Me.m_current_version,
07351                                 Me.m_current_prefix,
07352                                 Me.m_current_style);
07353 
07354 
07355     //
07356     //  Definitions for installation area mechanisms
07357     //
07358   /*
07359   if (get_strategy ("InstallArea"))
07360     {
07361       CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
07362 
07363       //cout << "#IA6>" << endl;
07364 
07365       ia_mgr.setup_current_installarea ();
07366     }
07367   */
07368 
07369   builder.fill_for_current_package (Me.m_current_dir);
07370 
07371   builder.fill_for_branches ();
07372   builder.fill_for_project ();
07373 
07374   builder.fill_for_install_area ();
07375 
07376   builder.fill_for_use_requirements ();
07377   builder.fill_for_use_includes ();
07378   builder.fill_for_use_fincludes ();
07379   builder.fill_for_use_stamps ();
07380   builder.fill_for_use_cflags ();
07381   builder.fill_for_use_pp_cflags ();
07382   builder.fill_for_use_cppflags ();
07383   builder.fill_for_use_pp_cppflags ();
07384   builder.fill_for_use_fflags ();
07385   builder.fill_for_use_pp_fflags ();
07386   builder.fill_for_use_linkopts ();
07387   builder.fill_for_use_libraries ();
07388   builder.fill_for_includes ();
07389   builder.fill_for_fincludes ();
07390   builder.fill_for_all_constituents ();
07391   builder.fill_for_constituent_macros ();
07392 }
07393 
07394 void Cmt::set_all_sets_done ()
07395 {
07396   Me.m_all_sets_done = true;
07397 }
07398 
07399 void Cmt::reset_all_sets_done ()
07400 {
07401   Me.m_all_sets_done = false;
07402 }
07403 
07404 //----------------------------------------------------------
07405 void Cmt::use_cmt ()
07406 {
07407   UseRef use;
07408   bool recursive_copy = Me.m_recursive;
07409   bool debug_copy = Me.m_debug;
07410 
07411   if (Me.m_default_path.size () <= 0) return;
07412   if (Me.m_current_package == "CMT") return;
07413 
07414   Me.m_recursive = true;
07415   Me.m_debug = false;
07416   use = Use::add (Me.m_default_path, "CMT", Me.m_cmt_version, "", "", 0);
07417   Me.m_recursive = recursive_copy;
07418   Me.m_debug = debug_copy;
07419 }
07420 
07421 //----------------------------------------------------------
07422 void Cmt::use_home_requirements ()
07423 {
07424   use_special_requirements (Me.m_cmt_home, 
07425                             CmtSystem::get_home_package (), 
07426                             "requirements");
07427 }
07428 
07429 //----------------------------------------------------------
07430 void Cmt::use_user_context_requirements ()
07431 {
07432   use_special_requirements (Me.m_cmt_user_context, 
07433                             CmtSystem::get_user_context_package (), 
07434                             "requirements");
07435 }
07436 
07437 //----------------------------------------------------------
07438 void Cmt::use_special_requirements (const cmt_string& path, 
07439                                     const cmt_string& name, 
07440                                     const cmt_string& file_name)
07441 {
07442   if (path == "") 
07443     {
07444       return;
07445     }
07446 
07447   UseRef use;
07448   bool recursive_copy = Me.m_recursive;
07449 
07450   if (Me.m_default_path.size () <= 0) return;
07451   if (Me.m_current_package == "CMT") return;
07452 
07453   Me.m_recursive = true;
07454 
07455   use = Use::add (path, name, "v0", "", "", 0);
07456 
07457   cmt_string f = Me.m_cmt_user_context;
07458   f += CmtSystem::file_separator ();
07459   f += file_name;
07460   SyntaxParser::parse_requirements (f, use);
07461 
07462   Me.m_recursive = recursive_copy;
07463 }
07464 
07465 //-------------------------------------------------
07466 void Cmt::vector_to_string (const CmtSystem::cmt_string_vector& v,
07467                             const cmt_string& separator,
07468                             cmt_string& result)
07469 {
07470   result.erase (0);
07471 
07472   for (int i = 0; i < v.size (); i++)
07473     {
07474       const cmt_string& s = v[i];
07475       if (s == "") continue;
07476 
07477       if (i > 0) result += separator;
07478       result += v[i];
07479     }
07480 }
07481 
07482 //-------------------------------------------------
07483 cmt_string Cmt::vector_to_string (const CmtSystem::cmt_string_vector& v)
07484 {
07485   cmt_string result;
07486 
07487   vector_to_string (v, " ", result);
07488 
07489   return (result);
07490 }

Generated on Mon May 2 10:25:05 2005 for CMT by doxygen 1.3.5