source: CMT/HEAD/source/cmt_parser.cxx @ 550

Last change on this file since 550 was 550, checked in by rybkin, 14 years ago

See C.L. 435

  • Property svn:eol-style set to native
File size: 230.8 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// Modified by garonne@lal.in2p3.fr
5// See the complete license in cmt_license.txt "http://www.cecill.info".
6//-----------------------------------------------------------
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <ctype.h>
12
13//----------------------------------------------------------
14
15#include "cmt_parser.h"
16#include "cmt_version.h"
17
18#include "cmt_database.h"
19#include "cmt_include.h"
20#include "cmt_script.h"
21#include "cmt_generator.h"
22#include "cmt_system.h"
23#include "cmt.h"
24#include "cmt_error.h"
25#include "cmt_cvs.h"
26#include "cmt_vcs.h"
27#include "cmt_lock.h"
28#include "cmt_triggers.h"
29#include "cmt_model.h"
30#include "cmt_awk.h"
31#include "cmt_syntax.h"
32#include "cmt_install_area.h"
33#include "cmt_cmtpath_pattern.h"
34#include "cmt_sequence.h"
35#include "cmt_map.h"
36#include "cmt_project.h"
37#include "cmt_log.h"
38#include "cmt_commands.h"
39
40//----------------------------------------------------------
41//
42//  Static object definitions for the CmtContext class.
43//
44
45static CmtContext Me;
46
47CmtContext::CmtContext ()
48{
49  clear ();
50}
51
52CmtContext::~CmtContext ()
53{
54}
55
56void CmtContext::clear ()
57{
58  m_action         = action_none;
59  m_build_nmake    = false;
60  m_cmt_config     = "";
61  //m_cmt_path.clear ();
62  //m_cmt_path_pwds.clear ();
63  //m_cmt_path_sources.clear ();
64  m_cmt_root       = "";
65  m_cmt_version    = "";
66  m_current_dir     = "";
67  m_current_file_path = "";
68  m_current_package = "";
69  m_current_config  = "";
70  m_current_path    = "";
71  m_current_prefix  = "";
72  m_current_cmtpath = "";
73  m_current_offset  = "";
74
75  m_current_access   = DeveloperMode;
76
77  m_current_tag      = "";
78  m_current_target   = "";
79  m_current_version  = "";
80  m_default_path     = "";
81
82  //m_quiet            = false;
83
84  m_disable_warnings = false;
85  m_warnings         = false;
86  m_recursive        = false;
87
88  m_scope_filtering_mode = default_filtering_mode;
89  m_simulation       = false;
90
91  m_standard_macros_done = false;
92  m_current_access = UserMode;
93  m_current_style = cmt_style;
94  m_current_structuring_style = default_structuring_style;
95  m_all_sets_done = false;
96  m_autoconfigure_cmtpath = false;
97  m_debug = false;
98  if (getenv ("CMTDEBUG") != 0) m_debug = true;
99}
100
101//----------------------------------------------------------
102
103
104//----------------------------------------------------------
105//
106//   Utility classes
107//
108//----------------------------------------------------------
109
110/**
111 *  This PathScanner actor simply displays the package name/version/path
112 *  It is used by the cmt show packages operation
113 */
114class PackageViewer : public PathScanner::actor
115{
116public:
117  void run (const cmt_string& package,
118            const cmt_string& version,
119            const cmt_string& path,
120            const bool without_version_directory=false);
121};
122
123
124/**
125 *  This PathScanner actor accumulates all found packages into a cmt_string_vector
126 *  It is used by the broadcast operation
127 */
128class PackageSelector : public PathScanner::actor
129{
130public:
131  PackageSelector (CmtSystem::cmt_string_vector& uses);
132  void run (const cmt_string& package,
133            const cmt_string& version,
134            const cmt_string& path,
135            const bool without_version_directory=false);
136private:
137  CmtSystem::cmt_string_vector& m_uses;
138};
139
140
141
142/**
143 *  This PathScanner actor collects all packages clients of the specified one
144 *  It is used by the cmt show clients operation
145 */
146class ClientCollector : public PathScanner::actor
147{
148public:
149  ClientCollector (const cmt_string& package,
150                   const cmt_string& version);
151  void run (const cmt_string& package,
152            const cmt_string& version,
153            const cmt_string& path,
154            const bool without_version_directory=false);
155  int count ();
156
157private:
158  const cmt_string& m_package;
159  const cmt_string& m_version;
160  int m_count;
161};
162
163//----------------------------------------------------------
164void PackageViewer::run (const cmt_string& package,
165                         const cmt_string& version,
166                         const cmt_string& path,
167                         const bool without_version_directory)
168{
169  cout << package << " " << version << " " << path << endl;
170}
171
172//----------------------------------------------------------
173PackageSelector::PackageSelector (CmtSystem::cmt_string_vector& uses) : m_uses(uses)
174{
175}
176
177//----------------------------------------------------------
178void PackageSelector::run (const cmt_string& package,
179                           const cmt_string& version,
180                           const cmt_string& path,
181                           const bool without_version_directory)
182{
183  //
184  // this might be called on a package with no version directory.
185  // then simply the version argument is empty.
186  //
187
188  cmt_string r = CmtSystem::file_separator ();
189  r += "requirements";
190
191  cmt_string temp;
192
193  if (version == "")
194    {
195      temp = path;
196      //temp += CmtSystem::file_separator ();
197      //temp += package;
198      temp += CmtSystem::file_separator ();
199      temp += "cmt";
200      temp += r;
201     
202      if (!CmtSystem::test_file (temp)) return;
203    }
204  else
205    {
206      temp = path;
207      //temp += CmtSystem::file_separator ();
208      //temp += package;
209      temp += CmtSystem::file_separator ();
210      temp += version;
211      temp += CmtSystem::file_separator ();
212      temp += "cmt";
213      temp += r;
214     
215      if (!CmtSystem::test_file (temp))
216        {
217          temp = path;
218          //temp += CmtSystem::file_separator ();
219          //temp += package;
220          temp += CmtSystem::file_separator ();
221          temp += version;
222          temp += CmtSystem::file_separator ();
223          temp += "mgr";
224          temp += r;
225         
226          if (!CmtSystem::test_file (temp))
227            {
228              return;
229            }
230        }
231    }
232
233  temp.replace (r.c_str(), "");
234  cmt_string& use = m_uses.add ();
235  use = temp;
236}
237
238//----------------------------------------------------------
239ClientCollector::ClientCollector (const cmt_string& package,
240                                  const cmt_string& version) :
241  m_package (package), m_version (version), m_count (0)
242{
243}
244
245//----------------------------------------------------------
246void ClientCollector::run (const cmt_string& package,
247                           const cmt_string& version,
248                           const cmt_string& path,
249                           const bool without_version_directory)
250{
251  cmt_string dir = path;
252  dir += CmtSystem::file_separator ();
253  dir += package;
254  dir += CmtSystem::file_separator ();     
255  if (version != "" && ! without_version_directory)
256    {
257      dir += version;
258      dir += CmtSystem::file_separator ();
259    }
260
261  cmt_string req;
262 
263  req  = dir;
264  req += "cmt";
265  req += CmtSystem::file_separator ();
266  req += "requirements";
267
268  cmt_string requirements;
269  cmt_string line;
270  CmtSystem::cmt_string_vector words;
271
272  if (CmtSystem::test_file (req))
273    {
274      requirements.read (req);
275    }
276  else
277    {
278      req = dir;
279      req += "mgr";
280      req += CmtSystem::file_separator ();
281      req += "requirements";
282      if (CmtSystem::test_file (req))
283        {
284          requirements.read (req);
285        }
286    }
287
288  if (requirements != "")
289    {
290      int pos = 0;
291      int max_pos = requirements.size ();
292
293      while (pos < max_pos)
294        {
295          int cr = requirements.find (pos, "\r\n");
296          int nl = requirements.find (pos, '\n');
297          int first = nl;
298          int length = 1;
299               
300          if (cr != cmt_string::npos)
301            {
302              if (nl == cmt_string::npos)
303                {
304                  first = cr;
305                  length = 2;
306                }
307              else
308                {
309                  first = (nl < cr) ? nl : cr;
310                  length = (nl < cr) ? 1 : 2;
311                }
312            }
313               
314          if (first == cmt_string::npos)
315            {
316              requirements.substr (pos, line);
317              pos = max_pos;
318            }
319          else if (first > pos)
320            {
321              requirements.substr (pos, first - pos, line);
322              pos = first + length;
323            }
324          else
325            {
326              line.erase (0);
327              pos += length;
328            }
329
330          CmtSystem::split (line, " \t", words);
331
332          if ((words.size () >= 2) && (words[0] == "use")) 
333            {
334              if ((words[1] == m_package) && 
335                  ( (m_version == "") || (words[2] == m_version)))
336                {
337                  cout << "# " << package << " " << version << " " << path;
338                  if (m_version == "" && words.size () > 2)
339                    {
340                      cout << " (use version " << words[2] << ")";
341                    }
342                  cout << endl;
343                  m_count++;
344                }
345            }
346        }
347    }
348}
349
350//----------------------------------------------------------
351int ClientCollector::count ()
352{
353  return (m_count);
354}
355
356
357
358
359//----------------------------------------------------------
360//
361//   The Cmt methods
362//
363//----------------------------------------------------------
364
365
366
367/**
368 *   Append "CONFIG" to the prefix
369 */
370void Cmt::build_config (const cmt_string& prefix,
371                        cmt_string& config)
372{
373  /*
374    Building the config from <prefix>
375  */
376
377  config = prefix;
378  config += "CONFIG";
379}
380
381//----------------------------------------------------------
382void Cmt::build_makefile (const cmt_string& target)
383{
384  Constituent* constituent = 0;
385
386  if (target.size () > 0)
387    {
388      /*
389        Do genmake for one specific target.
390      */
391      constituent = Constituent::find (target);
392      if (constituent != 0)
393        {
394          constituent->build_makefile (Me.m_simulation);
395        }
396    }
397  else
398    {
399      /*
400        Do genmake for all possible targets.
401      */
402      Constituent::build_all_makefiles (Me.m_simulation);
403    }
404}
405
406//----------------------------------------------------------
407void Cmt::build_msdev_file (const cmt_string& target)
408{
409  Constituent* constituent = 0;
410
411  set_standard_macros ();
412
413  if (target != "")
414    {
415      /*
416        Do genmsdev for one specific target.
417      */
418      constituent = Constituent::find (target);
419      if (constituent != 0)
420        {
421          constituent->build_msdev_file (Me.m_simulation);
422        }
423    }
424  else
425    {
426      /*
427        Do genmsdev for all possible targets.
428      */
429      Constituent::build_all_msdev_files (Me.m_simulation);
430    }
431}
432
433/**
434   Visual Studio.net Support                                 
435*/
436void Cmt::build_vsnet_file (const cmt_string& target)       
437{                                                           
438  Constituent* constituent = 0;                             
439                                                             
440  set_standard_macros ();                                   
441                                                             
442  if (target != "")                                         
443    {                                                       
444      /*                                                     
445                                                             Do genvsnet for one specific target.                 
446      */                                                     
447      constituent = Constituent::find (target);             
448      if (constituent != 0)                                 
449        {                                                   
450          constituent->build_vsnet_file (Me.m_simulation);       
451        }                                                   
452    }                                                       
453  else                                                       
454    {                                                       
455      /*                                                     
456                                                             Do genvsnet for all possible targets.               
457      */                                                     
458      Constituent::build_all_vsnet_files (Me.m_simulation);       
459    }                                                       
460}                                                           
461
462//----------------------------------------------------------
463bool Cmt::build_nmake ()
464{
465  return (Me.m_build_nmake);
466}
467
468//----------------------------------------------------------
469void Cmt::build_OS9_makefile (const cmt_string& target)
470{
471  build_makefile (target);
472}
473
474/**
475 *   Convert a package name to its upper case copy
476 */
477void Cmt::build_prefix (const cmt_string& package, cmt_string& prefix)
478{
479  int pos;
480  char c;
481
482  /*
483    Building the prefix from <package>
484  */
485
486  prefix = package;
487
488  for (pos = 0; pos < package.size (); pos++)
489    {
490      c = package[pos];
491      prefix[pos] = toupper (c);
492    }
493}
494
495//----------------------------------------------------------
496void Cmt::clear ()
497{
498  Me.m_quiet = false;
499  Me.clear ();
500
501  Database::clear ();
502  Include::clear_all ();
503  Script::clear_all ();
504  CmtError::clear ();
505}
506
507//----------------------------------------------------------
508//void Cmt::configure ()
509void Cmt::configure (const ArgParser& ap)
510{
511  Log;
512  static bool configured = false;
513
514  if (configured) return;
515
516  Me.clear ();
517
518  log << "configure_cmt_message" << log_endl;
519  //configure_cmt_message ();
520  configure_cmt_message (ap);
521
522  log << "configure_default_path" << log_endl;
523  configure_default_path ();
524  log << "configure_version_tag" << log_endl;
525  configure_version_tag ();
526  log << "configure_uname_tag" << log_endl;
527  configure_uname_tag ();
528  log << "configure_hosttype_tag" << log_endl;
529  configure_hosttype_tag ();
530  log << "configure_config_tag" << log_endl;
531  configure_config_tag ();
532  log << "configure_site_tag" << log_endl;
533  configure_site_tag (0);
534  log << "configure_current_dir" << log_endl;
535  configure_current_dir ();
536  log << "configure_home" << log_endl;
537  // CMTHOME, CMTUSERCONTEXT and CMTPATH
538  configure_home (0);
539  //  log << "configure_current_dir" << log_endl;
540
541
542  bool save_quiet = Me.m_quiet;
543  Me.m_quiet = true;
544
545  Me.m_autoconfigure_cmtpath = true;
546  configure_cmt_path (0);
547  Me.m_autoconfigure_cmtpath = false;
548
549  Me.m_quiet = save_quiet;
550
551  //  configure_current_dir ();
552
553  guess_current_project ();
554
555  log << "configure_current_structuring_style" << log_endl;
556  //  configure_current_structuring_style ();
557  configure_current_structuring_style (ap);
558
559  log << "configure_current_package" << log_endl;
560  configure_current_package ();
561
562  Use& use = Use::current();
563
564  use.set (Me.m_current_package,
565           Me.m_current_version,
566           Me.m_current_path,
567           "",
568           "");
569
570  use.style = Me.m_current_style;
571  use.structuring_style = Me.m_current_structuring_style;
572
573  use.change_path (Me.m_current_path);
574
575  if (CmtError::has_pending_error ()) 
576    {
577      Me.m_configure_error = CmtError::get_last_error ();
578    }
579}
580
581//----------------------------------------------------------
582void Cmt::configure_cmt_path (Use* use)
583{
584  if (!Me.m_autoconfigure_cmtpath) return;
585
586  cmt_string s;
587
588  s = Symbol::get_env_value ("CMTPATH");
589
590  {
591    bool q = Me.m_quiet;
592    Me.m_quiet = true; 
593
594    Symbol::filter_path_value ("CMTPATH", s);
595
596    Me.m_quiet = q;
597  }
598
599  IProjectFactory& factory = ProjectFactory::instance ();
600  factory.reset ();
601
602  CmtSystem::get_cmt_paths (factory, s, Me.m_cmt_user_context, Me.m_cmt_home);
603}
604
605//----------------------------------------------------------
606void Cmt::configure_config_tag ()
607{
608  Me.m_cmt_config = CmtSystem::get_cmt_config ();
609  if (Me.m_cmt_config != "")
610    {
611      Tag* tag;
612
613      tag = Tag::add (Me.m_cmt_config, PriorityConfig, "CMTCONFIG", 0);
614      tag->mark ();
615    }
616}
617
618//----------------------------------------------------------
619void Cmt::configure_current_cmtpath ()
620{
621  Use& current_use = Use::current ();
622
623  Me.m_current_cmtpath = "";
624  Me.m_current_offset = "";
625
626  Me.m_current_cmtpath = Project::find_in_cmt_paths (current_use.path);
627
628  if (Me.m_current_cmtpath != "")
629    {
630      static const cmt_string empty_string;
631      static const cmt_string fs = CmtSystem::file_separator ();
632
633      Me.m_current_offset = current_use.path;
634
635      /**
636         try to remove this current CMTPATH entry from path.  This
637         has a meaning when the specified path already contains an
638         absolute path.
639      */
640     
641      Me.m_current_offset.replace (Me.m_current_cmtpath, empty_string);
642      if (Me.m_current_offset[0] == CmtSystem::file_separator ())
643        {
644          // Just in case there is a part left after removing the cmtpath entry
645         
646          Me.m_current_offset.replace (fs, empty_string);
647        }
648    }
649}
650
651class CmtMountFilterParser : public FAwk
652{
653public:
654
655  CmtMountFilterParser ()
656  {
657    reset ();
658  }
659
660  void reset ()
661  {
662    m_current_dir = CmtSystem::pwd ();
663
664    m_done = false;
665    m_prefix = "";
666  }
667
668  bool is_done () const
669  {
670    return (m_done);
671  }
672
673  const cmt_string& get_current_dir () const
674  {
675    return (m_current_dir);
676  }
677
678  void set_prefix (const cmt_string& prefix)
679  {
680    m_prefix = prefix;
681  }
682
683  void filter (const cmt_string& line)
684  {
685    if (m_done) 
686      {
687        stop ();
688        return;
689      }
690
691    CmtSystem::cmt_string_vector words;
692
693    CmtSystem::split (line, " \t", words);
694
695    int requested = 2;
696
697    if (m_prefix != "")
698      {
699        requested++;
700      }
701
702    if (words.size () < requested) return;
703
704    int n = 0;
705
706    if (m_prefix != "")
707      {
708        if (words[n] != m_prefix) return;
709        n++;
710      }
711
712    cmt_string& path_name = words[n];
713    cmt_string& replacement = words[n+1];
714   
715    if (m_current_dir.find (path_name) != cmt_string::npos)
716      {
717        m_current_dir.replace (path_name, replacement);
718        m_done = true;
719        stop ();
720      }
721  }
722
723private:
724  bool m_done;
725  cmt_string m_prefix;
726  cmt_string m_current_dir;
727};
728
729//----------------------------------------------------------
730void Cmt::configure_current_dir ()
731{
732  cmt_string file_name;
733
734  /*
735    Building current_dir :
736
737    o we first get the physical value (using getwd)
738    o then this value is possibly filtered using the
739    cmt_mount_filter file.
740  */
741
742  CmtMountFilterParser mount_filter;
743
744  /**
745     First try with ${CMTROOT}/mgr/cmt_mount_filter
746     with no prefix on lines
747  */
748
749  file_name = Me.m_default_path;
750  if (file_name != "")
751    {
752      file_name += CmtSystem::file_separator ();
753      file_name += "CMT";
754      file_name += CmtSystem::file_separator ();
755      file_name += Me.m_cmt_version;
756      file_name += CmtSystem::file_separator ();
757      file_name += "mgr";
758      file_name += CmtSystem::file_separator ();
759    }
760
761  file_name += "cmt_mount_filter";
762
763  mount_filter.run (file_name);
764
765  /**
766     Now try with .cmtrc
767     with "mount_filter" keyword
768  */
769
770  mount_filter.set_prefix ("mount_filter");
771
772  mount_filter.run (".cmtrc");
773
774  /**
775     Now try with ${HOME}/.cmtrc
776     with "mount_filter" keyword
777  */
778
779  if (CmtSystem::get_home_directory (file_name))
780    {
781      file_name += CmtSystem::file_separator ();
782      file_name += ".cmtrc";
783      mount_filter.run (file_name);
784    }
785
786  Me.m_current_dir = mount_filter.get_current_dir ();
787  Me.m_current_file_path = mount_filter.get_current_dir ();
788
789  cmt_string t = Me.m_current_file_path;
790}
791
792//----------------------------------------------------------
793void Cmt::configure_current_package ()
794{
795  /*
796    Build current_package and current_prefix.
797
798    This is only possible if we are within the cmt/mgr branch of a
799    standard directory tree (i.e. <package>/<version>/cmt or mgr)
800  */
801
802  cmt_string req = "..";
803  req += CmtSystem::file_separator ();
804  req += "cmt";
805  req += CmtSystem::file_separator ();
806  req += "requirements";
807
808  if (CmtSystem::test_file (req))
809    {
810      Me.m_current_style = cmt_style;
811    }
812  else
813    {
814      cmt_string req = "..";
815      req += CmtSystem::file_separator ();
816      req += "mgr";
817      req += CmtSystem::file_separator ();
818      req += "requirements";
819
820      if (CmtSystem::test_file (req))
821        {
822          Me.m_current_style = mgr_style;
823        }
824      else
825        {
826          // This package is probably a standalone one
827          Me.m_current_style = none_style;
828        }
829    }
830
831
832  if (Me.m_current_style != none_style)
833    {
834      //
835      //  Here there is a ../cmt or ../mgr branch in front of us
836      //  and there is a requirements file there
837      //
838
839      cmt_string up_dir;
840      cmt_string up_branch;
841
842      CmtSystem::dirname (Me.m_current_dir, up_dir);
843      CmtSystem::basename (up_dir, up_branch);
844
845      cmt_string cmt_dir = "..";
846      cmt_dir += CmtSystem::file_separator ();
847      switch (Me.m_current_style)
848        {
849        case cmt_style:
850          cmt_dir += "cmt";
851          break;
852        case mgr_style:
853          cmt_dir += "mgr";
854          break;
855        default:
856          break;
857        }
858      //      version_file += CmtSystem::file_separator ();
859      //      version_file += "version.cmt";
860
861      //      if (CmtSystem::test_file (version_file))
862      if (CmtSystem::test_file (cmt_dir
863                                + CmtSystem::file_separator ()
864                                + Package::get_version_file_name ())
865          )
866        {
867          //
868          // There is an explicit version descriptor. This one takes precedence
869          // and forces the structuring style to no directory
870          //
871
872          Me.m_current_package = up_branch;
873          CmtSystem::dirname (up_dir, Me.m_current_path);
874
875          /*
876          if (Me.m_current_version.read (version_file))
877            {
878              int pos;
879
880              pos = Me.m_current_version.find ('\n');
881              if (pos != cmt_string::npos) Me.m_current_version.erase (pos);
882              pos = Me.m_current_version.find ('\r');
883              if (pos != cmt_string::npos) Me.m_current_version.erase (pos);
884            }
885          else
886            {
887              Me.m_current_version = "v*";
888              CmtMessage::warning ("Could not read `" + version_file + "'."
889                                   " Default version `" + Me.m_current_version + "'");
890            }
891          */
892          cmt_string v;
893          //      if (Package::get_version (v, version_file))
894          if (Package::get_version (v, cmt_dir))
895            {
896              Me.m_current_version = v;
897            }
898          else
899            {
900              Me.m_current_version = "v*";
901              CmtMessage::warning ("Structuring style used `without_version_directory'."
902                                   " Could not determine version in `" + cmt_dir + "'."
903                                   " Default version `" + Me.m_current_version + "'");
904            }
905
906          if (Me.m_debug)
907            {
908              cout << "Cmt::configure_current_package>" << endl
909                   << " m_current_package " << Me.m_current_package << endl
910                   << " m_current_version " << Me.m_current_version << endl
911                   << " m_current_dir " << Me.m_current_dir << endl
912                   << " pwd " << CmtSystem::pwd ()
913                   << endl;
914            }
915
916          Me.m_current_structuring_style = without_version_directory;
917          //          Me.m_current_style = no_version_style;
918        }
919      else
920        {
921          // Try to use directory structure and
922          // package statement in requirements, if available
923          cmt_string up_up_dir;
924          cmt_string up_up_branch;
925          CmtSystem::dirname (up_dir, up_up_dir);
926          CmtSystem::basename (up_up_dir, up_up_branch);
927
928          cmt_string n;
929          bool done (false);
930          if (Package::get_name (n, cmt_dir))
931            {
932              if (n == up_branch)
933                {
934                  Me.m_current_package = up_branch;
935                  Me.m_current_path = up_up_dir;
936                  Me.m_current_structuring_style = without_version_directory;
937                  cmt_string v;
938                  if (Package::get_version (v, cmt_dir))
939                    {
940                      Me.m_current_version = v;
941                    }
942                  else
943                    {
944                      // No version descriptor
945                      // No version directory. The version is defaulted to v*
946                      Me.m_current_version = "v*";
947                      CmtMessage::warning ("Structuring style used `without_version_directory'."
948                                           " Could not determine version in `" + cmt_dir + "'."
949                                           " Default version `" + Me.m_current_version + "'");
950                    }
951                  done =true;
952                }
953              else if (n == up_up_branch)
954                {
955                  // The up branch IS a version directory.
956                  Me.m_current_version = up_branch;
957                  Me.m_current_package = up_up_branch;
958                  CmtSystem::dirname (up_up_dir, Me.m_current_path);
959                  Me.m_current_structuring_style = with_version_directory;
960                  done =true;
961                }
962              else
963                {
964                  CmtMessage::warning ("Package name `" + n + "' in `" + cmt_dir +
965                                       "' does not correspond to directory"
966                                       " structure");
967                }
968            }
969
970          if (!done)
971            {
972          // Try to determine the structuring style from:
973          //
974          CmtStructuringStyle structuring_style(default_structuring_style);
975          CmtStructuringStyle style(default_structuring_style);
976          // - the command line options
977          //   or
978          // - the CMTSTRUCTURINGSTYLE environment variable
979          if (structuring_style == default_structuring_style)
980            {
981              structuring_style = get_current_structuring_style ();
982            }
983          // - the project the package belongs to
984          if (structuring_style == default_structuring_style)
985            {
986              Project* p = Project::get_current ();
987              if (p)
988                {
989                  style = p->get_strategy ("VersionDirectory") ? with_version_directory : without_version_directory ;
990                  StrategyDef* def = StrategyMgr::find_strategy ("VersionDirectory");
991                  if (def != 0)
992                    {
993                      if (p->is_specified (def)) structuring_style = style;
994                    }
995                }
996            }
997          // - the child projects of the project the package belongs to
998          if (structuring_style == default_structuring_style)
999            {
1000              structuring_style = style;
1001            }
1002          // - the default value of the Structure strategy
1003          if (structuring_style == default_structuring_style)
1004            {
1005              structuring_style = StrategyMgr::get_default_strategy ("VersionDirectory") ? with_version_directory : without_version_directory ;
1006            }
1007
1008          // Make use of the structuring style
1009          //
1010          if (structuring_style == with_version_directory && CmtSystem::is_version_directory (up_branch))
1011            {
1012              // The up branch IS a version directory.
1013              Me.m_current_version = up_branch;
1014              Me.m_current_package = up_up_branch;
1015              CmtSystem::dirname (up_up_dir, Me.m_current_path);
1016              /*
1017              CmtSystem::dirname (up_dir, up_dir);
1018              CmtSystem::basename (up_dir, Me.m_current_package);
1019              CmtSystem::dirname (up_dir, Me.m_current_path);
1020              */
1021              Me.m_current_structuring_style = with_version_directory;
1022            }
1023          else
1024            {
1025              if (structuring_style == with_version_directory)
1026                {
1027                  CmtMessage::warning ("`" + up_branch + "' is not correct version syntax."
1028                                       " Assuming it is package name");
1029                }
1030              Me.m_current_package = up_branch;
1031              Me.m_current_path = up_up_dir;
1032              //              CmtSystem::dirname (up_dir, Me.m_current_path);
1033              Me.m_current_structuring_style = without_version_directory;
1034              cmt_string v;
1035              if (Package::get_version (v, cmt_dir))
1036                {
1037                  Me.m_current_version = v;
1038                }
1039              else
1040                {
1041              // No version descriptor
1042              // No version directory. The version is defaulted to v*
1043                  Me.m_current_version = "v*";
1044                  CmtMessage::warning ("Structuring style used `without_version_directory'."
1045                                       " Could not determine version in `" + cmt_dir + "'."
1046                                       " Default version `" + Me.m_current_version + "'");
1047                }
1048             
1049              //              Me.m_current_style = no_version_style;
1050            }
1051            }
1052        }
1053      build_prefix (Me.m_current_package, Me.m_current_prefix);
1054      build_config (Me.m_current_prefix, Me.m_current_config);
1055    }
1056  else
1057    {
1058      Me.m_current_package = "cmt_standalone";
1059      Me.m_current_version = "v0";
1060      Me.m_current_path = Me.m_current_dir;
1061      Me.m_current_structuring_style = without_version_directory;
1062      //      Me.m_current_style = none_style;
1063      build_prefix (Me.m_current_package, Me.m_current_prefix);
1064      build_config (Me.m_current_prefix, Me.m_current_config);
1065    }
1066}
1067
1068//----------------------------------------------------------
1069//void Cmt::configure_current_structuring_style ()
1070void Cmt::configure_current_structuring_style (const ArgParser& ap)
1071{
1072  cmt_string s;
1073  s = CmtSystem::getenv ("CMTSTRUCTURINGSTYLE");
1074  if (s == "without_version_directory")
1075    {
1076      Me.m_current_structuring_style = without_version_directory;
1077    }
1078  else if (s == "with_version_directory")
1079    {
1080      Me.m_current_structuring_style = with_version_directory;
1081    } 
1082
1083  CmtSystem::cmt_string_vector flags;
1084  Cmt::get_cmt_flags (flags);
1085  for (int i = 0; i < flags.size (); i++)
1086    {
1087      const cmt_string& flag = flags[i];
1088      if (flag == "-without_version_directory")
1089        {
1090          Me.m_current_structuring_style = without_version_directory;
1091        }
1092      else if (flag == "-with_version_directory")
1093        {
1094          Me.m_current_structuring_style = with_version_directory;
1095        } 
1096    }
1097
1098  for (int i = 1; i < ap.argc; i++)
1099    {
1100      const cmt_string& arg = ap.argv[i];
1101      if (arg[0] != '-') break;
1102      if (arg == "-without_v" ||
1103          arg == "-without_ve" ||
1104          arg == "-without_ver" ||
1105          arg == "-without_vers" ||
1106          arg == "-without_versi" ||
1107          arg == "-without_versio" ||
1108          arg == "-without_version" ||
1109          arg == "-without_version_" ||
1110          arg == "-without_version_d" ||
1111          arg == "-without_version_di" ||
1112          arg == "-without_version_dir" ||
1113          arg == "-without_version_dire" ||
1114          arg == "-without_version_direc" ||
1115          arg == "-without_version_direct" ||
1116          arg == "-without_version_directo" ||
1117          arg == "-without_version_director" ||
1118          arg == "-without_version_directory")
1119        {
1120          Me.m_current_structuring_style = without_version_directory;
1121          //      if (!CmtSystem::putenv ("CMTSTRUCTURINGSTYLE", "without_version_directory"))
1122          //        CmtMessage::error ("Cannot set `CMTSTRUCTURINGSTYLE' to"
1123          //                           " `without_version_directory' in the environment");
1124          if (!Cmt::add_cmt_flag ("-without_version_directory"))
1125            CmtMessage::error ("Cannot add flag `-without_version_directory'");
1126        }
1127      else if (arg == "-with_v" ||
1128               arg == "-with_ve" ||
1129               arg == "-with_ver" ||
1130               arg == "-with_vers" ||
1131               arg == "-with_versi" ||
1132               arg == "-with_versio" ||
1133               arg == "-with_version" ||
1134               arg == "-with_version_" ||
1135               arg == "-with_version_d" ||
1136               arg == "-with_version_di" ||
1137               arg == "-with_version_dir" ||
1138               arg == "-with_version_dire" ||
1139               arg == "-with_version_direc" ||
1140               arg == "-with_version_direct" ||
1141               arg == "-with_version_directo" ||
1142               arg == "-with_version_director" ||
1143               arg == "-with_version_directory")
1144        {
1145          Me.m_current_structuring_style = with_version_directory;
1146          //      if (!CmtSystem::putenv ("CMTSTRUCTURINGSTYLE", "with_version_directory"))
1147          //        CmtMessage::error ("Cannot set `CMTSTRUCTURINGSTYLE' to"
1148          //                           " `with_version_directory' in the environment");
1149          if (!Cmt::add_cmt_flag ("-with_version_directory"))
1150            CmtMessage::error ("Cannot add flag `-with_version_directory'");
1151        }
1152    }
1153}
1154
1155//----------------------------------------------------------
1156void Cmt::configure_default_path ()
1157{
1158  Me.m_default_path = CmtSystem::get_cmt_root ();
1159  CmtSystem::get_cmt_version (Me.m_cmt_version);
1160  Me.m_cmt_root = Me.m_default_path;
1161  Me.m_cmt_root += CmtSystem::file_separator ();
1162  Me.m_cmt_root += "CMT";
1163  Me.m_cmt_root += CmtSystem::file_separator ();
1164  Me.m_cmt_root += Me.m_cmt_version;
1165}
1166
1167//----------------------------------------------------------
1168void Cmt::configure_home (Use* use)
1169{
1170  Me.m_cmt_home = "";
1171
1172  Symbol* symbol = Symbol::find ("CMTHOME");
1173  if (symbol != 0)
1174    {
1175      Me.m_cmt_home = symbol->build_macro_value ();
1176      Symbol::expand (Me.m_cmt_home);
1177    }
1178  else if (CmtSystem::testenv ("CMTHOME"))
1179    {
1180      Me.m_cmt_home = CmtSystem::getenv ("CMTHOME");
1181    }
1182
1183  if ((Me.m_cmt_home != "") && !CmtSystem::test_directory (Me.m_cmt_home))
1184    {
1185      Me.m_cmt_home = "";
1186    }
1187
1188  configure_user_context (0);
1189}
1190
1191//----------------------------------------------------------
1192void Cmt::configure_user_context (Use* use)
1193{
1194  Me.m_cmt_user_context = "";
1195
1196  Symbol* symbol = Symbol::find ("CMTUSERCONTEXT");
1197  if (symbol != 0)
1198    {
1199      Me.m_cmt_user_context = symbol->build_macro_value ();
1200      Symbol::expand (Me.m_cmt_user_context);
1201    }
1202  else if (CmtSystem::testenv ("CMTUSERCONTEXT"))
1203    {
1204      Me.m_cmt_user_context = CmtSystem::getenv ("CMTUSERCONTEXT");
1205    }
1206
1207  if ((Me.m_cmt_user_context != "") && !CmtSystem::test_directory (Me.m_cmt_user_context))
1208    {
1209      Me.m_cmt_user_context = "";
1210    }
1211
1212  if (Me.m_debug) cout << "configure_user_context> user_context=" << Me.m_cmt_user_context << endl;
1213
1214  configure_cmt_path (0);
1215}
1216
1217//----------------------------------------------------------
1218void Cmt::configure_hosttype_tag ()
1219{
1220  cmt_string hosttype;
1221
1222  CmtSystem::get_hosttype (hosttype);
1223
1224  if (hosttype != "")
1225    {
1226      Tag* tag;
1227
1228      tag = Tag::add (hosttype, PriorityUname, "HOSTTYPE", 0);
1229      tag->mark ();
1230    }
1231}
1232
1233//----------------------------------------------------------
1234void Cmt::configure_site_tag (Use* use)
1235{
1236  Symbol* symbol = Symbol::find ("CMTSITE");
1237  if (symbol != 0)
1238    {
1239      Me.m_cmt_site = symbol->build_macro_value ();
1240      Symbol::expand (Me.m_cmt_site);
1241    }
1242  else
1243    {
1244      Me.m_cmt_site = CmtSystem::get_cmt_site ();
1245    }
1246
1247  if (Me.m_cmt_site != "")
1248    {
1249      cmt_string s = "CMTSITE";
1250
1251      if (use != 0)
1252        {
1253          s += " in ";
1254        }
1255
1256      Tag* tag;
1257
1258      tag = Tag::add (Me.m_cmt_site, PrioritySite, s, use);
1259      tag->mark ();
1260    }
1261}
1262
1263//----------------------------------------------------------
1264void Cmt::restore_all_tags (Use* use)
1265{
1266  //cerr << "restore_all_tags" << endl;
1267
1268  Cmt::configure_tags (use);
1269
1270  /*
1271    Then get existing extra tags
1272  */
1273
1274  if (CmtSystem::testenv ("CMTEXTRATAGS"))
1275    {
1276      cmt_string s = "CMTEXTRATAGS";
1277
1278      if (use != 0)
1279        {
1280          s += " in ";
1281        }
1282
1283      Tag* tag;
1284      CmtSystem::cmt_string_vector words;
1285     
1286      cmt_string tags = CmtSystem::getenv ("CMTEXTRATAGS");
1287     
1288      CmtSystem::split (tags, " \t,", words);
1289
1290      Me.m_extra_tags = ",";
1291     
1292      for (int i = 0; i < words.size (); i++)
1293        {
1294          const cmt_string& a = words[i];
1295
1296          Me.m_extra_tags += a;
1297          Me.m_extra_tags += ",";
1298         
1299          tag = Tag::add (a, PriorityUserTag, s, use);
1300         
1301          tag->mark ();
1302        }
1303    }
1304}
1305
1306//----------------------------------------------------------
1307void Cmt::configure_tags (Use* use)
1308{
1309  cmt_string config_tag;
1310
1311  Log;
1312
1313  log << "current_tag=" << Me.m_current_tag << log_endl;
1314
1315  Symbol* symbol = Symbol::find ("CMTCONFIG");
1316  if (symbol != 0)
1317    {
1318      bool show_set_hidden = false;
1319
1320      if (Me.m_action == action_show_set)
1321        {
1322          show_set_hidden = true;
1323          Me.m_action = action_none;
1324        }
1325
1326      config_tag = symbol->build_macro_value ();
1327      Symbol::expand (config_tag);
1328
1329      if (show_set_hidden)
1330        {
1331          show_set_hidden = false;
1332          Me.m_action = action_show_set;
1333        }
1334    }
1335  else if (CmtSystem::testenv ("CMTCONFIG"))
1336    {
1337      config_tag = CmtSystem::getenv ("CMTCONFIG");
1338    }
1339  else if (CmtSystem::testenv ("CMTBIN"))
1340    {
1341      config_tag = CmtSystem::getenv ("CMTBIN");
1342    }
1343
1344  if (config_tag == "")
1345    {
1346      CmtSystem::get_uname (config_tag);
1347    }
1348
1349  log << "current_tag=" << Me.m_current_tag << log_endl;
1350
1351  cmt_string s = "CMTCONFIG";
1352
1353  if (use != 0)
1354    {
1355      s += " in ";
1356    }
1357
1358  Tag* tag;
1359
1360  tag = Tag::add (config_tag, PriorityConfig, s, use);
1361  tag->mark ();
1362
1363  //Me.m_current_tag = config_tag;
1364}
1365
1366//----------------------------------------------------------
1367void Cmt::configure_uname_tag ()
1368{
1369  cmt_string uname;
1370
1371  CmtSystem::get_uname (uname);
1372
1373  if (uname != "")
1374    {
1375      Tag* tag;
1376
1377      tag = Tag::add (uname, PriorityUname, "uname", 0);
1378      tag->mark ();
1379    }
1380}
1381
1382//----------------------------------------------------------
1383void Cmt::configure_devenv_tag ()
1384{
1385  cmt_string devenv_command;
1386  Symbol* devenv_command_macro = Symbol::find ("devenv_command");
1387  if (0 == devenv_command_macro) return;
1388
1389  devenv_command = devenv_command_macro->resolve_macro_value ();
1390  if (devenv_command == "") return;
1391  devenv_command += " 2>&1";
1392
1393  cmt_string output;
1394  if (0 != CmtSystem::execute (devenv_command, output)) return;
1395  cmt_string devenv;
1396  int pos;
1397  pos = output.find ("Microsoft");
1398  if (pos != cmt_string::npos) devenv = "vs";
1399  else return;
1400
1401  //
1402  // Make the output as one single big line.
1403  //
1404
1405  output.replace_all ("\n", " ");
1406  output.replace_all ("\r", " ");
1407
1408  CmtSystem::cmt_string_vector words;
1409  CmtSystem::split (output, " \t", words);
1410
1411  cmt_string version;
1412  bool need_version (false);
1413  for (int i = 0; i < words.size (); i++)
1414    {
1415      if (need_version && words[i] != "")
1416        {
1417          version = words[i];
1418          break;
1419        }
1420      if (words[i] == "Version")
1421        need_version = true;
1422    }
1423
1424  if (version == "")
1425    {
1426      devenv += "00";
1427    }
1428  else
1429    {
1430      CmtSystem::cmt_string_vector nbrs;
1431      CmtSystem::split (version, ".", nbrs);
1432      if (1 == nbrs.size ())
1433        devenv += nbrs[0];
1434      else
1435        devenv += nbrs[0] + nbrs[1];
1436    }
1437
1438  if (devenv != "")
1439    {
1440      Tag* tag;
1441
1442      tag = Tag::add (devenv, PriorityUname, "devenv", 0);
1443      tag->mark ();
1444    }
1445}
1446
1447//----------------------------------------------------------
1448void Cmt::configure_version_tag ()
1449{
1450  int v = 0;
1451  int r = 0;
1452  int p = 0;
1453
1454  CmtSystem::is_version_directory (CMTVERSION, v, r, p);
1455
1456  Tag* tag;
1457
1458  static char temp[80];
1459
1460  sprintf (temp, "CMTv%d", v);
1461
1462  tag = Tag::add (temp, PriorityVersion, "CMTVERSION", 0);
1463  tag->mark ();
1464
1465  sprintf (temp, "CMTr%d", r);
1466
1467  tag = Tag::add (temp, PriorityVersion, "CMTVERSION", 0);
1468  tag->mark ();
1469
1470  sprintf (temp, "CMTp%d", p);
1471
1472  tag = Tag::add (temp, PriorityVersion, "CMTVERSION", 0);
1473  tag->mark ();
1474
1475}
1476
1477//----------------------------------------------------------
1478//void Cmt::configure_cmt_message ()
1479void Cmt::configure_cmt_message (const ArgParser& ap)
1480{
1481  cmt_string s;
1482
1483  s = CmtSystem::getenv ("CMTMSGPREFIX");
1484  if (s != "")
1485    CmtMessage::set_prefix (s);
1486
1487  s = CmtSystem::getenv ("CMTFATAL");
1488  if (s != "")
1489    {
1490      CmtMessage::set_level (Fatal);
1491    }
1492
1493  s = CmtSystem::getenv ("CMTERROR");
1494  if (s != "")
1495    {
1496      CmtMessage::set_level (Error);
1497    }
1498
1499  s = CmtSystem::getenv ("CMTWARNING");
1500  if (s != "")
1501    {
1502      CmtMessage::set_level (Warning);
1503    }
1504
1505  s = CmtSystem::getenv ("CMTINFO");
1506  if (s != "")
1507    {
1508      CmtMessage::set_level (Info);
1509    }
1510
1511  s = CmtSystem::getenv ("CMTVERBOSE");
1512  if (s != "")
1513    {
1514      CmtMessage::set_level (Verbose);
1515    }
1516
1517  s = CmtSystem::getenv ("CMTDEBUG");
1518  if (s != "")
1519    {
1520      CmtMessage::set_level (Debug);
1521    }
1522
1523  CmtSystem::cmt_string_vector flags;
1524  Cmt::get_cmt_flags (flags);
1525  for (int i = 0; i < flags.size (); i++)
1526    {
1527      const cmt_string& flag = flags[i];
1528      if (flag == "-disable_warnings")
1529        {
1530          Me.m_disable_warnings = true;
1531          if (CmtMessage::level () <= Warning)
1532            CmtMessage::set_level (Error);
1533        }
1534      else if (flag == "-quiet")
1535        {
1536          Me.m_quiet = true;
1537          if (CmtMessage::level () <= Error)
1538            CmtMessage::set_level (Fatal);
1539        }
1540      else if (flag == "-warnings")
1541        {
1542          Me.m_warnings = true;
1543          if (CmtMessage::level () != Warning)
1544            CmtMessage::set_level (Warning);
1545          //      if (CmtMessage::level () > Warning)
1546        }
1547    }
1548
1549  for (int i = 1; i < ap.argc; i++)
1550    {
1551      const cmt_string& arg = ap.argv[i];
1552      if (arg[0] != '-') break;
1553      if (arg == "-d" ||
1554          arg == "-di" ||
1555          arg == "-dis" ||
1556          arg == "-disa" ||
1557          arg == "-disab" ||
1558          arg == "-disabl" ||
1559          arg == "-disable" ||
1560          arg == "-disable_" ||
1561          arg == "-disable_w" ||
1562          arg == "-disable_wa" ||
1563          arg == "-disable_war" ||
1564          arg == "-disable_warn" ||
1565          arg == "-disable_warni" ||
1566          arg == "-disable_warnin" ||
1567          arg == "-disable_warning" ||
1568          arg == "-disable_warnings")
1569        {
1570          Me.m_disable_warnings = true;
1571          if (CmtMessage::level () <= Warning)
1572            {
1573              CmtMessage::set_level (Error);
1574              //              if (!CmtSystem::putenv ("CMTERROR", "1"))
1575              //                CmtMessage::error ("Cannot set `CMTERROR' in the environment");
1576            }
1577          if (!Cmt::add_cmt_flag ("-disable_warnings"))
1578            CmtMessage::error ("Cannot add flag `-disable_warnings'");
1579        }
1580      else if (arg == "-q" ||
1581               arg == "-qu" ||
1582               arg == "-qui" ||
1583               arg == "-quie" ||
1584               arg == "-quiet")
1585        {
1586          Me.m_quiet = true;
1587          if (CmtMessage::level () <= Error)
1588            {
1589              CmtMessage::set_level (Fatal);
1590              //              if (!CmtSystem::putenv ("CMTFATAL", "1"))
1591              //                CmtMessage::error ("Cannot set `CMTFATAL' in the environment");
1592            }
1593          if (!Cmt::add_cmt_flag ("-quiet"))
1594            CmtMessage::error ("Cannot add flag `-quiet'");
1595        }
1596      else if (arg == "-warn" ||
1597               arg == "-warni" ||
1598               arg == "-warnin" ||
1599               arg == "-warning" ||
1600               arg == "-warnings")
1601        {
1602          Me.m_warnings = true;
1603          //      if (CmtMessage::level () > Warning)
1604          if (CmtMessage::level () != Warning)
1605            {
1606              CmtMessage::set_level (Warning);
1607              //              if (!CmtSystem::putenv ("CMTWARNING", "1"))
1608              //                CmtMessage::error ("Cannot set `CMTWARNING' in the environment");
1609            }
1610          if (!Cmt::add_cmt_flag ("-warnings"))
1611            CmtMessage::error ("Cannot add flag `-warnings'");
1612        }
1613    }
1614}
1615
1616//----------------------------------------------------------
1617//
1618//   Actions
1619//
1620//----------------------------------------------------------
1621
1622class AwkActor : public Awk
1623{
1624public:
1625
1626  void filter (const cmt_string& line)
1627  {
1628    cout << line << endl;
1629  }
1630};
1631
1632//----------------------------------------------------------
1633void Cmt::do_awk (const ArgParser& ap)
1634{
1635  if (ap.arguments.size () < 1)
1636    {
1637      CmtMessage::error ("cmt awk <file> <pattern>");
1638      //      cerr << "#CMT> cmt awk <file> <pattern>" << endl;
1639      return;
1640    }
1641
1642  const cmt_string& file = ap.arguments[0];
1643  const cmt_string& pattern = ap.arguments[1];
1644  cmt_string text;
1645
1646  text.read (file);
1647
1648  static AwkActor a;
1649
1650  cmt_regexp exp (pattern);
1651
1652  a.run (text, exp);
1653}
1654
1655//----------------------------------------------------------
1656void Cmt::do_broadcast (const ArgParser& ap)
1657{
1658  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
1659
1660  CmtSystem::cmt_string_vector uses;
1661  CmtSystem::cmt_string_vector packages;
1662  CmtSystem::cmt_string_vector versions;
1663  CmtSystem::cmt_string_vector path_selections;
1664  CmtSystem::cmt_string_vector selections;
1665  CmtSystem::cmt_string_vector exclusions;
1666  cmt_string begin;
1667  cmt_string command;
1668  bool is_cmt = false;
1669  int first = 0;
1670  int i;
1671  bool ignore_errors = false;
1672  bool all_packages = false;
1673
1674  bool local = true;
1675
1676  for (i = 0; i < ap.arguments.size (); i++)
1677    {
1678      const cmt_string& w = ap.arguments[i];
1679
1680      //cerr << "broadcast: arg=[" << w << "]" << endl;
1681
1682      if (command == "")
1683        {
1684          if (w.substr (0, 13) == "-all_packages")
1685            {
1686              local = false;
1687              all_packages = true;
1688            }
1689          else if (w.substr (0, 7) == "-depth=")
1690            {
1691              local = false;
1692
1693              cmt_string depth_str;
1694              int depth_value = 0;
1695                         
1696              w.substr (7, depth_str);
1697              if ((sscanf (depth_str.c_str (), "%d", &depth_value) < 1) ||
1698                  (depth_value < 1))
1699                {
1700                  // Syntax error
1701                  //  We shall restrict to packages found within
1702                  // the <depth_value> first elements of CMTPATH.
1703                  //  If CMTPATH is empty, nothing is selected.
1704                  // depth=1 is equivalent to local
1705                }
1706
1707              Project::fill_selection (depth_value, path_selections);
1708            }
1709          else if (w.substr (0, 9) == "-exclude=")
1710            {
1711              cmt_string exclusion;
1712
1713              w.substr (9, exclusion);
1714
1715              int size = exclusion.size ();
1716             
1717              if (size >= 2)
1718                {
1719                  if (((exclusion[0] == '"') && (exclusion[size - 1] == '"')) ||
1720                      ((exclusion[0] == '\'') && (exclusion[size - 1] == '\'')))
1721                    {
1722                      exclusion.erase (size - 1);
1723                      exclusion.erase (0, 1);
1724                    }
1725
1726                  CmtSystem::split (exclusion, " \t", exclusions);
1727                }
1728            }
1729          else if (w.substr (0, 7) == "-global")
1730            {
1731              path_selections.clear ();
1732
1733              local = false;
1734            }
1735          else if (w.substr (0, 6) == "-local")
1736            {
1737              local = true;
1738            }
1739          else if (w.substr (0, 8) == "-select=")
1740            {
1741              cmt_string selection;
1742
1743              w.substr (8, selection);
1744
1745              //cerr << "Select=[" << selection << "]" << endl;
1746
1747              int size = selection.size ();
1748             
1749              if (size >= 2)
1750                {
1751                  if (((selection[0] == '"') && (selection[size - 1] == '"')) ||
1752                      ((selection[0] == '\'') && (selection[size - 1] == '\'')))
1753                    {
1754                      selection.erase (size - 1);
1755                      selection.erase (0, 1);
1756                    }
1757                }
1758
1759              CmtSystem::split (selection, " \t", selections);
1760
1761              //cerr << "Selections.size () = " << selections.size () << endl;
1762            }
1763          else if (w.substr (0, 7) == "-begin=")
1764            {
1765              w.substr (7, begin);
1766            }
1767          else
1768            {
1769              command = w;
1770            }
1771        }
1772      else
1773        {
1774          command += " ";
1775          command += w;
1776        }
1777
1778    }
1779
1780  if (local)
1781    {
1782      Project::fill_selection (1, path_selections);
1783    }
1784
1785  if (command[0] == '-')
1786    {
1787      ignore_errors = true;
1788      command.erase (0, 1);
1789    }
1790
1791  //if (command.substr (0, 3) == "cmt") is_cmt = true;
1792
1793  cmt_string curuse = CmtSystem::pwd ();
1794  if (all_packages)
1795    {
1796      PackageSelector selector (uses);
1797      PathScanner scanner;
1798      Project::scan_paths (scanner, selector);
1799    }
1800  else
1801    {
1802      for (i = Uses.size () - 1; i >= 0; i--)
1803        {
1804          Use* use = Uses[i];
1805                 
1806          if (use->discarded) continue;
1807          if (use->m_hidden) continue;
1808
1809          if (!use->located ())
1810            {
1811              CmtMessage::warning ("package " + use->get_package_name ()
1812                                   + " " + use->version + " " + use->path
1813                                   + " not found");
1814              /*
1815              if (!Me.m_quiet)
1816                {
1817                  cerr << "#CMT> package " << use->get_package_name () <<
1818                    " " << use->version << " " << use->path <<
1819                    " not found" <<
1820                    endl;
1821                }
1822              */
1823            }
1824          else
1825            {
1826              if (use->get_package_name () != "CMT")
1827                {
1828                  cmt_string& s = uses.add ();
1829
1830                  use->get_full_path (s);
1831
1832                  s += CmtSystem::file_separator ();
1833                  if (use->style == mgr_style) s += "mgr";
1834                  else s += "cmt";
1835
1836                  cmt_string& v = versions.add ();
1837                  v = use->version;
1838
1839                  cmt_string& p = packages.add ();
1840                  p = use->get_package_name ();
1841                }
1842            }
1843        }
1844         
1845      {
1846        cmt_string& s = uses.add ();
1847                 
1848        Use* use = &(Use::current ());
1849
1850        if (use->get_package_name ().find ("cmt_standalone") != cmt_string::npos)
1851          {
1852            s = CmtSystem::pwd ();
1853          }
1854        else
1855          {
1856            use->get_full_path (s);
1857
1858            s += CmtSystem::file_separator ();
1859                 
1860            if (use->style == mgr_style) s += "mgr";
1861            else s += "cmt";
1862          }
1863
1864        curuse = s;
1865
1866        cmt_string& v = versions.add ();
1867        v = use->version;
1868
1869        cmt_string& p = packages.add ();
1870        p = use->get_package_name ();
1871      }
1872    }
1873
1874  bool started = false;
1875
1876  if (begin == "") started = true;
1877
1878  set_standard_macros ();
1879  Cmt::reset_all_sets_done ();
1880  Symbol::all_set ();
1881
1882  for (i = 0; i < uses.size (); i++)
1883    {
1884      const cmt_string& s = uses[i];
1885      const cmt_string& v = versions[i];
1886      const cmt_string& p = packages[i];
1887      cmt_string cmtpath;
1888
1889      bool ok = true;
1890      bool selected = true;
1891      bool excluded = false;
1892
1893      /**
1894         Ensure that the current package is not skipped
1895         due to symlinks in the paths
1896       */
1897      //      if (path_selections.size () > 0)
1898      if (path_selections.size () > 0 && s != curuse)
1899        {
1900          selected = false;
1901
1902          for (int j = 0; j < path_selections.size (); j++)
1903            {
1904              const cmt_string& sel = path_selections[j];
1905             
1906              if (s.find (sel) != cmt_string::npos) 
1907                {
1908                  cmtpath = sel;
1909                  selected = true;
1910                  break;
1911                }
1912            }
1913
1914          ok = selected;
1915        }
1916
1917      if (ok)
1918        {
1919          if (selections.size () > 0)
1920            {
1921              selected = false;
1922             
1923              for (int j = 0; j < selections.size (); j++)
1924                {
1925                  const cmt_string& sel = selections[j];
1926                 
1927                  if (s.find (sel) != cmt_string::npos) 
1928                    {
1929                      selected = true;
1930                      break;
1931                    }
1932                }
1933             
1934              ok = selected;
1935            }
1936        }
1937
1938      if (ok && !started)
1939        {
1940          if (s.find (begin) != cmt_string::npos)
1941            {
1942              started = true;
1943              ok = true;
1944            }
1945          else
1946            {
1947              ok = false;
1948            }
1949        }
1950
1951
1952      if (ok)
1953        {
1954          excluded = false;
1955
1956          for (int j = 0; j < exclusions.size (); j++)
1957            {
1958              const cmt_string& exc = exclusions[j];
1959             
1960              if (s.find (exc) != cmt_string::npos) 
1961                {
1962                  excluded = true;
1963                  break;
1964                }
1965            }
1966
1967          if (excluded) ok = false;
1968        }
1969
1970      if (!ok) 
1971        {
1972          continue;
1973        }
1974
1975
1976
1977      if (!CmtSystem::cd (s))
1978        {
1979          if (s.find ("cmt_standalone") != cmt_string::npos)
1980            {
1981              CmtMessage::warning ("Currently not in a CMT package");
1982              //              cerr << "#CMT> Currently not in a CMT package" << endl;
1983            }
1984          else
1985            {
1986              char num[32]; sprintf (num, "%d/%d", i+1, uses.size ());
1987              CmtMessage::error ("Cannot move to the package in " + s
1988                                 + " (" + num + ")");
1989              /*
1990              cerr << "#CMT> Cannot move to the package in " << s << " (" << i+1 << "/"
1991                   << uses.size () << ")"<< endl;
1992              */
1993            }
1994
1995          if (!ignore_errors) break;
1996
1997          continue;
1998        }
1999
2000      if (CmtLock::check () == CmtLock::locked_by_another_user)
2001        {
2002          char num[32]; sprintf (num, "%d/%d", i+1, uses.size ());
2003          CmtMessage::warning ("Ignore locked package in " + s
2004                               + " (" + num + ")");
2005          /*
2006          cerr << "#CMT> Ignore locked package in " << s << " (" << i+1 << "/"
2007               << uses.size () << ")" << endl;
2008          */
2009          continue;
2010        }
2011
2012      if (cmtpath == "")
2013        {
2014          cmt_string sel = CmtSystem::pwd ();
2015          cmtpath = Project::find_in_cmt_paths (sel);
2016        }
2017
2018      cmt_string cmd = command;
2019      static const cmt_string version_template = "<version>";
2020      cmd.replace_all (version_template, v);
2021
2022      static const cmt_string package_template = "<package>";
2023      cmd.replace_all (package_template, p);
2024
2025      static const cmt_string cmtpath_template = "<package_cmtpath>";
2026      cmd.replace_all (cmtpath_template, cmtpath);
2027
2028      static const cmt_string offset_template = "<package_offset>";
2029
2030      static const cmt_string empty_string;
2031      static const cmt_string fs = CmtSystem::file_separator ();
2032      cmt_string offset = s;
2033      offset.replace (cmtpath, empty_string);
2034      if (offset[0] == CmtSystem::file_separator ())
2035        {
2036          offset.replace (fs, empty_string);
2037        }
2038      CmtSystem::dirname (offset, offset);
2039
2040      cmt_string n;
2041      CmtSystem::basename (offset, n);
2042      if (n == p)
2043        {
2044          CmtSystem::dirname (offset, offset);
2045        }
2046      else
2047        {
2048          CmtSystem::dirname (offset, offset);
2049          CmtSystem::dirname (offset, offset);
2050        }
2051
2052      cmd.replace_all (offset_template, offset);
2053
2054
2055  if (CmtMessage::active (Error))
2056    {
2057      cout << "#--------------------------------------------------------------" << endl;
2058      cout << "# Now trying [" << cmd << "] in " << s << " (" << i+1 << "/" << uses.size () 
2059           << ")" << endl;
2060      cout << "#--------------------------------------------------------------" << endl;
2061    }
2062
2063      if (is_cmt)
2064        {
2065          //
2066          //  There is a bug in the recursive use of the parser. Macros are not set correctly.
2067          //  Thus the recursive optimization is now discarded.
2068          //
2069          if (parser (cmd) != 0)
2070            {
2071              CmtError::set (CmtError::execution_error, cmd);
2072              break;
2073            }
2074        }
2075      else
2076        {
2077          int status = CmtSystem::execute (cmd);
2078
2079          //cerr << "do_broadcast> status=" << status << " ignore_errors=" << ignore_errors << endl;
2080
2081          if ((status != 0) && !ignore_errors)
2082            //if ((status != 0) && !ignore_errors)
2083            {
2084              //              if (status != 2) CmtError::set (CmtError::execution_error, cmd);
2085              CmtError::set (CmtError::execution_error, cmd);
2086              break;
2087            }
2088        }
2089    }
2090}
2091
2092//----------------------------------------------------------
2093void Cmt::do_build_constituent_makefile (const ArgParser& ap)
2094{
2095  if (CmtLock::check () == CmtLock::locked_by_another_user)
2096    {
2097      CmtError::set (CmtError::conflicting_lock, "build_constituent_makefile>");
2098      return;
2099    }
2100  if (ap.arguments.size () > 0) 
2101    {
2102      set_standard_macros ();
2103      Generator::build_constituent_makefile (ap.arguments);
2104    }
2105}
2106
2107//----------------------------------------------------------
2108void Cmt::do_build_constituent_config (const ArgParser& ap)
2109{
2110  if (CmtLock::check () == CmtLock::locked_by_another_user)
2111    {
2112      CmtError::set (CmtError::conflicting_lock, "build_constituent_config>");
2113      return;
2114    }
2115  if (ap.arguments.size () == 0) return;
2116  set_standard_macros ();
2117
2118  CmtSystem::cmt_string_vector files (2);
2119  cmt_string  outdir, name;
2120  for (int i = 0; i < ap.arguments.size (); i++)
2121    {
2122      cmt_string arg = ap.arguments[i];
2123      if (arg.substr (0, 5) == "-out=")
2124        {
2125          arg.erase (0, 5);
2126          CmtSystem::dirname (arg, outdir);
2127        }
2128      else
2129        {
2130          name = arg;
2131        }
2132    }
2133
2134  Generator::build_constituent_makefile (ap.arguments);
2135
2136  const Constituent* constituent = Constituent::find (name);
2137  if (constituent == 0)
2138    {
2139      // generate error
2140      return;
2141    }
2142  if (!constituent->has_target_tag) return;
2143  //  cerr << "constituent: " << name << endl;
2144
2145  cmt_string tag;
2146  {
2147    Symbol* macro = Symbol::find ("tag");
2148    if (macro != 0)
2149      {
2150        tag = macro->build_macro_value ();
2151        Symbol::expand (tag);
2152      }
2153  }
2154
2155  //cmt_local_tagfile = $(bin)$(tag).make
2156  //cmt_final_setup = $(bin)setup.make
2157  //cmt_local_tagfile_${CONSTITUENT} = $(bin)$(${PACKAGE}_tag)_${CONSTITUENT}.make
2158  //cmt_final_setup_${CONSTITUENT} = $(bin)setup_${CONSTITUENT}.make
2159  files[0] = tag + "_" + name;
2160  files[1] = "setup_" + name;
2161  for (int i = 0; i < files.size (); i++)
2162    {
2163      if (Cmt::build_nmake ())
2164        files[i] += ".nmake";
2165      else
2166        files[i] += ".make";
2167
2168      if (outdir != "")
2169        {
2170          if (outdir [outdir.size () - 1] != CmtSystem::file_separator ())
2171            outdir += CmtSystem::file_separator ();
2172          files[i] = outdir + files[i];
2173        }
2174      //      cerr << "files[" << i << "]: " << files[i] << endl;
2175    }
2176
2177  ofstream t (files[0]);
2178  if (!t)
2179    {
2180      CmtError::set (CmtError::file_access_error, files[0]);
2181      return;
2182    }
2183  t.exceptions (ios::failbit | ios::badbit);
2184  try
2185    {
2186      print_macros (Make, "", t);
2187      t.close (); // ios_base::failbit
2188    }
2189  catch (const ios::failure& e)
2190    {
2191      CmtSystem::close_ostream (NULL, files[0] + ": " + cmt_string (e.what ()));
2192    }
2193
2194  bool gen_setup (true);
2195  ostringstream os;
2196  ofstream s;
2197  s.open (files[1], ios::in);
2198  if (s) // file already exists
2199    {
2200      //      cerr << files[1] << " already exists" << endl;
2201      do_show_setup (ap, os);
2202      ostringstream osn;
2203      osn << s.rdbuf ();
2204      if (os.str () == osn.str ())
2205        {
2206          //      cerr << files[1] << " up-to-date" << endl;
2207          gen_setup = false;
2208        }
2209    }
2210  s.clear ();
2211  s.close ();
2212  if (gen_setup)
2213    {
2214      s.open (files[1]);
2215      if (!s)
2216        {
2217          CmtError::set (CmtError::file_access_error, files[1]);
2218          return;
2219        }
2220      s.exceptions (ios::failbit | ios::badbit);
2221      try
2222        {
2223          if (os.str ().size () != 0)
2224            {
2225              //              cerr << files[1] << " contents already generated" << endl;
2226              s << os.str ();
2227            }
2228          else
2229            {
2230              do_show_setup (ap, s);
2231            }
2232          s.close (); // ios_base::failbit
2233        }
2234      catch (const ios::failure& e)
2235        {
2236          CmtSystem::close_ostream (NULL, files[1] + ": " + cmt_string (e.what ()));
2237        }
2238    }
2239}
2240
2241//----------------------------------------------------------
2242void Cmt::do_build_constituents_makefile (const ArgParser& ap)
2243{
2244  if (CmtLock::check () == CmtLock::locked_by_another_user)
2245    {
2246      CmtError::set (CmtError::conflicting_lock, "build_constituents_makefile>");
2247      return;
2248    }
2249  set_standard_macros ();
2250
2251  Generator::build_constituents_makefile (Me.m_current_package, ap.arguments);
2252}
2253
2254//----------------------------------------------------------
2255void Cmt::do_build_constituents_config (const ArgParser& ap)
2256{
2257  if (CmtLock::check () == CmtLock::locked_by_another_user)
2258    {
2259      CmtError::set (CmtError::conflicting_lock, "build_constituents_config>");
2260      return;
2261    }
2262  set_standard_macros ();
2263
2264  CmtSystem::cmt_string_vector files (2);
2265  cmt_string outdir;
2266  if (ap.arguments.size () > 0)
2267    {
2268      cmt_string arg = ap.arguments[0];
2269      if (arg.substr (0, 5) == "-out=")
2270        {
2271          arg.erase (0, 5);
2272          CmtSystem::dirname (arg, outdir);
2273        }
2274      else if (arg.substr (0, 8) == "-outdir=")
2275        {
2276          arg.erase (0, 8);
2277          outdir = arg;
2278        }
2279    }
2280  //  cerr << "outdir: " << outdir << endl;
2281
2282  cmt_string tag;
2283  {
2284    Symbol* macro = Symbol::find ("tag");
2285    if (macro != 0)
2286      {
2287        tag = macro->build_macro_value ();
2288        Symbol::expand (tag);
2289      }
2290  }
2291
2292  //cmt_local_tagfile = $(bin)$(tag).make
2293  //cmt_final_setup = $(bin)setup.make
2294  files[0] = tag;
2295  files[1] = "setup";
2296  for (int i = 0; i < files.size (); i++)
2297    {
2298      if (Cmt::build_nmake ())
2299        files[i] += ".nmake";
2300      else
2301        files[i] += ".make";
2302
2303      if (outdir != "")
2304        {
2305          if (outdir [outdir.size () - 1] != CmtSystem::file_separator ())
2306            outdir += CmtSystem::file_separator ();
2307          files[i] = outdir + files[i];
2308        }
2309      //      cerr << "files[" << i << "]: " << files[i] << endl;
2310    }
2311
2312  //  files[0] = "/dev/full";
2313  ofstream t (files[0]);
2314  if (!t)
2315    {
2316      CmtError::set (CmtError::file_access_error, files[0]);
2317      return;
2318    }
2319  t.exceptions (ios::failbit | ios::badbit);
2320  try
2321    {
2322      print_macros (Make, "", t);
2323      t.close (); // ios_base::failbit
2324    }
2325  catch (const ios::failure& e)
2326    {
2327      CmtSystem::close_ostream (NULL, files[0] + ": " + cmt_string (e.what ()));
2328    }
2329
2330  bool gen_setup (true);
2331  ostringstream os;
2332  ofstream s;
2333  s.open (files[1], ios::in);
2334  if (s) // file already exists
2335    {
2336      //      cerr << files[1] << " already exists" << endl;
2337      do_show_setup (ap, os);
2338      ostringstream osn;
2339      osn << s.rdbuf ();
2340      if (os.str () == osn.str ())
2341        {
2342          //      cerr << files[1] << " up-to-date" << endl;
2343          gen_setup = false;
2344        }
2345    }
2346  s.clear ();
2347  s.close ();
2348  if (gen_setup)
2349    {
2350      s.open (files[1]);
2351      if (!s)
2352        {
2353          CmtError::set (CmtError::file_access_error, files[1]);
2354          return;
2355        }
2356      s.exceptions (ios::failbit | ios::badbit);
2357      try
2358        {
2359          if (os.str ().size () != 0)
2360            {
2361              //              cerr << files[1] << " contents already generated" << endl;
2362              s << os.str ();
2363            }
2364          else
2365            {
2366              do_show_setup (ap, s);
2367            }
2368          s.close (); // ios_base::failbit
2369        }
2370      catch (const ios::failure& e)
2371        {
2372          CmtSystem::close_ostream (NULL, files[1] + ": " + cmt_string (e.what ()));
2373        }
2374    }
2375
2376  Generator::build_constituents_makefile (Me.m_current_package, ap.arguments);
2377}
2378
2379//----------------------------------------------------------
2380void Cmt::do_build_dependencies (const ArgParser& ap,
2381                                 int argc,
2382                                 char* argv[])
2383{
2384  if (CmtLock::check () == CmtLock::locked_by_another_user)
2385    {
2386      CmtError::set (CmtError::conflicting_lock, "build_dependencies>");
2387      return;
2388    }
2389  if (ap.arguments.size () > 0)
2390    {
2391      set_standard_macros ();
2392
2393      Generator::build_dependencies (ap.arguments);
2394    }
2395}
2396
2397//----------------------------------------------------------
2398void Cmt::do_build_library_links (const ArgParser& ap)
2399{
2400  cmt_string cmtinstallarea = "";
2401  cmt_string tag = "";
2402  cmt_string shlibsuffix;
2403  cmt_string symlinkcmd;
2404
2405  if (CmtLock::check () == CmtLock::locked_by_another_user)
2406    {
2407      CmtError::set (CmtError::conflicting_lock, "build_library_links>");
2408      return;
2409    }
2410
2411  set_standard_macros ();
2412
2413  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
2414  Use& current_use = Use::current ();
2415  int i;
2416
2417  {
2418    Symbol* macro = Symbol::find ("shlibsuffix");
2419    if (macro == 0) return;
2420    shlibsuffix = macro->build_macro_value ();
2421    Symbol::expand (shlibsuffix);
2422  }
2423
2424  {
2425    Symbol* macro = Symbol::find ("library_install_command");
2426    if (macro != 0)
2427      {
2428        symlinkcmd = macro->build_macro_value ();
2429        Symbol::expand (symlinkcmd);
2430      }
2431  }
2432
2433  if (current_use.get_strategy ("InstallArea"))
2434    {
2435      const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
2436     
2437      cmt_string s1 = ia_mgr.get_installarea ();
2438
2439      {
2440        Symbol* symbol = Symbol::find ("CMTINSTALLAREA");
2441        if (symbol != 0)
2442          {
2443            s1 = symbol->build_macro_value ();
2444            Symbol::expand (s1);
2445          }
2446      }
2447
2448      cmtinstallarea = s1;
2449                 
2450      cmt_string s2;
2451
2452      {
2453        Symbol* macro = Symbol::find ("tag");
2454        if (macro != 0)
2455          {
2456            s2 = macro->build_macro_value ();
2457            Symbol::expand (s2);
2458          }
2459      }
2460
2461      tag = s2;
2462
2463      cmt_string s = s1;
2464      s += CmtSystem::file_separator ();
2465      s += s2;
2466      s += CmtSystem::file_separator ();
2467      s += "lib";
2468
2469      CmtSystem::mkdir (s);
2470    }
2471
2472  current_use.build_library_links (cmtinstallarea, tag, shlibsuffix, symlinkcmd);
2473
2474  for (i = 0; i < Uses.size (); i++)
2475    {
2476      Use* use = Uses[i];
2477
2478      if (use == 0) continue;
2479      if (use->discarded) continue;
2480      if (use->m_hidden) continue;
2481
2482      if (use->get_package_name () == "CMT") continue;
2483      if (use->get_package_name () == current_use.get_package_name ()) continue;
2484
2485      use->build_library_links (cmtinstallarea, tag, shlibsuffix, symlinkcmd);
2486    }
2487}
2488
2489//----------------------------------------------------------
2490void Cmt::do_build_make_setup (const ArgParser& ap)
2491{
2492  if (CmtLock::check () == CmtLock::locked_by_another_user)
2493    {
2494      CmtError::set (CmtError::conflicting_lock, "build_make_setup>");
2495      return;
2496    }
2497  set_standard_macros ();
2498  Generator::build_make_setup (Me.m_current_package);
2499}
2500
2501//----------------------------------------------------------
2502void Cmt::do_build_msdev (const ArgParser& ap)
2503{
2504  if (CmtLock::check () == CmtLock::locked_by_another_user)
2505    {
2506      CmtError::set (CmtError::conflicting_lock, "build_msdev>");
2507      return;
2508    }
2509
2510  if (true)
2511    {
2512      set_standard_macros ();
2513      if (ap.arguments.size () > 0) build_msdev_file (ap.arguments[0]);
2514      else build_msdev_file ("");
2515    }
2516}
2517
2518void Cmt::do_build_CMT_pacman (const ArgParser& ap)
2519{
2520  cmt_string pacman_file;
2521
2522  pacman_file = Me.m_cmt_root;
2523  pacman_file += CmtSystem::file_separator ();
2524  pacman_file += "mgr";
2525  pacman_file += CmtSystem::file_separator ();
2526  pacman_file += "CMT.pacman";
2527
2528  cmt_string pacman;
2529  cmt_string pattern = "<version>";
2530  cmt_string replacement = CMTVERSION;
2531
2532  pacman.read (pacman_file);
2533
2534  pacman.replace_all (pattern, replacement);
2535
2536  cout << pacman << endl;
2537}
2538
2539// Visual Studio.net Support                                                 
2540//----------------------------------------------------------                 
2541void Cmt::do_build_vsnet (const ArgParser& ap)     
2542{                                                                           
2543  if (CmtLock::check () == CmtLock::locked_by_another_user)                 
2544    {                                                                       
2545      CmtError::set (CmtError::conflicting_lock, "build_vsnet>");           
2546      return;                                                               
2547    }                                                                       
2548                                                                             
2549  if (true)                                                                 
2550    {                                                                       
2551      set_standard_macros ();                                               
2552      if (ap.arguments.size () > 0) build_vsnet_file (ap.arguments[0]);           
2553      else build_vsnet_file ("");                                           
2554    }                                                                       
2555}                                                                           
2556
2557//----------------------------------------------------------
2558void Cmt::do_build_os9_makefile (const ArgParser& ap)
2559{
2560  if (CmtLock::check () == CmtLock::locked_by_another_user)
2561    {
2562      CmtError::set (CmtError::conflicting_lock, "build_os9_makefile>");
2563      return;
2564    }
2565
2566  if (ap.arguments.size () > 0) 
2567    {
2568      set_standard_macros ();
2569      build_OS9_makefile (ap.arguments[0]);
2570    }
2571}
2572
2573//----------------------------------------------------------
2574void Cmt::do_build_prototype (const ArgParser& ap)
2575{
2576  if (CmtLock::check () == CmtLock::locked_by_another_user)
2577    {
2578      CmtError::set (CmtError::conflicting_lock, "build_prototype>");
2579      return;
2580    }
2581
2582  if (ap.arguments.size () > 0) 
2583    {
2584      set_standard_macros ();
2585      Generator::build_prototype (ap.arguments[0]);
2586    }
2587}
2588
2589//----------------------------------------------------------
2590void Cmt::do_build_readme (const ArgParser& ap)
2591{
2592  if (CmtLock::check () == CmtLock::locked_by_another_user)
2593    {
2594      CmtError::set (CmtError::conflicting_lock, "build_readme>");
2595      return;
2596    }
2597
2598  set_standard_macros ();
2599  Generator::build_readme (ap.arguments);
2600}
2601
2602//----------------------------------------------------------
2603void Cmt::do_build_tag_makefile (const ArgParser& ap)
2604{
2605  if (CmtLock::check () == CmtLock::locked_by_another_user)
2606    {
2607      CmtError::set (CmtError::conflicting_lock, "build_tag_makefile>");
2608      return;
2609    }
2610
2611  print_macros (Make);
2612}
2613
2614//----------------------------------------------------------
2615void Cmt::do_build_temporary_name (const ArgParser& ap)
2616{
2617  cmt_string name = CmtSystem::get_temporary_name ();
2618  cout << name << endl;
2619}
2620
2621//----------------------------------------------------------
2622void Cmt::do_build_triggers (const ArgParser& ap)
2623{
2624  if (CmtLock::check () == CmtLock::locked_by_another_user)
2625    {
2626      CmtError::set (CmtError::conflicting_lock, "build_tag_makefile>");
2627      return;
2628    }
2629
2630  if (ap.arguments.size () > 0) 
2631    {
2632      set_standard_macros ();
2633      TriggerGenerator::run (ap.arguments[0]);
2634    }
2635}
2636
2637//----------------------------------------------------------
2638void Cmt::do_build_windefs (const ArgParser& ap)
2639{
2640  if (CmtLock::check () == CmtLock::locked_by_another_user)
2641    {
2642      CmtError::set (CmtError::conflicting_lock, "build_windefs>");
2643      return;
2644    }
2645
2646  if (ap.arguments.size () > 0) 
2647    {
2648      set_standard_macros ();
2649      //      Generator::build_windefs (ap.arguments[0]);
2650      Generator::build_windefs (ap.arguments);
2651    }
2652}
2653
2654//----------------------------------------------------------
2655void Cmt::do_check_configuration (const ArgParser& ap)
2656{
2657  cmt_string env;
2658  Tag* tag;
2659
2660  set_standard_macros ();
2661
2662  static CmtSystem::cmt_string_vector tags;
2663
2664  CmtSystem::split (Me.m_extra_tags, " \t,", tags);
2665
2666  for (int i = 0; i < tags.size (); i++)
2667    {
2668      const cmt_string& t = tags[i];
2669
2670      tag = Tag::find (t);
2671      if (tag == 0) continue;
2672
2673      if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag)) 
2674        {
2675          CmtMessage::warning ("The tag " + t + " is not used in any tag expression. Please check spelling");
2676          //      cerr << "#CMT> The tag " << t << " is not used in any tag expression. Please check spelling" << endl;
2677        }
2678    }
2679
2680  Symbol::check_all_paths ();
2681
2682  env = CmtSystem::getenv ("CMTSITE");
2683  if (env == "") 
2684    {
2685      return;
2686    }
2687
2688  tag = Tag::find (env);
2689  if (tag == 0) 
2690    {
2691      return;
2692    }
2693
2694  if (!Tag::check_tag_used (tag) && !Symbol::check_tag_used (tag) && Cmt::get_warnings ()) 
2695    {
2696      CmtMessage::warning ("The CMTSITE value " + env + " is not used in any tag expression. Please check spelling");
2697      //      cerr << "#CMT> The CMTSITE value " << env << " is not used in any tag expression. Please check spelling" << endl;
2698    }
2699
2700}
2701
2702//----------------------------------------------------------
2703void Cmt::do_check_files (const ArgParser& ap)
2704{
2705  if (ap.arguments.size () >= 2) 
2706    {
2707      cmt_string first_file = ap.arguments[0];
2708      cmt_string second_file = ap.arguments[1];
2709         
2710      if (first_file == "") return;
2711      if (second_file == "") return;
2712         
2713      CmtSystem::compare_and_update_files (first_file, second_file);
2714    }
2715}
2716
2717//----------------------------------------------------------
2718void Cmt::do_check_version (const ArgParser& ap)
2719{
2720  if (ap.arguments.size () > 0)
2721    {
2722      cmt_string name = ap.arguments[0];
2723         
2724      if (name == "") return;
2725      int v = 0;
2726      int r = 0;
2727      int p = 0;
2728         
2729      bool ok = CmtSystem::is_version_directory (name, v, r, p);
2730         
2731      if (ok)
2732        {
2733          cout << "# " << name << " is version " << v << " release " << r << " patch " << p << endl;
2734        }
2735      else
2736        {
2737          cout << "# " << name << " is not a version tag" << endl;
2738        }
2739    }
2740}
2741
2742//----------------------------------------------------------
2743void Cmt::do_checkout (const ArgParser& ap)
2744{
2745  Vcs::checkout (ap.arguments);
2746  //  Cvs::checkout (ap.arguments);
2747}
2748
2749//----------------------------------------------------------
2750void Cmt::do_cleanup (const ArgParser& ap)
2751{
2752  print_clean (ap.mode);
2753}
2754
2755//----------------------------------------------------------
2756void Cmt::do_config (const ArgParser& ap)
2757{
2758  if (CmtLock::check () == CmtLock::locked_by_another_user)
2759    {
2760      CmtError::set (CmtError::conflicting_lock, "config>");
2761      return;
2762    }
2763
2764  //Use::UsePtrVector& Uses = Use::get_ordered_uses ();
2765
2766  Use& current_use = Use::current ();
2767
2768  if (Me.m_debug)
2769    {
2770      cout << "Cmt::do_config> " << endl;
2771      cout << "pwd " << CmtSystem::pwd () << endl;
2772      cout << "current_dir " << Me.m_current_dir << endl;
2773      cout << "default_path " << Me.m_default_path << endl;
2774      cout << "cmt config " <<
2775        Me.m_current_package << " " <<
2776        Me.m_current_version << " " <<
2777        Me.m_current_path << endl;
2778    }
2779
2780  if (Me.m_current_package == "CMT") return;
2781  if (Me.m_current_package == "methods") return;
2782
2783  cmt_string branch;
2784
2785  CmtSystem::basename (Me.m_current_dir, branch);
2786
2787  if ((branch != "mgr") && (branch != "cmt"))
2788    {
2789
2790      //
2791      // Here we are in a standalone package (ie completely unstructured)
2792      //
2793
2794      if (CmtSystem::test_file ("requirements"))
2795        {
2796          if (CmtMessage::active (Error))
2797            {
2798          cout << "------------------------------------------" << endl;
2799          cout << "Configuring environment for standalone package." << endl;
2800          cout << "CMT version " << Me.m_cmt_version << "." << endl;
2801          cout << "System is " << Me.m_cmt_config << endl;
2802          cout << "------------------------------------------" << endl;
2803            }
2804
2805          install_test_setup_scripts ();
2806          install_test_cleanup_scripts ();
2807
2808          Generator::build_default_makefile ();
2809        }
2810      else
2811        {
2812          cout << "==============================================" << endl;
2813          cout << "cmt config must be operated either upon "
2814            "an existing package" << endl;
2815          cout << " (ie. when a requirements file already exists)" << endl;
2816          cout << "   > cd ..." << endl;
2817          cout << "   > cmt config" << endl;
2818          cout << "or to create a new package" << endl;
2819          cout << "   > cmt config <package> <version> [<path>]" << endl;
2820          cout << "==============================================" << endl;
2821        }
2822
2823      return;
2824    }
2825
2826  //  configure_current_package ();
2827
2828  //  Generator::build_default_makefile ();
2829
2830  CmtSystem::cmt_string_vector makes;
2831  cmt_regexp expression ("[.]n?make(sav)?$");
2832
2833  CmtSystem::scan_dir (".", expression, makes);
2834 
2835  if (makes.size () > 0)
2836    {
2837      if (CmtMessage::active (Info))
2838        cout << "Removing all previous make fragments from " << branch << endl;
2839
2840      for (int i = 0; i < makes.size (); i++)
2841        {
2842          const cmt_string& s = makes[i];
2843          CmtSystem::cmt_string_vector words;
2844          CmtSystem::split (s, '.', words);
2845          if (words.size()>=2)
2846            if (CmtSystem::get_makefile_suffix () == "nmake" && words[1] == "nmake")
2847              CmtSystem::remove_file (s);
2848            else if (CmtSystem::get_makefile_suffix () == "make" && words[1] == "make")
2849              CmtSystem::remove_file (s);
2850        }
2851    }
2852 
2853
2854  CmtSystem::cd ("..");
2855
2856  CmtSystem::scan_dir (Me.m_cmt_config, expression, makes); 
2857   
2858  if (makes.size () > 0) 
2859    {
2860      if (CmtMessage::active (Info))
2861        {
2862          cout << "Removing all previous make fragments from "
2863               << Me.m_cmt_config << endl; 
2864        }
2865
2866      for (int i = 0; i < makes.size (); i++) 
2867        { 
2868          const cmt_string& s = makes[i];
2869          CmtSystem::cmt_string_vector words;
2870          CmtSystem::split (s, '.', words);
2871          if (words.size()>=2)
2872            if (CmtSystem::get_makefile_suffix () == "nmake" && words[1] == "nmake")
2873              CmtSystem::remove_file (s);
2874            else if (CmtSystem::get_makefile_suffix () == "make" && words[1] == "make")
2875              CmtSystem::remove_file (s);
2876        }   
2877    } 
2878
2879  CmtSystem::cd (branch); 
2880
2881  Use& use = Use::current ();
2882
2883  use.set (Me.m_current_package,
2884           Me.m_current_version,
2885           Me.m_current_path,
2886           "",
2887           "");
2888
2889  use.change_path (Me.m_current_path);
2890  use.style     = Me.m_current_style;
2891  use.structuring_style = Me.m_current_structuring_style;
2892
2893  Me.m_quiet = true;
2894
2895  if (!reach_current_package ())
2896    {
2897      CmtMessage::error ("Cannot read the requirements file");
2898      //      cout << "Cannot read the requirements file" << endl;
2899      return;
2900    }
2901
2902  install_setup_scripts ();
2903  install_cleanup_scripts ();
2904  install_native_version_file ();
2905
2906  Generator::build_default_makefile ();
2907
2908  CmtSystem::cd ("..");
2909
2910  Branch::BranchVector& branches = Branch::branches ();
2911
2912  int i;
2913
2914  for (i = 0; i < branches.size (); i++)
2915    {
2916      const Branch& branch = branches[i];
2917      const cmt_string& branch_name = branch.name ();
2918
2919      if (!CmtSystem::test_directory (branch_name))
2920        {
2921          if (!CmtSystem::mkdir (branch_name))
2922            {
2923              CmtMessage::error ("Cannot create the " + branch_name + " branch");
2924              //              cout << "Cannot create the " << branch_name <<" branch" << endl;
2925            }
2926          else
2927            {
2928              if (CmtMessage::active (Info))
2929                cout << "Installing the " << branch_name << " directory" << endl;
2930            }
2931        }
2932      else
2933        {
2934          if (CmtMessage::active (Info))
2935            cout << branch_name << " directory already installed" << endl;
2936        }
2937    }
2938}
2939
2940
2941//----------------------------------------------------------
2942void Cmt::do_relocate (const ArgParser& ap)
2943{
2944  if (CmtLock::check () == CmtLock::locked_by_another_user)
2945    {
2946      CmtError::set (CmtError::conflicting_lock, "relocate>");
2947      return;
2948    }
2949
2950  Use& current_use = Use::current ();
2951
2952  if (Me.m_debug)
2953    {
2954      cout << "Cmt::do_relocate> " << endl;
2955      cout << "pwd "          << CmtSystem::pwd () << endl;
2956      cout << "current_dir "  << Me.m_current_dir << endl;
2957      cout << "default_path " << Me.m_default_path << endl;
2958      cout << "cmt config "   <<
2959        Me.m_current_package << " " <<
2960        Me.m_current_version << " " <<
2961        Me.m_current_path << endl;
2962    }
2963
2964  if (Me.m_current_package == "CMT")     return;
2965  if (Me.m_current_package == "methods") return;
2966
2967  cmt_string branch;
2968
2969  CmtSystem::basename (Me.m_current_dir, branch);
2970
2971  if ((branch != "mgr") && (branch != "cmt"))
2972    {
2973
2974      //
2975      // Here we are in a standalone package (ie completely unstructured)
2976      //
2977
2978      if (CmtSystem::test_file ("requirements"))
2979        {
2980          if (CmtMessage::active (Error))
2981            {
2982          cout << "------------------------------------------" << endl;
2983          cout << "Configuring environment for standalone package." << endl;
2984          cout << "CMT version " << Me.m_cmt_version << "." << endl;
2985          cout << "System is "   << Me.m_cmt_config << endl;
2986          cout << "------------------------------------------" << endl;
2987            }
2988          install_test_setup_scripts ();
2989          install_test_cleanup_scripts ();
2990
2991          Generator::build_default_makefile ();
2992        }
2993      else
2994        {
2995          cout << "==============================================" << endl;
2996          cout << "cmt relocate must be operated either upon "
2997            "an existing package" << endl;
2998          cout << " (ie. when a requirements file already exists)" << endl;
2999          cout << "   > cd ..." << endl;
3000          cout << "   > cmt relocate" << endl;
3001          cout << "or to create a new package" << endl;
3002          cout << "   > cmt relocate <package> <version> [<path>]" << endl;
3003          cout << "==============================================" << endl;
3004        }
3005
3006      return;
3007    }
3008
3009  //  configure_current_package ();
3010
3011  //  Generator::build_default_makefile ();
3012 
3013  CmtSystem::cd ("..");   
3014  CmtSystem::cd (branch); 
3015
3016  Use& use = Use::current ();
3017
3018  use.set (Me.m_current_package,
3019           Me.m_current_version,
3020           Me.m_current_path,
3021           "",
3022           "");
3023
3024  use.change_path (Me.m_current_path);
3025  use.style     = Me.m_current_style;
3026  use.structuring_style = Me.m_current_structuring_style;
3027
3028  Me.m_quiet = true;
3029   
3030  if (!reach_current_package ())
3031    {
3032      CmtMessage::error ("Cannot read the requirements file");
3033      //      cout << "Cannot read the requirements file" << endl;
3034      return;
3035    }
3036
3037  install_setup_scripts ();
3038  install_cleanup_scripts ();
3039
3040  Generator::build_default_makefile ();
3041
3042  CmtSystem::cd ("..");
3043
3044  Branch::BranchVector& branches = Branch::branches ();
3045
3046  int i;
3047
3048  for (i = 0; i < branches.size (); i++)
3049    {
3050      const Branch& branch = branches[i];
3051      const cmt_string& branch_name = branch.name ();
3052
3053      if (!CmtSystem::test_directory (branch_name))
3054        {
3055          if (!CmtSystem::mkdir (branch_name))
3056            {
3057              CmtMessage::error ("Cannot create the " + branch_name + " branch");
3058              //              cout << "Cannot create the " << branch_name <<" branch" << endl;
3059            }
3060          else
3061            {
3062              if (CmtMessage::active (Info))
3063                cout << "Installing the " << branch_name << " directory" << endl;
3064            }
3065        }
3066      else
3067        {
3068          if (CmtMessage::active (Info))
3069            cout << branch_name << " directory already installed" << endl;
3070        }
3071    }
3072}
3073
3074//----------------------------------------------------------
3075void Cmt::do_create (const ArgParser& ap)
3076{
3077  if (ap.arguments.size () < 2) return;
3078
3079  const cmt_string& package = ap.arguments[0];
3080  const cmt_string& version = ap.arguments[1];
3081  cmt_string offset;
3082  if (ap.arguments.size () >= 3) offset = ap.arguments[2];
3083
3084  if (Me.m_debug)
3085    {
3086      cout << "do_create>Me.m_current_package=" << Me.m_current_package << endl;
3087      cout << "do_create>package=" << package << endl;
3088    }
3089
3090  //if (Me.m_current_package == "CMT") return;
3091  //if (Me.m_current_package == "methods") return;
3092
3093  cmt_string the_path;
3094
3095  the_path = CmtSystem::pwd ();
3096
3097  if (offset != "")
3098    {
3099      if (!CmtSystem::absolute_path (offset))
3100        {
3101          // offset is really a relative offset
3102          the_path += CmtSystem::file_separator ();
3103          the_path += offset;
3104        }
3105      else // absolute path
3106        {
3107          the_path = offset;
3108        }
3109    }
3110
3111  CmtSystem::compress_path (the_path);
3112
3113  // Now 'the_path' contains the complete path where the package will be created
3114
3115  if (CmtMessage::active (Error))
3116    {
3117  cout << "------------------------------------------" << endl;
3118  cout << "Configuring environment for package " << package <<
3119    " version " << version << "." << endl;
3120  cout << "CMT version " << Me.m_cmt_version << "." << endl;
3121  cout << "Root set to " << the_path << "." << endl;
3122  cout << "System is " << Me.m_cmt_config << endl;
3123  cout << "------------------------------------------" << endl;
3124    }
3125
3126  if (!CmtSystem::test_directory (the_path))
3127    {
3128      if (!CmtSystem::mkdir (the_path))
3129        {
3130          CmtMessage::error ("Cannot create the path directory");
3131          //          cout << "Cannot create the path directory" << endl;
3132          return;
3133        }
3134      else
3135        {
3136          if (CmtMessage::active (Info))
3137            cout << "Installing the path directory" << endl;
3138        }
3139    }
3140
3141  CmtSystem::cd (the_path);
3142
3143  if (!CmtSystem::test_directory (package))
3144    {
3145      if (!CmtSystem::mkdir (package))
3146        {
3147          CmtMessage::error ("Cannot create the package directory");
3148          //          cout << "Cannot create the package directory" << endl;
3149          return;
3150        }
3151      else
3152        {
3153          if (CmtMessage::active (Info))
3154            cout << "Installing the package directory" << endl;
3155        }
3156    }
3157  else
3158    {
3159      if (CmtMessage::active (Info))
3160        cout << "Package directory already installed" << endl;
3161    }
3162
3163  CmtSystem::cd (package);
3164
3165  Use& current_use = Use::current ();
3166
3167  bool with_version_dir = current_use.get_strategy ("VersionDirectory");
3168
3169  CmtStructuringStyle style = get_current_structuring_style ();
3170
3171  if (style != default_structuring_style)
3172    {
3173      if (with_version_dir)
3174        {
3175          if (style == without_version_directory)
3176            {
3177              with_version_dir = false;
3178            }
3179        }
3180      else
3181        {
3182          if (style == with_version_directory)
3183            {
3184              with_version_dir = true;
3185            }
3186        }
3187    }
3188
3189  if (with_version_dir)
3190    {
3191      if (!CmtSystem::test_directory (version))
3192        {
3193          if (!CmtSystem::mkdir (version))
3194            {
3195              CmtMessage::error ("Cannot create the version directory");
3196              //              cout << "Cannot create the version directory" << endl;
3197              return;
3198            }
3199          else
3200            {
3201              if (CmtMessage::active (Info))
3202                cout << "Installing the version directory" << endl;
3203            }
3204        }
3205      else
3206        {
3207          if (CmtMessage::active (Info))
3208            cout << "Version directory already installed" << endl;
3209        }
3210
3211      CmtSystem::cd (version);
3212    }
3213  else
3214    {
3215      if (CmtMessage::active (Info))
3216        cout << "Version directory will not be created due to structuring style" << endl;
3217    }
3218
3219  if (!CmtSystem::test_directory ("cmt"))
3220    {
3221      if (!CmtSystem::test_directory ("mgr"))
3222        {
3223          if (!CmtSystem::mkdir ("cmt"))
3224            {
3225              CmtMessage::error ("Cannot create the cmt directory");
3226//              cout << "Cannot create the cmt directory" << endl;
3227              return;
3228            }
3229          else
3230            {
3231              Me.m_current_style = cmt_style;
3232              if (with_version_dir)
3233                {
3234                  Me.m_current_structuring_style = with_version_directory;
3235                }
3236              else
3237                {
3238                  Me.m_current_structuring_style = without_version_directory;
3239                  //                  Me.m_current_style = no_version_style;
3240                }
3241
3242              if (CmtMessage::active (Info))
3243                cout << "Installing the cmt directory" << endl;
3244            }
3245        }
3246      else
3247        {
3248          Me.m_current_style = mgr_style;
3249          if (with_version_dir)
3250            {
3251              Me.m_current_structuring_style = with_version_directory;
3252              //              Me.m_current_style = mgr_style;
3253            }
3254          else
3255            {
3256              Me.m_current_structuring_style = without_version_directory;
3257              //              Me.m_current_style = no_version_style;
3258            }
3259         
3260          if (CmtMessage::active (Info))
3261            cout << "Mgr directory already installed" << endl;
3262        }
3263    }
3264  else
3265    {
3266      Me.m_current_style = cmt_style;
3267      if (with_version_dir)
3268        {
3269          Me.m_current_structuring_style = with_version_directory;
3270          //          Me.m_current_style = cmt_style;
3271        }
3272      else
3273        {
3274          Me.m_current_structuring_style = without_version_directory;
3275          //          Me.m_current_style = no_version_style;
3276        }
3277
3278      if (CmtMessage::active (Info))
3279        cout << "Cmt directory already installed" << endl;
3280    }
3281
3282  if (!CmtSystem::test_directory ("src"))
3283    {
3284      if (!CmtSystem::mkdir ("src"))
3285        {
3286          CmtMessage::error ("Cannot create the src directory");
3287          //          cout << "Cannot create the src directory" << endl;
3288          return;
3289        }
3290      else
3291        {
3292          if (CmtMessage::active (Info))
3293            cout << "Installing the src directory" << endl;
3294        }
3295    }
3296  else
3297    {
3298      if (CmtMessage::active (Info))
3299        cout << "src directory already installed" << endl;
3300    }
3301
3302  switch (Me.m_current_style)
3303    {
3304    case cmt_style:
3305      //    case no_version_style:
3306      CmtSystem::cd ("cmt");
3307      break;
3308    case mgr_style:
3309      CmtSystem::cd ("mgr");
3310      break;
3311    }
3312
3313  Generator::build_default_makefile ();
3314
3315  if (!CmtSystem::test_file ("requirements"))
3316    {
3317      // create an empty requirement file.
3318      ofstream f ("requirements");
3319      if (f)
3320        {
3321          f << "package " << package << endl;
3322          f << endl;
3323          f.close ();
3324        }
3325    }
3326
3327  if (!with_version_dir)
3328    {
3329      //      ofstream f ("version.cmt");
3330      ofstream f (Package::get_version_file_name ());
3331      if (f)
3332        {
3333          f << version << endl;
3334          f.close ();
3335        }
3336    }
3337
3338  Me.m_current_package = package;
3339  Me.m_current_version = version;
3340  Me.m_current_path    = the_path;
3341  Me.m_current_dir     = CmtSystem::pwd ();
3342
3343  do_config (ap);
3344}
3345
3346//----------------------------------------------------------
3347void Cmt::do_create_project (const ArgParser& ap)
3348{
3349  int argc = ap.arguments.size ();
3350  int arg = 0;
3351
3352  if (argc < 1) return;
3353
3354  cmt_string project;
3355  cmt_string release;
3356  cmt_string path;
3357
3358  project = ap.arguments[arg]; argc--; arg++;
3359
3360  if (argc > 0)
3361    {
3362      release = ap.arguments[arg];
3363
3364      if (release[0] != '-')
3365        {
3366          argc--; 
3367          arg++;
3368          if (argc > 0)
3369            {
3370              path = ap.arguments[arg];
3371              if (path[0] != '-')
3372                {
3373                  argc--; arg++;
3374                }
3375              else
3376                {
3377                  path = "";
3378                }
3379            }
3380        }
3381      else
3382        {
3383          release = "";
3384        }
3385    }
3386
3387  if (Project::create (project, release, path))
3388    {
3389      while (argc > 0)
3390        {
3391          const cmt_string& argument = ap.arguments[arg]; argc--; arg++;
3392         
3393          if (argument.substr (0, 5) == "-use=")
3394            {
3395              cmt_string use;
3396
3397              argument.substr (5, use);
3398
3399              CmtSystem::cmt_string_vector words;
3400              CmtSystem::split (use, ":", words);
3401
3402              ofstream f (Project::get_project_file_name (), ios_base::app);
3403              if (f)
3404                {
3405                  f << "use " << words[0] << " " << words[1] << " " << words[2] << endl;
3406                  f << endl;
3407                  f.close ();
3408                }
3409            }
3410        }
3411    }
3412}
3413
3414//----------------------------------------------------------
3415void Cmt::do_cvsbranches (const ArgParser& ap)
3416{
3417  Cvs::branches (ap.arguments[0]);
3418}
3419
3420//----------------------------------------------------------
3421void Cmt::do_cvssubpackages (const ArgParser& ap)
3422{
3423  Cvs::subpackages (ap.arguments[0]);
3424}
3425
3426//----------------------------------------------------------
3427void Cmt::do_cvssubprojects (const ArgParser& ap)
3428{
3429  Cvs::subprojects (ap.arguments[0]);
3430}
3431
3432//----------------------------------------------------------
3433void Cmt::do_cvstags (const ArgParser& ap)
3434{
3435  Cvs::tags (ap.arguments);
3436}
3437
3438//----------------------------------------------------------
3439void Cmt::do_do (const ArgParser& ap)
3440{
3441  if (ap.arguments.size () > 0) 
3442    {
3443      set_standard_macros ();
3444      Cmt::reset_all_sets_done ();
3445      Symbol::all_set ();
3446      Generator::build_default_makefile ();
3447
3448      Symbol* symbol = Symbol::find (ap.arguments[0]);
3449
3450      if (symbol == 0)
3451        {
3452          Me.m_action = action_show_action_names;
3453          /*
3454            if (!Me.m_quiet)
3455            {
3456            cerr << "Existing actions:" << endl;
3457            print_symbol_names (ap.mode);
3458            }
3459          */
3460          CmtError::set (CmtError::unknown_command, ap.arguments[0]);
3461          return;
3462        }
3463
3464      /*
3465        We convert extra arguments into the standard macro cmt_args
3466      */
3467
3468      cmt_string args;
3469
3470      for (int i = 1; i < ap.arguments.size (); i++)
3471        {
3472          cmt_string s = ap.arguments[i];
3473          if (i > 1) args += " ";
3474          args += s;
3475        }
3476
3477      cmt_string r = "macro cmt_args \"";
3478      r += args;
3479      r += "\"";
3480
3481      Use* current_use = &(Use::current ());
3482     
3483      SyntaxParser::parse_requirements_line (r, current_use);
3484
3485      cmt_string cmd = symbol->build_macro_value ();
3486      Symbol::expand (cmd);
3487
3488      CmtMessage::info ("Execute action " + ap.arguments[0] + " => " + cmd);
3489
3490      int status = CmtSystem::execute (cmd);
3491      if (status != 0)
3492        {
3493          CmtError::set (CmtError::execution_failed, ap.arguments[0], status);
3494        }
3495    }
3496}
3497
3498//----------------------------------------------------------
3499void Cmt::do_expand_model (const ArgParser& ap)
3500{
3501  set_standard_macros ();
3502
3503  if ((ap.arguments[0] == "-strict") && (ap.arguments.size () > 1))
3504    {
3505      CmtModel::strict_expand (ap.arguments[1]);
3506    }
3507  else if ((ap.arguments[0] == "-test") && (ap.arguments.size () > 2))
3508    {
3509      CmtModel::test_regexp (ap.arguments[1], ap.arguments[2]);
3510    }
3511  else if (ap.arguments.size () > 0)
3512    {
3513      CmtModel::expand (ap.arguments[0]);
3514    }
3515}
3516
3517/**
3518 *  Handle free filtering of text files containing $(xxx) or ${xxx} patterns
3519 *
3520 *  Substitution is performed against CMT macros and environment variables.
3521 *
3522 *  Arguments:
3523 *
3524 *    cmt filter input-file-name output-file-name
3525 *
3526 */
3527void Cmt::do_filter (const ArgParser& ap)
3528{
3529  if (ap.arguments.size () < 2) return;
3530
3531  cmt_string& input = ap.arguments[0];
3532  cmt_string& output = ap.arguments[1];
3533
3534  if (!CmtSystem::test_file (input))
3535    {
3536      CmtError::set (CmtError::path_not_found, input);
3537      //      CmtMessage::error ("File " + input + " not found");
3538      return;
3539    }
3540
3541  cmt_string text;
3542
3543  text.read (input);
3544
3545  set_standard_macros ();
3546
3547  Symbol::expand (text);
3548
3549  FILE* file = fopen (output, "wb");
3550  if (file != NULL)
3551    {
3552      text.write (file);
3553      CmtSystem::close_ostream (file, output);
3554      //      fclose (file);
3555    }
3556  else
3557    {
3558      CmtError::set (CmtError::file_access_error, output);
3559      //      CmtMessage::error ("Cannot write filtered file " + output);
3560    }
3561}
3562
3563//----------------------------------------------------------
3564void Cmt::do_help (const ArgParser& ap)
3565{
3566  //cerr << "ap.help_action=" << ap.help_action << " Me.m_action=" << Me.m_action << endl;
3567  if (Me.m_action == action_none)
3568    {
3569      CommandHelp::show_all ();
3570    }
3571  else
3572    {
3573      CommandHelp::show (Me.m_action);
3574    }
3575}
3576
3577//----------------------------------------------------------
3578void Cmt::do_lock (const ArgParser& ap)
3579{
3580  const cmt_string& package = Me.m_current_package;
3581  const cmt_string& version = Me.m_current_version;
3582  const cmt_string& path    = Me.m_current_path;
3583
3584  //(unsused) Use& use = Use::current();
3585
3586  CmtMessage::info ("try to lock package " + package + " in " + CmtSystem::pwd ());
3587  //  cerr << "try to lock package " << package << " in " << CmtSystem::pwd () << endl;
3588
3589  set_standard_macros ();
3590
3591  CmtLock::status status = CmtLock::lock ();
3592}
3593
3594//----------------------------------------------------------
3595void Cmt::do_remove (const ArgParser& ap)
3596{
3597  const cmt_string& package = Me.m_current_package;
3598  const cmt_string& version = Me.m_current_version;
3599  const cmt_string& path    = Me.m_current_path;
3600
3601  //Use::UsePtrVector& Uses = Use::get_ordered_uses ();
3602
3603  if (Me.m_current_package == "CMT") return;
3604  if (Me.m_current_package == "methods") return;
3605
3606  cmt_string the_path;
3607
3608  //the_path = Me.m_default_path;
3609  the_path = CmtSystem::pwd ();
3610
3611  if (path != "")
3612    {
3613      if (!CmtSystem::absolute_path (path))
3614        {
3615          // path is just a suffix
3616          the_path += CmtSystem::file_separator ();
3617          the_path += path;
3618        }
3619      else // absolute path
3620        {
3621          the_path = path;
3622        }
3623    }
3624
3625  CmtSystem::compress_path (the_path);
3626
3627  if (CmtMessage::active (Info))
3628    {
3629  cout << "------------------------------------------" << endl;
3630  cout << "Removing package " << package <<
3631    " version " << version << "." << endl;
3632  cout << "CMT version " << Me.m_cmt_version << "." << endl;
3633  cout << "Root set to " << the_path << "." << endl;
3634  cout << "System is " << Me.m_cmt_config << endl;
3635  cout << "------------------------------------------" << endl;
3636    }
3637
3638  the_path += CmtSystem::file_separator ();
3639  the_path += package;
3640
3641  if (!CmtSystem::cd (the_path))
3642    {
3643      CmtMessage::error ("Path " + the_path + " not reachable");
3644      //      cerr << "Path " << the_path << " not reachable" << endl;
3645      return;
3646    }
3647
3648  if (CmtSystem::test_directory (version))
3649    {
3650      if (CmtSystem::remove_directory (version))
3651        {
3652          if (CmtMessage::active (Info))
3653            cerr << "Version " << version << " has been removed from " << the_path << endl;
3654          CmtSystem::cmt_string_vector contents;
3655          CmtSystem::scan_dir (".", contents);
3656          if (contents.size () == 0)
3657            {
3658              CmtSystem::cd ("..");
3659              if (CmtSystem::remove_directory (package))
3660                {
3661                  if (CmtMessage::active (Info))
3662                    cerr << "Package " << package << " has no more versions. Thus it has been removed."<< endl;
3663                }
3664            }
3665        }
3666      else
3667        {
3668          CmtMessage::warning ("Impossible to remove version " + version + " from " + the_path);
3669          //          cerr << "Impossible to remove version " << version << " from " << the_path << endl;
3670        }
3671    }
3672  else if (CmtSystem::test_directory ("cmt"))
3673    {
3674      CmtSystem::cd ("cmt");
3675
3676      cmt_string v;
3677
3678      //      v.read ("version.cmt");
3679      v.read (Package::get_version_file_name ());
3680      if (v == version)
3681        {
3682          CmtSystem::cd ("..");
3683          if (!CmtSystem::remove_directory ("cmt"))
3684            {
3685              if (CmtMessage::active (Info))
3686                {
3687              cerr << "Unstructured version " << version
3688                   << " has been removed from " << the_path << endl;
3689                }
3690            }
3691          else
3692            {
3693              CmtMessage::warning ("Impossible to remove unstructured version " + version + " from " + the_path);
3694              //              cerr << "Impossible to remove unstructured version " << version
3695              //                   << " from " << the_path << endl;
3696            }
3697        }
3698      else
3699        {
3700          CmtMessage::warning ("Version " + version + " not found");
3701          //          cerr << "Version " << version << " not found" << endl;
3702        }
3703    }
3704  else
3705    {
3706      CmtMessage::warning ("Version " + version + " not found");
3707      //      cerr << "Version " << version << " not found" << endl;
3708    }
3709}
3710
3711//----------------------------------------------------------
3712void Cmt::do_remove_library_links (const ArgParser& ap)
3713{
3714  if (CmtLock::check () == CmtLock::locked_by_another_user)
3715    {
3716      CmtError::set (CmtError::conflicting_lock, "remove_library_links>");
3717      return;
3718    }
3719
3720  set_standard_macros ();
3721
3722  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
3723  Use& current_use = Use::current ();
3724  Use::UsePtrVector uses (Uses);
3725  uses.push_back (&Use::current ());
3726  int i;
3727  cmt_string shlibsuffix;
3728  cmt_string symunlink;
3729
3730  {
3731    Symbol* macro = Symbol::find ("shlibsuffix");
3732    if (macro == 0) return;
3733    shlibsuffix = macro->build_macro_value ();
3734    Symbol::expand (shlibsuffix);
3735  }
3736
3737  {
3738    Symbol* macro = Symbol::find ("symunlink");
3739    if (macro == 0) return;
3740    symunlink = macro->build_macro_value ();
3741    Symbol::expand (symunlink);
3742  }
3743
3744//   for (i = 0; i < Uses.size (); i++)
3745//     {
3746//       Use* use = Uses[i];
3747  for (i = 0; i < uses.size (); i++)
3748    {
3749      Use* use = uses[i];
3750
3751      if (use->discarded) continue;
3752      if (use->m_hidden) continue;
3753
3754      if (!use->located ())
3755        {
3756          CmtMessage::warning ("package " + use->get_package_name ()
3757                               + " " + use->version + " " + use->path
3758                               + " not found");
3759              /*
3760          if (!Me.m_quiet)
3761            {
3762              cerr << "#CMT> package " << use->get_package_name () <<
3763                " " << use->version << " " << use->path <<
3764                " not found" <<
3765                endl;
3766            }
3767              */
3768        }
3769      else
3770        {
3771          if (use->get_package_name () == "CMT") continue;
3772//           if (use->get_package_name () == current_use.get_package_name ()) continue;
3773
3774          cmt_string s;
3775
3776          s = use->get_package_name ();
3777          s += "_libraries";
3778
3779          Symbol* libraries_macro = Symbol::find (s);
3780
3781          if (libraries_macro == 0) continue;
3782
3783          cmt_string libraries = libraries_macro->build_macro_value ();
3784          Symbol::expand (libraries);
3785
3786          static CmtSystem::cmt_string_vector values;
3787
3788          CmtSystem::split (libraries, " \t", values);
3789
3790          for (int j = 0; j < values.size (); j++)
3791            {
3792              const cmt_string& library = values[j];
3793
3794              static cmt_string libname;
3795              static cmt_string name;
3796
3797              // Is it a simple name or a complete path?
3798
3799              libname = library;
3800              Symbol::expand (libname);
3801
3802              if (CmtSystem::absolute_path (libname))
3803                {
3804                  /**
3805                   *   We assume here that "library" contains a complete path.
3806                   *   (including the complete syntax libxxx.so)
3807                   */
3808
3809                  cmt_string suffix;
3810                  CmtSystem::basename (library, name);
3811                }
3812              else
3813                {
3814                  /**
3815                   *   Here we expect that only the base name of the library
3816                   *   is given : ie it should not contain the "lib" prefix,
3817                   *   nor the suffix .so, nor any path prefix.
3818                   *    This of course should generally correspond to a constituent name.
3819                   */
3820
3821                  name = "lib";
3822                  name += libname;
3823                  name += ".";
3824                  name += shlibsuffix;
3825                }
3826
3827              Symbol::expand (libname);
3828
3829              if (current_use.get_strategy ("InstallArea"))
3830                {
3831                  const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
3832
3833                  cmt_string s1 = ia_mgr.get_installarea ();
3834
3835                  {
3836                    Symbol* symbol = Symbol::find ("CMTINSTALLAREA");
3837                    if (symbol != 0)
3838                      {
3839                        s1 = symbol->build_macro_value ();
3840                        Symbol::expand (s1);
3841                      }
3842                  }
3843                 
3844                  cmt_string s2;
3845
3846                  {
3847                    Symbol* macro = Symbol::find ("tag");
3848                    if (macro != 0)
3849                      {
3850                        s2 = macro->build_macro_value ();
3851                        Symbol::expand (s2);
3852                      }
3853                  }
3854
3855                  // Now deleting the reference file
3856
3857                  s = symunlink;
3858                  s += " ";
3859                  s += s1;
3860                  s += CmtSystem::file_separator ();
3861                  s += s2;
3862                  s += CmtSystem::file_separator ();
3863                  s += "lib";
3864                  s += CmtSystem::file_separator ();
3865                  s += name;
3866                  s += ".cmtref";
3867                  s += " ";
3868                  s += s1;
3869                  s += CmtSystem::file_separator ();
3870                  s += s2;
3871                  s += CmtSystem::file_separator ();
3872                  s += "lib";
3873                  s += CmtSystem::file_separator ();
3874                  s += name;
3875                }
3876              else
3877                {
3878                  s = symunlink;
3879                  s += " ../$(";
3880                  s += current_use.get_package_name ();
3881                  s += "_tag)/";
3882                  s += name;
3883                }
3884
3885              Symbol::expand (s);
3886
3887              if (!Me.m_quiet) cerr << s << endl;
3888
3889              int status = CmtSystem::execute (s);
3890
3891              if (status != 0)
3892                {
3893                  //                  if (status != 2) CmtError::set (CmtError::execution_error, s);
3894                  CmtError::set (CmtError::execution_error, s);
3895
3896                  CmtMessage::warning ("Cannot remove the symbolic link " + s);
3897                  //                  cerr << "#CMT> Cannot remove the symbolic link " << s << endl;
3898
3899                  break;
3900                }
3901            }
3902        }
3903    }
3904}
3905
3906//----------------------------------------------------------
3907void Cmt::do_run (const ArgParser& ap)
3908{
3909  if (ap.arguments.size () > 0) 
3910    {
3911      set_standard_macros ();
3912      Cmt::reset_all_sets_done ();
3913      Symbol::all_set ();
3914
3915      cmt_string cmd;
3916
3917      for (int i = 0; i < ap.arguments.size (); i++)
3918        {
3919          cmd += ap.arguments[i];
3920          cmd += " ";
3921        }
3922
3923      int status = CmtSystem::execute (cmd);
3924      if (status != 0)
3925        {
3926          CmtError::set (CmtError::execution_failed, ap.arguments[0], status);
3927        }
3928      //      CmtSystem::execute (cmd);
3929    }
3930}
3931
3932//----------------------------------------------------------
3933void Cmt::do_run_sequence (const ArgParser& ap)
3934{
3935  if (ap.arguments.size () == 0)
3936    CmtMessage::warning ("run_sequence: no sequence specified");
3937  //cerr << "#CMT> run_sequence: no sequence specified" << endl;
3938
3939  SequenceRunner runner;
3940
3941  if (CmtMessage::active (Info))
3942    cerr << "# cmt run_sequence: sequence " << ap.arguments[0] << endl;
3943
3944  runner.run (ap.arguments[0]);
3945}
3946
3947//----------------------------------------------------------
3948void Cmt::do_set_version (const ArgParser& ap)
3949{
3950  if (ap.arguments.size () == 0)
3951    CmtMessage::warning ("set version: no version specified");
3952  //cerr << "#CMT> set version: no version specified" << endl;
3953
3954  const cmt_string& version = ap.arguments[0];
3955
3956  int v, r, p;
3957
3958  if (!CmtSystem::is_version_directory (version, v, r, p))
3959    {
3960      CmtMessage::error ("set version " + version + " is not a correct version syntax");
3961      //      cerr << "#CMT> set version " << version << " is not a correct version syntax" << endl;
3962      return;
3963    }
3964
3965  if ((v == -1) || (r == -1) || (p == -1))
3966    {
3967      CmtMessage::error ("set version " + version
3968                         + " You cannot use wild card to set a version");
3969      //      cerr << "#CMT> set version " << version
3970      //           << " You cannot use wild card to set a version" << endl;
3971      return;
3972    }
3973
3974  // We want to install the version.cmt file
3975
3976  // We first check we are in a cmt branch
3977  cmt_string h = CmtSystem::pwd ();
3978  cmt_string branch;
3979  CmtSystem::basename (h, branch);
3980
3981  if (branch != "cmt")
3982    {
3983      CmtMessage::error ("set version " + version
3984                         + " must be applied in a cmt directory");
3985      //      cerr << "#CMT> set version " << version << " must be applied in a cmt directory"
3986      //           << endl;
3987      return;
3988    }
3989
3990  CmtSystem::dirname (h, h);
3991  CmtSystem::basename (h, branch);
3992
3993  if (branch == version)
3994    {
3995      CmtMessage::warning ("set version " + version
3996                           + " is already available as a version directory");
3997      //      cerr << "#CMT> set version " << version << " is already available as a version directory"
3998      //           << endl;
3999      return;
4000    }
4001
4002  CmtMessage::info ("Writing version file : " + version);
4003  //  cerr << "Writing version file : " << version << endl;
4004
4005  //  version.write ("version.cmt");
4006  version.write (Package::get_version_file_name ());
4007}
4008
4009//----------------------------------------------------------
4010void Cmt::do_set_versions (const ArgParser& ap)
4011{
4012  CmtSystem::cmt_string_vector args;
4013
4014  args = ap.arguments;
4015  {
4016    cmt_string& s = args.add ();
4017    s = "cmt";
4018  }
4019  {
4020    cmt_string& s = args.add ();
4021    s = "set";
4022  }
4023  {
4024    cmt_string& s = args.add ();
4025    s = "version";
4026  }
4027  {
4028    cmt_string& s = args.add ();
4029    s = "<version>";
4030  }
4031
4032  Me.m_action = action_broadcast;
4033
4034  do_broadcast (ap);
4035}
4036
4037//----------------------------------------------------------
4038void Cmt::do_setup (const ArgParser& ap)
4039{
4040  Use& current_use = Use::current ();
4041
4042  do_check_configuration (ap);
4043
4044  switch (ap.mode)
4045    {
4046    case Xml :
4047      Cmt::print_xml_prolog ("setup");
4048      cout << "<setup>";
4049      break;
4050    }
4051  print (ap.mode);
4052  switch (ap.mode)
4053    {
4054    case Xml :
4055      cout << "</setup>" << endl;
4056      break;
4057    }
4058
4059  //
4060  //  Try a cleanup of the installation area
4061  //
4062  if (current_use.get_strategy ("InstallArea"))
4063    {
4064      CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
4065
4066      ia_mgr.setup ();
4067    }
4068}
4069
4070//----------------------------------------------------------
4071void Cmt::do_show_action (const ArgParser& ap)
4072{
4073  cmt_string target;
4074
4075  if (ap.arguments.size () > 0) target = ap.arguments[0];
4076
4077  Symbol* symbol;
4078
4079  set_standard_macros ();
4080
4081  symbol = Symbol::find (target);
4082
4083  if (symbol == 0) 
4084    {
4085      cmt_string t (target);
4086      t += " is not defined";
4087
4088      CmtError::set (CmtError::symbol_not_found, t);
4089
4090      return;
4091    }
4092  else
4093    {
4094      cmt_string t = target;
4095      t += " is a ";
4096
4097      if ((Me.m_action == action_show_action) ||
4098          (Me.m_action == action_show_action_value))
4099        {
4100          if (symbol->type != Symbol::SymbolAction)
4101            {
4102              if (symbol->type == Symbol::SymbolMacro)
4103                {
4104                  t += "macro";
4105                }
4106              else if (symbol->type == Symbol::SymbolSet)
4107                {
4108                  t += "set";
4109                }
4110              else if (symbol->type == Symbol::SymbolPath)
4111                {
4112                  t += "path";
4113                }
4114              else if (symbol->type == Symbol::SymbolAlias)
4115                {
4116                  t += "alias";
4117                }
4118
4119              CmtError::set (CmtError::wrong_symbol_type, t);
4120            }
4121        }
4122    }
4123
4124  if (symbol->value_lists.size () < 1) return;
4125
4126  symbol->show_macro (ap.mode);
4127}
4128
4129//----------------------------------------------------------
4130void Cmt::do_show_action_names (const ArgParser& ap)
4131{
4132  if (ap.arguments.size () > 0)
4133    {
4134      const cmt_string& pattern = ap.arguments[0];
4135      print_symbol_names (ap.mode, pattern);
4136    }
4137  else
4138    {
4139      print_symbol_names (ap.mode);
4140    }
4141}
4142
4143//----------------------------------------------------------
4144void Cmt::do_show_action_value (const ArgParser& ap)
4145{
4146  do_show_macro (ap);
4147}
4148
4149//----------------------------------------------------------
4150void Cmt::do_show_actions (const ArgParser& ap)
4151{
4152  if (ap.arguments.size () > 0)
4153    {
4154      const cmt_string& pattern = ap.arguments[0];
4155      print_macros (ap.mode, pattern);
4156    }
4157  else
4158    {
4159      print_macros (ap.mode);
4160    }
4161}
4162
4163//----------------------------------------------------------
4164void Cmt::do_show_all_tags (const ArgParser& /*ap*/)
4165{
4166  Tag::TagPtrVector tags = Tag::tags ();
4167  int index;
4168
4169  set_standard_macros ();
4170
4171  for (index = 0; index < tags.size (); index++)
4172    {
4173      const Tag* tag = tags[index];
4174      if (tag != 0)
4175        {
4176          tag->show_definition (true);
4177        }
4178    }
4179}
4180
4181//----------------------------------------------------------
4182void Cmt::do_show_applied_patterns (const ArgParser& /*ap*/)
4183{
4184  Pattern::show_all_applied_patterns ();
4185}
4186
4187//----------------------------------------------------------
4188void Cmt::do_show_author (const ArgParser& /*ap*/)
4189{
4190  Use& use = Use::current();
4191
4192  cout << use.author << endl;
4193 
4194}
4195//----------------------------------------------------------
4196void Cmt::do_show_project_author (const ArgParser& /*ap*/)
4197{
4198  cmt_string cmtpath;
4199  cmt_string offset;
4200
4201  Use& use = Use::current();   
4202  use.get_cmtpath_and_offset (cmtpath, offset);
4203
4204  Project* p = Project::find_by_cmtpath (cmtpath);
4205
4206  cout << p->get_author () << endl;
4207}
4208
4209//----------------------------------------------------------
4210void Cmt::do_show_branches (const ArgParser& ap)
4211{
4212  Branch::print_all (ap.mode);
4213}
4214
4215//----------------------------------------------------------
4216void Cmt::do_show_clients (const ArgParser& ap)
4217{
4218  cmt_string package   = "";
4219  cmt_string version   = "";
4220  cmt_string path_name = "";
4221
4222  if (ap.arguments.size () >= 1) package  = ap.arguments[0];
4223  if (ap.arguments.size () >= 2) version  = ap.arguments[1];
4224  if (ap.arguments.size () >= 3) path_name = ap.arguments[2];
4225
4226  PathScanner scanner;
4227  ClientCollector collector (package, version);
4228
4229  clear     ();
4230  //  configure ();
4231  configure (ap);
4232
4233  cout << "# ----------- Clients of " << package
4234       << (version != "" ? " " + version : "")
4235       << (path_name != "" ? " (" + path_name + ")": "")
4236    //    " " << version <<
4237    //    " " << path_name <<
4238       << endl;
4239
4240  if (path_name == "")
4241    {
4242      Project::scan_paths (scanner, collector);
4243    }
4244  else
4245    {
4246      scanner.scan_path (path_name, collector);
4247    }
4248
4249  cout << "# ----------- " << collector.count () << " clients found." << endl;
4250}
4251
4252//----------------------------------------------------------
4253void Cmt::do_show_cmtpath_patterns (const ArgParser& /*ap*/)
4254{
4255  set_standard_macros ();
4256  CmtPathPattern::show_all ();
4257}
4258
4259//----------------------------------------------------------
4260void Cmt::do_show_constituent (const ArgParser& ap)
4261{
4262  if (ap.arguments.size () > 0) 
4263    {
4264      set_standard_macros ();
4265
4266      Constituent* c = Constituent::find (ap.arguments[0]);
4267      if (c != 0)
4268        {
4269          c->show ();
4270        }
4271      else
4272        {
4273          cmt_string t (ap.arguments[0]);
4274          CmtError::set (CmtError::constituent_not_found, t);
4275        }
4276    }
4277}
4278
4279//----------------------------------------------------------
4280void Cmt::do_show_constituent_names (const ArgParser& /*ap*/)
4281{
4282  set_standard_macros ();
4283  Constituent::show_names ();
4284}
4285
4286//----------------------------------------------------------
4287void Cmt::do_show_constituents (const ArgParser& /*ap*/)
4288{
4289  set_standard_macros ();
4290  Constituent::show_all ();
4291}
4292
4293//----------------------------------------------------------
4294void Cmt::do_show_container (const ArgParser& ap)
4295{
4296  if (ap.arguments.size () == 0)
4297    {
4298      Project::show_container ();
4299    }
4300  else
4301    {
4302      for (int i = 0; i < ap.arguments.size (); i++)
4303        {
4304          const cmt_string& path_name = ap.arguments[i];
4305          if (CmtSystem::test_directory (path_name))
4306            {
4307              Project::show_container (path_name);
4308            }
4309          else
4310            {
4311              CmtMessage::warning ("No such directory: " + path_name);
4312              CmtError::set (CmtError::path_not_found, path_name);
4313            }
4314        }
4315    }
4316}
4317
4318//----------------------------------------------------------
4319void Cmt::do_show_cycles (const ArgParser& /*ap*/)
4320{
4321  set_standard_macros ();
4322  Use& use = Use::current();
4323
4324  use.show_cycles ();
4325}
4326
4327//----------------------------------------------------------
4328void Cmt::do_show_fragment (const ArgParser& ap)
4329{
4330  if (ap.arguments.size () > 0) Fragment::show (ap.arguments[0]);
4331}
4332
4333//----------------------------------------------------------
4334void Cmt::do_show_fragments (const ArgParser& /*ap*/)
4335{
4336  Fragment::show_all ();
4337}
4338
4339//----------------------------------------------------------
4340void Cmt::do_show_groups (const ArgParser& /*ap*/)
4341{
4342  Constituent::parse_all ();
4343  //  set_standard_macros ();
4344  Group::show_all ();
4345}
4346
4347//----------------------------------------------------------
4348void Cmt::do_show_include_dirs (const ArgParser& /*ap*/)
4349{
4350  cmt_string temp;
4351
4352  Use& use = Use::current();
4353
4354  set_standard_macros ();
4355
4356  if (use.include_path == "")
4357    {
4358      temp += "$(src) ";
4359    }
4360  else if (use.include_path != "none")
4361    {
4362      temp += use.include_path;
4363      temp += " ";
4364    }
4365
4366  for (int include_number = 0;
4367       include_number < use.includes.size ();
4368       include_number++)
4369    {
4370      Include& incl = use.includes[include_number];
4371
4372      if (incl.name == "") continue;
4373
4374      temp += incl.name;
4375      temp += " ";
4376    }
4377
4378  cout << temp << endl;
4379}
4380
4381//----------------------------------------------------------
4382void Cmt::do_show_language (const ArgParser& ap)
4383{
4384  if (ap.arguments.size () > 0) 
4385    {
4386      set_standard_macros ();
4387      Language::show (ap.arguments[0]);
4388    }
4389}
4390
4391//----------------------------------------------------------
4392void Cmt::do_show_languages (const ArgParser& /*ap*/)
4393{
4394  set_standard_macros ();
4395  Language::show_all ();
4396}
4397
4398//----------------------------------------------------------
4399static bool is_upperroot (const cmt_string& name)
4400{
4401  int r = name.find_last_of ("ROOT");
4402  if (r == cmt_string::npos ||
4403      (r + 4) != name.size () ||
4404      r == 0)
4405    return false;
4406  for (int i = 0; i < r; i++)
4407    if (islower (name[i])) return false;
4408  return true;
4409}
4410
4411//----------------------------------------------------------
4412void Cmt::do_show_macro (const ArgParser& ap)
4413{
4414  cmt_string target;
4415
4416  if (ap.arguments.size () > 0) target = ap.arguments[0];
4417
4418  Symbol* symbol;
4419
4420  set_standard_macros ();
4421
4422  symbol = Symbol::find (target);
4423
4424  if (symbol == 0) 
4425    {
4426      cmt_string t = " ";
4427      t += target;
4428      t += " is not defined ";
4429
4430      CmtError::set (CmtError::symbol_not_found, t);
4431
4432      return;
4433    }
4434  else
4435    {
4436      cmt_string t = target;
4437      t += " is a ";
4438
4439      if ((Me.m_action == action_show_macro) ||
4440          (Me.m_action == action_show_macro_value))
4441        {
4442          if (symbol->type != Symbol::SymbolMacro)
4443            {
4444              if (symbol->type == Symbol::SymbolAction)
4445                {
4446                  t += "action";
4447                }
4448              else if (symbol->type == Symbol::SymbolSet)
4449                {
4450                  t += "set";
4451                }
4452              else if (symbol->type == Symbol::SymbolPath)
4453                {
4454                  t += "path";
4455                }
4456              else if (symbol->type == Symbol::SymbolAlias)
4457                {
4458                  t += "alias";
4459                }
4460
4461              if (!is_upperroot (symbol->name))
4462                CmtError::set (CmtError::wrong_symbol_type, t);
4463            }
4464        }
4465      else if ((Me.m_action == action_show_set) ||
4466               (Me.m_action == action_show_set_value))
4467        {
4468          if ((symbol->type != Symbol::SymbolSet) &&
4469              (symbol->type != Symbol::SymbolPath) &&
4470              (symbol->type != Symbol::SymbolAction) &&
4471              (symbol->type != Symbol::SymbolAlias))
4472            {
4473              t += "macro";
4474
4475              if (!is_upperroot (symbol->name))
4476                CmtError::set (CmtError::wrong_symbol_type, t);
4477            }
4478        }
4479    }
4480
4481  if (symbol->value_lists.size () < 1) return;
4482
4483  symbol->show_macro (ap.mode);
4484}
4485
4486//----------------------------------------------------------
4487void Cmt::do_show_macro_names (const ArgParser& ap)
4488{
4489  if (ap.arguments.size () > 0)
4490    {
4491      const cmt_string& pattern = ap.arguments[0];
4492      print_symbol_names (ap.mode, pattern);
4493    }
4494  else
4495    {
4496      print_symbol_names (ap.mode);
4497    }
4498}
4499
4500//----------------------------------------------------------
4501void Cmt::do_show_macro_value (const ArgParser& ap)
4502{
4503  do_show_macro (ap);
4504}
4505
4506//----------------------------------------------------------
4507void Cmt::do_show_macros (const ArgParser& ap)
4508{
4509  if (ap.arguments.size () > 0)
4510    {
4511      const cmt_string& pattern = ap.arguments[0];
4512      print_macros (ap.mode, pattern);
4513    }
4514  else
4515    {
4516      print_macros (ap.mode);
4517    }
4518}
4519
4520//----------------------------------------------------------
4521void Cmt::do_show_manager (const ArgParser& /*ap*/)
4522{
4523  Use& use = Use::current();
4524
4525  cout << use.manager << endl;
4526}
4527
4528//----------------------------------------------------------
4529void Cmt::do_show_packages (const ArgParser& ap)
4530{
4531  PathScanner   scanner;
4532  PackageViewer viewer;
4533
4534  if (ap.arguments.size () == 0)
4535    {
4536      Project::scan_paths (scanner, viewer);
4537    }
4538  else
4539    {
4540      for (int i = 0; i < ap.arguments.size (); i++)
4541        {
4542          const cmt_string& path_name = ap.arguments[i];
4543          if (CmtSystem::test_directory (path_name))
4544            {
4545              scanner.scan_path (path_name, viewer);
4546            }
4547          else
4548            {
4549              CmtMessage::warning ("No such directory: " + path_name);
4550              CmtError::set (CmtError::path_not_found, path_name);
4551            }
4552        }
4553    }
4554}
4555
4556//----------------------------------------------------------
4557void Cmt::do_show_path (const ArgParser& ap, ostream& out)
4558{
4559  Project::show_paths (ap.arguments, out);
4560}
4561
4562//----------------------------------------------------------
4563void Cmt::do_show_pattern (const ArgParser& ap)
4564{
4565  cmt_string name;
4566  if (ap.arguments.size () > 0) name = ap.arguments[0];
4567  Pattern::show (name);
4568}
4569
4570//----------------------------------------------------------
4571void Cmt::do_show_pattern_names (const ArgParser& /*ap*/)
4572{
4573  Pattern::show_all_names ();
4574}
4575
4576//----------------------------------------------------------
4577void Cmt::do_show_patterns (const ArgParser& /*ap*/)
4578{
4579  Pattern::show_all ();
4580}
4581
4582//----------------------------------------------------------
4583void Cmt::do_show_projects (const ArgParser& ap)
4584//void Cmt::do_show_projects (const ArgParser& /*ap*/)
4585{
4586  Project::show_all (ap.mode);
4587}
4588
4589//----------------------------------------------------------
4590void Cmt::do_show_pwd (const ArgParser& /*ap*/)
4591{
4592  cout << Me.m_current_dir << endl;
4593}
4594
4595//----------------------------------------------------------
4596void Cmt::do_show_setup (const ArgParser& ap, ostream& out)
4597//void Cmt::do_show_setup (const ArgParser& ap)
4598{
4599  out << "----------> uses" << endl;
4600  do_show_uses (ap, out);
4601  // This is temporary to ensure that Make - which runs "cmt show setup" -
4602  // does not fail for packages with unresolved uses
4603  if (CmtError::get_last_error_code () == CmtError::package_not_found)
4604    CmtError::clear ();
4605
4606  out << "----------> tags" << endl;
4607  do_show_tags (ap, out);
4608
4609  out << "----------> CMTPATH" << endl;
4610  do_show_path (ap, out);
4611}
4612
4613//----------------------------------------------------------
4614void Cmt::do_show_set (const ArgParser& ap)
4615{
4616  do_show_macro (ap);
4617}
4618
4619//----------------------------------------------------------
4620void Cmt::do_show_set_names (const ArgParser& ap)
4621{
4622  if (ap.arguments.size () > 0)
4623    {
4624      const cmt_string& pattern = ap.arguments[0];
4625      print_symbol_names (ap.mode, pattern);
4626    }
4627  else
4628    {
4629      print_symbol_names (ap.mode);
4630    }
4631}
4632
4633//----------------------------------------------------------
4634void Cmt::do_show_set_value (const ArgParser& ap)
4635{
4636  do_show_macro (ap);
4637}
4638
4639//----------------------------------------------------------
4640void Cmt::do_show_sets (const ArgParser& ap)
4641{
4642  if (ap.arguments.size () > 0)
4643    {
4644      const cmt_string& pattern = ap.arguments[0];
4645      print_macros (ap.mode, pattern);
4646    }
4647  else
4648    {
4649      print_macros (ap.mode);
4650    }
4651}
4652
4653//----------------------------------------------------------
4654void Cmt::do_show_strategies (const ArgParser& /*ap*/)
4655{
4656  Use& current_use = Use::current ();
4657
4658  Project::show_specified_strategies_for_all ();
4659
4660  Project* p = Project::get_current ();
4661
4662  /*
4663    if (p != 0) p->show ();
4664    else cout << "No current project" << endl;
4665  */
4666
4667  cout << "Build strategy     : ";
4668
4669  if (current_use.get_strategy ("BuildPrototypes"))
4670    {
4671      cout << "prototypes";
4672    }
4673  else
4674    {
4675      cout << "no_prototypes";
4676    }
4677 
4678  if (current_use.get_strategy ("InstallArea"))
4679    {
4680      cout << " with_installarea";
4681    }
4682  else
4683    {
4684      cout << " without_installarea";
4685    }
4686 
4687  cout << endl;
4688
4689  cout << "Setup strategy     : ";
4690 
4691  if (current_use.get_strategy ("SetupConfig"))
4692    {
4693      cout << "config";
4694    }
4695  else
4696    {
4697      cout << "no_config";
4698    }
4699 
4700  if (current_use.get_strategy ("SetupRoot"))
4701    {
4702      cout << " root";
4703    }
4704  else
4705    {
4706      cout << " no_root";
4707    }
4708 
4709  if (current_use.get_strategy ("SetupCleanup"))
4710    {
4711      cout << " cleanup";
4712    }
4713  else
4714    {
4715      cout << " no_cleanup";
4716    }
4717
4718  if (current_use.get_strategy ("SetupScripts"))
4719    {
4720      cout << " scripts";
4721    }
4722  else
4723    {
4724      cout << " no_scripts";
4725    }
4726
4727  cout << endl;
4728 
4729  cout << "Structure strategy : ";
4730 
4731  if (current_use.get_strategy ("VersionDirectory"))
4732    {
4733      cout << "with_version_directory";
4734    }
4735  else
4736    {
4737      cout << "without_version_directory";
4738    }
4739 
4740  cout << endl;
4741
4742  if (Me.m_current_structuring_style != default_structuring_style)
4743    {
4744      cout << "Structuring style  : ";
4745
4746      switch (Me.m_current_structuring_style)
4747        {
4748        case without_version_directory:
4749          cout << "without_version_directory";
4750          break;
4751        case with_version_directory:
4752          cout << "with_version_directory";
4753          break;
4754        }
4755
4756      cout << endl;
4757    }
4758}
4759
4760//----------------------------------------------------------
4761void Cmt::do_show_tags (const ArgParser& /*ap*/, ostream& out)
4762{
4763  Tag::TagPtrVector tags = Tag::tags ();
4764  int index;
4765
4766  set_standard_macros ();
4767
4768  for (index = 0; index < tags.size (); index++)
4769    {
4770      const Tag* tag = tags[index];
4771      if (tag != 0)
4772        {
4773          tag->show (Me.m_quiet, out);
4774        }
4775    }
4776}
4777
4778//----------------------------------------------------------
4779void Cmt::do_show_use_paths (const ArgParser& ap)
4780{
4781  const cmt_string& to_name = ap.arguments[0];
4782
4783  Use* current = &(Use::current());
4784
4785  if (!current->get_all_clients (to_name))
4786    CmtError::set (CmtError::package_not_found, to_name);
4787}
4788
4789//----------------------------------------------------------
4790void Cmt::do_show_uses (const ArgParser& ap, ostream& out)
4791//void Cmt::do_show_uses (const ArgParser& /*ap*/, ostream& out)
4792{
4793  Use::show_all (false, out, ap.mode);
4794  //  Use::show_all (false, out);
4795}
4796
4797//----------------------------------------------------------
4798void Cmt::do_show_version (const ArgParser& /*ap*/)
4799{
4800  cout << Me.m_current_version << endl;
4801}
4802
4803//----------------------------------------------------------
4804void Cmt::do_show_versions (const ArgParser& ap)
4805{
4806  cmt_string package_name;
4807
4808  if (ap.arguments.size () > 0) package_name = ap.arguments[0];
4809
4810  PathScanner scanner;
4811
4812  Project::scan_paths_for_package (scanner, package_name);
4813}
4814
4815//----------------------------------------------------------
4816void Cmt::do_show_system (const ArgParser& /*ap*/)
4817{
4818  cout << CmtSystem::get_cmt_config () << endl;
4819}
4820
4821//----------------------------------------------------------
4822void Cmt::do_unlock (const ArgParser& /*ap*/)
4823{
4824  const cmt_string& package = Me.m_current_package;
4825  const cmt_string& version = Me.m_current_version;
4826  const cmt_string& path    = Me.m_current_path;
4827
4828  // (unused??) Use& use = Use::current();
4829
4830  CmtMessage::info ("try to unlock package " + package + " in " + CmtSystem::pwd ());
4831  //  cerr << "try to unlock package " << package << " in " << CmtSystem::pwd () << endl;
4832
4833  set_standard_macros ();
4834
4835  CmtLock::status status = CmtLock::unlock ();
4836}
4837
4838//----------------------------------------------------------
4839void Cmt::do_version (const ArgParser& /*ap*/)
4840{
4841  cout << CMTVERSION << endl;
4842}
4843
4844
4845
4846//----------------------------------------------------------
4847ActionType Cmt::get_action ()
4848{
4849  return (Me.m_action);
4850}
4851
4852/*
4853  const CmtSystem::cmt_string_vector& Cmt::get_cmt_path ()
4854  {
4855  return (Me.m_cmt_path);
4856  }
4857
4858  const CmtSystem::cmt_string_vector& Cmt::get_cmt_path_pwds ()
4859  {
4860  return (Me.m_cmt_path_pwds);
4861  }
4862
4863  const CmtSystem::cmt_string_vector& Cmt::get_cmt_path_sources ()
4864  {
4865  return (Me.m_cmt_path_sources);
4866  }
4867*/
4868
4869const cmt_string& Cmt::get_cmt_home ()
4870{
4871  return (Me.m_cmt_home);
4872}
4873
4874const cmt_string& Cmt::get_cmt_user_context ()
4875{
4876  return (Me.m_cmt_user_context);
4877}
4878
4879const cmt_string& Cmt::get_cmt_version ()
4880{
4881  return (Me.m_cmt_version);
4882}
4883
4884const cmt_string& Cmt::get_current_dir ()
4885{
4886  return (Me.m_current_dir);
4887}
4888
4889const cmt_string Cmt::get_current_dir_real ()
4890{
4891  cmt_string current_dir_real;
4892  if (CmtSystem::realpath_ (Me.m_current_dir, current_dir_real))
4893    return current_dir_real;
4894  return (Me.m_current_dir);
4895}
4896
4897const cmt_string& Cmt::get_current_package ()
4898{
4899  return (Me.m_current_package);
4900}
4901
4902const cmt_string& Cmt::get_current_path ()
4903{
4904  return (Me.m_current_path);
4905}
4906
4907const cmt_string& Cmt::get_current_cmtpath ()
4908{
4909  return (Me.m_current_cmtpath);
4910}
4911
4912const cmt_string& Cmt::get_current_offset ()
4913{
4914  return (Me.m_current_offset);
4915}
4916
4917AccessMode Cmt::get_current_access ()
4918{
4919  return (Me.m_current_access);
4920}
4921
4922CmtStructuringStyle Cmt::get_current_structuring_style ()
4923{
4924  return (Me.m_current_structuring_style);
4925}
4926
4927CmtDirStyle Cmt::get_current_style ()
4928{
4929  return (Me.m_current_style);
4930}
4931
4932const cmt_string& Cmt::get_current_version ()
4933{
4934  return (Me.m_current_version);
4935}
4936
4937const cmt_string& Cmt::get_current_target ()
4938{
4939  return (Me.m_current_target);
4940}
4941
4942bool Cmt::get_debug ()
4943{
4944  return (Me.m_debug);
4945}
4946
4947bool Cmt::get_quiet ()
4948{
4949  return (Me.m_quiet);
4950}
4951
4952bool Cmt::get_disable_warnings ()
4953{
4954  return (Me.m_disable_warnings);
4955}
4956
4957bool Cmt::get_warnings ()
4958{
4959  return (Me.m_warnings);
4960}
4961
4962bool Cmt::get_recursive ()
4963{
4964  return (Me.m_recursive);
4965}
4966
4967CmtScopeFilteringMode Cmt::get_scope_filtering_mode ()
4968{
4969  if (Me.m_scope_filtering_mode == default_filtering_mode)
4970    {
4971      return (block_private_uses);
4972    }
4973  else
4974    {
4975      return (Me.m_scope_filtering_mode);
4976    }
4977}
4978
4979//----------------------------------------------------------
4980bool Cmt::get_all_sets_done ()
4981{
4982  return (Me.m_all_sets_done);
4983}
4984
4985//----------------------------------------------------------
4986void Cmt::get_cmt_flags (CmtSystem::cmt_string_vector& flags)
4987{
4988  CmtSystem::split (CmtSystem::getenv ("CMTFLAGS"), " \t", flags);
4989}
4990
4991//----------------------------------------------------------
4992cmt_string Cmt::get_cmt_flags ()
4993{
4994  return CmtSystem::getenv ("CMTFLAGS");
4995}
4996
4997//----------------------------------------------------------
4998bool Cmt::set_cmt_flags (const cmt_string& cmtflags)
4999{
5000  return CmtSystem::putenv ("CMTFLAGS", cmtflags) ?
5001    true :
5002    (CmtMessage::error ("Cannot set `CMTFLAGS' to `" + cmtflags +
5003                        "' in the environment"),
5004     false) ;
5005}
5006
5007//----------------------------------------------------------
5008bool Cmt::add_cmt_flag (const cmt_string& flag)
5009{
5010  CmtSystem::cmt_string_vector flags;
5011  get_cmt_flags (flags);
5012  cmt_string cmtflags;
5013  for (int i = 0; i < flags.size (); i++)
5014    {
5015      if (flags[i] == flag) continue;
5016      if (cmtflags == "")
5017        cmtflags = flags[i]; 
5018      else
5019        cmtflags += " " + flags[i]; 
5020    }
5021
5022  if (cmtflags == "")
5023    cmtflags = flag; 
5024  else
5025    cmtflags += " " + flag; 
5026
5027  return set_cmt_flags (cmtflags);
5028}
5029
5030/**---------------------------------------------------------
5031   guess_current_project
5032
5033   if current directory is in one of the CMTPATHs, do nothing.
5034
5035   Otherwise, we want to guess the current project
5036
5037   move up in directories until cmt/project.cmt is found
5038
5039   for (;;)
5040   {
5041   if test -f ./cmt/project.cmt
5042   ok:
5043   this directory should become the first entry of the CMTPATH
5044   break
5045
5046   if (at top) break;
5047
5048   move up
5049   }
5050*/
5051void Cmt::guess_current_project ()
5052{
5053  Log;
5054
5055  log << "guess_current_project" << log_endl;
5056
5057  cmt_string here = CmtSystem::pwd ();
5058
5059  Use& use = Use::current();
5060  cmt_string current_path (Me.m_current_dir);
5061  if (use.located ())
5062    {
5063      current_path = use.real_path;
5064      CmtMessage::verbose ("Using current use real_path `" + current_path + "'");
5065    }
5066
5067  if (Project::find_in_cmt_paths (current_path) == "")
5068    //  if (Project::find_in_cmt_paths (Me.m_current_dir) == "")
5069    {
5070      if (!CmtSystem::cd (current_path))
5071        {
5072          CmtError::set (CmtError::file_access_error, current_path);
5073          CmtError::print ();
5074          return;
5075        }
5076      cmt_string project_file = "cmt";
5077      project_file += CmtSystem::file_separator ();
5078      project_file += Project::get_project_file_name ();
5079
5080      cmt_string pwd;
5081
5082      for (;;)
5083        {
5084          pwd = CmtSystem::pwd ();
5085          if (CmtSystem::test_file (project_file))
5086            {
5087              //this directory should become the first entry of the CMTPATH
5088
5089              IProjectFactory& factory = ProjectFactory::instance ();
5090              factory.create_project ("", pwd, "CurrentProject", 0);
5091
5092              break;
5093            }
5094
5095          log << "pwd=" << CmtSystem::pwd () << log_endl;
5096         
5097          if (!CmtSystem::cd (".."))
5098            {
5099              log << "Cannot cd up..." << log_endl;
5100              break;
5101            }
5102
5103          if (CmtSystem::pwd () == pwd)
5104            {
5105              log << "Looks the same pwd..." << log_endl;
5106              break;
5107            }
5108        }
5109
5110      CmtSystem::cd (Me.m_current_dir);
5111    }
5112
5113  //cmt_string buffer = "path CMTPATH \n";
5114  cmt_string buffer;
5115  Project::fill_cmtpaths (buffer);
5116  //cerr << "buffer = " << buffer << endl;
5117  //  Use& use = Use::current();
5118
5119  bool save_quiet = Me.m_quiet;
5120  Me.m_quiet = true;
5121
5122  SyntaxParser::parse_requirements_text (buffer, "", &use);
5123
5124  Me.m_quiet = save_quiet;
5125
5126  Me.m_autoconfigure_cmtpath = true;
5127
5128  CmtSystem::cd (here);
5129}
5130
5131//----------------------------------------------------------
5132const cmt_string& Cmt::filter_dir (const cmt_string& dir)
5133{
5134  static cmt_string newdir;
5135
5136  CmtSystem::compress_path (dir, newdir);
5137
5138  return (newdir);
5139}
5140
5141//----------------------------------------------------------
5142static void dos_script_prefix (FILE* f, 
5143                               const cmt_string& cmt_root, 
5144                               const cmt_string& package, 
5145                               const cmt_string& version, 
5146                               const cmt_string& path, 
5147                               const cmt_string& action, 
5148                               const cmt_string& option = "")
5149{
5150  cmt_string no_device = path;
5151
5152  if (CmtSystem::absolute_path (path)) 
5153    {
5154      if (path[1] == ':')
5155        {
5156          no_device = path.substr (2);
5157        }
5158    }
5159
5160  if (package == "cmt_standalone")
5161    {
5162      no_device = "";
5163    }
5164  else
5165    {
5166      no_device = "..\\..\\..";
5167      if (Cmt::get_current_structuring_style () == without_version_directory)
5168        //      if (Cmt::get_current_style () == no_version_style)
5169        {
5170          no_device = "..\\..";
5171        }
5172    }
5173
5174
5175  fprintf (f, "@echo off\n");
5176  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 ());
5177  fprintf (f, "\n");
5178  fprintf (f, "set cmttempfile=\"%%TEMP%%\\tmpsetup.bat\"\n");
5179  fprintf (f, "%%CMTROOT%%\\%%CMTBIN%%\\cmt.exe %s -bat "
5180           " -pack=%s -version=%s -path=\"%%~d0%%~p0%s\" "
5181           " %s "
5182           "%%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >%%cmttempfile%%\n",
5183           action.c_str (),
5184           package.c_str (),
5185           version.c_str (),
5186           no_device.c_str (),
5187           option.c_str ());
5188  fprintf (f, "if exist %%cmttempfile%% call %%cmttempfile%%\n");
5189  fprintf (f, "if exist %%cmttempfile%% del %%cmttempfile%%\n");
5190  fprintf (f, "set cmttempfile=\n");
5191}
5192
5193//----------------------------------------------------------
5194void Cmt::install_cleanup_scripts ()
5195{
5196#ifdef WIN32
5197  static const int modes = 1;
5198  static const cmt_string suffix[1]   = {"bat"};
5199  static const PrintMode  mode[1]     = {Bat};
5200#else
5201  static const int modes = 2;
5202  static const cmt_string suffix[2]   = {"csh", "sh"};
5203  static const PrintMode  mode[2]     = {Csh, Sh};
5204#endif
5205
5206  Use& current_use = Use::current ();
5207
5208  if (!current_use.get_strategy ("SetupScripts"))
5209    {
5210      for (int i = 0; i < modes; i++)
5211        {
5212          cmt_string old_file_name = "cleanup";
5213          old_file_name += ".";
5214          old_file_name += suffix[i];
5215          if (CmtSystem::test_file (old_file_name))
5216            {
5217              if (CmtMessage::active (Error))
5218                cerr << "Removing cleanup script " + old_file_name << endl;
5219              CmtSystem::remove_file (old_file_name);
5220            }
5221        }
5222      return;
5223    }
5224
5225  if (CmtMessage::active (Error))
5226    cerr << "Creating cleanup scripts." << endl;
5227
5228  cmt_string temp;
5229  int i;
5230
5231  cmt_string version = Me.m_current_version;
5232  if (version == "v*") version = "";
5233
5234  for (i = 0; i < modes; i++)
5235    {
5236      cmt_string file_name = "cleanup";
5237      file_name += ".";
5238      file_name += suffix[i];
5239      file_name += ".";
5240      file_name += "new";
5241
5242      FILE* f = fopen (file_name.c_str (), "wb");
5243      if (f != NULL)
5244        {
5245          if (mode[i] == Csh)
5246            {
5247              fprintf (f, "if ( $?CMTROOT == 0 ) then\n");
5248              fprintf (f, "  setenv CMTROOT %s\n", Me.m_cmt_root.c_str ());
5249              fprintf (f, "endif\n");
5250              fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
5251              fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
5252              fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
5253              fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s "
5254                       "-pack=%s -version=%s -path=%s $* >${tempfile}\n",
5255                       suffix[i].c_str (),
5256                       Me.m_current_package.c_str (),
5257                       version.c_str (),
5258                       Me.m_current_path.c_str ());
5259              fprintf (f,
5260                       "if ( $status != 0 ) then\n"
5261                       "  echo \"${CMTROOT}/mgr/cmt cleanup -%s "
5262                       "-pack=%s -version=%s -path=%s $* >${tempfile}\"\n"
5263                       "  set cmtcleanupstatus=2\n"
5264                       "  /bin/rm -f ${tempfile}\n"
5265                       "  exit $cmtcleanupstatus\n"
5266                       "endif\n"
5267                       "set cmtcleanupstatus=0\n"
5268                       "source ${tempfile}\n"
5269                       "if ( $status != 0 ) then\n"
5270                       "  set cmtcleanupstatus=2\n"
5271                       "endif\n"
5272                       "/bin/rm -f ${tempfile}\n"
5273                       "exit $cmtcleanupstatus\n",
5274                       suffix[i].c_str (),
5275                       Me.m_current_package.c_str (),
5276                       version.c_str (),
5277                       Me.m_current_path.c_str ());
5278            }
5279          else if (mode[i] == Sh)
5280            {
5281              fprintf (f, "if test \"${CMTROOT}\" = \"\"; then\n");
5282              fprintf (f, "  CMTROOT=%s; export CMTROOT\n", Me.m_cmt_root.c_str ());
5283              fprintf (f, "fi\n");
5284              fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
5285              fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
5286              fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
5287              fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s "
5288                       "-pack=%s -version=%s -path=%s $* >${tempfile}\n",
5289                       suffix[i].c_str (),
5290                       Me.m_current_package.c_str (),
5291                       version.c_str (),
5292                       Me.m_current_path.c_str ());
5293              fprintf (f,
5294                       "if test $? != 0 ; then\n"
5295                       "  echo >&2 \"${CMTROOT}/mgr/cmt cleanup -%s "
5296                       "-pack=%s -version=%s -path=%s $* >${tempfile}\"\n"
5297                       "  cmtcleanupstatus=2\n"
5298                       "  /bin/rm -f ${tempfile}\n"
5299                       "  return $cmtcleanupstatus\n"
5300                       "fi\n"
5301                       "cmtcleanupstatus=0\n"
5302                       ". ${tempfile}\n"
5303                       "if test $? != 0 ; then\n"
5304                       "  cmtcleanupstatus=2\n"
5305                       "fi\n"
5306                       "/bin/rm -f ${tempfile}\n"
5307                       "return $cmtcleanupstatus\n",
5308                       suffix[i].c_str (),
5309                       Me.m_current_package.c_str (),
5310                       version.c_str (),
5311                       Me.m_current_path.c_str ());
5312            }
5313          else if (mode[i] == Bat)
5314            {
5315              dos_script_prefix (f, Me.m_cmt_root, 
5316                                 Me.m_current_package, version, Me.m_current_path,
5317                                 "cleanup");
5318            }
5319
5320          fprintf (f, "\n");
5321
5322          CmtSystem::close_ostream (f, file_name);
5323          //          fclose (f);
5324
5325          cmt_string old_file_name = "cleanup";
5326          old_file_name += ".";
5327          old_file_name += suffix[i];
5328
5329          CmtSystem::compare_and_update_files (file_name, old_file_name);
5330        }
5331      else
5332        {
5333          CmtError::set (CmtError::file_access_error, file_name);
5334        }
5335    }
5336}
5337
5338//----------------------------------------------------------
5339void Cmt::install_setup_scripts ()
5340{
5341#ifdef WIN32
5342  static const int modes = 1;
5343  static const cmt_string suffix[1]   = {"bat"};
5344  static const PrintMode  mode[1]     = {Bat};
5345#else
5346  static const int modes = 2;
5347  static const cmt_string suffix[2]   = {"csh", "sh"};
5348  static const PrintMode  mode[2]     = {Csh, Sh};
5349#endif
5350
5351  Use& current_use = Use::current ();
5352
5353  if (!current_use.get_strategy ("SetupScripts"))
5354    {
5355      for (int i = 0; i < modes; i++)
5356        {
5357          cmt_string old_file_name = "setup";
5358          old_file_name += ".";
5359          old_file_name += suffix[i];
5360          if (CmtSystem::test_file (old_file_name))
5361            {
5362              if (CmtMessage::active (Error))
5363                cerr << "Removing setup script " + old_file_name << endl;
5364              CmtSystem::remove_file (old_file_name);
5365            }
5366        }
5367      return;
5368    }
5369
5370  if (CmtMessage::active (Error))
5371    cerr << "Creating setup scripts." << endl;
5372 
5373  cmt_string no_cleanup_opt;
5374
5375  if (current_use.get_strategy ("SetupCleanup"))
5376    {
5377      no_cleanup_opt = " -no_cleanup";
5378    }
5379
5380  cmt_string temp;
5381  int i;
5382
5383  cmt_string version = Me.m_current_version;
5384  if (version == "v*") version = "";
5385
5386  for (i = 0; i < modes; i++)
5387    {
5388      cmt_string file_name = "setup";
5389      file_name += ".";
5390      file_name += suffix[i];
5391      file_name += ".";
5392      file_name += "new";
5393
5394      FILE* f = fopen (file_name.c_str (), "wb");
5395      if (f != NULL)
5396        {
5397          if (mode[i] == Csh)
5398            {
5399              fprintf (f, "# echo \"Setting %s %s in %s\"\n",
5400                       Me.m_current_package.c_str (),
5401                       version.c_str (),
5402                       Me.m_current_path.c_str ());
5403              fprintf (f, "\n");
5404
5405              fprintf (f, "if ( $?CMTROOT == 0 ) then\n");
5406              fprintf (f, "  setenv CMTROOT %s\n", Me.m_cmt_root.c_str ());
5407              fprintf (f, "endif\n");
5408              fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
5409              fprintf (f, "\n");
5410              fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
5411              fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
5412              fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
5413                       "-pack=%s -version=%s -path=%s %s $* >${tempfile}\n",
5414                       suffix[i].c_str (),
5415                       Me.m_current_package.c_str (),
5416                       version.c_str (),
5417                       Me.m_current_path.c_str (),
5418                       no_cleanup_opt.c_str ());
5419              fprintf (f,
5420                       "if ( $status != 0 ) then\n"
5421                       "  echo \"${CMTROOT}/mgr/cmt setup -%s "
5422                       "-pack=%s -version=%s -path=%s %s $* >${tempfile}\"\n"
5423                       "  set cmtsetupstatus=2\n"
5424                       "  /bin/rm -f ${tempfile}\n"
5425                       "  exit $cmtsetupstatus\n"
5426                       "endif\n"
5427                       "set cmtsetupstatus=0\n"
5428                       "source ${tempfile}\n"
5429                       "if ( $status != 0 ) then\n"
5430                       "  set cmtsetupstatus=2\n"
5431                       "endif\n"
5432                       "/bin/rm -f ${tempfile}\n"
5433                       "exit $cmtsetupstatus\n",
5434                       suffix[i].c_str (),
5435                       Me.m_current_package.c_str (),
5436                       version.c_str (),
5437                       Me.m_current_path.c_str (),
5438                       no_cleanup_opt.c_str ());
5439            }
5440          else if (mode[i] == Sh)
5441            {
5442              fprintf (f, "# echo \"Setting %s %s in %s\"\n",
5443                       Me.m_current_package.c_str (),
5444                       version.c_str (),
5445                       Me.m_current_path.c_str ());
5446              fprintf (f, "\n");
5447
5448              fprintf (f, "if test \"${CMTROOT}\" = \"\"; then\n");
5449              fprintf (f, "  CMTROOT=%s; export CMTROOT\n", Me.m_cmt_root.c_str ());
5450              fprintf (f, "fi\n");
5451              fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
5452              fprintf (f, "\n");
5453              fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
5454              fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
5455              fprintf (f, "${CMTROOT}/mgr/cmt setup -%s "
5456                       "-pack=%s -version=%s -path=%s %s $* >${tempfile}\n",
5457                       suffix[i].c_str (),
5458                       Me.m_current_package.c_str (),
5459                       version.c_str (),
5460                       Me.m_current_path.c_str (),
5461                       no_cleanup_opt.c_str ());
5462              fprintf (f,
5463                       "if test $? != 0 ; then\n"
5464                       "  echo >&2 \"${CMTROOT}/mgr/cmt setup -%s "
5465                       "-pack=%s -version=%s -path=%s %s $* >${tempfile}\"\n"
5466                       "  cmtsetupstatus=2\n"
5467                       "  /bin/rm -f ${tempfile}\n"
5468                       "  return $cmtsetupstatus\n"
5469                       "fi\n"
5470                       "cmtsetupstatus=0\n"
5471                       ". ${tempfile}\n"
5472                       "if test $? != 0 ; then\n"
5473                       "  cmtsetupstatus=2\n"
5474                       "fi\n"
5475                       "/bin/rm -f ${tempfile}\n"
5476                       "return $cmtsetupstatus\n",
5477                       suffix[i].c_str (),
5478                       Me.m_current_package.c_str (),
5479                       version.c_str (),
5480                       Me.m_current_path.c_str (),
5481                       no_cleanup_opt.c_str ());
5482            }
5483          else if (mode[i] == Bat)
5484            {
5485              fprintf (f, "rem Setting %s %s in %%~d0%%~p0\n",
5486                       Me.m_current_package.c_str (),
5487                       version.c_str ());
5488              dos_script_prefix (f, Me.m_cmt_root, 
5489                                 Me.m_current_package, version, Me.m_current_path,
5490                                 "setup", no_cleanup_opt);
5491            }
5492
5493          fprintf (f, "\n");
5494
5495          CmtSystem::close_ostream (f, file_name);
5496          //          fclose (f);
5497
5498          cmt_string old_file_name = "setup";
5499          old_file_name += ".";
5500          old_file_name += suffix[i];
5501
5502          CmtSystem::compare_and_update_files (file_name, old_file_name);
5503        }
5504      else
5505        {
5506          CmtError::set (CmtError::file_access_error, file_name);
5507        }
5508    }
5509}
5510
5511//----------------------------------------------------------
5512void Cmt::install_test_cleanup_scripts ()
5513{
5514#ifdef WIN32
5515  static const int modes = 1;
5516  static const cmt_string suffix[1]   = {"bat"};
5517  static const PrintMode  mode[1]     = {Bat};
5518#else
5519  static const int modes = 2;
5520  static const cmt_string suffix[2]   = {"csh", "sh"};
5521  static const PrintMode  mode[2]     = {Csh, Sh};
5522#endif
5523
5524  Use& current_use = Use::current ();
5525
5526  if (!current_use.get_strategy ("SetupScripts"))
5527    {
5528      for (int i = 0; i < modes; i++)
5529        {
5530          cmt_string old_file_name = "cleanup";
5531          old_file_name += ".";
5532          old_file_name += suffix[i];
5533          if (CmtSystem::test_file (old_file_name))
5534            {
5535              if (CmtMessage::active (Error))
5536                cerr << "Removing cleanup script " + old_file_name << endl;
5537              CmtSystem::remove_file (old_file_name);
5538            }
5539        }
5540      return;
5541    }
5542
5543  if (CmtMessage::active (Error))
5544    cerr << "Creating cleanup scripts." << endl;
5545
5546  cmt_string temp;
5547  int i;
5548
5549  cmt_string version = Me.m_current_version;
5550  if (version == "v*") version = "";
5551
5552  for (i = 0; i < modes; i++)
5553    {
5554      cmt_string file_name = "cleanup";
5555      file_name += ".";
5556      file_name += suffix[i];
5557      file_name += ".";
5558      file_name += "new";
5559
5560      FILE* f = fopen (file_name.c_str (), "wb");
5561      if (f != NULL)
5562        {
5563          if (mode[i] == Csh)
5564            {
5565              fprintf (f, "if ( $?CMTROOT == 0 ) then\n");
5566              fprintf (f, "  setenv CMTROOT %s\n", Me.m_cmt_root.c_str ());
5567              fprintf (f, "endif\n");
5568              fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
5569              fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
5570              fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
5571              fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}\n",
5572                       suffix[i].c_str (),
5573                       Me.m_current_path.c_str ());
5574              fprintf (f,
5575                       "if ( $status != 0 ) then\n"
5576                       "  echo \"${CMTROOT}/mgr/cmt cleanup -%s "
5577                       "-pack=cmt_standalone -path=%s $* >${tempfile}\"\n"
5578                       "  set cmtcleanupstatus=2\n"
5579                       "  /bin/rm -f ${tempfile}\n"
5580                       "  exit $cmtcleanupstatus\n"
5581                       "endif\n"
5582                       "set cmtcleanupstatus=0\n"
5583                       "source ${tempfile}\n"
5584                       "if ( $status != 0 ) then\n"
5585                       "  set cmtcleanupstatus=2\n"
5586                       "endif\n"
5587                       "/bin/rm -f ${tempfile}\n"
5588                       "exit $cmtcleanupstatus\n",
5589                       suffix[i].c_str (),
5590                       Me.m_current_path.c_str ());
5591            }
5592          else if (mode[i] == Sh)
5593            {
5594              fprintf (f, "if test \"${CMTROOT}\" = \"\"; then\n");
5595              fprintf (f, "  CMTROOT=%s; export CMTROOT\n", Me.m_cmt_root.c_str ());
5596              fprintf (f, "fi\n");
5597              fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
5598              fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
5599              fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
5600              fprintf (f, "${CMTROOT}/mgr/cmt cleanup -%s -pack=cmt_standalone -path=%s $* >${tempfile}\n",
5601                       suffix[i].c_str (),
5602                       Me.m_current_path.c_str ());
5603              fprintf (f,
5604                       "if test $? != 0 ; then\n"
5605                       "  echo >&2 \"${CMTROOT}/mgr/cmt cleanup -%s "
5606                       "-pack=cmt_standalone -path=%s $* >${tempfile}\"\n"
5607                       "  cmtcleanupstatus=2\n"
5608                       "  /bin/rm -f ${tempfile}\n"
5609                       "  return $cmtcleanupstatus\n"
5610                       "fi\n"
5611                       "cmtcleanupstatus=0\n"
5612                       ". ${tempfile}\n"
5613                       "if test $? != 0 ; then\n"
5614                       "  cmtcleanupstatus=2\n"
5615                       "fi\n"
5616                       "/bin/rm -f ${tempfile}\n"
5617                       "return $cmtcleanupstatus\n",
5618                       suffix[i].c_str (),
5619                       Me.m_current_path.c_str ());
5620            }
5621          else
5622            {
5623              dos_script_prefix (f, Me.m_cmt_root, 
5624                                 "cmt_standalone", "", Me.m_current_path, 
5625                                 "cleanup");
5626            }
5627
5628          fprintf (f, "\n");
5629
5630          CmtSystem::close_ostream (f, file_name);
5631          //          fclose (f);
5632
5633          cmt_string old_file_name = "cleanup";
5634          old_file_name += ".";
5635          old_file_name += suffix[i];
5636
5637          CmtSystem::compare_and_update_files (file_name, old_file_name);
5638        }
5639      else
5640        {
5641          CmtError::set (CmtError::file_access_error, file_name);
5642        }
5643    }
5644}
5645
5646//----------------------------------------------------------
5647void Cmt::install_native_version_file ()
5648{   
5649  Use& current_use        = Use::current ();
5650  cmt_string package_name = current_use.get_package_name();
5651  cmt_string macro_name   = package_name + "_native_version";
5652  Symbol* macro           = Symbol::find (macro_name);
5653  if (macro != 0)
5654    {
5655      cmt_string value = macro->resolve_macro_value ();
5656      if (value != "")
5657        {
5658          if (CmtMessage::active (Info))
5659            cerr << "Creating native_version file." << endl;   
5660
5661          cmt_string file_name ("new.native_version.cmt");
5662          FILE* f = fopen (file_name.c_str (), "wb");
5663          if (f != NULL)
5664            {
5665              fprintf (f, "%s\n", value.c_str ());
5666              CmtSystem::close_ostream (f, file_name);
5667              //          fclose (f);
5668             
5669              CmtSystem::compare_and_update_files ("new.native_version.cmt", "native_version.cmt");
5670            }     
5671          else
5672            {
5673              CmtError::set (CmtError::file_access_error, file_name);
5674            }
5675        } 
5676    }   
5677}
5678//----------------------------------------------------------
5679void Cmt::install_test_setup_scripts ()
5680{
5681#ifdef WIN32
5682  static const int modes = 1;
5683  static const cmt_string suffix[1]   = {"bat"};
5684  static const PrintMode  mode[1]     = {Bat};
5685#else
5686  static const int modes = 2;
5687  static const cmt_string suffix[2]   = {"csh", "sh"};
5688  static const PrintMode  mode[2]     = {Csh, Sh};
5689#endif
5690
5691  Use& current_use = Use::current ();
5692
5693  if (!current_use.get_strategy ("SetupScripts"))
5694    {
5695      for (int i = 0; i < modes; i++)
5696        {
5697          cmt_string old_file_name = "setup";
5698          old_file_name += ".";
5699          old_file_name += suffix[i];
5700          if (CmtSystem::test_file (old_file_name))
5701            {
5702              if (CmtMessage::active (Error))
5703                cerr << "Removing setup script " + old_file_name << endl;
5704              CmtSystem::remove_file (old_file_name);
5705            }
5706        }
5707      return;
5708    }
5709
5710  if (CmtMessage::active (Error))
5711    cerr << "Creating setup scripts." << endl;
5712
5713  cmt_string no_cleanup_opt;
5714
5715  if (current_use.get_strategy ("SetupCleanup"))
5716    {
5717      no_cleanup_opt = " -no_cleanup";
5718    }
5719
5720  cmt_string temp;
5721  int i;
5722
5723  for (i = 0; i < modes; i++)
5724    {
5725      cmt_string file_name = "setup";
5726      file_name += ".";
5727      file_name += suffix[i];
5728      file_name += ".";
5729      file_name += "new";
5730
5731      FILE* f = fopen (file_name.c_str (), "wb");
5732      if (f != NULL)
5733        {
5734          if (mode[i] == Csh)
5735            {
5736              fprintf (f, "# echo \"Setting standalone package\"\n");
5737              fprintf (f, "\n");
5738
5739              fprintf (f, "if ( $?CMTROOT == 0 ) then\n");
5740              fprintf (f, "  setenv CMTROOT %s\n", Me.m_cmt_root.c_str ());
5741              fprintf (f, "endif\n");
5742              fprintf (f, "source ${CMTROOT}/mgr/setup.csh\n");
5743              fprintf (f, "set tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
5744              fprintf (f, "if $status != 0 then\n  set tempfile=/tmp/cmt.$$\nendif\n");
5745              fprintf (f, "${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}\n",
5746                       suffix[i].c_str (),
5747                       Me.m_current_path.c_str (),
5748                       no_cleanup_opt.c_str ());
5749              fprintf (f,
5750                       "if ( $status != 0 ) then\n"
5751                       "  echo \"${CMTROOT}/mgr/cmt setup -%s "
5752                       "-pack=cmt_standalone -path=%s %s $* >${tempfile}\"\n"
5753                       "  set cmtsetupstatus=2\n"
5754                       "  /bin/rm -f ${tempfile}\n"
5755                       "  exit $cmtsetupstatus\n"
5756                       "endif\n"
5757                       "set cmtsetupstatus=0\n"
5758                       "source ${tempfile}\n"
5759                       "if ( $status != 0 ) then\n"
5760                       "  set cmtsetupstatus=2\n"
5761                       "endif\n"
5762                       "/bin/rm -f ${tempfile}\n"
5763                       "exit $cmtsetupstatus\n",
5764                       suffix[i].c_str (),
5765                       Me.m_current_path.c_str (),
5766                       no_cleanup_opt.c_str ());
5767            }
5768          else if (mode[i] == Sh)
5769            {
5770              fprintf (f, "# echo \"Setting standalone package\"\n");
5771              fprintf (f, "\n");
5772
5773              fprintf (f, "if test \"${CMTROOT}\" = \"\"; then\n");
5774              fprintf (f, "  CMTROOT=%s; export CMTROOT\n", Me.m_cmt_root.c_str ());
5775              fprintf (f, "fi\n");
5776              fprintf (f, ". ${CMTROOT}/mgr/setup.sh\n");
5777              fprintf (f, "\n");
5778              fprintf (f, "tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`\n");
5779              fprintf (f, "if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi\n");
5780              fprintf (f, "${CMTROOT}/mgr/cmt setup -%s -pack=cmt_standalone -path=%s %s $* >${tempfile}\n",
5781                       suffix[i].c_str (),
5782                       Me.m_current_path.c_str (),
5783                       no_cleanup_opt.c_str ());
5784              fprintf (f,
5785                       "if test $? != 0 ; then\n"
5786                       "  echo >&2 \"${CMTROOT}/mgr/cmt setup -%s "
5787                       "-pack=cmt_standalone -path=%s %s $* >${tempfile}\"\n"
5788                       "  cmtsetupstatus=2\n"
5789                       "  /bin/rm -f ${tempfile}\n"
5790                       "  return $cmtsetupstatus\n"
5791                       "fi\n"
5792                       "cmtsetupstatus=0\n"
5793                       ". ${tempfile}\n"
5794                       "if test $? != 0 ; then\n"
5795                       "  cmtsetupstatus=2\n"
5796                       "fi\n"
5797                       "/bin/rm -f ${tempfile}\n"
5798                       "return $cmtsetupstatus\n",
5799                       suffix[i].c_str (),
5800                       Me.m_current_path.c_str (),
5801                       no_cleanup_opt.c_str ());
5802            }
5803          else
5804            {
5805              fprintf (f, "rem Setting standalone package\n");
5806              dos_script_prefix (f, Me.m_cmt_root, 
5807                                 "cmt_standalone", "", Me.m_current_path, 
5808                                 "setup", no_cleanup_opt);
5809            }
5810
5811          fprintf (f, "\n");
5812
5813          CmtSystem::close_ostream (f, file_name);
5814          //          fclose (f);
5815
5816          cmt_string old_file_name = "setup";
5817          old_file_name += ".";
5818          old_file_name += suffix[i];
5819
5820          CmtSystem::compare_and_update_files (file_name, old_file_name);
5821        }
5822      else
5823        {
5824          CmtError::set (CmtError::file_access_error, file_name);
5825        }
5826    }
5827}
5828
5829/**
5830 *    load is only called from the Windows GUI which pretends to access directly
5831 *   the internal data model.
5832 *    This is considered to be rather unsafe, and should be replaced by query functions.
5833 */
5834//bool Cmt::load (const cmt_string& path,
5835bool Cmt::load (const ArgParser& ap,
5836                const cmt_string& path,
5837                const cmt_string& package,
5838                const cmt_string& version,
5839                const cmt_string& tag_name)
5840{
5841  clear ();
5842  //  configure ();
5843  configure (ap);
5844
5845  Me.m_action  = action_load;
5846  Me.m_recursive = true;
5847
5848  if (((package != "") && (version != "")) || (Me.m_current_package == ""))
5849    {
5850      //
5851      //  Here we want to connect to a new package, or to the current package
5852      //  but with another tag.
5853      //
5854      //   the 'package' argument may include a directory offset. Thus 'path'
5855      //  is only expected to hold the base directory.
5856      //
5857      cmt_string offset;
5858      cmt_string package_name;
5859     
5860      CmtSystem::dirname (package, offset);
5861      CmtSystem::basename (package, package_name);
5862     
5863      if (offset != "")
5864        {
5865          Me.m_current_path = path;
5866          Me.m_current_path += CmtSystem::file_separator ();
5867          Me.m_current_path += offset;
5868        }
5869      else
5870        {
5871          Me.m_current_path = path;
5872        }
5873     
5874      Me.m_current_package = package_name;
5875      Me.m_current_version = version;
5876    }
5877
5878  if (tag_name != "")
5879    {
5880      Tag* tag;
5881
5882      Tag::unmark_all ();
5883      configure_version_tag ();
5884      configure_site_tag (0);
5885      configure_uname_tag ();
5886      configure_hosttype_tag ();
5887
5888      Me.m_current_tag = tag_name;
5889
5890      //if (!Me.m_quiet) cerr << "load1> current_tag=" << Me.m_current_tag << endl;
5891
5892      tag = Tag::add (tag_name, PriorityTag, "load", 0);
5893      tag->mark ();
5894    }
5895
5896  /*
5897    Set to developer mode if positioned into the package
5898    (which is detected since we were able to retreive the
5899    Version, Package and Path)
5900  */
5901
5902  if ((Me.m_current_path == "") ||
5903      (Me.m_current_package == "") ||
5904      (Me.m_current_version == ""))
5905    {
5906      Me.m_current_access = UserMode;
5907    }
5908  else
5909    {
5910      Me.m_current_access = DeveloperMode;
5911    }
5912
5913  use_cmt ();
5914
5915  cmt_string dir;
5916
5917  /*
5918    Try to access the package.
5919  */
5920
5921  if (Me.m_current_path != "")
5922    {
5923      dir = Me.m_current_path;
5924    }
5925  else
5926    {
5927      dir = Me.m_default_path;
5928    }
5929
5930  if (!CmtSystem::cd (Me.m_current_path))
5931    {
5932      CmtMessage::error ("Cannot reach the directory " + Me.m_current_path);
5933      /*
5934      if (!Me.m_quiet)
5935        {
5936          cerr << "#CMT> Cannot reach the directory " <<
5937            Me.m_current_path << endl;
5938        }
5939      */
5940      CmtError::set (CmtError::package_not_found, "Load> Cannot reach the path directory");
5941      CmtSystem::cd (Me.m_current_dir);
5942
5943      return (false);
5944    }
5945
5946  dir += CmtSystem::file_separator ();
5947  dir += Me.m_current_package;
5948
5949  if (!CmtSystem::cd (Me.m_current_package))
5950    {
5951      CmtMessage::error ("Cannot reach the package " + Me.m_current_package);
5952      /*
5953      if (!Me.m_quiet)
5954        {
5955          cerr << "#CMT::load> Cannot reach the package " <<
5956            Me.m_current_package << endl;
5957        }
5958      */
5959      CmtError::set (CmtError::package_not_found, "Load> Cannot reach the package directory");
5960      CmtSystem::cd (Me.m_current_dir);
5961
5962      return (false);
5963    }
5964
5965  dir += CmtSystem::file_separator ();
5966  dir += Me.m_current_version;
5967
5968  Me.m_current_style = none_style;
5969  Me.m_current_structuring_style = without_version_directory;
5970
5971  if (!CmtSystem::cd (Me.m_current_version))
5972    {
5973      if (!CmtSystem::test_directory ("cmt"))
5974        {
5975          CmtMessage::error ("Cannot reach the version " + Me.m_current_version);
5976          /*
5977          if (!Me.m_quiet)
5978            {
5979              cerr << "#CMT> Cannot reach the version " <<
5980                Me.m_current_version << endl;
5981            }
5982          */
5983          CmtError::set (CmtError::package_not_found, "Load> Cannot reach the version directory");
5984          CmtSystem::cd (Me.m_current_dir);
5985
5986          return (false);
5987        }
5988      else
5989        {
5990          Me.m_current_style = cmt_style;
5991          Me.m_current_structuring_style = without_version_directory;
5992          //          Me.m_current_style = no_version_style;
5993        }
5994    }
5995
5996  if (CmtSystem::cd ("cmt"))
5997    {
5998      dir += CmtSystem::file_separator ();
5999      dir += "cmt";
6000      if (Me.m_current_style == none_style)
6001        {
6002          Me.m_current_style = cmt_style;
6003          Me.m_current_structuring_style = with_version_directory;
6004        }
6005    }
6006  else
6007    {
6008      /*
6009        if (!Me.m_quiet)
6010        {
6011        cerr << "Cannot reach the cmt branch" << endl;
6012        }
6013      */
6014
6015      if (CmtSystem::cd ("mgr"))
6016        {
6017          dir += CmtSystem::file_separator ();
6018          dir += "mgr";
6019          if (Me.m_current_style == none_style)
6020            {
6021              Me.m_current_style = mgr_style;
6022              Me.m_current_structuring_style = with_version_directory;
6023            }
6024        }
6025      else
6026        {
6027          CmtMessage::error ("Cannot reach the mgr branch");
6028          /*
6029          if (!Me.m_quiet)
6030            {
6031              cerr << "#CMT> Cannot reach the mgr branch" << endl;
6032            }
6033          */
6034
6035          CmtError::set (CmtError::package_not_found,
6036                         "Load> Cannot reach the mgr/cmt directory");
6037          CmtSystem::cd (Me.m_current_dir);
6038
6039          return (false);
6040        }
6041    }
6042
6043  /*
6044    Check Tag is always set up
6045  */
6046
6047  if (Me.m_current_tag == "")
6048    {
6049      char* env;
6050
6051      env = getenv (Me.m_current_config.c_str ());
6052      if (env != 0)
6053        {
6054          Tag* tag;
6055
6056          tag = Tag::add (env, PriorityConfig, "load", 0);
6057          tag->mark ();
6058          Me.m_current_tag = env;
6059
6060          //if (!Me.m_quiet) cerr << "load2> current_tag=" << Me.m_current_tag << endl;
6061
6062        }
6063      else
6064        {
6065          Me.m_current_tag = Me.m_cmt_config;
6066
6067          //if (!Me.m_quiet) cerr << "load3> current_tag=" << Me.m_current_tag << endl;
6068
6069        }
6070    }
6071
6072  if (Me.m_debug)
6073    {
6074      cout << "pwd = " << CmtSystem::pwd () << endl;
6075    }
6076
6077  configure_current_dir ();
6078  build_prefix (Me.m_current_package, Me.m_current_prefix);
6079  build_config (Me.m_current_prefix, Me.m_current_config);
6080
6081  Use* use = &(Use::current());
6082  use->path    = Me.m_current_path;
6083  use->set_package_name (Me.m_current_package);
6084  use->version = Me.m_current_version;
6085  use->prefix  = Me.m_current_prefix;
6086  use->done    = false;
6087  use->style   = Me.m_current_style;
6088  use->structuring_style  = Me.m_current_structuring_style;
6089
6090  /*
6091    Work on the requirements file.
6092  */
6093
6094  dir += CmtSystem::file_separator ();
6095  dir += "requirements";
6096  SyntaxParser::parse_requirements (dir, use);
6097
6098  if (CmtError::has_pending_error ()) return (false);
6099
6100  /**
6101   * See reach_current_package for an explanation of this call
6102   */
6103  Pattern::apply_all_globals ();
6104
6105  /*
6106    Select all possible tags
6107  */
6108
6109  Tag::restore_tree ();
6110
6111  return (true);
6112}
6113
6114//----------------------------------------------------------
6115bool Cmt::need_prototypes ()
6116{
6117  Use& current_use = Use::current ();
6118
6119  if (current_use.get_strategy ("BuildPrototypes")) return (true);
6120  else return (false);
6121}
6122
6123//----------------------------------------------------------
6124void Cmt::parse_arguments (ArgParser& ap)
6125{
6126  /*
6127    Decoding arguments.
6128
6129    While decoding all arguments, no requirements analysis should
6130    occur. Every new option, or parameter should be saved and
6131    used later at actual analysis time.
6132  */
6133
6134  Me.m_action = action_none;
6135
6136  restore_all_tags (0);
6137
6138#ifdef WIN32
6139  Me.m_build_nmake = true;
6140#endif
6141
6142  ap.parse ();
6143}
6144
6145//----------------------------------------------------------
6146int Cmt::parser (const cmt_string& command_line)
6147{
6148  CmtSystem::cmt_string_vector v;
6149
6150  CmtSystem::split (command_line, " \t", v);
6151
6152  int argc = v.size ();
6153
6154  char** argv = (char**) malloc ((argc + 1) * sizeof (char*));
6155
6156  int i;
6157  for (i = 0; i < argc; i++)
6158    {
6159      argv[i] = (char*) v[i].c_str ();
6160    }
6161  argv[argc] = 0;
6162
6163  int status = parser (argc, argv);
6164
6165  free (argv);
6166
6167  return (status);
6168}
6169
6170//----------------------------------------------------------
6171int Cmt::parser (int argc, char* argv[])
6172{
6173  ArgParser ap (Me);
6174 
6175  ap.argc = argc;
6176  ap.argv = argv;
6177
6178  if (argc <= 1)
6179    {
6180      do_help (ap);
6181      return 2;
6182      //      exit (0);
6183    }
6184
6185  // save CMTFLAGS
6186  cmt_string cmtflags (get_cmt_flags ());
6187
6188  clear ();
6189
6190  //  configure ();
6191  configure (ap);
6192
6193  CmtError::clear ();
6194
6195  /*
6196    Set private if positioned inside the package
6197    (which is detected since we were able to retreive the
6198    Version, Package and Path)
6199  */
6200
6201  if ((Me.m_current_path.size () == 0) ||
6202      (Me.m_current_package.size () == 0) ||
6203      (Me.m_current_version.size () == 0))
6204    {
6205      Me.m_current_access = UserMode;
6206    }
6207  else
6208    {
6209      Me.m_current_access = DeveloperMode;
6210    }
6211 
6212  parse_arguments (ap);
6213 
6214  if (Me.m_debug)
6215    {
6216      cout << "After parse_argument> pack=" << Me.m_current_package
6217           << " Me.m_current_tag=" << Me.m_current_tag
6218           << " cwd=" << CmtSystem::pwd () 
6219           << " mode=" << Me.m_current_access
6220           << endl;
6221    }
6222
6223  if (Me.m_configure_error != "")
6224    {
6225      CmtMessage::error (Me.m_configure_error);
6226      //      if (!Me.m_quiet) cerr << "#CMT> Error: " << Me.m_configure_error << endl;
6227      return (CmtError::execution_error);
6228    }
6229
6230  if (CmtError::has_pending_error ())
6231    {
6232      int code = CmtError::get_last_error_code ();
6233      CmtError::print ();
6234      //      if (!Me.m_quiet) CmtError::print ();
6235      clear ();
6236
6237      return (code);
6238    }
6239
6240  /*
6241    Now actual requirements analysis can take place.
6242
6243    Extra lines or files are analysed first.
6244  */
6245
6246  if (strlen (ap.extra_file.c_str ()) > 0) SyntaxParser::parse_requirements (ap.extra_file, (Use*) 0);
6247  if (strlen (ap.extra_line.c_str ()) > 0) SyntaxParser::parse_requirements_line (ap.extra_line, (Use*) 0);
6248
6249  //
6250  //  For some of the actions, the CMT package must be automatically
6251  //  included
6252  //
6253
6254  if (Me.m_debug) cout << "parser1> current_tag=" << Me.m_current_tag << endl;
6255
6256  if (ap.help_action == action_help)
6257    {
6258      do_help (ap);
6259      int code (0);
6260      if (CmtError::has_pending_error ())
6261        {
6262          code = CmtError::get_last_error_code ();
6263          CmtError::print ();
6264        }
6265      return code;
6266      //return (0);
6267    }
6268
6269  switch (Me.m_action)
6270    {
6271      // case action_none :
6272    case action_awk :
6273    case action_broadcast :
6274    case action_build_constituent_makefile :
6275    case action_build_constituent_config :
6276    case action_build_constituents_makefile :
6277    case action_build_constituents_config :
6278    case action_build_dependencies :
6279    case action_build_library_links :
6280    case action_build_make_setup :
6281    case action_build_msdev :
6282    case action_build_CMT_pacman :
6283    case action_build_vsnet :     
6284    case action_build_os9_makefile :
6285      // case action_build_prototype :
6286    case action_build_readme :
6287    case action_build_tag_makefile :
6288      // case action_build_temporary_name :
6289    case action_build_triggers :
6290    case action_build_windefs :
6291    case action_check_configuration :
6292      // case action_check_files :
6293      // case action_check_version :
6294    case action_checkout :
6295    case action_cleanup :
6296    case action_config :
6297    case action_create :
6298      // case action_create_project :
6299    case action_cvsbranches :
6300    case action_cvssubpackages :
6301    case action_cvssubprojects :
6302    case action_cvstags :
6303    case action_do :
6304    case action_expand_model :
6305    case action_filter :
6306      // case action_help :
6307    case action_load :
6308    case action_lock :
6309    case action_relocate:
6310    case action_remove :
6311    case action_remove_library_links :
6312    case action_run :
6313    case action_run_sequence :
6314    case action_set_version :
6315    case action_set_versions :
6316    case action_setup :
6317    case action_show_action :
6318    case action_show_action_names :
6319    case action_show_action_value :
6320    case action_show_actions :
6321    case action_show_all_tags :
6322    case action_show_applied_patterns :
6323      // case action_show_author :
6324      // case action_show_branches :
6325      // case action_show_clients :
6326    case action_show_cmtpath_patterns :
6327    case action_show_constituent :
6328    case action_show_constituent_names :
6329    case action_show_constituents :
6330    case action_show_container :
6331    case action_show_cycles :
6332    case action_show_fragment :
6333    case action_show_fragments :
6334    case action_show_groups :
6335    case action_show_include_dirs :
6336    case action_show_language :
6337    case action_show_languages :
6338    case action_show_macro :
6339    case action_show_macro_names :
6340    case action_show_macro_value :
6341    case action_show_macros :
6342      // case action_show_manager :
6343    case action_show_packages :
6344    case action_show_path :
6345    case action_show_pattern :
6346    case action_show_pattern_names :
6347    case action_show_patterns :
6348    case action_show_projects :
6349      // case action_show_pwd :
6350    case action_show_setup :
6351    case action_show_set :
6352    case action_show_set_names :
6353    case action_show_set_value :
6354    case action_show_sets :
6355    case action_show_strategies :
6356    case action_show_tags :
6357    case action_show_use_paths :
6358    case action_show_uses :
6359    case action_show_version :
6360      // case action_show_versions :
6361      // case action_system :
6362    case action_unlock :
6363    case action_version :
6364      use_cmt ();
6365      //
6366      // Now parse the requirements file stored in ${CMTHOME}
6367      //
6368     
6369      use_home_requirements ();
6370
6371      configure_devenv_tag ();
6372
6373      break;
6374    default:
6375      break;
6376    }
6377
6378  if (Me.m_debug) cout << "parser2> current_tag=" << Me.m_current_tag << endl;
6379
6380  //
6381  // Setting up recursive actions
6382  //
6383
6384  switch (Me.m_action)
6385    {
6386      // case action_none :
6387    case action_awk :
6388    case action_broadcast :
6389    case action_build_constituent_makefile :
6390    case action_build_constituent_config :
6391    case action_build_constituents_makefile :
6392    case action_build_constituents_config :
6393    case action_build_dependencies :
6394    case action_build_library_links :
6395    case action_build_make_setup :
6396    case action_build_msdev :
6397    case action_build_CMT_pacman :
6398    case action_build_vsnet :     
6399    case action_build_os9_makefile :
6400      // case action_build_prototype :
6401    case action_build_readme :
6402    case action_build_tag_makefile :
6403      // case action_build_temporary_name :
6404    case action_build_triggers :
6405    case action_build_windefs :
6406    case action_check_configuration :
6407      // case action_check_files :
6408      // case action_check_version :
6409      // case action_checkout :
6410    case action_cleanup :
6411    case action_config :
6412      // case action_create :
6413      // case action_create_project :
6414      // case action_cvsbranches :
6415      // case action_cvssubpackages :
6416      // case action_cvssubprojects :
6417      // case action_cvstags :
6418    case action_do :
6419    case action_expand_model :
6420    case action_filter :
6421      // case action_help :
6422    case action_load :
6423      // case action_lock :
6424      // case action_remove :
6425    case action_relocate:
6426    case action_remove_library_links :
6427    case action_run :
6428    case action_run_sequence :
6429      // case action_set_version :
6430    case action_set_versions :
6431    case action_setup :
6432    case action_show_action :
6433    case action_show_action_names :
6434    case action_show_action_value :
6435    case action_show_actions :
6436    case action_show_all_tags :
6437    case action_show_applied_patterns :
6438      // case action_show_author :
6439      // case action_show_branches :
6440      // case action_show_clients :
6441    case action_show_cmtpath_patterns :
6442    case action_show_constituent :
6443    case action_show_constituent_names :
6444    case action_show_constituents :
6445    case action_show_container :
6446    case action_show_cycles :
6447    case action_show_fragment :
6448    case action_show_fragments :
6449    case action_show_groups :
6450    case action_show_include_dirs :
6451    case action_show_language :
6452    case action_show_languages :
6453    case action_show_macro :
6454    case action_show_macro_names :
6455    case action_show_macro_value :
6456    case action_show_macros :
6457      // case action_show_manager :
6458    case action_show_packages :
6459    case action_show_path :
6460    case action_show_pattern :
6461    case action_show_pattern_names :
6462    case action_show_patterns :
6463    case action_show_projects :
6464      // case action_show_pwd :
6465    case action_show_setup :
6466    case action_show_set :
6467    case action_show_set_names :
6468    case action_show_set_value :
6469    case action_show_sets :
6470    case action_show_strategies :
6471    case action_show_tags :
6472    case action_show_use_paths :
6473    case action_show_uses :
6474      // case action_show_version :
6475      // case action_show_versions :
6476      // case action_system :
6477      // case action_unlock :
6478      // case action_version :
6479      Me.m_recursive = true;
6480      break;
6481    default:
6482      Me.m_recursive = false;
6483      break;
6484    }
6485
6486  //
6487  //  Actions for which the context of the package is checked,
6488  //  and the requirements file is analysed.
6489  //
6490
6491  switch (Me.m_action)
6492    {
6493    case action_none :
6494    case action_awk :
6495    case action_broadcast :
6496    case action_build_constituent_makefile :
6497    case action_build_constituent_config :
6498    case action_build_constituents_makefile :
6499    case action_build_constituents_config :
6500    case action_build_dependencies :
6501    case action_build_library_links :
6502    case action_build_make_setup :
6503    case action_build_msdev :
6504    case action_build_CMT_pacman :
6505    case action_build_vsnet :     
6506    case action_build_os9_makefile :
6507      // case action_build_prototype :
6508    case action_build_readme :
6509    case action_build_tag_makefile :
6510      // case action_build_temporary_name :
6511    case action_build_triggers :
6512    case action_build_windefs :
6513    case action_check_configuration :
6514      // case action_check_files :
6515      // case action_check_version :
6516      // case action_checkout :
6517    case action_cleanup :
6518    case action_config :
6519      // case action_create :
6520      // case action_create_project :
6521      // case action_cvsbranches :
6522      // case action_cvssubpackages :
6523      // case action_cvssubprojects :
6524      // case action_cvstags :
6525    case action_do :
6526    case action_expand_model :
6527    case action_filter :
6528      // case action_help :
6529    case action_load :
6530    case action_lock :
6531      // case action_remove :
6532    case action_relocate :
6533    case action_remove_library_links :
6534    case action_run :
6535      // case action_run_sequence :
6536      // case action_set_version :
6537    case action_set_versions :
6538    case action_setup :
6539    case action_show_action :
6540    case action_show_action_names :
6541    case action_show_action_value :
6542    case action_show_actions :
6543    case action_show_all_tags :
6544    case action_show_applied_patterns :
6545    case action_show_author :
6546    case action_show_branches :
6547      // case action_show_clients :
6548    case action_show_cmtpath_patterns :
6549    case action_show_constituent :
6550    case action_show_constituent_names :
6551    case action_show_constituents :
6552    case action_show_container :
6553    case action_show_cycles :
6554    case action_show_fragment :
6555    case action_show_fragments :
6556    case action_show_groups :
6557    case action_show_include_dirs :
6558    case action_show_language :
6559    case action_show_languages :
6560    case action_show_macro :
6561    case action_show_macro_names :
6562    case action_show_macro_value :
6563    case action_show_macros :
6564    case action_show_manager :
6565    case action_show_packages :
6566    case action_show_path :
6567    case action_show_pattern :
6568    case action_show_pattern_names :
6569    case action_show_patterns :
6570    case action_show_projects :
6571    case action_show_project_author :
6572    case action_show_pwd :
6573    case action_show_setup :
6574    case action_show_set :
6575    case action_show_set_names :
6576    case action_show_set_value :
6577    case action_show_sets :
6578    case action_show_strategies :
6579    case action_show_tags :
6580    case action_show_use_paths :
6581    case action_show_uses :
6582    case action_show_version :
6583      // case action_show_versions :
6584      // case action_system :
6585    case action_unlock :
6586      // case action_version :
6587      {
6588        bool w = Me.m_warnings;
6589        Me.m_warnings = false;
6590        reach_current_package ();
6591        use_user_context_requirements ();
6592        Me.m_warnings = w;
6593      }
6594      break;
6595    default:
6596      break;
6597    }
6598
6599  if (Me.m_debug) cout << "parser3> current_tag=" << Me.m_current_tag << endl;
6600
6601  //
6602  // Perform some actions even if there is an error
6603  //
6604
6605  if (CmtError::has_pending_error ())
6606    {
6607      int code = CmtError::get_last_error_code ();
6608      if (!Me.m_quiet) CmtError::print ();
6609
6610      switch (Me.m_action)
6611        {
6612          // case action_none :
6613          // case action_awk :
6614          // case action_broadcast :
6615        case action_build_constituent_makefile :
6616        case action_build_constituent_config :
6617        case action_build_constituents_makefile :
6618        case action_build_constituents_config :
6619        case action_build_dependencies :
6620        case action_build_library_links :
6621        case action_build_make_setup :
6622        case action_build_msdev :
6623        case action_build_CMT_pacman :
6624        case action_build_vsnet :     
6625        case action_build_os9_makefile :
6626        case action_build_prototype :
6627        case action_build_readme :
6628        case action_build_tag_makefile :
6629          // case action_build_temporary_name :
6630        case action_build_triggers :
6631        case action_build_windefs :
6632        case action_check_configuration :
6633          // case action_check_files :
6634          // case action_check_version :
6635          // case action_checkout :
6636        case action_cleanup :
6637          // case action_config :
6638          // case action_create :
6639          // case action_create_project :
6640          // case action_cvsbranches :
6641          // case action_cvssubpackages :
6642          // case action_cvssubprojects :
6643          // case action_cvstags :
6644          // case action_do :
6645          // case action_expand_model :
6646          // case action_filter :
6647          // case action_help :
6648        case action_load :
6649        case action_lock :
6650        case action_relocate :
6651        case action_remove :
6652        case action_remove_library_links :
6653          // case action_run :
6654        case action_run_sequence :
6655          // case action_set_version :
6656          // case action_set_versions :
6657        case action_setup :
6658          // case action_show_action :
6659          // case action_show_action_names :
6660          // case action_show_action_value :
6661          // case action_show_actions :
6662          // case action_show_all_tags :
6663          // case action_show_applied_patterns :
6664          // case action_show_author :
6665          // case action_show_branches :
6666          // case action_show_clients :
6667          // case action_show_cmtpath_patterns :
6668          // case action_show_constituent :
6669          // case action_show_container :
6670          // case action_show_constituent_names :
6671          // case action_show_constituents :
6672          // case action_show_cycles :
6673          // case action_show_fragment :
6674          // case action_show_fragments :
6675          // case action_show_groups :
6676          // case action_show_include_dirs :
6677          // case action_show_language :
6678          // case action_show_languages :
6679          // case action_show_macro :
6680          // case action_show_macro_names :
6681          // case action_show_macro_value :
6682          // case action_show_macros :
6683          // case action_show_manager :
6684          // case action_show_packages :
6685          // case action_show_path :
6686          // case action_show_pattern :
6687          // case action_show_pattern_names :
6688          // case action_show_patterns :
6689          // case action_show_projects :
6690          // case action_show_pwd :
6691          // case action_show_setup :
6692          // case action_show_set :
6693          // case action_show_set_names :
6694          // case action_show_set_value :
6695          // case action_show_sets :
6696          // case action_show_strategies :
6697          // case action_show_tags :
6698          // case action_show_use_paths :
6699          // case action_show_uses :
6700          // case action_show_version :
6701          // case action_show_versions :
6702          // case action_system :
6703        case action_unlock :
6704          // case action_version :
6705          clear ();
6706          return (code);
6707        default:
6708          CmtError::clear ();
6709          break;
6710        }
6711    }
6712
6713  //
6714  // Perform actions
6715  //
6716
6717  if (!Me.m_simulation)
6718    {
6719      switch (Me.m_action)
6720        {
6721        case action_none :
6722          //CmtError::set (CmtError::syntax_error, "ParseArguments> ");
6723          break;
6724        case action_awk :
6725          do_awk (ap);
6726          break;
6727        case action_broadcast :
6728          do_broadcast (ap);
6729          break;
6730        case action_build_constituent_makefile :
6731          do_build_constituent_makefile (ap);
6732          break;
6733        case action_build_constituent_config :
6734          do_build_constituent_config (ap);
6735          break;
6736        case action_build_constituents_makefile :
6737          do_build_constituents_makefile (ap);
6738          break;
6739        case action_build_constituents_config :
6740          do_build_constituents_config (ap);
6741          break;
6742        case action_build_dependencies :
6743          do_build_dependencies (ap, argc, argv);
6744          break;
6745        case action_build_library_links :
6746          do_build_library_links (ap);
6747          break;
6748        case action_build_make_setup :
6749          do_build_make_setup (ap);
6750          break;
6751        case action_build_msdev :
6752          do_build_msdev (ap);
6753          break;
6754        case action_build_CMT_pacman :
6755          do_build_CMT_pacman (ap);
6756          break;
6757        case action_build_vsnet :     
6758          do_build_vsnet (ap);
6759          break;
6760        case action_build_os9_makefile :
6761          do_build_os9_makefile (ap);
6762          break;
6763        case action_build_prototype :
6764          do_build_prototype (ap);
6765          break;
6766        case action_build_readme :
6767          do_build_readme (ap);
6768          break;
6769        case action_build_tag_makefile :
6770          do_build_tag_makefile (ap);
6771          break;
6772        case action_build_temporary_name :
6773          do_build_temporary_name (ap);
6774          break;
6775        case action_build_triggers :
6776          do_build_triggers (ap);
6777          break;
6778        case action_build_windefs :
6779          do_build_windefs (ap);
6780          break;
6781        case action_check_configuration :
6782          do_check_configuration (ap);
6783          break;
6784        case action_check_files :
6785          do_check_files (ap);
6786          break;
6787        case action_check_version :
6788          do_check_version (ap);
6789          break;
6790        case action_checkout :
6791          do_checkout (ap);
6792          break;
6793        case action_cleanup :
6794          do_cleanup (ap);
6795          break;
6796        case action_config :
6797          do_config (ap);
6798          break;
6799        case action_create :
6800          do_create (ap);
6801          break;
6802        case action_create_project :
6803          do_create_project (ap);
6804          break;
6805        case action_cvsbranches :
6806          do_cvsbranches (ap);
6807          break;
6808        case action_cvssubpackages :
6809          do_cvssubpackages (ap);
6810          break;
6811        case action_cvssubprojects :
6812          do_cvssubprojects (ap);
6813          break;
6814        case action_cvstags :
6815          do_cvstags (ap);
6816          break;
6817        case action_do :
6818          do_do (ap);
6819          break;
6820        case action_expand_model :
6821          do_expand_model (ap);
6822          break;
6823        case action_filter :
6824          do_filter (ap);
6825          break;
6826        case action_help :
6827          do_help (ap);
6828          break;
6829        case action_load :
6830          CmtMessage::error ("action not implemented");
6831          //      cerr << "#CMT> action not implemented" << endl;
6832          break;
6833        case action_lock :
6834          do_lock (ap);
6835          break;
6836        case action_relocate :
6837          do_relocate (ap);
6838          break;
6839        case action_remove :
6840          do_remove (ap);
6841          break;
6842        case action_remove_library_links :
6843          do_remove_library_links (ap);
6844          break;
6845        case action_run :
6846          do_run (ap);
6847          break;
6848        case action_run_sequence :
6849          do_run_sequence (ap);
6850          break;
6851        case action_set_version :
6852          do_set_version (ap);
6853          break;
6854        case action_set_versions :
6855          do_set_versions (ap);
6856          break;
6857        case action_setup :
6858          do_setup (ap);
6859          break;
6860        case action_show_action :
6861          do_show_action (ap);
6862          break;
6863        case action_show_action_names :
6864          do_show_action_names (ap);
6865          break;
6866        case action_show_action_value :
6867          do_show_action_value (ap);
6868          break;
6869        case action_show_actions :
6870          do_show_actions (ap);
6871          break;
6872        case action_show_all_tags :
6873          do_show_all_tags (ap);
6874          break;
6875        case action_show_applied_patterns :
6876          do_show_applied_patterns (ap);
6877          break;
6878        case action_show_author :
6879          do_show_author (ap);
6880          break;
6881        case action_show_branches :
6882          do_show_branches (ap);
6883          break;
6884        case action_show_container :
6885          do_show_container (ap);
6886          break;
6887        case action_show_clients :
6888          do_show_clients (ap);
6889          break;
6890        case action_show_cmtpath_patterns :
6891          do_show_cmtpath_patterns (ap);
6892          break;
6893        case action_show_constituent :
6894          do_show_constituent (ap);
6895          break;
6896        case action_show_constituent_names :
6897          do_show_constituent_names (ap);
6898          break;
6899        case action_show_constituents :
6900          do_show_constituents (ap);
6901          break;
6902        case action_show_cycles :
6903          do_show_cycles (ap);
6904          break;
6905        case action_show_fragment :
6906          do_show_fragment (ap);
6907          break;
6908        case action_show_fragments :
6909          do_show_fragments (ap);
6910          break;
6911        case action_show_groups :
6912          do_show_groups (ap);
6913          break;
6914        case action_show_include_dirs :
6915          do_show_include_dirs (ap);
6916          break;
6917        case action_show_language :
6918          do_show_language (ap);
6919          break;
6920        case action_show_languages :
6921          do_show_languages (ap);
6922          break;
6923        case action_show_macro :
6924          do_show_macro (ap);
6925          break;
6926        case action_show_macro_names :
6927          do_show_macro_names (ap);
6928          break;
6929        case action_show_macro_value :
6930          do_show_macro_value (ap);
6931          break;
6932        case action_show_macros :
6933          do_show_macros (ap);
6934          break;
6935        case action_show_manager :
6936          do_show_manager (ap);
6937          break;
6938        case action_show_packages :
6939          do_show_packages (ap);
6940          break;
6941        case action_show_path :
6942          do_show_path (ap);
6943          break;
6944        case action_show_pattern :
6945          do_show_pattern (ap);
6946          break;
6947        case action_show_pattern_names :
6948          do_show_pattern_names (ap);
6949          break;
6950        case action_show_patterns :
6951          do_show_patterns (ap);
6952          break;
6953        case action_show_projects :
6954          do_show_projects (ap);
6955          break;
6956        case action_show_project_author :
6957          do_show_project_author (ap);
6958          break;
6959        case action_show_pwd :
6960          do_show_pwd (ap);
6961          break;
6962        case action_show_setup :
6963          do_show_setup (ap);
6964          break;
6965        case action_show_set :
6966          do_show_set (ap);
6967          break;
6968        case action_show_set_names :
6969          do_show_set_names (ap);
6970          break;
6971        case action_show_set_value :
6972          do_show_set_value (ap);
6973          break;
6974        case action_show_sets :
6975          do_show_sets (ap);
6976          break;
6977        case action_show_strategies :
6978          do_show_strategies (ap);
6979          break;
6980        case action_show_tags :
6981          do_show_tags (ap);
6982          break;
6983        case action_show_use_paths :
6984          do_show_use_paths (ap);
6985          break;
6986        case action_show_uses :
6987          do_show_uses (ap);
6988          break;
6989        case action_show_version :
6990          do_show_version (ap);
6991          break;
6992        case action_show_versions :
6993          do_show_versions (ap);
6994          break;
6995        case action_system :
6996          do_show_system (ap);
6997          break;
6998        case action_unlock :
6999          do_unlock (ap);
7000          break;
7001        case action_version :
7002          do_version (ap);
7003          break;
7004        default:
7005          CmtError::set (CmtError::syntax_error, "ParseArguments>");
7006          break;
7007        }
7008    }
7009
7010  // restore CMTFLAGS
7011  set_cmt_flags (cmtflags);
7012
7013  if (CmtError::has_pending_error ())
7014    {
7015      int code = CmtError::get_last_error_code ();     
7016      if (code == CmtError::execution_failed)
7017        {
7018          code = CmtError::get_last_execution_error();
7019        }   
7020     
7021      CmtError::print ();
7022      //      if (!Me.m_quiet) CmtError::print ();
7023      clear ();
7024      return (code);
7025    }
7026  else
7027    {
7028      clear ();
7029      return (0);
7030    }
7031}
7032
7033
7034/**
7035 * Format as one single line a set of 'setenv' statements
7036 * joined with semi-colons to form one shell command.
7037 */
7038void Cmt::print (PrintMode mode)
7039{
7040  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
7041  Use& current_use = Use::current ();
7042
7043  cmt_string tag;
7044
7045  set_standard_macros ();
7046
7047  //cerr << "# current_tag=" << Me.m_current_tag << endl;
7048  //cerr << "# current_config=" << Me.m_current_config << endl;
7049
7050  if (Me.m_current_tag == "")
7051    {
7052      if (mode == Bat) tag = "%CMTCONFIG%";
7053      else tag = "${CMTCONFIG}";
7054    }
7055  else
7056    {
7057      tag = Me.m_current_tag;
7058    }
7059
7060  //
7061  //  Now check if all extra tags are still valid. Some of them
7062  //  may be discarded du to some conflict with highest priority
7063  //  tags, or with exclude statements
7064  //
7065
7066  {
7067    CmtSystem::cmt_string_vector words;
7068     
7069    cmt_string tags;
7070
7071    tags = Me.m_extra_tags;
7072     
7073    CmtSystem::split (tags, " \t,", words);
7074
7075    Me.m_extra_tags = ",";
7076     
7077    for (int i = 0; i < words.size (); i++)
7078      {
7079        Tag* tag;
7080        const cmt_string& a = words[i];
7081
7082        tag = Tag::find (a);
7083
7084        if ((tag != 0) && (tag->is_selected ()))
7085          {
7086            Me.m_extra_tags += a;
7087            Me.m_extra_tags += ",";
7088          }
7089      }
7090  }
7091
7092  if (mode == Requirements)
7093    {
7094      //do_show_tags (ap, cout);
7095      Tag::TagPtrVector tags = Tag::tags ();
7096      for (int index = 0; index < tags.size (); index++)
7097        {
7098          const Tag* tag = tags[index];
7099          if (tag != 0)
7100            {
7101              tag->show (true, cout, "apply_tag ");
7102            }
7103        }
7104    }
7105
7106  if (Me.m_debug)
7107    {
7108      cout << "Before all print contexts" << endl;
7109    }
7110
7111  if (Uses.size () > 0)
7112    {
7113      int number;
7114
7115      for (number = 0; number < Uses.size (); number++)
7116        {
7117          Use& use = *(Uses[number]);
7118
7119          if (use.discarded) continue;
7120          if (use.m_hidden) continue;
7121         
7122          print_context (use, mode, tag);
7123        }
7124    }
7125
7126  print_context (Use::current (), mode, tag);
7127
7128  if (Me.m_debug)
7129    {
7130      cout << "After all print contexts" << endl;
7131    }
7132
7133  Symbol::all_print (mode);
7134  // Script::all_print (mode);
7135
7136  if (Me.m_debug)
7137    {
7138      cout << "After all print" << endl;
7139    }
7140
7141  switch (mode)
7142    {
7143    case Xml :
7144      break;
7145    default :
7146  cout << endl;
7147      break;
7148    }
7149}
7150
7151
7152/**
7153 * Format as one single line a set of 'unsetenv' statements
7154 * joined with semi-colons to form one shell command.
7155 */
7156void Cmt::print_clean (PrintMode mode)
7157{
7158  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
7159
7160  set_standard_macros ();
7161
7162  Script::all_print_clean (mode);
7163  Symbol::all_print_clean (mode);
7164
7165  switch (mode)
7166    {
7167    case Csh :
7168      if (Me.m_current_package != "CMT")
7169        {
7170          cout << "unsetenv " << Me.m_current_prefix << "ROOT" << endl;
7171          cout << "unsetenv " << Me.m_current_prefix << "CONFIG" << endl;
7172        }
7173      break;
7174    case Sh :
7175      if (Me.m_current_package != "CMT")
7176        {
7177          cout << "unset " << Me.m_current_prefix << "ROOT" << endl;
7178          cout << "unset " << Me.m_current_prefix << "CONFIG" << endl;
7179        }
7180      break;
7181    case Bat :
7182      if (Me.m_current_package != "CMT")
7183        {
7184          cout << "set " << Me.m_current_prefix << "ROOT=" << endl;
7185          cout << "set " << Me.m_current_prefix << "CONFIG=" << endl;
7186        }
7187      break;
7188    }
7189
7190  if (Uses.size () > 0)
7191    {
7192      int number;
7193
7194      for (number = 0; number < Uses.size (); number++)
7195        {
7196          Use* use = Uses[number];
7197
7198          if (use->discarded) continue;
7199          if (use->m_hidden) continue;
7200
7201          Package* p = use->get_package ();
7202          if (p->is_cmt ()) continue;
7203
7204
7205          switch (mode)
7206            {
7207            case Csh :
7208              cout << "unsetenv " << use->prefix << "ROOT" << endl;
7209              cout << "unsetenv " << use->prefix << "CONFIG" << endl;
7210              break;
7211            case Sh :
7212              cout << "unset " << use->prefix << "ROOT" << endl;
7213              cout << "unset " << use->prefix << "CONFIG" << endl;
7214              break;
7215            case Bat :
7216              cout << "set " << use->prefix << "ROOT=" << endl;
7217              cout << "set " << use->prefix << "CONFIG=" << endl;
7218              break;
7219            }
7220        }
7221    }
7222
7223  switch (mode)
7224    {
7225    case Csh :
7226      cout << "unsetenv CMTEXTRATAGS" << endl;
7227      break;
7228    case Sh :
7229      cout << "unset CMTEXTRATAGS" << endl;
7230      break;
7231    case Bat :
7232      cout << "set CMTEXTRATAGS=" << endl;
7233      break;
7234    }
7235
7236  cout << endl;
7237}
7238
7239//----------------------------------------------------------
7240void Cmt::print_context (Use& use, PrintMode mode, const cmt_string& tag)
7241{
7242  if (use.get_package_name () == "cmt_standalone") return;
7243
7244  cmt_string fs = CmtSystem::file_separator ();
7245
7246  use.real_path.replace_all (CmtSystem::file_separator (), fs);
7247
7248  cmt_string system = CmtSystem::get_cmt_config ();
7249
7250  bool do_config = use.get_strategy ("SetupConfig");
7251  bool do_root   = use.get_strategy ("SetupRoot");
7252   
7253 
7254  switch (mode)
7255    {
7256    case Csh :
7257      if (do_root)
7258        {
7259          cout << "setenv " << use.prefix << "ROOT \"" <<
7260            use.get_full_path () << "\"" << endl;
7261        }
7262
7263      if (use.get_package_name () == "CMT")
7264        {
7265          cout << "setenv CMTCONFIG " << system << endl;
7266        }
7267      else
7268        {
7269          if (do_config)
7270            {
7271              cout << "setenv " << use.prefix << "CONFIG \"" << tag << "\"" << endl;
7272            }
7273        }
7274       
7275      break;
7276    case Sh :
7277      if (do_root)
7278        {
7279          cout << use.prefix << "ROOT=\"" <<
7280            use.get_full_path () << "\"; export " <<
7281            use.prefix << "ROOT" << endl;
7282        }
7283
7284      if (use.get_package_name () == "CMT")
7285        {
7286          cout << "CMTCONFIG=" << system << "; export CMTCONFIG" << endl;
7287        }
7288      else
7289        {
7290          if (do_config)
7291            {
7292              cout << use.prefix << "CONFIG=\"" <<
7293                tag << "\"; export " <<
7294                use.prefix << "CONFIG" << endl;
7295            }
7296        }
7297       
7298      break;
7299    case Bat :
7300      if (do_root)
7301        {
7302          cout << "set " << use.prefix << "ROOT=" <<
7303            use.get_full_path () << endl;
7304        }
7305
7306      if (use.get_package_name () == "CMT")
7307        {
7308          cout << "set CMTCONFIG=" << system << endl;
7309        }
7310      else
7311        {
7312          if (do_config)
7313            {
7314              cout << "set " << use.prefix << "CONFIG=" << tag << endl;
7315            }
7316        }
7317       
7318      break;
7319    case Xml :
7320      if (do_root)
7321        {
7322          cout << "<variable><name>" << use.prefix << "ROOT</name>"
7323               << "<value>" << use.get_full_path () << "</value></variable>";
7324        }
7325
7326      if (use.get_package_name () == "CMT")
7327        {
7328          cout << "<variable><name>CMTCONFIG</name>"
7329               << "<value>" << system << "</value></variable>";
7330        }
7331      else
7332        {
7333          if (do_config)
7334            {
7335              cout << "<variable><name>" << use.prefix << "CONFIG</name>"
7336                   << "<value>" << tag << "</value></variable>";
7337            }
7338        }
7339       
7340      break;
7341    case Requirements :
7342      if (do_root &&
7343          use.get_package_name () != "CMT")
7344        {
7345          cout << "set " << use.prefix << "ROOT \"" <<
7346            use.get_full_path () << "\"" << endl;
7347
7348          cmt_string name (use.prefix + "ROOT");
7349          Symbol* symbol = Symbol::find (name);
7350          if (symbol != 0) 
7351            {
7352              symbol->printed = true;
7353            }
7354          if (symbol == 0 || symbol->type != Symbol::SymbolMacro)
7355            {
7356              CmtMessage::warning
7357                (CmtError::get_error_name (CmtError::symbol_not_found)
7358                 + ": macro " + name);
7359            }
7360        }
7361
7362      if (use.get_package_name () == "CMT")
7363        {
7364          cout << "set CMTCONFIG \"" << system << "\"" << endl;
7365        }
7366      else
7367        {
7368          if (do_config)
7369            {
7370              cout << "set " << use.prefix << "CONFIG \"" << tag << "\"" << endl;
7371            }
7372        }
7373       
7374      break;
7375    }
7376}
7377
7378/**
7379 *  Format a set of make macro definitions (one per line)
7380 * Each macro value is provided enclosed in single quotes
7381 *
7382 *  Take the macro values from the macro statements found
7383 * in recursively read requirements files.
7384 */
7385void Cmt::print_symbol_names (PrintMode mode, const cmt_string& pattern)
7386{
7387  int number;
7388
7389  set_standard_macros ();
7390
7391  cmt_regexp expression (pattern);
7392
7393  bool has_pattern = (pattern != "");
7394
7395  for (number = 0; number < Symbol::symbol_number (); number++)
7396    {
7397      Symbol& symbol = Symbol::symbol (number);
7398
7399      if (has_pattern)
7400        {
7401          if (!expression.match (symbol.name)) continue;
7402        }
7403
7404      if (Me.m_action == action_show_macro_names)
7405        {
7406          // Only keep macros.
7407          if ((symbol.type == Symbol::SymbolSet) ||
7408              (symbol.type == Symbol::SymbolAlias) ||
7409              (symbol.type == Symbol::SymbolPath) ||
7410              (symbol.type == Symbol::SymbolAction)) continue;
7411        }
7412      else if (Me.m_action == action_show_set_names)
7413        {
7414          // Exclude macros.
7415          if ((symbol.type == Symbol::SymbolMacro) ||
7416              (symbol.type == Symbol::SymbolAction)) continue;
7417        }
7418      else if (Me.m_action == action_show_action_names)
7419        {
7420          // Exclude macros.
7421          if (symbol.type != Symbol::SymbolAction) continue;
7422        }
7423
7424      cout << symbol.name << endl;
7425    }
7426}
7427
7428/**
7429 *  Format a set of make macro definitions (one per line)
7430 * Each macro value is provided enclosed in single quotes
7431 *
7432 *  Take the macro values from the macro statements found
7433 * in recursively read requirements files.
7434 */
7435void Cmt::print_macros (PrintMode mode, const cmt_string& pattern, ostream& out)
7436//void Cmt::print_macros (PrintMode mode, const cmt_string& pattern)
7437{
7438  int number;
7439
7440  set_standard_macros ();
7441
7442  cmt_regexp expression (pattern);
7443
7444  bool has_pattern = (pattern != "");
7445
7446  for (number = 0; number < Symbol::symbol_number (); number++)
7447    {
7448      Symbol& symbol = Symbol::symbol (number);
7449
7450      if (has_pattern)
7451        {
7452          if (!expression.match (symbol.name)) continue;
7453        }
7454
7455      if (Me.m_action == action_show_macros)
7456        {
7457          // Only keep macros.
7458          if ((symbol.type == Symbol::SymbolSet) ||
7459              (symbol.type == Symbol::SymbolAlias) ||
7460              (symbol.type == Symbol::SymbolPath) ||
7461              (symbol.type == Symbol::SymbolAction)) continue;
7462        }
7463      else if (Me.m_action == action_show_sets)
7464        {
7465          // Exclude macros.
7466          if ((symbol.type == Symbol::SymbolMacro) ||
7467              (symbol.type == Symbol::SymbolAction)) continue;
7468        }
7469      else if ((Me.m_action == action_build_tag_makefile) ||
7470               (Me.m_action == action_build_constituents_config) ||
7471               (Me.m_action == action_build_constituent_config))
7472        {
7473          // Exclude scripts and actions
7474          if ((symbol.type == Symbol::SymbolSetupScript) ||
7475              (symbol.type == Symbol::SymbolCleanupScript) ||
7476              (symbol.type == Symbol::SymbolAction)) continue;
7477        }
7478      else if (Me.m_action == action_show_actions)
7479        {
7480          if (symbol.type != Symbol::SymbolAction) continue;
7481        }
7482
7483      if (symbol.value_lists.size () < 1) continue;
7484
7485      symbol.show_macro (mode, out);
7486      //      symbol.show_macro (mode);
7487    }
7488}
7489
7490//----------------------------------------------------------
7491void Cmt::print_tabs (int tabs)
7492{
7493  while (tabs > 0)
7494    {
7495      cout << "  ";
7496      tabs--;
7497    }
7498}
7499
7500//----------------------------------------------------------
7501void Cmt::print_xml_prolog (const cmt_string& root, ostream& out)
7502{
7503  out << "<?xml version=\"1.0\" standalone=\"no\"?>" << endl;
7504  cmt_string dtd_file (Me.m_cmt_root);
7505  dtd_file += CmtSystem::file_separator ();
7506  dtd_file += "mgr";
7507  dtd_file += CmtSystem::file_separator ();
7508  dtd_file += "CMT.dtd";
7509  out << "<!DOCTYPE " + root + " SYSTEM \"" + dtd_file + "\">" << endl;
7510}
7511
7512//----------------------------------------------------------
7513int Cmt::reach_current_package ()
7514{
7515  Use& use = Use::current ();
7516  cmt_string dir;
7517
7518  if (Me.m_debug)
7519    {
7520      cout << "Cmt::reach_current_package> pwd = " 
7521           << CmtSystem::pwd () 
7522           << " path=" << Me.m_current_path
7523           << " package=" << Me.m_current_package
7524           << endl;
7525    }
7526
7527  /*
7528    Try to access the package.
7529  */
7530
7531  if (Me.m_current_package == "cmt_standalone")
7532    {
7533      if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
7534        {
7535          if (!CmtSystem::cd (Me.m_current_path))
7536            {
7537              CmtError::set (CmtError::package_not_found,
7538                             "ReachCurrentPackage> Cannot reach the path directory");
7539              return (0);
7540            }
7541        }
7542
7543      if (!CmtSystem::test_file ("requirements"))
7544        {
7545          return (0);
7546        }
7547    }
7548  else if (Me.m_current_package != "")
7549    {
7550      if (!use.move_to () && !use.move_to ("", true))
7551        //      if (!use.move_to ())
7552        {
7553          CmtError::set (CmtError::package_not_found,
7554                         "ReachCurrentPackage> Cannot reach the path directory");
7555          return (0);
7556        }
7557
7558      Me.m_current_path = use.real_path;
7559    }
7560  else
7561    {
7562      //
7563      // The cmt command has been given without explicit search for
7564      // a package. Thus it is expected that we are in the context of a
7565      // true package.
7566      //
7567      //  This means that there should be a requirements file visible.
7568      //
7569      //  If this is not true, we'll make a try into ../cmt and then
7570      // a last try into ../mgr
7571      //
7572
7573      if (!CmtSystem::test_file ("requirements"))
7574        {
7575          if (CmtSystem::cd ("../cmt") && 
7576              CmtSystem::test_file ("requirements"))
7577            {
7578              Me.m_current_style = cmt_style;
7579            }
7580          else if (CmtSystem::cd ("../mgr") && 
7581                   CmtSystem::test_file ("requirements"))
7582            {
7583              Me.m_current_style = mgr_style;
7584            }
7585          else
7586            {
7587              CmtMessage::error ("Cannot reach the mgr branch");
7588              /*
7589              if (!Me.m_quiet)
7590                {
7591                  cerr << "#CMT> Cannot reach the mgr branch" << endl;
7592                }
7593              */
7594             
7595              CmtError::set (CmtError::package_not_found,
7596                             "ReachCurrentPackage> Cannot reach the mgr/cmt directory");
7597              return (0);
7598            }
7599        }
7600      else
7601        Me.m_current_style = none_style;
7602
7603      dir = CmtSystem::pwd ();
7604
7605      CmtSystem::dirname (dir, Me.m_current_path);
7606      CmtSystem::basename (Me.m_current_path, Me.m_current_version);
7607
7608      if (CmtSystem::is_version_directory (Me.m_current_version))
7609        {
7610          CmtSystem::dirname (Me.m_current_path, Me.m_current_path);
7611          CmtSystem::basename (Me.m_current_path, Me.m_current_package);
7612          CmtSystem::dirname (Me.m_current_path, Me.m_current_path);
7613          Me.m_current_structuring_style = with_version_directory;
7614        }
7615      else
7616        {
7617          Me.m_current_package = Me.m_current_version;
7618          Me.m_current_version = "";
7619          CmtSystem::dirname (Me.m_current_path, Me.m_current_path);
7620          Me.m_current_structuring_style = without_version_directory;
7621          //          Me.m_current_style = no_version_style;
7622        }
7623
7624      use.set_package_name (Me.m_current_package);
7625      use.version = Me.m_current_version;
7626      use.path    = Me.m_current_path;
7627      use.style   = Me.m_current_style;
7628      use.structuring_style = Me.m_current_structuring_style;
7629    }
7630
7631  configure_current_dir ();
7632  build_prefix (Me.m_current_package, Me.m_current_prefix);
7633  build_config (Me.m_current_prefix, Me.m_current_config);
7634
7635  /*
7636    Check Tag is always set up
7637  */
7638
7639  if (Me.m_debug) cout << "reach_current_package0> current_tag=" << Me.m_current_tag << endl;
7640
7641  if (Me.m_current_tag == "")
7642    {
7643      cmt_string env;
7644
7645      env = CmtSystem::getenv (Me.m_current_config);
7646      if (env != "")
7647        {
7648          Tag* tag;
7649
7650          tag = Tag::add (env, PriorityConfig, "reach current package", 0);
7651          tag->mark ();
7652          //Me.m_current_tag = env;
7653
7654          //if (!Me.m_quiet) cerr << "reach_current_package1> current_tag=" << Me.m_current_tag << endl;
7655
7656        }
7657    }
7658
7659  if (Me.m_debug)
7660    {
7661      cout << "pwd = " << CmtSystem::pwd () << endl;
7662    }
7663
7664  /*
7665    Work on the requirements file.
7666  */
7667
7668  if (dir != "") dir += CmtSystem::file_separator ();
7669  dir += "requirements";
7670  SyntaxParser::parse_requirements (dir, &use);
7671
7672  if (Me.m_debug) cout << "reach_current_package2> current_tag=" << Me.m_current_tag << endl;
7673
7674  /**
7675   *   It would be useful to change this mechanism. Instead of
7676   *  applying all global patterns at once to all use contexts, it
7677   *  would be much better to apply it at the end of each
7678   *  requirements file parsing, and only in the context the
7679   *  appropriate Use.
7680   *
7681   *   This would avoid the current flaw which is that when a global
7682   *  pattern specifies a "private" definition, it is actually
7683   *  applied in the scope context of the Current Use and not in
7684   *  each individual Use. Therefore the private is lost.
7685   *
7686   *   However, this induces problems since some pattern definitions
7687   *  are done AFTER the use statements, which will NOT receive the
7688   *  pattern aplications.
7689   *
7690   *   Therefore it is decided to leave this "bad" mechanism until
7691   *  everybody is aware of this constraint.
7692   *
7693   *
7694   */
7695  Pattern::apply_all_globals ();
7696
7697  /*
7698    Select all possible tags
7699  */
7700
7701  Tag::restore_tree ();
7702
7703  return (1);
7704}
7705
7706static cmt_string get_best_form (const CmtSystem::cmt_string_vector& pwd,
7707                                 const cmt_string& path)
7708{
7709  static cmt_string fs = CmtSystem::file_separator ();
7710  cmt_string result;
7711
7712  /*
7713  //if (CmtSystem::getenv ("CMTTESTPREFIX") != "")
7714  {
7715  */
7716
7717  //
7718  //  If there is a common prefix between
7719  //  use->real_path and pwd
7720  //  we have
7721  //  use->real_path = /<prefix>/aaa
7722  //  pwd            = /<prefix>/bbb
7723  //
7724  //  Then use->real_path may be expressed as:
7725  //  ../..../../aaa
7726  //   where ../..../../ moves up to /<prefix>
7727  //
7728  //   Then we try to find the shortest between
7729  //
7730  //     /<prefix> and ../..../..
7731  //
7732  cmt_string a = path;
7733 
7734  CmtSystem::cmt_string_vector va;
7735 
7736  va.clear ();
7737 
7738  CmtSystem::split (a, fs, va);
7739 
7740  int m = va.size ();
7741  if (pwd.size () < m) m = pwd.size ();
7742 
7743  int i;
7744 
7745  for (i = 0; i < m; i++)
7746    {
7747      const cmt_string& fa = va[i];
7748      const cmt_string& fb = pwd[i];
7749     
7750      if (fa != fb) break;
7751    }
7752 
7753  cmt_string ups = "";
7754 
7755  if (i > 0)
7756    {
7757      // We have the prefix.
7758      // if we count what remains from pwd, then
7759      // we have the number of ../ required to
7760      // move to /<prefix>
7761      int j;
7762     
7763      for (j = i; j < pwd.size (); j++)
7764        {
7765          if (j > i) ups += fs;
7766          ups += "..";
7767        }
7768
7769      for (j = i; j < va.size (); j++)
7770        {
7771          ups += fs;
7772          ups += va[j];
7773        }
7774    }
7775 
7776  //
7777  // Here ups contains the ../..../../aaa form
7778  // for the use->real_path or is empty when there
7779  // were no common prefix.
7780  //
7781 
7782  //if (ups != "")
7783  if ((ups != "") &&
7784      (ups.size () < path.size ()))
7785    {
7786      result = ups;
7787    }
7788  else
7789    {
7790      result = path;
7791    }
7792
7793  return (result);
7794}
7795
7796/**
7797 *   This completely local class holds primitive actions for building
7798 *   standard macros.
7799 */
7800class StandardMacroBuilder
7801{
7802public:
7803
7804  /**
7805   *  CMTVERSION
7806   */
7807  void fill_for_CMTVERSION ()
7808  {
7809    buffer = "macro CMTVERSION \"";
7810    buffer += CMTVERSION;
7811    buffer += "\"";
7812    apply ();
7813  }
7814
7815  StandardMacroBuilder (const cmt_string& tag,
7816                        const cmt_string& package,
7817                        const cmt_string& version,
7818                        const cmt_string& prefix,
7819                        CmtDirStyle style)
7820  {
7821    fs = CmtSystem::file_separator ();
7822    buffer = "";
7823    pwd = CmtSystem::pwd ();
7824    CmtSystem::split (pwd, fs, vb);
7825    current_use = &(Use::current ());
7826    current_tag = tag;
7827    current_package = package;
7828    current_version = version;
7829    current_prefix = prefix;
7830    current_style = style;
7831  }
7832
7833  void apply ()
7834  {
7835    SyntaxParser::parse_requirements_line (buffer, current_use);
7836    buffer = "";
7837  }
7838
7839  /**
7840   *   tag
7841   */
7842  void fill_for_tag ()
7843  {
7844    static bool tag_debug = CmtSystem::testenv ("TAGDEBUG");
7845
7846    if (!Symbol::is_selected ("tag"))
7847      {
7848        if (tag_debug) cerr << "set_standard_macro2.1> current_tag=" << current_tag << endl;
7849
7850        if (current_tag == "")
7851          {
7852            buffer = "macro tag \"$(CMTCONFIG)\"";
7853          }
7854        else
7855          {
7856            buffer = "macro tag \"";
7857            buffer += current_tag;
7858            buffer += "\"";
7859          }
7860       
7861        if (tag_debug) cerr << " define tag: " << buffer << endl;
7862       
7863        apply ();
7864      }
7865  }
7866
7867  /**
7868   *   PACKAGE_ROOT
7869   */
7870  void fill_for_package (const cmt_string& current_dir)
7871  {
7872    buffer = "macro package \"";
7873    buffer += current_package;
7874    buffer += "\"";
7875    apply ();
7876
7877    buffer = "macro version \"";
7878    buffer += current_version;
7879    buffer += "\"";
7880    apply ();
7881
7882    if (!Symbol::is_selected ("PACKAGE_ROOT"))
7883      {
7884        buffer = "macro PACKAGE_ROOT \"$(";
7885        buffer += current_prefix;
7886        buffer += "ROOT";
7887        buffer += ")\"";
7888
7889        apply ();
7890      }
7891  }
7892
7893  /**
7894   *   srcdir
7895   *   src       =$(srcdir)/
7896   *   inc
7897   *   mgrdir
7898   *   mgr       =../$(mgrdir)/
7899   *   bin
7900   *   javabin
7901   *   doc
7902   *   version
7903   *   package
7904   *
7905   *   <package>_project
7906   *   <package>_cmtpath
7907   *   <package>_offset
7908   *   package_cmtpath
7909   *   package_offset
7910   *   project
7911   *
7912   */
7913  void fill_for_branches ()
7914  {
7915    /**
7916     *    Basic macros  (src, mgr, ...)
7917     */
7918   
7919    if (current_style == none_style)
7920      {
7921        if (!Symbol::is_selected ("srcdir"))
7922          {
7923            buffer = "macro srcdir \".";
7924            buffer += "\"";
7925            apply ();
7926          }
7927
7928        if (!Symbol::is_selected ("src"))
7929          {
7930            buffer = "macro src \".";
7931            buffer += fs;
7932            buffer += "\"";
7933            apply ();
7934          }
7935
7936        if (!Symbol::is_selected ("inc"))
7937          {
7938            buffer = "macro inc \".";
7939            buffer += fs;
7940            buffer += "\"";
7941            apply ();
7942          }
7943
7944        if (!Symbol::is_selected ("doc"))
7945          {
7946            buffer = "macro doc \".";
7947            buffer += fs;
7948            buffer += "\"";
7949            apply ();
7950          }
7951
7952        if (!Symbol::is_selected ("bin"))
7953          {
7954            buffer = "macro bin \".";
7955            buffer += fs;
7956            buffer += "\"";
7957            apply ();
7958          }
7959
7960        if (!Symbol::is_selected ("BIN"))
7961          {
7962            /*
7963            buffer = "macro BIN \"";
7964            buffer += pwd;
7965            buffer += fs;
7966            buffer += "\"";
7967            apply ();
7968            */
7969            cmt_string temp = "$(bin)";
7970            Symbol::expand (temp);
7971            int len (temp.size());
7972            cmt_string atemp;
7973            if (CmtSystem::absolute_path (temp))
7974              {
7975                CmtSystem::compress_path (temp, atemp);
7976              }
7977            else
7978              {
7979                atemp = pwd + fs + temp;
7980                CmtSystem::compress_path (atemp);
7981              }
7982            buffer = "macro BIN \"";
7983            buffer += atemp;
7984            buffer += "\"";
7985            apply ();
7986            if (0 != len && fs != temp[len - 1])
7987              {
7988                buffer = "macro_append bin \"";
7989                buffer += fs;
7990                buffer += "\"";
7991                apply ();
7992
7993                buffer = "macro_append BIN \"";
7994                buffer += fs;
7995                buffer += "\"";
7996                apply ();
7997              }
7998          }
7999
8000        if (!Symbol::is_selected ("javabin"))
8001          {
8002            buffer = "macro javabin \".";
8003            buffer += fs;
8004            buffer += "\"";
8005            apply ();
8006          }
8007
8008        if (!Symbol::is_selected ("mgr"))
8009          {
8010            buffer = "macro mgr \".";
8011            buffer += fs;
8012            buffer += "\"";
8013            apply ();
8014          }
8015      }
8016    else
8017      {
8018        if (!Symbol::is_selected ("srcdir"))
8019          {
8020            buffer = "macro srcdir \"..";
8021            buffer += fs;
8022            buffer += "src";
8023            buffer += "\"";
8024            apply ();
8025          }
8026       
8027        if (!Symbol::is_selected ("src"))
8028          {
8029            buffer = "macro src \"..";
8030            buffer += fs;
8031            buffer += "src";
8032            buffer += fs;
8033            buffer += "\"";
8034            apply ();
8035          }
8036       
8037        if (!Symbol::is_selected ("inc"))
8038          {
8039            buffer = "macro inc \"..";
8040            buffer += fs;
8041            buffer += "src";
8042            buffer += fs;
8043            buffer += "\"";
8044            apply ();
8045          }
8046       
8047        if (!Symbol::is_selected ("doc"))
8048          {
8049            buffer = "macro doc \"..";
8050            buffer += fs;
8051            buffer += "doc";
8052            buffer += fs;
8053            buffer += "\"";
8054            apply ();
8055          }
8056       
8057        if (!Symbol::is_selected ("bin"))
8058          {
8059            cmt_string package_tag = current_package;
8060            package_tag += "_tag";
8061
8062            buffer = "macro bin \"..";
8063            buffer += fs;
8064            buffer += "$(";
8065            buffer += package_tag;
8066            buffer += ")";
8067            buffer += fs;
8068            buffer += "\"";
8069            apply ();
8070          }
8071
8072        if (!Symbol::is_selected ("BIN"))
8073          {
8074            /*
8075            cmt_string pardir;
8076            CmtSystem::dirname (pwd, pardir);
8077            //            buffer = "macro BIN \"$(PACKAGE_ROOT)";
8078            buffer = "macro BIN \"";
8079            buffer += pardir;
8080            buffer += fs;
8081            buffer += "$(";
8082            buffer += package_tag;
8083            buffer += ")";
8084            buffer += fs;
8085            buffer += "\"";
8086            apply ();
8087            */
8088            cmt_string temp = "$(bin)";
8089            Symbol::expand (temp);
8090            int len (temp.size());
8091            cmt_string atemp;
8092            if (CmtSystem::absolute_path (temp))
8093              {
8094                CmtSystem::compress_path (temp, atemp);
8095              }
8096            else
8097              {
8098                atemp = pwd + fs + temp;
8099                CmtSystem::compress_path (atemp);
8100              }
8101            buffer = "macro BIN \"";
8102            buffer += atemp;
8103            buffer += "\"";
8104            apply ();
8105            if (0 != len && fs != temp[len - 1])
8106              {
8107                buffer = "macro_append bin \"";
8108                buffer += fs;
8109                buffer += "\"";
8110                apply ();
8111
8112                buffer = "macro_append BIN \"";
8113                buffer += fs;
8114                buffer += "\"";
8115                apply ();
8116              }
8117          }
8118
8119        if (!Symbol::is_selected ("javabin"))
8120          {
8121            buffer = "macro javabin \"..";
8122            buffer += fs;
8123            buffer += "classes";
8124            buffer += fs;
8125            buffer += "\"";
8126            apply ();
8127          }
8128       
8129        if (current_style == mgr_style)
8130          {
8131            buffer = "macro mgrdir \"mgr\"";
8132            apply ();
8133
8134            buffer = "macro mgr \"..";
8135            buffer += fs;
8136            buffer += "mgr";
8137            buffer += fs;
8138            buffer += "\"";
8139            apply ();
8140          }
8141        else
8142          {
8143            buffer = "macro mgrdir \"cmt\"";
8144            apply ();
8145
8146            buffer = "macro mgr \"..";
8147            buffer += fs;
8148            buffer += "cmt";
8149            buffer += fs;
8150            buffer += "\"";
8151            apply ();
8152          }
8153
8154        Cmt::configure_current_cmtpath ();
8155      }
8156  }
8157
8158  /**
8159   *   project
8160   */
8161  void fill_for_project ()
8162  {
8163    if (current_style == none_style) return;
8164
8165    cmt_string project_name;
8166    Project* project = Project::get_current ();
8167    if (project != 0)
8168      {
8169        project_name = project->get_name ();
8170      }
8171
8172    buffer = "macro project \"";
8173    buffer += project_name;
8174    buffer += "\"";
8175    apply ();
8176  }
8177
8178  /**
8179   *   use_requirements
8180   */
8181  void fill_for_use_requirements ()
8182  {
8183    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8184
8185    if (Uses.size () == 0) return;
8186
8187    if (!Symbol::is_selected ("use_requirements"))
8188      {
8189        buffer  = "macro use_requirements \"";
8190        buffer += "requirements ";
8191       
8192        for (int number = 0; number < Uses.size (); number++)
8193          {
8194            Use* use = Uses[number];
8195           
8196            if (use->discarded) continue;
8197            if (use->m_hidden) continue;
8198           
8199            if (use->located ())
8200              {
8201                buffer += "$(";
8202                buffer += use->get_package_name ();
8203                buffer += "_root)";
8204//                 buffer += use->prefix;
8205//                 buffer += "ROOT)";
8206               
8207                if (use->style == cmt_style)
8208                  {
8209                    buffer += fs;
8210                    buffer += "cmt";
8211                  }
8212                else if (use->style == mgr_style)
8213                  {
8214                    buffer += fs;
8215                    buffer += "mgr";
8216                  }
8217                //                else buffer += "cmt";
8218               
8219                buffer += fs;
8220                buffer += "requirements ";
8221              }
8222          }
8223       
8224        buffer += "\"";
8225       
8226        apply ();
8227      }
8228  }
8229
8230  /**
8231   *   use_includes
8232   */
8233  void fill_for_use_includes ()
8234  {
8235    Include::parse_all (&(Use::current()));
8236
8237    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8238
8239    if (Uses.size () == 0) return;
8240
8241    if (!Symbol::is_selected ("use_includes"))
8242      {
8243        buffer = "macro_append use_includes \' ";
8244       
8245        for (int number = 0; number < Uses.size (); number++)
8246          {
8247            Use* use = Uses[number];
8248           
8249            if (use->discarded) continue;
8250            if (use->m_hidden) continue;
8251
8252            Package* p = use->get_package ();
8253            if (p->is_cmt ()) continue;
8254
8255            if (Cmt::get_debug ())
8256              {
8257                cout << "fill use_includes for " << use->get_package_name () 
8258                     << " discarded=" << use->discarded
8259                     << " auto_imports=" << use->auto_imports << endl;
8260              }
8261           
8262            if (use->auto_imports == Off) continue;
8263           
8264            Include::parse_all (use);
8265
8266            use->fill_includes_macro (buffer);
8267          }
8268       
8269        buffer += "\'";
8270       
8271        apply ();
8272      }
8273  }
8274
8275  /**
8276   *   use_fincludes
8277   */
8278  void fill_for_use_fincludes ()
8279  {
8280    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8281
8282    if (Uses.size () == 0) return;
8283
8284    if (!Symbol::is_selected ("use_fincludes"))
8285      {
8286        buffer = "macro_append use_fincludes \" $(use_includes)\"";
8287        apply ();
8288      }
8289  }
8290
8291  /**
8292   *   use_stamps
8293   */
8294  void fill_for_use_stamps ()
8295  {
8296    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8297
8298    if (Uses.size () == 0) return;
8299
8300    if (!Symbol::is_selected ("use_stamps"))
8301      {
8302        /*
8303        buffer = "macro use_stamps \"";
8304        (Use::current()).fill_macro (buffer, "stamps");
8305       
8306        for (int number = 0; number < Uses.size (); number++)
8307          {
8308            Use* use = Uses[number];
8309           
8310            if (use->discarded) continue;
8311            if (use->m_hidden) continue;
8312
8313            Package* p = use->get_package ();
8314            if (p->is_cmt ()) continue;
8315           
8316            use->fill_macro (buffer, "stamps");
8317          }
8318       
8319        buffer += "\"";
8320        */
8321        Use::fill_macro_all (buffer, "stamps");
8322        apply ();
8323      }
8324  }
8325
8326  /**
8327   *   use_cflags
8328   */
8329  void fill_for_use_cflags ()
8330  {
8331    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8332
8333    if (Uses.size () == 0) return;
8334
8335    if (!Symbol::is_selected ("use_cflags"))
8336      {
8337        Use::fill_macro_all (buffer, "cflags");
8338        apply ();
8339      }
8340  }
8341
8342  /**
8343   *   use_pp_cflags
8344   */
8345  void fill_for_use_pp_cflags ()
8346  {
8347    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8348
8349    if (Uses.size () == 0) return;
8350
8351    if (!Symbol::is_selected ("use_pp_cflags"))
8352      {
8353        Use::fill_macro_all (buffer, "pp_cflags");
8354        apply ();
8355      }
8356  }
8357
8358  /**
8359   *   use_cppflags
8360   */
8361  void fill_for_use_cppflags ()
8362  {
8363    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8364
8365    if (Uses.size () == 0) return;
8366
8367    if (!Symbol::is_selected ("use_cppflags"))
8368      {
8369        Use::fill_macro_all (buffer, "cppflags");
8370        apply ();
8371      }
8372  }
8373
8374  /**
8375   *   use_pp_cppflags
8376   */
8377  void fill_for_use_pp_cppflags ()
8378  {
8379    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8380
8381    if (Uses.size () == 0) return;
8382
8383    if (!Symbol::is_selected ("use_pp_cppflags"))
8384      {
8385        Use::fill_macro_all (buffer, "pp_cppflags");
8386        apply ();
8387      }
8388  }
8389
8390  /**
8391   *   use_fflags
8392   */
8393  void fill_for_use_fflags ()
8394  {
8395    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8396
8397    if (Uses.size () == 0) return;
8398
8399    if (!Symbol::is_selected ("use_fflags"))
8400      {
8401        Use::fill_macro_all (buffer, "fflags");
8402        apply ();
8403      }
8404  }
8405
8406  /**
8407   *   use_pp_fflags
8408   */
8409  void fill_for_use_pp_fflags ()
8410  {
8411    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8412
8413    if (Uses.size () == 0) return;
8414
8415    if (!Symbol::is_selected ("use_pp_fflags"))
8416      {
8417        Use::fill_macro_all (buffer, "pp_fflags");
8418        apply ();
8419      }
8420  }
8421
8422  /**
8423   *   use_linkopts
8424   */
8425  void fill_for_use_linkopts ()
8426  {
8427    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8428
8429    if (Uses.size () == 0) return;
8430
8431    if (!Symbol::is_selected ("use_linkopts"))
8432      {
8433        Use::fill_macro_all (buffer, "linkopts");
8434        apply ();
8435      }
8436  }
8437
8438  /**
8439   *   use_libraries
8440   */
8441  void fill_for_use_libraries ()
8442  {
8443    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8444
8445    if (Uses.size () == 0) return;
8446
8447    if (!Symbol::is_selected ("use_libraries"))
8448      {
8449        buffer  = "macro use_libraries \"";
8450
8451        for (int number = 0; number < Uses.size (); number++)
8452          {
8453            Use* use = Uses[number];
8454           
8455            if (use->discarded) continue;
8456            if (use->m_hidden) continue;
8457           
8458            Package* p = use->get_package ();
8459            if (p->is_cmt ()) continue;
8460
8461            use->fill_macro (buffer, "libraries");
8462          }
8463       
8464        buffer += "\"";
8465
8466        apply ();
8467      }
8468  }
8469
8470  /**
8471   *   includes
8472   */
8473  void fill_for_includes ()
8474  {
8475    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8476
8477    if (Uses.size () == 0) return;
8478
8479    if (!Symbol::is_selected ("includes"))
8480      {
8481        buffer = "macro_append includes \' ";
8482
8483        Use& use = Use::current();
8484
8485        if (use.include_path == "")
8486          {
8487            buffer += "$(ppcmd)\"$(srcdir)\" ";
8488          }
8489        else if (use.include_path != "none")
8490          {
8491            buffer += "$(ppcmd)\"";
8492            buffer += use.include_path;
8493            buffer += "\" ";
8494          }
8495
8496        for (int include_number = 0;
8497             include_number < use.includes.size ();
8498             include_number++)
8499          {
8500            Include& incl = use.includes[include_number];
8501
8502            if (incl.name == "") continue;
8503
8504            buffer += "$(ppcmd)\"";
8505            buffer += incl.name;
8506            buffer += "\" ";
8507          }
8508       
8509        buffer += "$(use_includes)\'";
8510       
8511        apply ();
8512      }
8513  }
8514
8515  /**
8516   *   fincludes
8517   */
8518  void fill_for_fincludes ()
8519  {
8520    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8521
8522    if (Uses.size () == 0) return;
8523
8524    if (!Symbol::is_selected ("fincludes"))
8525      {
8526        buffer = "macro_append fincludes \" $(includes)\"";
8527        apply ();
8528      }
8529  }
8530
8531  /**
8532   *  Macros specific to constituents.
8533   *  This includes the compiler flags
8534   *  and fills in these macros from uses packages. This takes care
8535   *  of -no_auto_imports and -import= directives
8536   *
8537   *    <constituent>_use_linkopts
8538   *    <prefix>_<constituent>_cflags
8539   *    <prefix>_<constituent>_pp_cflags
8540   *    <prefix>_<constituent>_cppflags
8541   *    <prefix>_<constituent>_pp_cppflags
8542   *    <prefix>_<constituent>_fflags
8543   *    <prefix>_<constituent>_pp_fflags
8544   *    <constituent>linkopts
8545   *    <constituent>_GUID
8546   *    <constituent>_stamps
8547   *
8548   */
8549  void fill_for_all_constituents ()
8550  {
8551    /// First, finish the parsing of constituent parameters.
8552    if (Cmt::get_debug ())
8553      {
8554        cout << "fill_for_all_constituents>" << endl;
8555      }
8556
8557    Constituent::parse_all ();
8558
8559    Use::UsePtrVector& Uses = Use::get_ordered_uses ();
8560   
8561    const Constituent::ConstituentVector& constituents =
8562      Constituent::constituents ();
8563
8564 
8565    // Prepare the auto_imports states in a vector
8566    cmt_vector<bool> base_auto_imports_states;
8567
8568    base_auto_imports_states.resize (Uses.size ());
8569
8570    int number;
8571   
8572    for (number = 0; number < Uses.size (); number++)
8573      {
8574        Use* use = Uses[number];
8575        base_auto_imports_states[number] = (use->auto_imports != Off);
8576      }
8577   
8578    // Now scan all constituents
8579       
8580    for (number = 0; number < constituents.size (); number++)
8581      {
8582        const Constituent& constituent = constituents[number];
8583       
8584        //==== GLAST addition for vs.net ==========
8585        buffer = "macro ";
8586        buffer += constituent.name;
8587        buffer += "_GUID \"{88BF15AB-5A2D-4bea-B64F-02752C2A1F4F}\" ";
8588        apply ();
8589       
8590        if (Cmt::get_debug ())
8591          {
8592            cout << "Checking " << constituent.name  << " against imports requests" << endl;
8593          }
8594        Use::UsePtrVector imports;
8595        int i;
8596       
8597        /**
8598         *  Problem for imports in constituents.
8599         *
8600         *     1) use_xxx has holes due to the corresponding
8601         *         -no_auto_imports options attached to some
8602         *        use statements (including the transitive ones)
8603         *
8604         *     2) the -import=yyy options provided to a given constituent
8605         *        should restore the appropriate holes as well as
8606         *        all transitive ones.
8607         *
8608         *     3) for use_linkopts, missing pieces must be filled at
8609         *        the right position. (for others, order is not relevant
8610         *        while transitive access is required for all)
8611         *
8612         */
8613       
8614        if (constituent.type == Document)
8615          { 
8616            continue;
8617          }
8618       
8619        if (constituent.imports.size () == 0) 
8620          {
8621            buffer = "macro_append ";
8622            buffer += constituent.name;
8623            buffer += "_use_linkopts ";
8624            buffer += " \" ";
8625           
8626            current_use->fill_macro (buffer, "linkopts");
8627           
8628            for (i = 0; i < Uses.size (); i++)
8629              {
8630                if (base_auto_imports_states[i])
8631                  {
8632                    Use* u = Uses[i];
8633                   
8634                    if (u->discarded) continue;
8635                    if (u->m_hidden) continue;
8636                   
8637                    Package* p = u->get_package ();
8638                    if (p->is_cmt ()) continue;
8639                   
8640                    u->fill_macro (buffer, "linkopts");
8641                  }
8642              }
8643            buffer += "\"";
8644            apply ();
8645           
8646            /*
8647              buffer = "macro_append ";
8648              buffer += constituent.name;
8649              buffer += "_use_linkopts ";
8650             
8651              buffer += " \" $(use_linkopts)\"";
8652              apply ();
8653            */
8654           
8655            continue;
8656          }
8657       
8658        // From here on, the constituent HAS import options.
8659       
8660        /**
8661         * Create a private copy of the state vector. This private copy
8662         * will be updated according to -import=xxx modifiers for the
8663         * current constituent.
8664         */
8665        cmt_vector<bool> auto_imports_states (base_auto_imports_states);
8666       
8667        for (i = 0; i < constituent.imports.size (); i++)
8668          {
8669            const cmt_string& import = constituent.imports[i];
8670           
8671            //
8672            // Resolve the imported uses
8673            //
8674           
8675            int use_index = Use::find_index (import, "", "");
8676           
8677            if (use_index >= 0)
8678              {
8679                Use* u = Uses[use_index];
8680               
8681                if (u->discarded) continue;
8682                if (u->m_hidden) continue;
8683               
8684                if (Cmt::get_debug ())
8685                  {
8686                    cout << constituent.name  << " needs imports " << import << " "
8687                         << use_index << " " 
8688                         << u->get_package()->get_name() << " "
8689                         << " u->auto_imports=" << u->auto_imports
8690                         << " Off=" << Off
8691                         << " On=" << On
8692                         << endl;
8693                  }
8694               
8695                Package* p = u->get_package ();
8696                if (p->is_cmt ()) continue;
8697               
8698                if (u->auto_imports != Off) continue;
8699               
8700                Use::set_auto_imports_state (use_index, auto_imports_states);
8701              }
8702            else
8703              {
8704                if (Me.m_action == action_build_constituents_makefile ||
8705                    Me.m_action == action_build_constituents_config)
8706                  CmtMessage::warning ("package " + import +
8707                                       " cannot be imported (requested for " +
8708                                       constituent.name +")");
8709              }
8710          }
8711       
8712        if (Cmt::get_debug ())
8713          {
8714            cout << constituent.name  << " has imports " << endl;
8715          }
8716       
8717       
8718        /**
8719         *   Find all newly exposed packages and precompute this list inside
8720         *   a vector.
8721         */
8722        for (i = 0; i < base_auto_imports_states.size (); i++)
8723          {
8724            //      if (base_auto_imports_states[i]== On && auto_imports_states[i] == Off) continue;
8725            if (base_auto_imports_states[i] == On || auto_imports_states[i] == Off) continue;
8726            /**
8727             *  Consider the package (i) for import only if it is:
8728             *   o not imported yet (i.e., base_auto_imports_states[i] != On)
8729             *   o requested for import according to -import=xxx modifiers for
8730             *     the current constituent (i.e., auto_imports_states[i] != Off)
8731             */
8732            Use* u = Uses[i];
8733           
8734            if (u->discarded) continue;
8735            if (u->m_hidden)  continue;
8736           
8737            Package* p = u->get_package ();
8738            if (p->is_cmt ()) continue;
8739           
8740            if (Cmt::get_debug ())
8741              {
8742                cout << constituent.name  << " has import " << p->get_name () << endl;
8743              }
8744           
8745            imports.push_back (u);
8746          }
8747       
8748        /**
8749         *  Only for linkopts we take care of the order. This means
8750         *  that ${CONSTITUENT}_use_linkopts should be used in place of use_linkopts.
8751         *
8752         *  (see the application fragments)
8753         *  that ${CONSTITUENT}_use_linkopts will be used in place of use_linkopts.
8754         */
8755        buffer = "macro_append ";
8756        buffer += constituent.name;
8757        buffer += "_use_linkopts ";
8758        buffer += " \" ";
8759       
8760        current_use->fill_macro (buffer, "linkopts");
8761       
8762        for (i = 0; i < Uses.size (); i++)
8763          {
8764            if (auto_imports_states[i])
8765              {
8766                Use* u = Uses[i];
8767               
8768                if (u->discarded) continue;
8769                if (u->m_hidden) continue;
8770               
8771                Package* p = u->get_package ();
8772                if (p->is_cmt ()) continue;
8773               
8774                u->fill_macro (buffer, "linkopts");
8775              }
8776          }
8777        buffer += "\"";
8778        apply ();
8779       
8780        if (imports.size () == 0) continue;
8781       
8782        cmt_string prefix;
8783       
8784        //
8785        // Documents are not considered
8786        //
8787        switch (constituent.type)
8788          {
8789          case Application:
8790            prefix = "app_";
8791            break;
8792          case Library:
8793            prefix = "lib_";
8794            break;
8795          }
8796       
8797        buffer = "macro_append ";
8798        buffer += prefix;
8799        buffer += constituent.name;
8800        buffer += "_cflags ";
8801        buffer += " \' ";
8802        for (i = 0; i < imports.size (); i++)
8803          {
8804            Use* u = imports[i];
8805           
8806            u->fill_includes_macro (buffer);
8807            u->fill_macro (buffer, "cflags");
8808          }
8809        buffer += "\'";
8810        apply ();
8811       
8812        buffer = "macro_append ";
8813        buffer += prefix;
8814        buffer += constituent.name;
8815        buffer += "_pp_cflags ";
8816        buffer += " \" ";
8817        for (i = 0; i < imports.size (); i++)
8818          {
8819            Use* u = imports[i];
8820           
8821            u->fill_macro (buffer, "pp_cflags");
8822          }
8823        buffer += "\"";
8824        apply ();
8825       
8826        buffer = "macro_append ";
8827        buffer += prefix;
8828        buffer += constituent.name;
8829        buffer += "_cppflags ";
8830        buffer += " \' ";
8831        for (i = 0; i < imports.size (); i++)
8832          {
8833            Use* u = imports[i];
8834           
8835            u->fill_includes_macro (buffer);
8836            u->fill_macro (buffer, "cppflags");
8837          }
8838        buffer += "\'";
8839        apply ();
8840       
8841        buffer = "macro_append ";
8842        buffer += prefix;
8843        buffer += constituent.name;
8844        buffer += "_pp_cppflags ";
8845        buffer += " \" ";
8846        for (i = 0; i < imports.size (); i++)
8847          {
8848            Use* u = imports[i];
8849           
8850            u->fill_macro (buffer, "pp_cppflags");
8851          }
8852        buffer += "\"";
8853        apply ();
8854       
8855        buffer = "macro_append ";
8856        buffer += prefix;
8857        buffer += constituent.name;
8858        buffer += "_fflags ";
8859        buffer += " \' ";
8860        for (i = 0; i < imports.size (); i++)
8861          {
8862            Use* u = imports[i];
8863           
8864            u->fill_includes_macro (buffer);
8865            u->fill_macro (buffer, "fflags");
8866          }
8867        buffer += "\'";
8868        apply ();
8869       
8870        buffer = "macro_append ";
8871        buffer += prefix;
8872        buffer += constituent.name;
8873        buffer += "_pp_fflags ";
8874        buffer += " \" ";
8875        for (i = 0; i < imports.size (); i++)
8876          {
8877            Use* u = imports[i];
8878           
8879            u->fill_macro (buffer, "pp_fflags");
8880          }
8881        buffer += "\"";
8882        apply ();
8883
8884        buffer = "macro_append ";
8885        buffer += constituent.name;
8886        buffer += "_stamps ";
8887        buffer += " \" ";
8888        for (i = 0; i < imports.size (); i++)
8889          {
8890            Use* u = imports[i];
8891           
8892            u->fill_macro (buffer, "stamps");
8893          }
8894        buffer += "\"";
8895        apply ();
8896
8897        /**
8898         *  Setting ${CONSTITUENT}linkopts is a temporary solution
8899         *  until the backward compatibility solution for a proper
8900         *  replacement of use_linkopts by ${CONSTITUENT}_use_linkopts
8901         *  is acheived.
8902         *
8903         */
8904        /**
8905        buffer = "macro_append ";
8906        buffer += constituent.name;
8907        buffer += "linkopts ";
8908        buffer += " \" ";
8909        for (i = 0; i < imports.size (); i++)
8910          {
8911            Use* u = imports[i];
8912           
8913            u->fill_macro (buffer, "linkopts");
8914          }
8915        buffer += "\"";
8916        apply ();
8917        */
8918      }
8919  }
8920 
8921  /**
8922   *   Macros implied or required to manage constituents.
8923   */
8924  void fill_for_constituent_macros ()
8925  {
8926    int number;
8927    cmt_string temp;
8928
8929    const Constituent::ConstituentVector& constituents = Constituent::constituents ();
8930 
8931    if (!Symbol::is_selected ("constituents"))
8932      {
8933        temp = "macro_append constituents \" ";
8934       
8935        for (number = 0; number < constituents.size (); number++)
8936          {
8937            const Constituent& constituent = constituents[number];
8938           
8939            if (constituent.group == 0)
8940              {
8941                temp += constituent.name;
8942                temp += " ";
8943              }
8944          }
8945       
8946        temp += "\"";
8947       
8948        SyntaxParser::parse_requirements_line (temp, current_use);
8949      }
8950   
8951    SyntaxParser::parse_requirements_line ("macro_append all_constituents \" $(constituents)\"", 
8952                                           current_use);
8953   
8954    if (!Symbol::is_selected ("constituentsclean"))
8955      {
8956        temp = "macro_append constituentsclean \" ";
8957       
8958        for (number = constituents.size () - 1; number >= 0 ; number--)
8959          {
8960            const Constituent& constituent = constituents[number];
8961           
8962            if (constituent.group == 0)
8963              {
8964                temp += constituent.name;
8965                temp += "clean ";
8966              }
8967          }
8968       
8969        temp += "\"";
8970       
8971        SyntaxParser::parse_requirements_line (temp, current_use);
8972      }
8973   
8974    SyntaxParser::parse_requirements_line ("macro_append all_constituentsclean \" $(constituentsclean)\"", 
8975                                           current_use);
8976   
8977    const Group::GroupVector& groups = Group::groups ();
8978   
8979    for (number = 0; number < groups.size (); number++)
8980      {
8981        const Group& group = groups[number];
8982       
8983        temp = "macro_append ";
8984        temp += group.name ();
8985        temp += "_constituents \" ";
8986       
8987        int i;
8988       
8989        for (i = 0; i < constituents.size (); i++)
8990          {
8991            const Constituent& constituent = constituents[i];
8992           
8993            if ((constituent.group != 0) && 
8994                (group.name () == constituent.group->name ()))
8995              {
8996                temp += constituent.name;
8997                temp += " ";
8998              }
8999          }
9000       
9001        temp += "\"";
9002       
9003        SyntaxParser::parse_requirements_line (temp, current_use);
9004       
9005        temp = "macro_append ";
9006        temp += group.name ();
9007        temp += "_constituentsclean \" ";
9008       
9009        for (i = constituents.size () - 1; i >= 0 ; i--)
9010          {
9011            const Constituent& constituent = constituents[i];
9012           
9013            if ((constituent.group != 0) && 
9014                (group.name () == constituent.group->name ()))
9015              {
9016                temp += constituent.name;
9017                temp += "clean ";
9018              }
9019          }
9020       
9021        temp += "\"";
9022       
9023        SyntaxParser::parse_requirements_line (temp, current_use);
9024      }
9025  }
9026
9027  /**
9028   *  Definitions for installation area mechanisms. Apply all cmtpath patterns
9029   */
9030  void fill_for_install_area ()
9031  {
9032    CmtPathPattern::apply_all ();
9033
9034    const Use& current_use = Use::current ();
9035
9036    if (current_use.get_strategy ("InstallArea"))
9037      {
9038        CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
9039       
9040        ia_mgr.setup ();
9041      }
9042  }
9043
9044  /**
9045   * Macros to be defined once current_package is known
9046   * and even before reading its requirements file.
9047   */
9048  void fill_for_current_package (const cmt_string& current_dir)
9049  {
9050    fill_for_tag ();
9051    fill_for_package (current_dir);
9052  }
9053
9054private:
9055  cmt_string fs;
9056  cmt_string buffer;
9057  CmtSystem::cmt_string_vector vb;
9058  cmt_string pwd;
9059  Use* current_use;
9060  cmt_string current_tag; 
9061  cmt_string current_package; 
9062  cmt_string current_version; 
9063  cmt_string current_prefix; 
9064  CmtDirStyle current_style;
9065};
9066
9067//----------------------------------------------------------
9068void Cmt::set_current_access (AccessMode mode)
9069{
9070  Me.m_current_access = mode;
9071}
9072
9073//----------------------------------------------------------
9074void Cmt::set_recursive (bool mode)
9075{
9076  Me.m_recursive = mode;
9077}
9078
9079//----------------------------------------------------------
9080void Cmt::set_scope_filtering_mode (CmtScopeFilteringMode mode)
9081{
9082  Me.m_scope_filtering_mode = mode;
9083}
9084
9085//----------------------------------------------------------
9086void Cmt::set_standard_macros ()
9087{
9088  if (Me.m_standard_macros_done) return;
9089
9090  Me.m_standard_macros_done = true;
9091
9092  //  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
9093  Use& current_use = Use::current ();
9094
9095  cmt_string fs = CmtSystem::file_separator ();
9096
9097  cmt_string pwd = CmtSystem::pwd ();
9098
9099  /**
9100   * This is a check for package names
9101   */
9102  if (CmtMessage::active (Verbose))
9103    {
9104      Use::UsePtrVector uses (Use::get_ordered_uses ());
9105      uses.push_back (&current_use);
9106      for (int i = uses.size () - 1; i >= 0; i--)
9107        {
9108          Use* use = uses[i];
9109          if (use->discarded) continue;
9110          if (use->m_hidden) continue;
9111          if (!use->located ()) continue;
9112          for (int j = i - 1; j >= 0; j--)
9113            {
9114              Use* use2 = uses[j];
9115              if (use2->discarded) continue;
9116              if (use2->m_hidden) continue;
9117              if (!use2->located ()) continue;
9118              if (use->prefix == use2->prefix)
9119                {
9120                  CmtMessage::warning (use->prefix + "ROOT, "
9121                                       + use->prefix + "VERSION ill-defined: "
9122                                       + use->get_package_name () + " and "
9123                                       + use2->get_package_name ()
9124                                       + " package name conflict");
9125                }
9126            }
9127        }
9128    }
9129  /**
9130   * This is already done in
9131   void Cmt::configure_current_package ()
9132
9133  if (CmtSystem::test_file ("../cmt/requirements")) Me.m_current_style = cmt_style;
9134  else if (CmtSystem::test_file ("../mgr/requirements")) Me.m_current_style = mgr_style;
9135  else Me.m_current_style = none_style;
9136
9137  {
9138    cmt_string v;
9139    CmtSystem::dirname (pwd, v);
9140    CmtSystem::basename (v, v);
9141    if (!CmtSystem::is_version_directory (v))
9142      {
9143        Me.m_current_style = no_version_style;
9144      }
9145  }
9146  */
9147
9148  // Prepare computation of the best form for relative path from current directory
9149  // to package directories.
9150  CmtSystem::cmt_string_vector vb;
9151  CmtSystem::split (pwd, fs, vb);
9152
9153
9154  /**
9155   *    TAG management
9156   */
9157
9158  bool tag_debug = CmtSystem::testenv ("TAGDEBUG");
9159
9160  if (tag_debug) cerr << "set_standard_macro0> current_tag=" << Me.m_current_tag << endl;
9161
9162  if (Me.m_current_tag != "")
9163    {
9164      // this is when some -tag= argument was used.
9165      if (tag_debug) cerr << "set_standard_macro0.1> current_tag=" << Me.m_current_tag << endl;
9166    }
9167  else if (Symbol::is_selected ("CMTCONFIG"))
9168    {
9169      // This is when CMTCONFIG has been set from some requirements file
9170      Symbol* macro = Symbol::find ("CMTCONFIG");
9171      if (macro != 0)
9172        {
9173          Me.m_current_tag = macro->build_macro_value ();
9174          if (tag_debug) cerr << "set_standard_macro1> current_tag=" << Me.m_current_tag << endl;
9175        }
9176    }
9177  else
9178    {
9179      // this is when no -tag= argument was used.
9180      if (tag_debug) cerr << "set_standard_macro(before2)> current_tag=" << Me.m_current_tag << endl;
9181      if (current_use.get_package_name () == "CMT")
9182        {
9183          Me.m_current_tag = CmtSystem::getenv ("CMTBIN");
9184        }
9185      else
9186        {
9187          Me.m_current_tag = CmtSystem::getenv ("CMTCONFIG");
9188        }
9189
9190      if (tag_debug) cerr << "set_standard_macro2> current_tag=" << Me.m_current_tag << endl;
9191    }
9192
9193  if (Me.m_debug)
9194    {
9195      cout << "set_standard_macro3>" << endl;
9196    }
9197
9198  StandardMacroBuilder builder (Me.m_current_tag,
9199                                Me.m_current_package,
9200                                Me.m_current_version,
9201                                Me.m_current_prefix,
9202                                Me.m_current_style);
9203
9204
9205  builder.fill_for_current_package (Me.m_current_dir);
9206
9207  builder.fill_for_branches ();
9208  builder.fill_for_project ();
9209
9210  builder.fill_for_install_area ();
9211
9212  builder.fill_for_use_requirements ();
9213  builder.fill_for_use_includes ();
9214  builder.fill_for_use_fincludes ();
9215  builder.fill_for_use_stamps ();
9216  builder.fill_for_use_cflags ();
9217  builder.fill_for_use_pp_cflags ();
9218  builder.fill_for_use_cppflags ();
9219  builder.fill_for_use_pp_cppflags ();
9220  builder.fill_for_use_fflags ();
9221  builder.fill_for_use_pp_fflags ();
9222  builder.fill_for_use_linkopts ();
9223  builder.fill_for_use_libraries ();
9224  builder.fill_for_includes ();
9225  builder.fill_for_fincludes ();
9226  builder.fill_for_all_constituents ();
9227  builder.fill_for_constituent_macros ();
9228}
9229
9230void Cmt::set_all_sets_done ()
9231{
9232  Me.m_all_sets_done = true;
9233}
9234
9235void Cmt::reset_all_sets_done ()
9236{
9237  Me.m_all_sets_done = false;
9238}
9239
9240//----------------------------------------------------------
9241void Cmt::use_cmt ()
9242{
9243  UseRef use;
9244  bool recursive_copy = Me.m_recursive;
9245  bool debug_copy = Me.m_debug;
9246
9247  if (Me.m_default_path.size () <= 0) return;
9248  if (Me.m_current_package == "CMT") return;
9249
9250  Me.m_recursive = true;
9251  //Me.m_debug = false;
9252  use = Use::add (Me.m_default_path, "CMT", Me.m_cmt_version, "", "", "", 0);
9253  Me.m_recursive = recursive_copy;
9254  Me.m_debug = debug_copy;
9255}
9256
9257//----------------------------------------------------------
9258void Cmt::use_home_requirements ()
9259{
9260  use_special_requirements (Me.m_cmt_home, 
9261                            CmtSystem::get_home_package (), 
9262                            "requirements");
9263}
9264
9265//----------------------------------------------------------
9266void Cmt::use_user_context_requirements ()
9267{
9268  use_special_requirements (Me.m_cmt_user_context, 
9269                            CmtSystem::get_user_context_package (), 
9270                            "requirements");
9271}
9272
9273//----------------------------------------------------------
9274void Cmt::use_special_requirements (const cmt_string& path, 
9275                                    const cmt_string& name, 
9276                                    const cmt_string& file_name)
9277{
9278  if (path == "") 
9279    {
9280      return;
9281    }
9282
9283  UseRef use;
9284  bool recursive_copy = Me.m_recursive;
9285
9286  if (Me.m_default_path.size () <= 0) return;
9287  if (Me.m_current_package == "CMT") return;
9288
9289  Me.m_recursive = true;
9290
9291  use = Use::add (path, name, "v0", "", "", "", 0);
9292
9293  cmt_string f = path;
9294  f += CmtSystem::file_separator ();
9295  f += file_name;
9296  if (CmtSystem::test_file (f))
9297    {
9298      use->m_located = true;
9299    }
9300  SyntaxParser::parse_requirements (f, use);
9301
9302  Me.m_recursive = recursive_copy;
9303}
9304
9305//-------------------------------------------------
9306void Cmt::vector_to_string (const CmtSystem::cmt_string_vector& v,
9307                            const cmt_string& separator,
9308                            cmt_string& result)
9309{
9310  result.erase (0);
9311
9312  for (int i = 0; i < v.size (); i++)
9313    {
9314      const cmt_string& s = v[i];
9315      if (s == "") continue;
9316
9317      if (i > 0) result += separator;
9318      result += v[i];
9319    }
9320}
9321
9322//-------------------------------------------------
9323cmt_string Cmt::vector_to_string (const CmtSystem::cmt_string_vector& v)
9324{
9325  cmt_string result;
9326
9327  vector_to_string (v, " ", result);
9328
9329  return (result);
9330}
Note: See TracBrowser for help on using the repository browser.