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

Last change on this file since 527 was 527, checked in by rybkin, 15 years ago

See C.L. 414

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