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

Last change on this file since 598 was 598, checked in by rybkin, 12 years ago

See C.L. 475

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