source: CMT/v1r18p20060301/source/cmt_commands.cxx @ 615

Last change on this file since 615 was 151, checked in by arnault, 18 years ago

Suppress some warnings see CL 298

  • Property svn:eol-style set to native
File size: 58.2 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// See the complete license in cmt_license.txt "http://www.cecill.info".
5//-----------------------------------------------------------
6
7#include "cmt_commands.h"
8#include "cmt_tag.h"
9#include "cmt_symbol.h"
10#include "cmt_project.h"
11
12ArgParser::ArgParser (CmtContext& context) : cmt(context), argc(0), argv(0), mode(Csh)
13{
14  arguments.clear ();
15
16  int i = 0;
17
18  parsers.add ("awk", i);
19  pv.push_back (&ArgParser::do_awk); i++;
20
21  parsers.add ("br", i);
22  parsers.add ("bro", i);
23  parsers.add ("broa", i);
24  parsers.add ("broad", i);
25  parsers.add ("broadc", i);
26  parsers.add ("broadca", i);
27  parsers.add ("broadcas", i);
28  parsers.add ("broadcast", i);
29  pv.push_back (&ArgParser::do_broadcast); i++;
30
31  parsers.add ("bu", i);
32  parsers.add ("bui", i);
33  parsers.add ("buil", i);
34  parsers.add ("build", i);
35  pv.push_back (&ArgParser::do_build); i++;
36
37  parsers.add ("check", i);
38  pv.push_back (&ArgParser::do_check); i++;
39
40  parsers.add ("check_f", i);
41  parsers.add ("check_fi", i);
42  parsers.add ("check_fil", i);
43  parsers.add ("check_file", i);
44  parsers.add ("check_files", i);
45  pv.push_back (&ArgParser::do_check_files); i++;
46
47  parsers.add ("co", i);
48  parsers.add ("checkout", i);
49  pv.push_back (&ArgParser::do_checkout); i++;
50
51  parsers.add ("cl", i);
52  parsers.add ("cle", i);
53  parsers.add ("clea", i);
54  parsers.add ("clean", i);
55  parsers.add ("cleanu", i);
56  parsers.add ("cleanup", i);
57  pv.push_back (&ArgParser::do_cleanup); i++;
58
59  parsers.add ("con", i);
60  parsers.add ("conf", i);
61  parsers.add ("confi", i);
62  parsers.add ("config", i);
63  pv.push_back (&ArgParser::do_config); i++;
64
65  parsers.add ("create", i);
66  pv.push_back (&ArgParser::do_create); i++;
67
68  parsers.add ("create_project", i);
69  pv.push_back (&ArgParser::do_create_project); i++;
70
71  parsers.add ("cvsb", i);
72  parsers.add ("cvsbr", i);
73  parsers.add ("cvsbra", i);
74  parsers.add ("cvsbran", i);
75  parsers.add ("cvsbranc", i);
76  parsers.add ("cvsbranch", i);
77  parsers.add ("cvsbranche", i);
78  parsers.add ("cvsbranches", i);
79  pv.push_back (&ArgParser::do_cvsbranches); i++;
80
81  parsers.add ("cvssubpa", i);
82  parsers.add ("cvssubpac", i);
83  parsers.add ("cvssubpack", i);
84  parsers.add ("cvssubpacka", i);
85  parsers.add ("cvssubpackag", i);
86  parsers.add ("cvssubpackage", i);
87  parsers.add ("cvssubpackages", i);
88  pv.push_back (&ArgParser::do_cvssubpackages); i++;
89
90  parsers.add ("cvssubpr", i);
91  parsers.add ("cvssubpro", i);
92  parsers.add ("cvssubproj", i);
93  parsers.add ("cvssubproje", i);
94  parsers.add ("cvssubprojec", i);
95  parsers.add ("cvssubproject", i);
96  parsers.add ("cvssubprojects", i);
97  pv.push_back (&ArgParser::do_cvssubprojects); i++;
98
99  parsers.add ("cvst", i);
100  parsers.add ("cvsta", i);
101  parsers.add ("cvstag", i);
102  parsers.add ("cvstags", i);
103  pv.push_back (&ArgParser::do_cvstags); i++;
104
105  parsers.add ("d", i);
106  parsers.add ("do", i);
107  pv.push_back (&ArgParser::do_do); i++;
108
109  parsers.add ("e", i);
110  parsers.add ("ex", i);
111  parsers.add ("exp", i);
112  parsers.add ("expa", i);
113  parsers.add ("expan", i);
114  parsers.add ("expand", i);
115  pv.push_back (&ArgParser::do_expand); i++;
116
117  parsers.add ("f", i);
118  parsers.add ("fi", i);
119  parsers.add ("fil", i);
120  parsers.add ("filt", i);
121  parsers.add ("filte", i);
122  parsers.add ("filter", i);
123  pv.push_back (&ArgParser::do_filter); i++;
124
125  parsers.add ("h", i);
126  parsers.add ("he", i);
127  parsers.add ("hel", i);
128  parsers.add ("help", i);
129  pv.push_back (&ArgParser::do_help); i++;
130
131  parsers.add ("l", i);
132  parsers.add ("lo", i);
133  parsers.add ("loc", i);
134  parsers.add ("lock", i);
135  pv.push_back (&ArgParser::do_lock); i++;
136
137  parsers.add ("re", i);
138  parsers.add ("rem", i);
139  parsers.add ("remo", i);
140  parsers.add ("remov", i);
141  parsers.add ("remove", i);
142  pv.push_back (&ArgParser::do_remove); i++;
143
144  parsers.add ("run", i);
145  pv.push_back (&ArgParser::do_run); i++;
146
147  parsers.add ("run_sequence", i);
148  pv.push_back (&ArgParser::do_run_sequence); i++;
149
150  parsers.add ("set", i);
151  pv.push_back (&ArgParser::do_set); i++;
152
153  parsers.add ("setup", i);
154  pv.push_back (&ArgParser::do_setup); i++;
155
156  parsers.add ("sh", i);
157  parsers.add ("sho", i);
158  parsers.add ("show", i);
159  pv.push_back (&ArgParser::do_show); i++;
160
161  parsers.add ("sy", i);
162  parsers.add ("sys", i);
163  parsers.add ("syst", i);
164  parsers.add ("syste", i);
165  parsers.add ("system", i);
166  pv.push_back (&ArgParser::do_system); i++;
167
168  parsers.add ("u", i);
169  parsers.add ("un", i);
170  parsers.add ("unl", i);
171  parsers.add ("unlo", i);
172  parsers.add ("unloc", i);
173  parsers.add ("unlock", i);
174  pv.push_back (&ArgParser::do_unlock); i++;
175
176  parsers.add ("v", i);
177  parsers.add ("ve", i);
178  parsers.add ("ver", i);
179  parsers.add ("vers", i);
180  parsers.add ("versi", i);
181  parsers.add ("versio", i);
182  parsers.add ("version", i);
183  parsers.add ("--version", i);
184  pv.push_back (&ArgParser::do_version); i++;
185
186  parsers.add ("-b", i);
187  parsers.add ("-ba", i);
188  parsers.add ("-bat", i);
189  pv.push_back (&ArgParser::option_bat); i++;
190
191  parsers.add ("-c", i);
192  parsers.add ("-cs", i);
193  parsers.add ("-csh", i);
194  pv.push_back (&ArgParser::option_csh); i++;
195
196  parsers.add ("-e", i);
197  pv.push_back (&ArgParser::option_e); i++;
198
199  parsers.add ("-f", i);
200  pv.push_back (&ArgParser::option_f); i++;
201
202  parsers.add ("-h", i);
203  parsers.add ("-he", i);
204  parsers.add ("-hel", i);
205  parsers.add ("-help", i);
206  parsers.add ("--h", i);
207  parsers.add ("--he", i);
208  parsers.add ("--hel", i);
209  parsers.add ("--help", i);
210  pv.push_back (&ArgParser::option_help); i++;
211
212  parsers.add ("-ho", i);
213  parsers.add ("-hom", i);
214  parsers.add ("-home", i);
215  pv.push_back (&ArgParser::option_home); i++;
216
217  parsers.add ("-n", i);
218  pv.push_back (&ArgParser::option_n); i++;
219
220  parsers.add ("-no_c", i);
221  parsers.add ("-no_cl", i);
222  parsers.add ("-no_cle", i);
223  parsers.add ("-no_clea", i);
224  parsers.add ("-no_clean", i);
225  parsers.add ("-no_cleanu", i);
226  parsers.add ("-no_cleanup", i);
227  pv.push_back (&ArgParser::option_no_cleanup); i++;
228
229  parsers.add ("-pac", i);
230  parsers.add ("-pack", i);
231  pv.push_back (&ArgParser::option_pack); i++;
232
233  parsers.add ("-pat", i);
234  parsers.add ("-path", i);
235  pv.push_back (&ArgParser::option_path); i++;
236
237  parsers.add ("-pr", i);
238  parsers.add ("-pri", i);
239  parsers.add ("-priv", i);
240  parsers.add ("-priva", i);
241  parsers.add ("-privat", i);
242  parsers.add ("-private", i);
243  pv.push_back (&ArgParser::option_private); i++;
244
245  parsers.add ("-pu", i);
246  parsers.add ("-pub", i);
247  parsers.add ("-publ", i);
248  parsers.add ("-publi", i);
249  parsers.add ("-public", i);
250  pv.push_back (&ArgParser::option_public); i++;
251
252  parsers.add ("-s", i);
253  parsers.add ("-sh", i);
254  pv.push_back (&ArgParser::option_sh); i++;
255
256  parsers.add ("-q", i);
257  parsers.add ("-qu", i);
258  parsers.add ("-qui", i);
259  parsers.add ("-quie", i);
260  parsers.add ("-quiet", i);
261  pv.push_back (&ArgParser::option_quiet); i++;
262
263  parsers.add ("-tag", i);
264  pv.push_back (&ArgParser::option_tag); i++;
265
266  parsers.add ("-tag_add", i);
267  pv.push_back (&ArgParser::option_tag_add); i++;
268
269  parsers.add ("-tag_remove", i);
270  pv.push_back (&ArgParser::option_tag_remove); i++;
271
272  parsers.add ("-u", i);
273  parsers.add ("-us", i);
274  parsers.add ("-use", i);
275  pv.push_back (&ArgParser::option_use); i++;
276
277  parsers.add ("-user", i);
278  parsers.add ("-user_", i);
279  parsers.add ("-user_c", i);
280  parsers.add ("-user_co", i);
281  parsers.add ("-user_con", i);
282  parsers.add ("-user_cont", i);
283  parsers.add ("-user_conte", i);
284  parsers.add ("-user_contex", i);
285  parsers.add ("-user_context", i);
286  pv.push_back (&ArgParser::option_user_context); i++;
287
288  parsers.add ("-v", i);
289  parsers.add ("-ve", i);
290  parsers.add ("-ver", i);
291  parsers.add ("-vers", i);
292  parsers.add ("-versi", i);
293  parsers.add ("-versio", i);
294  parsers.add ("-version", i);
295  pv.push_back (&ArgParser::option_version); i++;
296
297  parsers.add ("-warn", i);
298  parsers.add ("-warni", i);
299  parsers.add ("-warnin", i);
300  parsers.add ("-warning", i);
301  parsers.add ("-warnings", i);
302  pv.push_back (&ArgParser::option_warnings); i++;
303
304  parsers.add ("-with_v", i);
305  parsers.add ("-with_ve", i);
306  parsers.add ("-with_ver", i);
307  parsers.add ("-with_vers", i);
308  parsers.add ("-with_versi", i);
309  parsers.add ("-with_versio", i);
310  parsers.add ("-with_version", i);
311  parsers.add ("-with_version_", i);
312  parsers.add ("-with_version_d", i);
313  parsers.add ("-with_version_di", i);
314  parsers.add ("-with_version_dir", i);
315  parsers.add ("-with_version_dire", i);
316  parsers.add ("-with_version_direc", i);
317  parsers.add ("-with_version_direct", i);
318  parsers.add ("-with_version_directo", i);
319  parsers.add ("-with_version_director", i);
320  parsers.add ("-with_version_directory", i);
321  pv.push_back (&ArgParser::option_with_version_directory); i++;
322
323  parsers.add ("-without_v", i);
324  parsers.add ("-without_ve", i);
325  parsers.add ("-without_ver", i);
326  parsers.add ("-without_vers", i);
327  parsers.add ("-without_versi", i);
328  parsers.add ("-without_versio", i);
329  parsers.add ("-without_version", i);
330  parsers.add ("-without_version_", i);
331  parsers.add ("-without_version_d", i);
332  parsers.add ("-without_version_di", i);
333  parsers.add ("-without_version_dir", i);
334  parsers.add ("-without_version_dire", i);
335  parsers.add ("-without_version_direc", i);
336  parsers.add ("-without_version_direct", i);
337  parsers.add ("-without_version_directo", i);
338  parsers.add ("-without_version_director", i);
339  parsers.add ("-without_version_directory", i);
340  pv.push_back (&ArgParser::option_without_version_directory); i++;
341
342}
343
344void ArgParser::shift ()
345{
346  if (argc > 0)
347    {
348      argc--;
349      argv++;
350    }
351}
352
353void ArgParser::unshift ()
354{
355  argc++;
356  argv--;
357}
358
359void ArgParser::fill_arguments ()
360{
361  while (argc > 0)
362    {
363      cmt_string& s = arguments.add ();
364      s = argv[0];
365
366      //cerr << "Getting arg[" << s << "] " << endl;
367
368      shift ();
369    } 
370}
371
372cmt_string& ArgParser::fill_one_argument ()
373{
374  if (argc > 0)
375    {
376      cmt_string& s = arguments.add ();
377      s = argv[0];
378
379      //cerr << "Getting arg[" << s << "] " << endl;
380
381      shift ();
382
383      return (s);
384    }
385  else
386    {
387      static cmt_string empty = "";
388      return (empty);
389    }
390}
391
392cmt_string& ArgParser::fill_one_argument_filtered ()
393{
394  if (argc > 0)
395    {
396      cmt_string& s = arguments.add ();
397      s = argv[0];
398
399      if (s[0] == '-')
400        {
401          s = "";
402        }
403
404      //cerr << "Getting arg[" << s << "] " << endl;
405
406      shift ();
407
408      return (s);
409    }
410  else
411    {
412      static cmt_string empty = "";
413      return (empty);
414    }
415}
416
417void ArgParser::parse ()
418{
419  ArgParser& me = *this;
420
421  help_action = action_none;
422  arguments.clear ();
423  extra_line.erase (0);
424  extra_file.erase (0);
425  mode = Csh;
426
427  /// Skip first argument ("cmt")
428  shift ();
429
430  cmt.m_action = action_none;
431
432  while (argc > 0)
433    {
434      arg = argv[0];
435
436      shift ();
437
438      /// Suppress trailing carriage-return
439      int cr = arg.find ('\r');
440      if (cr != cmt_string::npos) arg.erase (cr);
441
442      /// Suppress enclosing quotes
443      if ((arg[0] == '\"') && (arg[arg.size () - 1] == '\"'))
444        {
445          arg.erase (0, 1);
446          arg.erase (arg.size () - 1, 1);
447        }
448
449      /// Detect and split arguments of the form a=b
450      /// left and right part of this argument
451      cmt_string reduced_arg = arg;
452      int pos = reduced_arg.find ('=');
453      if (pos != cmt_string::npos)
454        {
455          reduced_arg.erase (pos);
456          arg.erase (0, pos+1);
457        }
458      else
459        {
460          arg = "";
461        }
462
463      //cerr << "argc=" << argc << " reduced_arg=[" << reduced_arg << "] arg=[" << arg << "]" << endl;
464
465      if (parsers.has (reduced_arg))
466        {
467          // This argument corresponds to a known command
468
469          int i = (*parsers.find (reduced_arg));
470
471          parser p = pv[i];
472          (me.*p) ();
473        }
474      else if (cmt.m_action != action_none)
475        {
476          // We have unexpected arguments (not handled by the command handler). This may sign
477          // an unprotected handler implementation.
478          if (!cmt.m_quiet) cerr << "#CMT> warning : unexpected parameter " << reduced_arg << endl;
479        }
480      else
481        {
482          // This argument does not correspond to a known command. We expect then an action
483          // to be executed with that name
484
485          unshift ();
486          do_do ();
487
488          /*
489              if (!cmt.m_quiet) cerr << "#CMT> syntax error : bad command parameter " << arg << endl;
490              help_action = action_none;
491          */
492        }
493    }
494}
495
496void ArgParser::do_awk ()
497{
498  fill_arguments ();
499  cmt.m_action = action_awk;
500}
501
502void ArgParser::do_broadcast ()
503{
504  fill_arguments ();
505  cmt.m_action = action_broadcast;
506 
507  if (cmt.m_scope_filtering_mode == default_filtering_mode)
508    {
509      cmt.m_scope_filtering_mode = reach_private_uses;
510    }
511}
512
513void ArgParser::do_build ()
514{
515  if (argc > 0)
516    {
517      arg = argv[0];
518
519      if (arg == "-nmake")
520        {
521          cmt.m_build_nmake = true;
522          shift ();
523        }
524    }
525
526  if (argc > 0)
527    {
528      arg = argv[0];
529
530      shift ();
531
532      if (arg == "constituent_makefile")
533        {
534          if (argc > 0)
535            {
536              fill_one_argument ();
537              cmt.m_action = action_build_constituent_makefile;
538            }
539          else
540            {
541              if (!cmt.m_quiet) cerr << "#CMT> syntax error : constituent name missing" << endl;
542              cmt.m_action = action_build_constituent_makefile;
543              help_action = action_help;
544            }
545        }
546      else if (arg == "constituents_makefile")
547        {
548          fill_arguments ();
549          cmt.m_action = action_build_constituents_makefile;
550        }
551      else if (arg == "dependencies")
552        {
553          if (argc > 0)
554            {
555              fill_arguments ();
556              cmt.m_action = action_build_dependencies;
557            }
558          else
559            {
560              if (!cmt.m_quiet) cerr << "#CMT> syntax error : arguments missing " << endl;
561              help_action = action_help;
562              cmt.m_action = action_build_dependencies;
563            }
564        }
565      else if (arg == "library_links")
566        {
567          cmt.m_action = action_build_library_links;
568        }
569      else if (arg == "make_setup")
570        {
571          cmt.m_action = action_build_make_setup;
572        }
573      else if (arg == "msdev")
574        {
575          if (argc > 0)
576            {
577              fill_one_argument_filtered ();
578            }
579
580          cmt.m_action = action_build_msdev;
581        }
582      else if (arg == "CMT_pacman")
583        {
584          cmt.m_action = action_build_CMT_pacman;
585        }
586      else if (arg == "vsnet") 
587        {
588          if (argc > 0)
589            {
590              fill_one_argument_filtered ();
591            }
592                                                                   
593          cmt.m_action = action_build_vsnet;                 
594        }                                             
595      else if (arg == "os9_makefile")
596        {
597          if (argc > 0)
598            {
599              fill_one_argument ();
600              cmt.m_action = action_build_os9_makefile;
601            }
602          else
603            {
604              if (!cmt.m_quiet) cerr << "#CMT> syntax error : arguments missing " << endl;
605              help_action = action_help;
606              cmt.m_action = action_build_os9_makefile;
607            }
608        }
609      else if (arg == "prototype")
610        {
611          if (argc > 0)
612            {
613              fill_one_argument ();
614              cmt.m_action = action_build_prototype;
615            }
616          else
617            {
618              if (!cmt.m_quiet) cerr << "#CMT> syntax error : arguments missing" << endl;
619              help_action = action_help;
620              cmt.m_action = action_build_prototype;
621            }
622        }
623      else if (arg == "readme")
624        {
625          cmt.m_action = action_build_readme;
626
627          fill_arguments ();
628        }
629      else if (arg == "tag_makefile")
630        {
631          cmt.m_action = action_build_tag_makefile;
632        }
633      else if (arg == "temporary_name")
634        {
635          cmt.m_action = action_build_temporary_name;
636        }
637      else if (arg == "triggers")
638        {
639          if (argc > 0)
640            {
641              fill_one_argument ();
642              cmt.m_action = action_build_triggers;
643            }
644          else
645            {
646              if (!cmt.m_quiet) cerr << "#CMT> syntax error : arguments missing" << endl;
647              help_action = action_help;
648              cmt.m_action = action_build_triggers;
649            }
650        }
651      else if (arg == "windefs")
652        {
653          if (argc > 0)
654            {
655              fill_one_argument ();
656              cmt.m_action = action_build_windefs;
657            }
658          else
659            {
660              if (!cmt.m_quiet) cerr << "#CMT> syntax error : arguments missing" << endl;
661              help_action = action_help;
662              cmt.m_action = action_build_windefs;
663            }
664        }
665      else
666        {
667          if (!cmt.m_quiet) cerr << "#CMT> syntax error : wrong build argument" << endl;
668          help_action = action_help;
669          cmt.m_action = action_build;
670        }
671    }
672  else
673    {
674      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to build" << endl;
675      help_action = action_help;
676      cmt.m_action = action_build;
677    }
678}
679
680void ArgParser::do_check ()
681{
682  if (argc > 0)
683    {
684      arg = argv[0];
685
686      shift ();
687
688      if (arg == "configuration")
689        {
690          cmt.m_action = action_check_configuration;
691          //cmt.m_warnings = true;
692        }
693      else if (arg == "files")
694        {
695          if (argc > 0)
696            {
697              fill_one_argument ();
698              if (argc > 0)
699                {
700                  fill_one_argument ();
701                  cmt.m_action = action_check_files;
702                }
703              else
704                {
705                  if (!cmt.m_quiet) cerr << "#CMT> syntax error : reference file name missing" 
706                                         << endl;
707                  help_action = action_help;
708                  cmt.m_action = action_check_files;
709                }
710            }
711          else
712            {
713              if (!cmt.m_quiet) cerr << "#CMT> syntax error : file name missing" << endl;
714              help_action = action_help;
715              cmt.m_action = action_check_files;
716            }
717        }
718      else if (arg == "version")
719        {
720          if (argc > 0)
721            {
722              fill_one_argument ();
723              cmt.m_action = action_check_version;
724            }
725          else
726            {
727              if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
728              help_action = action_help;
729              cmt.m_action = action_check_version;
730            }
731        }
732      else
733        {
734          if (!cmt.m_quiet) cerr << "#CMT> syntax error : bad check option" << endl;
735          help_action = action_help;
736          cmt.m_action = action_check;
737        }
738    }
739  else
740    {
741      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to check" << endl;
742      help_action = action_help;
743      cmt.m_action = action_check;
744    }
745}
746
747void ArgParser::do_check_files ()
748{
749  if (argc > 0)
750    {
751      fill_one_argument ();
752      if (argc > 0)
753        {
754          fill_one_argument ();
755          cmt.m_action = action_check_files;
756        }
757      else
758        {
759          if (!cmt.m_quiet) cerr << "#CMT> syntax error : reference file missing" << endl;
760          help_action = action_help;
761          cmt.m_action = action_check_files;
762        }
763    }
764  else
765    {
766      if (!cmt.m_quiet) cerr << "#CMT> syntax error : file name missing" << endl;
767      help_action = action_help;
768      cmt.m_action = action_check_files;
769    }
770}
771
772void ArgParser::do_checkout ()
773{
774  if (argc > 0)
775    {
776      fill_arguments ();
777      cmt.m_action = action_checkout;
778    }
779  else
780    {
781      if (!cmt.m_quiet) cerr << "#CMT> syntax error : checkout arguments missing" << endl;
782      help_action = action_help;
783      cmt.m_action = action_checkout;
784    }
785}
786
787void ArgParser::do_cleanup ()
788{
789  cmt.m_action = action_cleanup;
790}
791
792void ArgParser::do_config ()
793{
794  cmt.m_action = action_config;
795}
796
797void ArgParser::do_create ()
798{
799  if (argc > 0)
800    {
801      fill_arguments ();
802      cmt.m_action = action_create;
803    }
804  else
805    {
806      if (!cmt.m_quiet) cerr << "#CMT> syntax error : create arguments missing" << endl;
807      help_action = action_help;
808      cmt.m_action = action_create;
809    }
810}
811
812void ArgParser::do_create_project ()
813{
814  if (argc > 0)
815    {
816      fill_arguments ();
817      cmt.m_action = action_create_project;
818    }
819  else
820    {
821      if (!cmt.m_quiet) cerr << "#CMT> syntax error : create_project arguments missing" << endl;
822      help_action = action_help;
823      cmt.m_action = action_create_project;
824    }
825}
826
827void ArgParser::do_cvsbranches ()
828{
829  if (argc > 0)
830    {
831      fill_one_argument ();
832      cmt.m_action = action_cvsbranches;
833    }
834  else
835    {
836      if (!cmt.m_quiet) cerr << "#CMT> syntax error : cvsbranches arguments missing" << endl;
837      help_action = action_help;
838      cmt.m_action = action_cvsbranches;
839    }
840}
841
842void ArgParser::do_cvssubpackages ()
843{
844  if (argc > 0)
845    {
846      fill_one_argument ();
847    }
848
849  cmt.m_action = action_cvssubpackages;
850}
851
852void ArgParser::do_cvssubprojects ()
853{
854  if (argc > 0)
855    {
856      fill_one_argument ();
857    }
858
859  cmt.m_action = action_cvssubprojects;
860}
861
862void ArgParser::do_cvstags ()
863{
864  if (argc > 0)
865    {
866      fill_arguments ();
867      cmt.m_action = action_cvstags;
868    }
869  else
870    {
871      if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
872      help_action = action_help;
873      cmt.m_action = action_cvstags;
874    }
875}
876
877void ArgParser::do_do ()
878{
879  if (argc > 0)
880    {
881      fill_arguments ();
882                 
883      {
884        cmt_string tag_name = "target_";
885        tag_name += arguments[0];
886
887        Tag* tag;
888        tag = Tag::add (tag_name, PriorityUserTag, "action", 0);                     
889        tag->mark ();
890      }
891
892      cmt.m_action = action_do;
893    }
894  else
895    {
896      if (!cmt.m_quiet) cerr << "#CMT> syntax error : action not specified" << endl;
897      help_action = action_help;
898      cmt.m_action = action_do;
899    }
900}
901
902void ArgParser::do_expand ()
903{
904  if (argc > 0)
905    {
906      arg = argv[0];
907
908      shift ();
909      if (arg == "model")
910        {
911          if (argc > 0)
912            {
913              fill_arguments ();
914              cmt.m_action = action_expand_model;
915            }
916          else
917            {
918              if (!cmt.m_quiet) cerr << "#CMT> syntax error : model not specified" << endl;
919              help_action = action_help;
920              cmt.m_action = action_expand_model;
921            }
922        }
923      else
924        {
925          if (!cmt.m_quiet) cerr << "#CMT> syntax error : bad expand option" << endl;
926          help_action = action_help;
927          cmt.m_action = action_expand_model;
928        }
929    }
930  else
931    {
932      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to expand" << endl;
933      help_action = action_help;
934      cmt.m_action = action_expand_model;
935    }
936}
937
938void ArgParser::do_filter ()
939{
940  if (argc > 0)
941    {
942      fill_arguments ();
943      cmt.m_action = action_filter;
944    }
945  else
946    {
947      if (!cmt.m_quiet) cerr << "#CMT> syntax error : file to filter not specified" << endl;
948      help_action = action_help;
949      cmt.m_action = action_filter;
950    }
951}
952
953void ArgParser::do_help ()
954{
955  help_action = action_help;
956}
957
958void ArgParser::do_lock ()
959{
960  if (argc > 0)
961    {
962      cmt.m_current_package = fill_one_argument ();
963      cmt.m_current_version.erase (0);
964      cmt.m_current_path.erase (0);
965
966      if (argc > 0)
967        {
968          cmt.m_current_version = fill_one_argument ();
969          cmt.m_action = action_lock;
970
971          if (argc > 0)
972            {
973              cmt.m_current_path = fill_one_argument_filtered ();
974            }
975
976          cmt.m_current_access = UserMode;
977          (Use::current()).set (cmt.m_current_package, 
978                                cmt.m_current_version, 
979                                cmt.m_current_path);
980
981        }
982      else
983        {
984          if (!cmt.m_quiet) cerr << "#CMT> syntax error : version missing" << endl;
985          help_action = action_help;
986          cmt.m_action = action_lock;
987        }
988    }
989  else
990    {
991      cmt.m_action = action_lock;
992    }
993}
994
995void ArgParser::do_remove ()
996{
997  if (argc > 0)
998    {
999      arg = argv[0];
1000
1001      if (arg == "library_links")
1002        {
1003          shift ();
1004          cmt.m_action = action_remove_library_links;
1005        }
1006      else
1007        {
1008          cmt.m_current_package = fill_one_argument ();
1009          cmt.m_current_version.erase (0);
1010          cmt.m_current_path.erase (0);
1011                     
1012          if (argc > 0)
1013            {
1014              cmt.m_current_version = fill_one_argument ();
1015
1016              if (argc > 0)
1017                {
1018                  cmt.m_current_path = fill_one_argument_filtered ();
1019                }
1020                           
1021              cmt.m_action = action_remove;
1022            }
1023          else
1024            {
1025              if (!cmt.m_quiet) cerr << "#CMT> syntax error : version missing" << endl;
1026              help_action = action_help;
1027              cmt.m_action = action_remove;
1028            }
1029        }
1030    }
1031  else
1032    {
1033      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to remove" << endl;
1034      help_action = action_help;
1035      cmt.m_action = action_remove;
1036    }
1037}
1038
1039void ArgParser::do_run ()
1040{
1041  if (argc > 0)
1042    {
1043      fill_arguments ();
1044      cmt.m_action = action_run;
1045    }
1046  else
1047    {
1048      if (!cmt.m_quiet) cerr << "#CMT> syntax error : run arguments missing" << endl;
1049      help_action = action_help;
1050      cmt.m_action = action_run;
1051    }
1052}
1053
1054void ArgParser::do_run_sequence ()
1055{
1056  if (argc > 0)
1057    {
1058      fill_one_argument ();
1059      cmt.m_action = action_run_sequence;
1060    }
1061  else
1062    {
1063      if (!cmt.m_quiet) cerr << "#CMT> syntax error : run_sequence arguments missing" << endl;
1064      help_action = action_help;
1065      cmt.m_action = action_run_sequence;
1066    }
1067}
1068
1069void ArgParser::do_set ()
1070{
1071  if (argc > 0)
1072    {
1073      arg = argv[0];
1074
1075      shift ();
1076
1077      if (arg == "version")
1078        {
1079          fill_arguments ();
1080          cmt.m_action = action_set_version;
1081        }
1082      else if (arg == "versions")
1083        {
1084          fill_arguments ();
1085
1086          cmt.m_action = action_set_versions;
1087
1088          if (cmt.m_scope_filtering_mode == default_filtering_mode)
1089            {
1090              cmt.m_scope_filtering_mode = reach_private_uses;
1091            }
1092        }
1093      else
1094        {
1095          if (!cmt.m_quiet) cerr << "#CMT> syntax error : bad set argument" << endl;
1096          help_action = action_help;
1097          //cmt.m_action = action_set;
1098        }
1099    }
1100  else
1101    {
1102      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to set" << endl;
1103      help_action = action_help;
1104      //cmt.m_action = action_set;
1105    }
1106}
1107
1108void ArgParser::do_setup ()
1109{
1110  cmt.m_action = action_setup;
1111  //cmt.m_warnings = true;
1112}
1113
1114void ArgParser::do_show ()
1115{
1116  if (argc > 0)
1117    {
1118      arg = argv[0];
1119
1120      //cerr << "Running show arg=" << arg << endl;
1121
1122      shift ();
1123
1124      if (arg == "action")
1125        {
1126          if (argc > 0)
1127            {
1128              cmt.m_current_target = fill_one_argument ();
1129              cmt.m_action = action_show_action;
1130            }
1131          else
1132            {
1133              if (!cmt.m_quiet) cerr << "#CMT> syntax error : action name missing" << endl;
1134              help_action = action_help;
1135              cmt.m_action = action_show_action;
1136            }
1137        }
1138      else if (arg == "action_names")
1139        {
1140          if (argc > 0)
1141            {
1142              fill_one_argument ();
1143            }
1144
1145          cmt.m_action = action_show_action_names;
1146        }
1147      else if (arg == "action_value")
1148        {
1149          cmt.m_quiet = true;
1150          if (argc > 0)
1151            {
1152              cmt.m_current_target = fill_one_argument ();
1153              cmt.m_action = action_show_action_value;
1154            }
1155          else
1156            {
1157              if (!cmt.m_quiet) cerr << "#CMT> syntax error : action name missing" << endl;
1158              help_action = action_help;
1159              cmt.m_action = action_show_action_value;
1160            }
1161        }
1162      else if (arg == "actions")
1163        {
1164          if (argc > 0)
1165            {
1166              fill_one_argument ();
1167            }
1168
1169          cmt.m_action = action_show_actions;
1170        }
1171      else if (arg == "all_tags")
1172        {
1173          cmt.m_action = action_show_all_tags;
1174        }
1175      else if (arg == "applied_patterns")
1176        {
1177          cmt.m_action = action_show_applied_patterns;
1178        }
1179      else if (arg == "author")
1180        {
1181          cmt.m_action = action_show_author;
1182        }
1183      else if (arg == "branches")
1184        {
1185          cmt.m_action = action_show_branches;
1186        }
1187      else if (arg == "clients")
1188        {
1189          if (argc > 0)
1190            {
1191              cmt.m_current_target = fill_one_argument ();
1192
1193              cmt.m_action = action_show_clients;
1194
1195              if (argc > 0)
1196                {
1197                  fill_one_argument ();
1198                  if (argc > 0)
1199                    {
1200                      fill_one_argument ();
1201                    }
1202                }
1203            }
1204          else
1205            {
1206              if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
1207              help_action = action_help;
1208              cmt.m_action = action_show_clients;
1209            }
1210        }
1211      else if (arg == "cmtpath_patterns")
1212        {
1213          cmt.m_action = action_show_cmtpath_patterns;
1214        }
1215      else if (arg == "constituent")
1216        {
1217          if (argc > 0)
1218            {
1219              cmt.m_current_target = fill_one_argument ();
1220              cmt.m_action = action_show_constituent;
1221            }
1222          else
1223            {
1224              if (!cmt.m_quiet) cerr << "#CMT> syntax error : constituent name missing" << endl;
1225              help_action = action_help;
1226              cmt.m_action = action_show_constituent;
1227            }
1228        }
1229      else if (arg == "constituent_names")
1230        {
1231          cmt.m_action = action_show_constituent_names;
1232        }
1233      else if (arg == "constituents")
1234        {
1235          cmt.m_action = action_show_constituents;
1236        }
1237      else if (arg == "cycles")
1238        {
1239          cmt.m_action = action_show_cycles;
1240        }
1241      else if (arg == "fragment")
1242        {
1243          if (argc > 0)
1244            {
1245              cmt.m_current_target = fill_one_argument ();
1246              cmt.m_action = action_show_fragment;
1247            }
1248          else
1249            {
1250              if (!cmt.m_quiet) cerr << "#CMT> syntax error : fragment name missing" << endl;
1251              help_action = action_help;
1252              cmt.m_action = action_show_fragment;
1253            }
1254        }
1255      else if (arg == "fragments")
1256        {
1257          cmt.m_action = action_show_fragments;
1258        }
1259      else if (arg == "groups")
1260        {
1261          cmt.m_action = action_show_groups;
1262        }
1263      else if (arg == "include_dirs")
1264        {
1265          cmt.m_action = action_show_include_dirs;
1266        }
1267      else if (arg == "language")
1268        {
1269          if (argc > 0)
1270            {
1271              cmt.m_current_target = fill_one_argument ();
1272              cmt.m_action = action_show_language;
1273            }
1274          else
1275            {
1276              if (!cmt.m_quiet) cerr << "#CMT> syntax error : language name missing" << endl;
1277              help_action = action_help;
1278              cmt.m_action = action_show_language;
1279            }
1280        }
1281      else if (arg == "languages")
1282        {
1283          cmt.m_action = action_show_languages;
1284        }
1285      else if (arg == "macro")
1286        {
1287          if (argc > 0)
1288            {
1289              cmt.m_current_target = fill_one_argument ();
1290              cmt.m_action = action_show_macro;
1291            }
1292          else
1293            {
1294              if (!cmt.m_quiet) cerr << "#CMT> syntax error : macro name missing" << endl;
1295              help_action = action_help;
1296              cmt.m_action = action_show_macro;
1297            }
1298        }
1299      else if (arg == "macro_names")
1300        {
1301          if (argc > 0)
1302            {
1303              fill_one_argument ();
1304            }
1305
1306          cmt.m_action = action_show_macro_names;
1307        }
1308      else if (arg == "macro_value")
1309        {
1310          cmt.m_quiet = true;
1311          if (argc > 0)
1312            {
1313              cmt.m_current_target = fill_one_argument ();
1314              cmt.m_action = action_show_macro_value;
1315            }
1316          else
1317            {
1318              if (!cmt.m_quiet) cerr << "#CMT> syntax error : macro name missing" << endl;
1319              help_action = action_help;
1320              cmt.m_action = action_show_macro_value;
1321            }
1322        }
1323      else if (arg == "macros")
1324        {
1325          if (argc > 0)
1326            {
1327              fill_one_argument ();
1328            }
1329
1330          cmt.m_action = action_show_macros;
1331        }
1332      else if (arg == "manager")
1333        {
1334          cmt.m_action = action_show_manager;
1335        }
1336      else if (arg == "packages")
1337        {
1338          if (argc > 0)
1339            {
1340              cmt.m_current_target = fill_one_argument ();
1341            }
1342
1343          cmt.m_action = action_show_packages;
1344        }
1345      else if (arg == "path")
1346        {
1347          cmt.m_action = action_show_path;
1348        }
1349      else if (arg == "pattern")
1350        {
1351          if (argc > 0)
1352            {
1353              cmt.m_current_target = fill_one_argument ();
1354              cmt.m_action = action_show_pattern;
1355            }
1356          else
1357            {
1358              if (!cmt.m_quiet) cerr << "#CMT> syntax error : pattern name missing" << endl;
1359              help_action = action_help;
1360              cmt.m_action = action_show_pattern;
1361            }
1362        }
1363      else if (arg == "pattern_names")
1364        {
1365          cmt.m_action = action_show_pattern_names;
1366        }
1367      else if (arg == "patterns")
1368        {
1369          cmt.m_action = action_show_patterns;
1370        }
1371      else if (arg == "projects")
1372        {
1373          cmt.m_action = action_show_projects;
1374        }
1375      else if (arg == "pwd")
1376        {
1377          cmt.m_action = action_show_pwd;
1378        }
1379      else if (arg == "setup")
1380        {
1381          cmt.m_action = action_show_setup;
1382
1383          if (cmt.m_scope_filtering_mode == default_filtering_mode)
1384            {
1385              cmt.m_scope_filtering_mode = reach_private_uses;
1386            }
1387        }
1388      else if (arg == "set_names")
1389        {
1390          if (argc > 0)
1391            {
1392              fill_one_argument ();
1393            }
1394
1395          cmt.m_action = action_show_set_names;
1396        }
1397      else if (arg == "set_value")
1398        {
1399          cmt.m_quiet = true;
1400          if (argc > 0)
1401            {
1402              cmt.m_current_target = fill_one_argument ();
1403              cmt.m_action = action_show_set_value;
1404            }
1405          else
1406            {
1407              if (!cmt.m_quiet) cerr << "#CMT> syntax error : set name missing" << endl;
1408              help_action = action_help;
1409              cmt.m_action = action_show_set_value;
1410            }
1411        }
1412      else if (arg == "set")
1413        {
1414          if (argc > 0)
1415            {
1416              cmt.m_current_target = fill_one_argument ();
1417              cmt.m_action = action_show_set;
1418            }
1419          else
1420            {
1421              if (!cmt.m_quiet) cerr << "#CMT> syntax error : set name missing" << endl;
1422              help_action = action_help;
1423              cmt.m_action = action_show_set;
1424            }
1425        }
1426      else if (arg == "sets")
1427        {
1428          if (argc > 0)
1429            {
1430              fill_one_argument ();
1431            }
1432
1433          cmt.m_action = action_show_sets;
1434        }
1435      else if (arg == "strategies")
1436        {
1437          cmt.m_action = action_show_strategies;
1438        }
1439      else if (arg == "tags")
1440        {
1441          cmt.m_action = action_show_tags;
1442        }
1443      else if (arg == "use_paths")
1444        {
1445          if (argc > 0)
1446            {
1447              while (argc > 0)
1448                {
1449                  if (strcmp (argv[0], "-private") == 0)
1450                    {
1451                      cmt.m_scope_filtering_mode = reach_private_uses;
1452                    }
1453                  else if (strcmp (argv[0], "--private") == 0)
1454                    {
1455                      cmt.m_scope_filtering_mode = reach_private_uses;
1456                    }
1457                  else
1458                    {
1459                      cmt_string& s = arguments.add ();
1460                      s = argv[0];
1461                    }
1462
1463                  shift ();
1464                }
1465
1466              cmt.m_action = action_show_use_paths;
1467            }
1468          else
1469            {
1470              if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
1471              help_action = action_help;
1472              cmt.m_action = action_show_use_paths;
1473            }
1474        }
1475      else if ((arg == "u") ||
1476               (arg == "us") ||
1477               (arg == "use") ||
1478               (arg == "uses"))
1479        {
1480          cmt.m_action = action_show_uses;
1481
1482          if (cmt.m_scope_filtering_mode == default_filtering_mode)
1483            {
1484              cmt.m_scope_filtering_mode = reach_private_uses;
1485            }
1486        }
1487      else if (arg == "version")
1488        {
1489          cmt.m_action = action_show_version;
1490        }
1491      else if (arg == "versions")
1492        {
1493          if (argc > 0)
1494            {
1495              cmt.m_current_target = fill_one_argument ();
1496              cmt.m_action = action_show_versions;
1497            }
1498          else
1499            {
1500              if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
1501              help_action = action_help;
1502              cmt.m_action = action_show_versions;
1503            }
1504        }
1505      else
1506        {
1507          if (!cmt.m_quiet) cerr << "#CMT> syntax error : bad show argument" << endl;
1508          help_action = action_help;
1509          cmt.m_action = action_show;
1510        }
1511    }
1512  else
1513    {
1514      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to show" << endl;
1515      help_action = action_help;
1516      cmt.m_action = action_show;
1517    }
1518}
1519
1520void ArgParser::do_system ()
1521{
1522  cmt.m_action = action_system;
1523}
1524
1525void ArgParser::do_unlock ()
1526{
1527  if (argc > 0)
1528    {
1529      cmt.m_current_package = fill_one_argument ();
1530      cmt.m_current_version.erase (0);
1531      cmt.m_current_path.erase (0);
1532                                       
1533      if (argc > 0)
1534        {
1535          cmt.m_current_version = fill_one_argument ();
1536          cmt.m_action = action_unlock;
1537
1538          if (argc > 0)
1539            {
1540              cmt.m_current_path = fill_one_argument_filtered ();
1541            }
1542                                               
1543          cmt.m_current_access = UserMode;
1544          (Use::current()).set (cmt.m_current_package, 
1545                                cmt.m_current_version, 
1546                                cmt.m_current_path);
1547
1548        }
1549      else
1550        {
1551          if (!cmt.m_quiet) cerr << "#CMT> syntax error : version missing" << endl;
1552          help_action = action_help;
1553          cmt.m_action = action_unlock;
1554        }
1555    }
1556  else
1557    {
1558      cmt.m_action = action_unlock;
1559    }
1560}
1561
1562void ArgParser::do_version ()
1563{
1564  cmt.m_action = action_version;
1565}
1566
1567void ArgParser::option_help ()
1568{
1569  help_action = action_help;
1570}
1571
1572void ArgParser::option_n ()
1573{
1574  cmt.m_simulation = true;
1575}
1576
1577void ArgParser::option_quiet ()
1578{
1579  cmt.m_quiet = true;
1580}
1581
1582void ArgParser::option_warnings ()
1583{
1584  cmt.m_warnings = true;
1585}
1586
1587void ArgParser::option_csh ()
1588{
1589  mode = Csh;
1590}
1591
1592void ArgParser::option_sh ()
1593{
1594  mode = Sh;
1595}
1596
1597void ArgParser::option_bat ()
1598{
1599  mode = Bat;
1600}
1601
1602void ArgParser::option_use ()
1603{
1604  if (cmt.m_action != action_create)
1605    {
1606      CmtSystem::cmt_string_vector words;
1607
1608      CmtSystem::split (arg, ":", words);
1609
1610      cmt.m_current_access = UserMode;
1611
1612      if (words.size () > 0) cmt.m_current_package = words[0];
1613      if (words.size () > 1) cmt.m_current_version = words[1];
1614      if (words.size () > 2) cmt.m_current_path    = words[2];
1615      (Use::current()).set (cmt.m_current_package, 
1616                            cmt.m_current_version, 
1617                            cmt.m_current_path);
1618    }
1619}
1620
1621void ArgParser::option_pack ()
1622{
1623  if ((cmt.m_action != action_create) && (cmt.m_current_package != arg))
1624    {
1625      //CmtSystem::cd (cmt.m_default_path);
1626
1627      cmt.m_current_access = UserMode;
1628
1629      cmt.m_current_package = arg;
1630      cmt.m_current_version = "";
1631
1632      /*
1633      cerr << "ArgParser::option_pack> "
1634           << " cp=" << cmt.m_current_package
1635           << " cv=" << cmt.m_current_version
1636           << " cp=" << cmt.m_current_path << endl;
1637      */
1638
1639      (Use::current()).set (cmt.m_current_package, 
1640                            cmt.m_current_version, 
1641                            cmt.m_current_path);
1642    }
1643}
1644
1645void ArgParser::option_version ()
1646{
1647  if ((cmt.m_action != action_create) && (cmt.m_current_version != arg))
1648    {
1649      cmt.m_current_access = UserMode;
1650      cmt.m_current_version = arg;
1651
1652      /*
1653      cerr << "ArgParser::option_version> "
1654           << " cp=" << cmt.m_current_package
1655           << " cv=" << cmt.m_current_version
1656           << " cp=" << cmt.m_current_path << endl;
1657      */
1658
1659      (Use::current()).set (cmt.m_current_package, 
1660                            cmt.m_current_version, 
1661                            cmt.m_current_path);
1662    }
1663}
1664
1665void ArgParser::option_path ()
1666{
1667  if ((cmt.m_action != action_create) && (cmt.m_current_path != arg))
1668    {
1669      cmt.m_current_access = UserMode;
1670      cmt.m_current_path = arg;
1671
1672      /*
1673      cerr << "ArgParser::option_path> "
1674           << " cp=" << cmt.m_current_package
1675           << " cv=" << cmt.m_current_version
1676           << " cp=" << cmt.m_current_path << endl;
1677      */
1678
1679      (Use::current()).set (cmt.m_current_package, 
1680                            cmt.m_current_version, 
1681                            cmt.m_current_path);
1682
1683      //IProjectFactory& factory = ProjectFactory::instance ();
1684      //CmtSystem::add_cmt_path (cmt.m_current_path, "argument", factory);
1685    }
1686}
1687
1688void ArgParser::option_f ()
1689{
1690  extra_file = arg;
1691}
1692
1693void ArgParser::option_e ()
1694{
1695  cerr << "#CMT> Warning: extra statement = " << arg << endl;
1696  extra_line = arg;
1697}
1698
1699void ArgParser::option_home ()
1700{
1701  if (CmtSystem::test_directory (arg))
1702    {
1703      cmt.m_cmt_home = arg;
1704    }
1705}
1706
1707void ArgParser::option_tag ()
1708{
1709  /*
1710    Here we are going to change the complete tag set
1711  */
1712             
1713  if (arg != "")
1714    {
1715      Tag* tag;
1716      CmtSystem::cmt_string_vector words;
1717
1718      // First reset selection of all existing tags
1719      //Tag::clear_all ();
1720      Tag::unmark_all ();
1721      cmt.m_extra_tags = ",";
1722                   
1723      // Then restore CMTSITE
1724      Cmt::configure_version_tag ();
1725      Cmt::configure_site_tag (0);
1726      Cmt::configure_uname_tag ();
1727      Cmt::configure_hosttype_tag ();
1728      Cmt::configure_config_tag ();
1729      Cmt::configure_home (0);
1730      Cmt::guess_current_project ();
1731
1732      CmtSystem::split (arg, " \t,", words);
1733                 
1734      for (int i = 0; i < words.size (); i++)
1735        {
1736          const cmt_string& a = words[i];
1737                     
1738          cmt_string s = ",";
1739          s += a;
1740          s += ",";
1741                     
1742          if (i == 0)
1743            {
1744              cmt.m_current_tag = a;
1745                         
1746              if (CmtSystem::testenv ("TAGDEBUG")) cerr
1747                << "parse_argument(tag_add)> current_tag=" << cmt.m_current_tag << endl;
1748            }
1749                     
1750          if (cmt.m_extra_tags.find (s) == cmt_string::npos)
1751            {
1752              //if (!cmt.m_quiet) cerr << "  a=[" << a << "]" << endl;
1753                         
1754              // Then restore uname if the specified tag is CMTCONFIG
1755              if (a == CmtSystem::get_cmt_config ())
1756                {
1757                  Cmt::configure_uname_tag ();
1758                }
1759                         
1760              tag = Tag::add (a, PriorityArgument, "arguments", 0);
1761                         
1762              tag->mark ();
1763                         
1764              cmt.m_extra_tags += a;
1765              cmt.m_extra_tags += ",";
1766            }
1767        }
1768    }
1769}
1770
1771void ArgParser::option_tag_add ()
1772{
1773  Tag* tag;
1774  CmtSystem::cmt_string_vector words;
1775             
1776  //if (!cmt.m_quiet) cerr << "-tag_add=" << arg << endl;
1777
1778  CmtSystem::split (arg, " \t,", words);
1779
1780  for (int i = 0; i < words.size (); i++)
1781    {
1782      const cmt_string& a = words[i];
1783
1784      cmt_string s = ",";
1785      s += a;
1786      s += ",";
1787
1788      if (cmt.m_extra_tags.find (s) == cmt_string::npos)
1789        {
1790          //if (!cmt.m_quiet) cerr << "  a=[" << a << "]" << endl;
1791
1792          /// Then restore uname if the specified tag is CMTCONFIG
1793          if (a == CmtSystem::get_cmt_config ())
1794            {
1795              Cmt::configure_uname_tag ();
1796            }
1797                     
1798          tag = Tag::add (a, PriorityUserTag, "arguments", 0);
1799                     
1800          tag->mark ();
1801
1802          cmt.m_extra_tags += a;
1803          cmt.m_extra_tags += ",";
1804        }
1805    }
1806}
1807
1808void ArgParser::option_tag_remove ()
1809{
1810  Tag::TagPtrVector tags = Tag::tags ();
1811  int i;
1812  Tag* tag;
1813
1814  /*
1815    for (i = 0; i < tags.size (); i++)
1816    {
1817    tag = tags[i];
1818    if ((tag != 0) &&
1819    (tag->selected))
1820    {
1821    if (!cmt.m_quiet) cerr << "  original tag_list=" << tag->name << tag->priority << endl;
1822    }
1823    }
1824  */
1825
1826  CmtSystem::cmt_string_vector words;
1827
1828  //if (!cmt.m_quiet) cerr << "-arg_remove=" << arg << endl;
1829
1830  CmtSystem::split (arg, " \t,", words);
1831
1832  //
1833  // Now erase all entries in the old list that match
1834  // the specified tags
1835  //
1836
1837  for (i = 0; i < words.size (); i++)
1838    {
1839      const cmt_string& a = words[i];
1840
1841      cmt_string s = ",";
1842      s += a;
1843      s += ",";
1844
1845      int pos;
1846
1847      pos = cmt.m_extra_tags.find (s);
1848
1849      if (pos != cmt_string::npos)
1850        {
1851          cmt.m_extra_tags.erase (pos, s.size () - 1);
1852        }
1853
1854      //if (!cmt.m_quiet) cerr << "  tag_list=[" << tag_list << "]" << endl;
1855    }
1856
1857  //
1858  // Now reinject the purged list of tags into the database
1859  // exactly as when using -tag=<tag-list>
1860  //
1861
1862  /// First forget about all existing tags
1863      Tag::unmark_all ();
1864
1865      /// Then restore CMTSITE
1866        Cmt::configure_version_tag ();
1867        Cmt::configure_site_tag (0);
1868        Cmt::configure_uname_tag ();
1869        Cmt::configure_hosttype_tag ();
1870             
1871        CmtSystem::split (cmt.m_extra_tags, " \t,", words);
1872
1873        for (i = 0; i < words.size (); i++)
1874          {
1875            const cmt_string& a = words[i];
1876
1877            //fprintf (stderr, "  a=[%s]\n", a.c_str ());
1878
1879            /// Then restore uname if the specified tag is CMTCONFIG
1880              if (a == CmtSystem::get_cmt_config ())
1881                {
1882                  Cmt::configure_uname_tag ();
1883                }
1884
1885              if (i == 0)
1886                {
1887                  cmt.m_current_tag = a;
1888
1889                  //if (!cmt.m_quiet) cerr << "parse_argument(tag_remove)> current_tag="
1890                  //<< cmt.m_current_tag << endl;
1891
1892                  tag = Tag::add (a, PriorityTag, "restore configuration", 0);
1893                }
1894              else
1895                {
1896                  tag = Tag::add (a, PriorityUserTag, "restore configuration", 0);
1897                }
1898
1899              tag->mark ();
1900          }
1901}
1902
1903void ArgParser::option_user_context ()
1904{
1905  if (CmtSystem::test_directory (arg))
1906    {
1907      cmt.m_cmt_user_context = arg;
1908    }
1909}
1910
1911void ArgParser::option_with_version_directory ()
1912{
1913  cmt.m_current_structuring_style = with_version_directory;
1914
1915  StrategyDef* def = StrategyMgr::find_strategy ("VersionDirectory");
1916  if (def != 0)
1917    {
1918      def->m_default_value = true;
1919      def->m_priority_value = false;
1920    }
1921}
1922
1923void ArgParser::option_without_version_directory ()
1924{
1925  cmt.m_current_structuring_style = without_version_directory;
1926
1927  StrategyDef* def = StrategyMgr::find_strategy ("VersionDirectory");
1928  if (def != 0)
1929    {
1930      def->m_default_value = false;
1931      def->m_priority_value = true;
1932    }
1933}
1934
1935void ArgParser::option_no_cleanup ()
1936{
1937  //cmt.m_current_setup_strategy |= SetupNoCleanup;
1938}
1939
1940void ArgParser::option_private ()
1941{
1942  cmt.m_scope_filtering_mode = reach_private_uses;
1943}
1944
1945void ArgParser::option_public ()
1946{
1947  cmt.m_scope_filtering_mode = block_private_uses;
1948}
1949
1950
1951
1952
1953
1954
1955CommandHelp::HelpMap& CommandHelp::get_help ()
1956{
1957  static CommandHelp& me = instance ();
1958
1959  return (me.m_help);
1960}
1961
1962CommandHelp::HelpTexts& CommandHelp::get_help_texts ()
1963{
1964  static CommandHelp& me = instance ();
1965
1966  return (me.m_help_texts);
1967}
1968
1969const cmt_string& CommandHelp::get_help_text (ActionType key)
1970{
1971  static const HelpTexts& help = get_help_texts ();
1972
1973  const cmt_string& h = help[key];
1974  return (h);
1975}
1976
1977void CommandHelp::show_all ()
1978{
1979  static HelpTexts& help_texts = get_help_texts ();
1980
1981  cerr << "#> cmt command [option...]" << endl;
1982  cerr << "# command :" << endl;
1983
1984  int i;
1985
1986  for (i = 0; ; i++)
1987    {
1988      const cmt_string& s = help_texts[i];
1989      if (s == "") break;
1990      cerr << "#   " << s << endl;
1991    }
1992
1993  cerr << "# global options :" << endl;
1994
1995  cerr << "#   -quiet                  : don't print errors" << endl;
1996  cerr << "#   -use=<p>:<v>:<path>     : set package version path" << endl;
1997  cerr << "#   -pack=<package>         : set package" << endl;
1998  cerr << "#   -version=<version>      : set version" << endl;
1999  cerr << "#   -path=<path>            : set root path" << endl;
2000  cerr << "#   -f=<requirement-file>   : set input file" << endl;
2001  cerr << "#   -e=<statement>          : add a one line statement" << endl;
2002  cerr << "#   -tag=<tag-list>         : select a new tag-set" << endl;
2003  cerr << "#   -tag_add=<tag-list>     : add specific comma-separated tag(s)" << endl;
2004  cerr << "#   -tag_remove=<tag-list>  : remove specific comma-separated tag(s)" << endl;
2005  cerr << "#   -warnings               : display various warnings" << endl;
2006  cerr << "#   -with_version_directory : reset to default structuring style" << endl;
2007  cerr << "#   -without_version_directory : switch structuring style" << endl;
2008  cerr << "#   -cleanup                : activate install area cleanup" << endl;
2009  cerr << "#   -no_cleanup             : inhibit install area cleanup" << endl;
2010}
2011
2012void CommandHelp::show (ActionType action)
2013{
2014  //cerr << "CommandHelp::show> action = " << action << endl;
2015
2016  static HelpTexts& help_texts = get_help_texts ();
2017
2018  if (action == action_build)
2019    {
2020      int i;
2021
2022      for (i = action_build_constituent_makefile; i <= action_build_windefs; i++)
2023        {
2024          const cmt_string& s = help_texts[i];
2025          cerr << "#   " << s << endl;
2026        }
2027    }
2028  if (action == action_check)
2029    {
2030      int i;
2031
2032      for (i = action_check_configuration; i <= action_check_version; i++)
2033        {
2034          const cmt_string& s = help_texts[i];
2035          cerr << "#   " << s << endl;
2036        }
2037    }
2038  else if (action == action_show)
2039    {
2040      int i;
2041
2042      for (i = (action_show + 1); i <= action_show_versions; i++)
2043        {
2044          const cmt_string& s = help_texts[i];
2045          cerr << "#   " << s << endl;
2046        }
2047    }
2048  else
2049    {
2050      const cmt_string& s = get_help_text (action);
2051      cerr << "#" << s << endl;
2052    }
2053}
2054
2055CommandHelp& CommandHelp::instance ()
2056{
2057  static CommandHelp me;
2058  return (me);
2059}
2060
2061CommandHelp::CommandHelp ()
2062{
2063  static HelpMap& help = m_help;
2064
2065  static HelpTexts& help_texts = m_help_texts;
2066
2067  help_texts.clear ();
2068
2069  help_texts.add () =  "none";
2070  help_texts.add () =  "awk";
2071  help_texts.add () =  "broadcast [-select=list] [-exclude=list] [-local] [-global] [-begin=pattern] [-depth=n] <command> : apply a command to [some of] the used packages";
2072  help_texts.add () =  "build <option>          : build actions. (Try cmt help build)";
2073  help_texts.add () =  "build constituent_makefile <constituent>  : generate constituent Makefile fragment";
2074  help_texts.add () =  "build constituents_makefile : generate constituents.make";
2075  help_texts.add () =  "build dependencies      : generate dependencies";
2076  help_texts.add () =  "build library_links     : build symbolic links towards all imported libraries";
2077  help_texts.add () =  "build make_setup        : build a compiled version of setup scripts";
2078  help_texts.add () =  "build msdev             : generate MSDEV files";
2079  help_texts.add () =  "build CMT_pacman        : generate PACMAN manifest file for CMT";
2080  help_texts.add () =  "build vsnet             : generate VS.NET files";
2081  help_texts.add () =  "build os9_makefile      : generate Makefile for OS9";
2082  help_texts.add () =  "build prototype         : generate prototype file";
2083  help_texts.add () =  "build readme            : generate README.html";
2084  help_texts.add () =  "build tag_makefile      : generate tag specific Makefile";
2085  help_texts.add () =  "build temporary_name    : generate a name for a temprary file";
2086  help_texts.add () =  "build triggers <constituent> : generate library trigger file";
2087  help_texts.add () =  "build windefs <library_name> : generate def file for Windows shared libraries";
2088  help_texts.add () =  "check <option>          : check actions. (Try cmt help check)";
2089  help_texts.add () =  "check configuration     : check configuration";
2090  help_texts.add () =  "check files <old> <new> : compare two files and overrides <old> by <new> if different";
2091  help_texts.add () =  "check version <name>    : check if a name follows a version tag syntax ";
2092  help_texts.add () =  "co | checkout           : perform a cvs checkout over a CMT package";
2093  help_texts.add () =  "cleanup [-csh|-sh|-bat] : generate a cleanup script";
2094  help_texts.add () =  "config                  : generate setup and cleanup scripts";
2095  help_texts.add () =  "create <package> <version> [<path>] : create and configure a new package";
2096  help_texts.add () =  "create_project <project> <name> [<path>] : create and configure a new project";
2097  help_texts.add () =  "cvsbranches <module>      : display the subdirectories for a module";
2098  help_texts.add () =  "cvssubpackages <module>   : display the subpackages for a module";
2099  help_texts.add () =  "cvssubprojects <module>   : display the subprojects for a module";
2100  help_texts.add () =  "cvstags <module>          : display the CVS tags for a module";
2101  help_texts.add () =  "do <action> [<param>=<value>] ... : Execute an action";
2102  help_texts.add () =  "expand model <model>    : ";
2103  help_texts.add () =  "filter <in> <out>       : filter a file against CMT macros and env. variables";
2104  help_texts.add () =  "help | -help | --help   : display this help";
2105  help_texts.add () =  "load";
2106  help_texts.add () =  "lock [<p> <v> [<path>]] : lock a package";
2107  help_texts.add () =  "remove <package> <version> [<path>] : remove a package version";
2108  help_texts.add () =  "remove library_links    : remove symbolic links towards all imported libraries";
2109  help_texts.add () =  "run '<command>'         : apply a command";
2110  help_texts.add () =  "run_sequence <sequence file> : execute a cmt equence file";
2111  help_texts.add () =  "set version <version>   : generate a version file in the current package";
2112  help_texts.add () =  "set versions            : generate version files into packages";
2113  help_texts.add () =  "setup [-csh|-sh|-bat]   : generate a setup script";
2114  help_texts.add () =  "show <option>           : query actions. (Try cmt help show)";
2115  help_texts.add () =  "show  action <name>     :  a formatted action definition";
2116  help_texts.add () =  "show  action_value <name> :  a raw action definition";
2117  help_texts.add () =  "show  action_names      :  all action names";
2118  help_texts.add () =  "show  actions           :  all action definitions";
2119  help_texts.add () =  "show  all_tags          :  all defined tags";
2120  help_texts.add () =  "show  applied_patterns  :  all patterns actually applied";
2121  help_texts.add () =  "show  author            :  package author";
2122  help_texts.add () =  "show  branches          :  added branches";
2123  help_texts.add () =  "show  clients           :  package clients";
2124  help_texts.add () =  "show  cmtpath_patterns  :  cmtpath_patterns";
2125  help_texts.add () =  "show  constituent <name>:  constituent definition";
2126  help_texts.add () =  "show  constituent_names :  constituent names";
2127  help_texts.add () =  "show  constituents      :  constituent definitions";
2128  help_texts.add () =  "show  cycles            :  cycles in the use graph";
2129  help_texts.add () =  "show  fragment <name>   :  one fragment definition";
2130  help_texts.add () =  "show  fragments         :  fragment definitions";
2131  help_texts.add () =  "show  groups            :  group definitions";
2132  help_texts.add () =  "show  include_dirs      :  ";
2133  help_texts.add () =  "show  language <name>   :  language definition";
2134  help_texts.add () =  "show  languages         :  language definitions";
2135  help_texts.add () =  "show  macro <name>      :  a formatted macro definition";
2136  help_texts.add () =  "show  macro_value <name>  :  a raw macro definition";
2137  help_texts.add () =  "show  macro_names       :  all macro names";
2138  help_texts.add () =  "show  macros            :  all macro definitions";
2139  help_texts.add () =  "show  manager           :  package manager";
2140  help_texts.add () =  "show  packages          :  packages reachable from the current context";
2141  help_texts.add () =  "show  path              :  the package search list";
2142  help_texts.add () =  "show  pattern <name>    :  the pattern definition and usages";
2143  help_texts.add () =  "show  pattern_names     :  pattern names";
2144  help_texts.add () =  "show  patterns          :  the pattern definitions";
2145  help_texts.add () =  "show  projects          :  project definitions";
2146  help_texts.add () =  "show  setup             :  setup definitions";
2147  help_texts.add () =  "show  pwd               :  filtered current directory";
2148  help_texts.add () =  "show  set <name>        :  a formatted set definition";
2149  help_texts.add () =  "show  set_names         :  set names";
2150  help_texts.add () =  "show  set_value <name>  :  a raw set definition";
2151  help_texts.add () =  "show  sets              :  set definitions";
2152  help_texts.add () =  "show  strategies        :  all strategies (build & version)";
2153  help_texts.add () =  "show  tags              :  all currently active tags";
2154  help_texts.add () =  "show  use_paths <pack>  :  all paths to the used package";
2155  help_texts.add () =  "show  uses              :  used packages";
2156  help_texts.add () =  "show  version           :  version of the current package";
2157  help_texts.add () =  "show  versions <name>   :  visible versions of the selected package";
2158  help_texts.add () =  "system                  : display the system tag";
2159  help_texts.add () =  "unlock [<p> <v> [<path>]] : unlock a package";
2160  help_texts.add () =  "version                 : version of CMT";
2161  help_texts.add () =  "";
2162
2163  //"build <key>             : build various components :"
2164  //"show <key>              : display various infos on :"
2165
2166  help.add (action_none, help_texts[action_none]);
2167  help.add (action_awk, help_texts[action_awk]);
2168  help.add (action_broadcast, help_texts[action_broadcast]);
2169  help.add (action_build, help_texts[action_build]);
2170  help.add (action_build_constituent_makefile, help_texts[action_build_constituent_makefile]);
2171  help.add (action_build_constituents_makefile, help_texts[action_build_constituents_makefile]);
2172  help.add (action_build_dependencies, help_texts[action_build_dependencies]);
2173  help.add (action_build_library_links, help_texts[action_build_library_links]);
2174  help.add (action_build_make_setup, help_texts[action_build_make_setup]);
2175  help.add (action_build_msdev, help_texts[action_build_msdev]);
2176  help.add (action_build_CMT_pacman, help_texts[action_build_CMT_pacman]);
2177  help.add (action_build_vsnet, help_texts[action_build_vsnet]);
2178  help.add (action_build_os9_makefile, help_texts[action_build_os9_makefile]);
2179  help.add (action_build_prototype, help_texts[action_build_prototype]);
2180  help.add (action_build_readme, help_texts[action_build_readme]);
2181  help.add (action_build_tag_makefile, help_texts[action_build_tag_makefile]);
2182  help.add (action_build_temporary_name, help_texts[action_build_temporary_name]);
2183  help.add (action_build_triggers, help_texts[action_build_triggers]);
2184  help.add (action_build_windefs, help_texts[action_build_windefs]);
2185  help.add (action_check_configuration, help_texts[action_check_configuration]);
2186  help.add (action_check_files, help_texts[action_check_files]);
2187  help.add (action_check_version, help_texts[action_check_version]);
2188  help.add (action_checkout, help_texts[action_checkout]);
2189  help.add (action_cleanup, help_texts[action_cleanup]);
2190  help.add (action_config, help_texts[action_config]);
2191  help.add (action_create, help_texts[action_create]);
2192  help.add (action_create_project, help_texts[action_create_project]);
2193  help.add (action_cvsbranches, help_texts[action_cvsbranches]);
2194  help.add (action_cvssubpackages, help_texts[action_cvssubpackages]);
2195  help.add (action_cvssubprojects, help_texts[action_cvssubprojects]);
2196  help.add (action_cvstags, help_texts[action_cvstags]);
2197  help.add (action_do, help_texts[action_do]);
2198  help.add (action_expand_model, help_texts[action_expand_model]);
2199  help.add (action_filter, help_texts[action_filter]);
2200  help.add (action_help, help_texts[action_help]);
2201  help.add (action_load, help_texts[action_load]);
2202  help.add (action_lock, help_texts[action_lock]);
2203  help.add (action_remove, help_texts[action_remove]);
2204  help.add (action_remove_library_links, help_texts[action_remove_library_links]);
2205  help.add (action_run, help_texts[action_run]);
2206  help.add (action_run_sequence, help_texts[action_run_sequence]);
2207  help.add (action_set_version, help_texts[action_set_version]);
2208  help.add (action_set_versions, help_texts[action_set_versions]);
2209  help.add (action_setup, help_texts[action_setup]);
2210  help.add (action_show, help_texts[action_show]);
2211  help.add (action_show_action, help_texts[action_show_action]);
2212  help.add (action_show_action_value, help_texts[action_show_action_value]);
2213  help.add (action_show_action_names, help_texts[action_show_action_names]);
2214  help.add (action_show_actions, help_texts[action_show_actions]);
2215  help.add (action_show_all_tags, help_texts[action_show_all_tags]);
2216  help.add (action_show_applied_patterns, help_texts[action_show_applied_patterns]);
2217  help.add (action_show_author, help_texts[action_show_author]);
2218  help.add (action_show_branches, help_texts[action_show_branches]);
2219  help.add (action_show_clients, help_texts[action_show_clients]);
2220  help.add (action_show_cmtpath_patterns, help_texts[action_show_cmtpath_patterns]);
2221  help.add (action_show_constituent, help_texts[action_show_constituent]);
2222  help.add (action_show_constituent_names, help_texts[action_show_constituent_names]);
2223  help.add (action_show_constituents, help_texts[action_show_constituents]);
2224  help.add (action_show_cycles, help_texts[action_show_cycles]);
2225  help.add (action_show_fragment, help_texts[action_show_fragment]);
2226  help.add (action_show_fragments, help_texts[action_show_fragments]);
2227  help.add (action_show_groups, help_texts[action_show_groups]);
2228  help.add (action_show_include_dirs, help_texts[action_show_include_dirs]);
2229  help.add (action_show_language, help_texts[action_show_language]);
2230  help.add (action_show_languages, help_texts[action_show_languages]);
2231  help.add (action_show_macro, help_texts[action_show_macro]);
2232  help.add (action_show_macro_value, help_texts[action_show_macro_value]);
2233  help.add (action_show_macro_names, help_texts[action_show_macro_names]);
2234  help.add (action_show_macros, help_texts[action_show_macros]);
2235  help.add (action_show_manager, help_texts[action_show_manager]);
2236  help.add (action_show_packages, help_texts[action_show_packages]);
2237  help.add (action_show_path, help_texts[action_show_path]);
2238  help.add (action_show_pattern, help_texts[action_show_pattern]);
2239  help.add (action_show_pattern_names, help_texts[action_show_pattern_names]);
2240  help.add (action_show_patterns, help_texts[action_show_patterns]);
2241  help.add (action_show_projects, help_texts[action_show_projects]);
2242  help.add (action_show_setup, help_texts[action_show_setup]);
2243  help.add (action_show_pwd, help_texts[action_show_pwd]);
2244  help.add (action_show_set, help_texts[action_show_set]);
2245  help.add (action_show_set_names, help_texts[action_show_set_names]);
2246  help.add (action_show_set_value, help_texts[action_show_set_value]);
2247  help.add (action_show_sets, help_texts[action_show_sets]);
2248  help.add (action_show_strategies, help_texts[action_show_strategies]);
2249  help.add (action_show_tags, help_texts[action_show_tags]);
2250  help.add (action_show_use_paths, help_texts[action_show_use_paths]);
2251  help.add (action_show_uses, help_texts[action_show_uses]);
2252  help.add (action_show_version, help_texts[action_show_version]);
2253  help.add (action_show_versions, help_texts[action_show_versions]);
2254  help.add (action_system, help_texts[action_system]);
2255  help.add (action_unlock, help_texts[action_unlock]);
2256  help.add (action_version, help_texts[action_version]);
2257}
2258
Note: See TracBrowser for help on using the repository browser.