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

Last change on this file since 615 was 109, checked in by arnault, 19 years ago

First implementation of a -warnings option.

  • 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        }
692      else if (arg == "files")
693        {
694          if (argc > 0)
695            {
696              fill_one_argument ();
697              if (argc > 0)
698                {
699                  fill_one_argument ();
700                  cmt.m_action = action_check_files;
701                }
702              else
703                {
704                  if (!cmt.m_quiet) cerr << "#CMT> syntax error : reference file name missing" 
705                                         << endl;
706                  help_action = action_help;
707                  cmt.m_action = action_check_files;
708                }
709            }
710          else
711            {
712              if (!cmt.m_quiet) cerr << "#CMT> syntax error : file name missing" << endl;
713              help_action = action_help;
714              cmt.m_action = action_check_files;
715            }
716        }
717      else if (arg == "version")
718        {
719          if (argc > 0)
720            {
721              fill_one_argument ();
722              cmt.m_action = action_check_version;
723            }
724          else
725            {
726              if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
727              help_action = action_help;
728              cmt.m_action = action_check_version;
729            }
730        }
731      else
732        {
733          if (!cmt.m_quiet) cerr << "#CMT> syntax error : bad check option" << endl;
734          help_action = action_help;
735          cmt.m_action = action_check;
736        }
737    }
738  else
739    {
740      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to check" << endl;
741      help_action = action_help;
742      cmt.m_action = action_check;
743    }
744}
745
746void ArgParser::do_check_files ()
747{
748  if (argc > 0)
749    {
750      fill_one_argument ();
751      if (argc > 0)
752        {
753          fill_one_argument ();
754          cmt.m_action = action_check_files;
755        }
756      else
757        {
758          if (!cmt.m_quiet) cerr << "#CMT> syntax error : reference file missing" << endl;
759          help_action = action_help;
760          cmt.m_action = action_check_files;
761        }
762    }
763  else
764    {
765      if (!cmt.m_quiet) cerr << "#CMT> syntax error : file name missing" << endl;
766      help_action = action_help;
767      cmt.m_action = action_check_files;
768    }
769}
770
771void ArgParser::do_checkout ()
772{
773  if (argc > 0)
774    {
775      fill_arguments ();
776      cmt.m_action = action_checkout;
777    }
778  else
779    {
780      if (!cmt.m_quiet) cerr << "#CMT> syntax error : checkout arguments missing" << endl;
781      help_action = action_help;
782      cmt.m_action = action_checkout;
783    }
784}
785
786void ArgParser::do_cleanup ()
787{
788  cmt.m_action = action_cleanup;
789}
790
791void ArgParser::do_config ()
792{
793  cmt.m_action = action_config;
794}
795
796void ArgParser::do_create ()
797{
798  if (argc > 0)
799    {
800      fill_arguments ();
801      cmt.m_action = action_create;
802    }
803  else
804    {
805      if (!cmt.m_quiet) cerr << "#CMT> syntax error : create arguments missing" << endl;
806      help_action = action_help;
807      cmt.m_action = action_create;
808    }
809}
810
811void ArgParser::do_create_project ()
812{
813  if (argc > 0)
814    {
815      fill_arguments ();
816      cmt.m_action = action_create_project;
817    }
818  else
819    {
820      if (!cmt.m_quiet) cerr << "#CMT> syntax error : create_project arguments missing" << endl;
821      help_action = action_help;
822      cmt.m_action = action_create_project;
823    }
824}
825
826void ArgParser::do_cvsbranches ()
827{
828  if (argc > 0)
829    {
830      fill_one_argument ();
831      cmt.m_action = action_cvsbranches;
832    }
833  else
834    {
835      if (!cmt.m_quiet) cerr << "#CMT> syntax error : cvsbranches arguments missing" << endl;
836      help_action = action_help;
837      cmt.m_action = action_cvsbranches;
838    }
839}
840
841void ArgParser::do_cvssubpackages ()
842{
843  if (argc > 0)
844    {
845      fill_one_argument ();
846    }
847
848  cmt.m_action = action_cvssubpackages;
849}
850
851void ArgParser::do_cvssubprojects ()
852{
853  if (argc > 0)
854    {
855      fill_one_argument ();
856    }
857
858  cmt.m_action = action_cvssubprojects;
859}
860
861void ArgParser::do_cvstags ()
862{
863  if (argc > 0)
864    {
865      fill_arguments ();
866      cmt.m_action = action_cvstags;
867    }
868  else
869    {
870      if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
871      help_action = action_help;
872      cmt.m_action = action_cvstags;
873    }
874}
875
876void ArgParser::do_do ()
877{
878  if (argc > 0)
879    {
880      fill_arguments ();
881                 
882      {
883        cmt_string tag_name = "target_";
884        tag_name += arguments[0];
885
886        Tag* tag;
887        tag = Tag::add (tag_name, PriorityUserTag, "action", 0);                     
888        tag->mark ();
889      }
890
891      cmt.m_action = action_do;
892    }
893  else
894    {
895      if (!cmt.m_quiet) cerr << "#CMT> syntax error : action not specified" << endl;
896      help_action = action_help;
897      cmt.m_action = action_do;
898    }
899}
900
901void ArgParser::do_expand ()
902{
903  if (argc > 0)
904    {
905      arg = argv[0];
906
907      shift ();
908      if (arg == "model")
909        {
910          if (argc > 0)
911            {
912              fill_arguments ();
913              cmt.m_action = action_expand_model;
914            }
915          else
916            {
917              if (!cmt.m_quiet) cerr << "#CMT> syntax error : model not specified" << endl;
918              help_action = action_help;
919              cmt.m_action = action_expand_model;
920            }
921        }
922      else
923        {
924          if (!cmt.m_quiet) cerr << "#CMT> syntax error : bad expand option" << endl;
925          help_action = action_help;
926          cmt.m_action = action_expand_model;
927        }
928    }
929  else
930    {
931      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to expand" << endl;
932      help_action = action_help;
933      cmt.m_action = action_expand_model;
934    }
935}
936
937void ArgParser::do_filter ()
938{
939  if (argc > 0)
940    {
941      fill_arguments ();
942      cmt.m_action = action_filter;
943    }
944  else
945    {
946      if (!cmt.m_quiet) cerr << "#CMT> syntax error : file to filter not specified" << endl;
947      help_action = action_help;
948      cmt.m_action = action_filter;
949    }
950}
951
952void ArgParser::do_help ()
953{
954  help_action = action_help;
955}
956
957void ArgParser::do_lock ()
958{
959  if (argc > 0)
960    {
961      cmt.m_current_package = fill_one_argument ();
962      cmt.m_current_version.erase (0);
963      cmt.m_current_path.erase (0);
964
965      if (argc > 0)
966        {
967          cmt.m_current_version = fill_one_argument ();
968          cmt.m_action = action_lock;
969
970          if (argc > 0)
971            {
972              cmt.m_current_path = fill_one_argument_filtered ();
973            }
974
975          cmt.m_current_access = UserMode;
976          (Use::current()).set (cmt.m_current_package, 
977                                cmt.m_current_version, 
978                                cmt.m_current_path);
979
980        }
981      else
982        {
983          if (!cmt.m_quiet) cerr << "#CMT> syntax error : version missing" << endl;
984          help_action = action_help;
985          cmt.m_action = action_lock;
986        }
987    }
988  else
989    {
990      cmt.m_action = action_lock;
991    }
992}
993
994void ArgParser::do_remove ()
995{
996  if (argc > 0)
997    {
998      arg = argv[0];
999
1000      if (arg == "library_links")
1001        {
1002          shift ();
1003          cmt.m_action = action_remove_library_links;
1004        }
1005      else
1006        {
1007          cmt.m_current_package = fill_one_argument ();
1008          cmt.m_current_version.erase (0);
1009          cmt.m_current_path.erase (0);
1010                     
1011          if (argc > 0)
1012            {
1013              cmt.m_current_version = fill_one_argument ();
1014
1015              if (argc > 0)
1016                {
1017                  cmt.m_current_path = fill_one_argument_filtered ();
1018                }
1019                           
1020              cmt.m_action = action_remove;
1021            }
1022          else
1023            {
1024              if (!cmt.m_quiet) cerr << "#CMT> syntax error : version missing" << endl;
1025              help_action = action_help;
1026              cmt.m_action = action_remove;
1027            }
1028        }
1029    }
1030  else
1031    {
1032      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to remove" << endl;
1033      help_action = action_help;
1034      cmt.m_action = action_remove;
1035    }
1036}
1037
1038void ArgParser::do_run ()
1039{
1040  if (argc > 0)
1041    {
1042      fill_arguments ();
1043      cmt.m_action = action_run;
1044    }
1045  else
1046    {
1047      if (!cmt.m_quiet) cerr << "#CMT> syntax error : run arguments missing" << endl;
1048      help_action = action_help;
1049      cmt.m_action = action_run;
1050    }
1051}
1052
1053void ArgParser::do_run_sequence ()
1054{
1055  if (argc > 0)
1056    {
1057      fill_one_argument ();
1058      cmt.m_action = action_run_sequence;
1059    }
1060  else
1061    {
1062      if (!cmt.m_quiet) cerr << "#CMT> syntax error : run_sequence arguments missing" << endl;
1063      help_action = action_help;
1064      cmt.m_action = action_run_sequence;
1065    }
1066}
1067
1068void ArgParser::do_set ()
1069{
1070  if (argc > 0)
1071    {
1072      arg = argv[0];
1073
1074      shift ();
1075
1076      if (arg == "version")
1077        {
1078          fill_arguments ();
1079          cmt.m_action = action_set_version;
1080        }
1081      else if (arg == "versions")
1082        {
1083          fill_arguments ();
1084
1085          cmt.m_action = action_set_versions;
1086
1087          if (cmt.m_scope_filtering_mode == default_filtering_mode)
1088            {
1089              cmt.m_scope_filtering_mode = reach_private_uses;
1090            }
1091        }
1092      else
1093        {
1094          if (!cmt.m_quiet) cerr << "#CMT> syntax error : bad set argument" << endl;
1095          help_action = action_help;
1096          //cmt.m_action = action_set;
1097        }
1098    }
1099  else
1100    {
1101      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to set" << endl;
1102      help_action = action_help;
1103      //cmt.m_action = action_set;
1104    }
1105}
1106
1107void ArgParser::do_setup ()
1108{
1109  cmt.m_action = action_setup;
1110}
1111
1112void ArgParser::do_show ()
1113{
1114  if (argc > 0)
1115    {
1116      arg = argv[0];
1117
1118      //cerr << "Running show arg=" << arg << endl;
1119
1120      shift ();
1121
1122      if (arg == "action")
1123        {
1124          if (argc > 0)
1125            {
1126              cmt.m_current_target = fill_one_argument ();
1127              cmt.m_action = action_show_action;
1128            }
1129          else
1130            {
1131              if (!cmt.m_quiet) cerr << "#CMT> syntax error : action name missing" << endl;
1132              help_action = action_help;
1133              cmt.m_action = action_show_action;
1134            }
1135        }
1136      else if (arg == "action_names")
1137        {
1138          if (argc > 0)
1139            {
1140              fill_one_argument ();
1141            }
1142
1143          cmt.m_action = action_show_action_names;
1144        }
1145      else if (arg == "action_value")
1146        {
1147          cmt.m_quiet = true;
1148          if (argc > 0)
1149            {
1150              cmt.m_current_target = fill_one_argument ();
1151              cmt.m_action = action_show_action_value;
1152            }
1153          else
1154            {
1155              if (!cmt.m_quiet) cerr << "#CMT> syntax error : action name missing" << endl;
1156              help_action = action_help;
1157              cmt.m_action = action_show_action_value;
1158            }
1159        }
1160      else if (arg == "actions")
1161        {
1162          if (argc > 0)
1163            {
1164              fill_one_argument ();
1165            }
1166
1167          cmt.m_action = action_show_actions;
1168        }
1169      else if (arg == "all_tags")
1170        {
1171          cmt.m_action = action_show_all_tags;
1172        }
1173      else if (arg == "applied_patterns")
1174        {
1175          cmt.m_action = action_show_applied_patterns;
1176        }
1177      else if (arg == "author")
1178        {
1179          cmt.m_action = action_show_author;
1180        }
1181      else if (arg == "branches")
1182        {
1183          cmt.m_action = action_show_branches;
1184        }
1185      else if (arg == "clients")
1186        {
1187          if (argc > 0)
1188            {
1189              cmt.m_current_target = fill_one_argument ();
1190
1191              cmt.m_action = action_show_clients;
1192
1193              if (argc > 0)
1194                {
1195                  fill_one_argument ();
1196                  if (argc > 0)
1197                    {
1198                      fill_one_argument ();
1199                    }
1200                }
1201            }
1202          else
1203            {
1204              if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
1205              help_action = action_help;
1206              cmt.m_action = action_show_clients;
1207            }
1208        }
1209      else if (arg == "cmtpath_patterns")
1210        {
1211          cmt.m_action = action_show_cmtpath_patterns;
1212        }
1213      else if (arg == "constituent")
1214        {
1215          if (argc > 0)
1216            {
1217              cmt.m_current_target = fill_one_argument ();
1218              cmt.m_action = action_show_constituent;
1219            }
1220          else
1221            {
1222              if (!cmt.m_quiet) cerr << "#CMT> syntax error : constituent name missing" << endl;
1223              help_action = action_help;
1224              cmt.m_action = action_show_constituent;
1225            }
1226        }
1227      else if (arg == "constituent_names")
1228        {
1229          cmt.m_action = action_show_constituent_names;
1230        }
1231      else if (arg == "constituents")
1232        {
1233          cmt.m_action = action_show_constituents;
1234        }
1235      else if (arg == "cycles")
1236        {
1237          cmt.m_action = action_show_cycles;
1238        }
1239      else if (arg == "fragment")
1240        {
1241          if (argc > 0)
1242            {
1243              cmt.m_current_target = fill_one_argument ();
1244              cmt.m_action = action_show_fragment;
1245            }
1246          else
1247            {
1248              if (!cmt.m_quiet) cerr << "#CMT> syntax error : fragment name missing" << endl;
1249              help_action = action_help;
1250              cmt.m_action = action_show_fragment;
1251            }
1252        }
1253      else if (arg == "fragments")
1254        {
1255          cmt.m_action = action_show_fragments;
1256        }
1257      else if (arg == "groups")
1258        {
1259          cmt.m_action = action_show_groups;
1260        }
1261      else if (arg == "include_dirs")
1262        {
1263          cmt.m_action = action_show_include_dirs;
1264        }
1265      else if (arg == "language")
1266        {
1267          if (argc > 0)
1268            {
1269              cmt.m_current_target = fill_one_argument ();
1270              cmt.m_action = action_show_language;
1271            }
1272          else
1273            {
1274              if (!cmt.m_quiet) cerr << "#CMT> syntax error : language name missing" << endl;
1275              help_action = action_help;
1276              cmt.m_action = action_show_language;
1277            }
1278        }
1279      else if (arg == "languages")
1280        {
1281          cmt.m_action = action_show_languages;
1282        }
1283      else if (arg == "macro")
1284        {
1285          if (argc > 0)
1286            {
1287              cmt.m_current_target = fill_one_argument ();
1288              cmt.m_action = action_show_macro;
1289            }
1290          else
1291            {
1292              if (!cmt.m_quiet) cerr << "#CMT> syntax error : macro name missing" << endl;
1293              help_action = action_help;
1294              cmt.m_action = action_show_macro;
1295            }
1296        }
1297      else if (arg == "macro_names")
1298        {
1299          if (argc > 0)
1300            {
1301              fill_one_argument ();
1302            }
1303
1304          cmt.m_action = action_show_macro_names;
1305        }
1306      else if (arg == "macro_value")
1307        {
1308          cmt.m_quiet = true;
1309          if (argc > 0)
1310            {
1311              cmt.m_current_target = fill_one_argument ();
1312              cmt.m_action = action_show_macro_value;
1313            }
1314          else
1315            {
1316              if (!cmt.m_quiet) cerr << "#CMT> syntax error : macro name missing" << endl;
1317              help_action = action_help;
1318              cmt.m_action = action_show_macro_value;
1319            }
1320        }
1321      else if (arg == "macros")
1322        {
1323          if (argc > 0)
1324            {
1325              fill_one_argument ();
1326            }
1327
1328          cmt.m_action = action_show_macros;
1329        }
1330      else if (arg == "manager")
1331        {
1332          cmt.m_action = action_show_manager;
1333        }
1334      else if (arg == "packages")
1335        {
1336          if (argc > 0)
1337            {
1338              cmt.m_current_target = fill_one_argument ();
1339            }
1340
1341          cmt.m_action = action_show_packages;
1342        }
1343      else if (arg == "path")
1344        {
1345          cmt.m_action = action_show_path;
1346        }
1347      else if (arg == "pattern")
1348        {
1349          if (argc > 0)
1350            {
1351              cmt.m_current_target = fill_one_argument ();
1352              cmt.m_action = action_show_pattern;
1353            }
1354          else
1355            {
1356              if (!cmt.m_quiet) cerr << "#CMT> syntax error : pattern name missing" << endl;
1357              help_action = action_help;
1358              cmt.m_action = action_show_pattern;
1359            }
1360        }
1361      else if (arg == "pattern_names")
1362        {
1363          cmt.m_action = action_show_pattern_names;
1364        }
1365      else if (arg == "patterns")
1366        {
1367          cmt.m_action = action_show_patterns;
1368        }
1369      else if (arg == "projects")
1370        {
1371          cmt.m_action = action_show_projects;
1372        }
1373      else if (arg == "pwd")
1374        {
1375          cmt.m_action = action_show_pwd;
1376        }
1377      else if (arg == "setup")
1378        {
1379          cmt.m_action = action_show_setup;
1380
1381          if (cmt.m_scope_filtering_mode == default_filtering_mode)
1382            {
1383              cmt.m_scope_filtering_mode = reach_private_uses;
1384            }
1385        }
1386      else if (arg == "set_names")
1387        {
1388          if (argc > 0)
1389            {
1390              fill_one_argument ();
1391            }
1392
1393          cmt.m_action = action_show_set_names;
1394        }
1395      else if (arg == "set_value")
1396        {
1397          cmt.m_quiet = true;
1398          if (argc > 0)
1399            {
1400              cmt.m_current_target = fill_one_argument ();
1401              cmt.m_action = action_show_set_value;
1402            }
1403          else
1404            {
1405              if (!cmt.m_quiet) cerr << "#CMT> syntax error : set name missing" << endl;
1406              help_action = action_help;
1407              cmt.m_action = action_show_set_value;
1408            }
1409        }
1410      else if (arg == "set")
1411        {
1412          if (argc > 0)
1413            {
1414              cmt.m_current_target = fill_one_argument ();
1415              cmt.m_action = action_show_set;
1416            }
1417          else
1418            {
1419              if (!cmt.m_quiet) cerr << "#CMT> syntax error : set name missing" << endl;
1420              help_action = action_help;
1421              cmt.m_action = action_show_set;
1422            }
1423        }
1424      else if (arg == "sets")
1425        {
1426          if (argc > 0)
1427            {
1428              fill_one_argument ();
1429            }
1430
1431          cmt.m_action = action_show_sets;
1432        }
1433      else if (arg == "strategies")
1434        {
1435          cmt.m_action = action_show_strategies;
1436        }
1437      else if (arg == "tags")
1438        {
1439          cmt.m_action = action_show_tags;
1440        }
1441      else if (arg == "use_paths")
1442        {
1443          if (argc > 0)
1444            {
1445              while (argc > 0)
1446                {
1447                  if (strcmp (argv[0], "-private") == 0)
1448                    {
1449                      cmt.m_scope_filtering_mode = reach_private_uses;
1450                    }
1451                  else if (strcmp (argv[0], "--private") == 0)
1452                    {
1453                      cmt.m_scope_filtering_mode = reach_private_uses;
1454                    }
1455                  else
1456                    {
1457                      cmt_string& s = arguments.add ();
1458                      s = argv[0];
1459                    }
1460
1461                  shift ();
1462                }
1463
1464              cmt.m_action = action_show_use_paths;
1465            }
1466          else
1467            {
1468              if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
1469              help_action = action_help;
1470              cmt.m_action = action_show_use_paths;
1471            }
1472        }
1473      else if ((arg == "u") ||
1474               (arg == "us") ||
1475               (arg == "use") ||
1476               (arg == "uses"))
1477        {
1478          cmt.m_action = action_show_uses;
1479
1480          if (cmt.m_scope_filtering_mode == default_filtering_mode)
1481            {
1482              cmt.m_scope_filtering_mode = reach_private_uses;
1483            }
1484        }
1485      else if (arg == "version")
1486        {
1487          cmt.m_action = action_show_version;
1488        }
1489      else if (arg == "versions")
1490        {
1491          if (argc > 0)
1492            {
1493              cmt.m_current_target = fill_one_argument ();
1494              cmt.m_action = action_show_versions;
1495            }
1496          else
1497            {
1498              if (!cmt.m_quiet) cerr << "#CMT> syntax error : package name missing" << endl;
1499              help_action = action_help;
1500              cmt.m_action = action_show_versions;
1501            }
1502        }
1503      else
1504        {
1505          if (!cmt.m_quiet) cerr << "#CMT> syntax error : bad show argument" << endl;
1506          help_action = action_help;
1507          cmt.m_action = action_show;
1508        }
1509    }
1510  else
1511    {
1512      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to show" << endl;
1513      help_action = action_help;
1514      cmt.m_action = action_show;
1515    }
1516}
1517
1518void ArgParser::do_system ()
1519{
1520  cmt.m_action = action_system;
1521}
1522
1523void ArgParser::do_unlock ()
1524{
1525  if (argc > 0)
1526    {
1527      cmt.m_current_package = fill_one_argument ();
1528      cmt.m_current_version.erase (0);
1529      cmt.m_current_path.erase (0);
1530                                       
1531      if (argc > 0)
1532        {
1533          cmt.m_current_version = fill_one_argument ();
1534          cmt.m_action = action_unlock;
1535
1536          if (argc > 0)
1537            {
1538              cmt.m_current_path = fill_one_argument_filtered ();
1539            }
1540                                               
1541          cmt.m_current_access = UserMode;
1542          (Use::current()).set (cmt.m_current_package, 
1543                                cmt.m_current_version, 
1544                                cmt.m_current_path);
1545
1546        }
1547      else
1548        {
1549          if (!cmt.m_quiet) cerr << "#CMT> syntax error : version missing" << endl;
1550          help_action = action_help;
1551          cmt.m_action = action_unlock;
1552        }
1553    }
1554  else
1555    {
1556      cmt.m_action = action_unlock;
1557    }
1558}
1559
1560void ArgParser::do_version ()
1561{
1562  cmt.m_action = action_version;
1563}
1564
1565void ArgParser::option_help ()
1566{
1567  help_action = action_help;
1568}
1569
1570void ArgParser::option_n ()
1571{
1572  cmt.m_simulation = true;
1573}
1574
1575void ArgParser::option_quiet ()
1576{
1577  cmt.m_quiet = true;
1578}
1579
1580void ArgParser::option_warnings ()
1581{
1582  cmt.m_warnings = true;
1583}
1584
1585void ArgParser::option_csh ()
1586{
1587  mode = Csh;
1588}
1589
1590void ArgParser::option_sh ()
1591{
1592  mode = Sh;
1593}
1594
1595void ArgParser::option_bat ()
1596{
1597  mode = Bat;
1598}
1599
1600void ArgParser::option_use ()
1601{
1602  if (cmt.m_action != action_create)
1603    {
1604      CmtSystem::cmt_string_vector words;
1605
1606      CmtSystem::split (arg, ":", words);
1607
1608      cmt.m_current_access = UserMode;
1609
1610      if (words.size () > 0) cmt.m_current_package = words[0];
1611      if (words.size () > 1) cmt.m_current_version = words[1];
1612      if (words.size () > 2) cmt.m_current_path    = words[2];
1613      (Use::current()).set (cmt.m_current_package, 
1614                            cmt.m_current_version, 
1615                            cmt.m_current_path);
1616    }
1617}
1618
1619void ArgParser::option_pack ()
1620{
1621  if ((cmt.m_action != action_create) && (cmt.m_current_package != arg))
1622    {
1623      //CmtSystem::cd (cmt.m_default_path);
1624
1625      cmt.m_current_access = UserMode;
1626
1627      cmt.m_current_package = arg;
1628      cmt.m_current_version = "";
1629
1630      /*
1631      cerr << "ArgParser::option_pack> "
1632           << " cp=" << cmt.m_current_package
1633           << " cv=" << cmt.m_current_version
1634           << " cp=" << cmt.m_current_path << endl;
1635      */
1636
1637      (Use::current()).set (cmt.m_current_package, 
1638                            cmt.m_current_version, 
1639                            cmt.m_current_path);
1640    }
1641}
1642
1643void ArgParser::option_version ()
1644{
1645  if ((cmt.m_action != action_create) && (cmt.m_current_version != arg))
1646    {
1647      cmt.m_current_access = UserMode;
1648      cmt.m_current_version = arg;
1649
1650      /*
1651      cerr << "ArgParser::option_version> "
1652           << " cp=" << cmt.m_current_package
1653           << " cv=" << cmt.m_current_version
1654           << " cp=" << cmt.m_current_path << endl;
1655      */
1656
1657      (Use::current()).set (cmt.m_current_package, 
1658                            cmt.m_current_version, 
1659                            cmt.m_current_path);
1660    }
1661}
1662
1663void ArgParser::option_path ()
1664{
1665  if ((cmt.m_action != action_create) && (cmt.m_current_path != arg))
1666    {
1667      cmt.m_current_access = UserMode;
1668      cmt.m_current_path = arg;
1669
1670      /*
1671      cerr << "ArgParser::option_path> "
1672           << " cp=" << cmt.m_current_package
1673           << " cv=" << cmt.m_current_version
1674           << " cp=" << cmt.m_current_path << endl;
1675      */
1676
1677      (Use::current()).set (cmt.m_current_package, 
1678                            cmt.m_current_version, 
1679                            cmt.m_current_path);
1680
1681      //IProjectFactory& factory = ProjectFactory::instance ();
1682      //CmtSystem::add_cmt_path (cmt.m_current_path, "argument", factory);
1683    }
1684}
1685
1686void ArgParser::option_f ()
1687{
1688  extra_file = arg;
1689}
1690
1691void ArgParser::option_e ()
1692{
1693  cerr << "#CMT> Warning: extra statement = " << arg << endl;
1694  extra_line = arg;
1695}
1696
1697void ArgParser::option_home ()
1698{
1699  if (CmtSystem::test_directory (arg))
1700    {
1701      cmt.m_cmt_home = arg;
1702    }
1703}
1704
1705void ArgParser::option_tag ()
1706{
1707  /*
1708    Here we are going to change the complete tag set
1709  */
1710             
1711  if (arg != "")
1712    {
1713      Tag* tag;
1714      CmtSystem::cmt_string_vector words;
1715
1716      // First reset selection of all existing tags
1717      //Tag::clear_all ();
1718      Tag::unmark_all ();
1719      cmt.m_extra_tags = ",";
1720                   
1721      // Then restore CMTSITE
1722      Cmt::configure_version_tag ();
1723      Cmt::configure_site_tag (0);
1724      Cmt::configure_uname_tag ();
1725      Cmt::configure_hosttype_tag ();
1726      Cmt::configure_config_tag ();
1727      Cmt::configure_home (0);
1728      Cmt::guess_current_project ();
1729
1730      CmtSystem::split (arg, " \t,", words);
1731                 
1732      for (int i = 0; i < words.size (); i++)
1733        {
1734          const cmt_string& a = words[i];
1735                     
1736          cmt_string s = ",";
1737          s += a;
1738          s += ",";
1739                     
1740          if (i == 0)
1741            {
1742              cmt.m_current_tag = a;
1743                         
1744              if (CmtSystem::testenv ("TAGDEBUG")) cerr
1745                << "parse_argument(tag_add)> current_tag=" << cmt.m_current_tag << endl;
1746            }
1747                     
1748          if (cmt.m_extra_tags.find (s) == cmt_string::npos)
1749            {
1750              //if (!cmt.m_quiet) cerr << "  a=[" << a << "]" << endl;
1751                         
1752              // Then restore uname if the specified tag is CMTCONFIG
1753              if (a == CmtSystem::get_cmt_config ())
1754                {
1755                  Cmt::configure_uname_tag ();
1756                }
1757                         
1758              tag = Tag::add (a, PriorityArgument, "arguments", 0);
1759                         
1760              tag->mark ();
1761                         
1762              cmt.m_extra_tags += a;
1763              cmt.m_extra_tags += ",";
1764            }
1765        }
1766    }
1767}
1768
1769void ArgParser::option_tag_add ()
1770{
1771  Tag* tag;
1772  CmtSystem::cmt_string_vector words;
1773             
1774  //if (!cmt.m_quiet) cerr << "-tag_add=" << arg << endl;
1775
1776  CmtSystem::split (arg, " \t,", words);
1777
1778  for (int i = 0; i < words.size (); i++)
1779    {
1780      const cmt_string& a = words[i];
1781
1782      cmt_string s = ",";
1783      s += a;
1784      s += ",";
1785
1786      if (cmt.m_extra_tags.find (s) == cmt_string::npos)
1787        {
1788          //if (!cmt.m_quiet) cerr << "  a=[" << a << "]" << endl;
1789
1790          /// Then restore uname if the specified tag is CMTCONFIG
1791          if (a == CmtSystem::get_cmt_config ())
1792            {
1793              Cmt::configure_uname_tag ();
1794            }
1795                     
1796          tag = Tag::add (a, PriorityUserTag, "arguments", 0);
1797                     
1798          tag->mark ();
1799
1800          cmt.m_extra_tags += a;
1801          cmt.m_extra_tags += ",";
1802        }
1803    }
1804}
1805
1806void ArgParser::option_tag_remove ()
1807{
1808  Tag::TagPtrVector tags = Tag::tags ();
1809  int i;
1810  Tag* tag;
1811
1812  /*
1813    for (i = 0; i < tags.size (); i++)
1814    {
1815    tag = tags[i];
1816    if ((tag != 0) &&
1817    (tag->selected))
1818    {
1819    if (!cmt.m_quiet) cerr << "  original tag_list=" << tag->name << tag->priority << endl;
1820    }
1821    }
1822  */
1823
1824  CmtSystem::cmt_string_vector words;
1825
1826  //if (!cmt.m_quiet) cerr << "-arg_remove=" << arg << endl;
1827
1828  CmtSystem::split (arg, " \t,", words);
1829
1830  //
1831  // Now erase all entries in the old list that match
1832  // the specified tags
1833  //
1834
1835  for (i = 0; i < words.size (); i++)
1836    {
1837      const cmt_string& a = words[i];
1838
1839      cmt_string s = ",";
1840      s += a;
1841      s += ",";
1842
1843      int pos;
1844
1845      pos = cmt.m_extra_tags.find (s);
1846
1847      if (pos != cmt_string::npos)
1848        {
1849          cmt.m_extra_tags.erase (pos, s.size () - 1);
1850        }
1851
1852      //if (!cmt.m_quiet) cerr << "  tag_list=[" << tag_list << "]" << endl;
1853    }
1854
1855  //
1856  // Now reinject the purged list of tags into the database
1857  // exactly as when using -tag=<tag-list>
1858  //
1859
1860  /// First forget about all existing tags
1861      Tag::unmark_all ();
1862
1863      /// Then restore CMTSITE
1864        Cmt::configure_version_tag ();
1865        Cmt::configure_site_tag (0);
1866        Cmt::configure_uname_tag ();
1867        Cmt::configure_hosttype_tag ();
1868             
1869        CmtSystem::split (cmt.m_extra_tags, " \t,", words);
1870
1871        for (i = 0; i < words.size (); i++)
1872          {
1873            const cmt_string& a = words[i];
1874
1875            //fprintf (stderr, "  a=[%s]\n", a.c_str ());
1876
1877            /// Then restore uname if the specified tag is CMTCONFIG
1878              if (a == CmtSystem::get_cmt_config ())
1879                {
1880                  Cmt::configure_uname_tag ();
1881                }
1882
1883              if (i == 0)
1884                {
1885                  cmt.m_current_tag = a;
1886
1887                  //if (!cmt.m_quiet) cerr << "parse_argument(tag_remove)> current_tag="
1888                  //<< cmt.m_current_tag << endl;
1889
1890                  tag = Tag::add (a, PriorityTag, "restore configuration", 0);
1891                }
1892              else
1893                {
1894                  tag = Tag::add (a, PriorityUserTag, "restore configuration", 0);
1895                }
1896
1897              tag->mark ();
1898          }
1899}
1900
1901void ArgParser::option_user_context ()
1902{
1903  if (CmtSystem::test_directory (arg))
1904    {
1905      cmt.m_cmt_user_context = arg;
1906    }
1907}
1908
1909void ArgParser::option_with_version_directory ()
1910{
1911  cmt.m_current_structuring_style = with_version_directory;
1912
1913  StrategyDef* def = StrategyMgr::find_strategy ("VersionDirectory");
1914  if (def != 0)
1915    {
1916      def->m_default_value = true;
1917      def->m_priority_value = false;
1918    }
1919}
1920
1921void ArgParser::option_without_version_directory ()
1922{
1923  cmt.m_current_structuring_style = without_version_directory;
1924
1925  StrategyDef* def = StrategyMgr::find_strategy ("VersionDirectory");
1926  if (def != 0)
1927    {
1928      def->m_default_value = false;
1929      def->m_priority_value = true;
1930    }
1931}
1932
1933void ArgParser::option_no_cleanup ()
1934{
1935  //cmt.m_current_setup_strategy |= SetupNoCleanup;
1936}
1937
1938void ArgParser::option_private ()
1939{
1940  cmt.m_scope_filtering_mode = reach_private_uses;
1941}
1942
1943void ArgParser::option_public ()
1944{
1945  cmt.m_scope_filtering_mode = block_private_uses;
1946}
1947
1948
1949
1950
1951
1952
1953CommandHelp::HelpMap& CommandHelp::get_help ()
1954{
1955  static CommandHelp& me = instance ();
1956
1957  return (me.m_help);
1958}
1959
1960CommandHelp::HelpTexts& CommandHelp::get_help_texts ()
1961{
1962  static CommandHelp& me = instance ();
1963
1964  return (me.m_help_texts);
1965}
1966
1967const cmt_string& CommandHelp::get_help_text (ActionType key)
1968{
1969  static const HelpTexts& help = get_help_texts ();
1970
1971  const cmt_string& h = help[key];
1972  return (h);
1973}
1974
1975void CommandHelp::show_all ()
1976{
1977  static HelpTexts& help_texts = get_help_texts ();
1978
1979  cerr << "#> cmt command [option...]" << endl;
1980  cerr << "# command :" << endl;
1981
1982  int i;
1983
1984  for (i = 0; ; i++)
1985    {
1986      const cmt_string& s = help_texts[i];
1987      if (s == "") break;
1988      cerr << "#   " << s << endl;
1989    }
1990
1991  cerr << "# global options :" << endl;
1992
1993  cerr << "#   -quiet                  : don't print errors" << endl;
1994  cerr << "#   -use=<p>:<v>:<path>     : set package version path" << endl;
1995  cerr << "#   -pack=<package>         : set package" << endl;
1996  cerr << "#   -version=<version>      : set version" << endl;
1997  cerr << "#   -path=<path>            : set root path" << endl;
1998  cerr << "#   -f=<requirement-file>   : set input file" << endl;
1999  cerr << "#   -e=<statement>          : add a one line statement" << endl;
2000  cerr << "#   -tag=<tag-list>         : select a new tag-set" << endl;
2001  cerr << "#   -tag_add=<tag-list>     : add specific comma-separated tag(s)" << endl;
2002  cerr << "#   -tag_remove=<tag-list>  : remove specific comma-separated tag(s)" << endl;
2003  cerr << "#   -warnings               : display various warnings" << endl;
2004  cerr << "#   -with_version_directory : reset to default structuring style" << endl;
2005  cerr << "#   -without_version_directory : switch structuring style" << endl;
2006  cerr << "#   -cleanup                : activate install area cleanup" << endl;
2007  cerr << "#   -no_cleanup             : inhibit install area cleanup" << endl;
2008}
2009
2010void CommandHelp::show (ActionType action)
2011{
2012  //cerr << "CommandHelp::show> action = " << action << endl;
2013
2014  static HelpTexts& help_texts = get_help_texts ();
2015
2016  if (action == action_build)
2017    {
2018      int i;
2019
2020      for (i = action_build_constituent_makefile; i <= action_build_windefs; i++)
2021        {
2022          const cmt_string& s = help_texts[i];
2023          cerr << "#   " << s << endl;
2024        }
2025    }
2026  if (action == action_check)
2027    {
2028      int i;
2029
2030      for (i = action_check_configuration; i <= action_check_version; i++)
2031        {
2032          const cmt_string& s = help_texts[i];
2033          cerr << "#   " << s << endl;
2034        }
2035    }
2036  else if (action == action_show)
2037    {
2038      int i;
2039
2040      for (i = (action_show + 1); i <= action_show_versions; i++)
2041        {
2042          const cmt_string& s = help_texts[i];
2043          cerr << "#   " << s << endl;
2044        }
2045    }
2046  else
2047    {
2048      const cmt_string& s = get_help_text (action);
2049      cerr << "#" << s << endl;
2050    }
2051}
2052
2053CommandHelp& CommandHelp::instance ()
2054{
2055  static CommandHelp me;
2056  return (me);
2057}
2058
2059CommandHelp::CommandHelp ()
2060{
2061  static HelpMap& help = m_help;
2062
2063  static HelpTexts& help_texts = m_help_texts;
2064
2065  help_texts.clear ();
2066
2067  help_texts.add () =  "none";
2068  help_texts.add () =  "awk";
2069  help_texts.add () =  "broadcast [-select=list] [-exclude=list] [-local] [-global] [-begin=pattern] [-depth=n] <command> : apply a command to [some of] the used packages";
2070  help_texts.add () =  "build <option>          : build actions. (Try cmt help build)";
2071  help_texts.add () =  "build constituent_makefile <constituent>  : generate constituent Makefile fragment";
2072  help_texts.add () =  "build constituents_makefile : generate constituents.make";
2073  help_texts.add () =  "build dependencies      : generate dependencies";
2074  help_texts.add () =  "build library_links     : build symbolic links towards all imported libraries";
2075  help_texts.add () =  "build make_setup        : build a compiled version of setup scripts";
2076  help_texts.add () =  "build msdev             : generate MSDEV files";
2077  help_texts.add () =  "build CMT_pacman        : generate PACMAN manifest file for CMT";
2078  help_texts.add () =  "build vsnet             : generate VS.NET files";
2079  help_texts.add () =  "build os9_makefile      : generate Makefile for OS9";
2080  help_texts.add () =  "build prototype         : generate prototype file";
2081  help_texts.add () =  "build readme            : generate README.html";
2082  help_texts.add () =  "build tag_makefile      : generate tag specific Makefile";
2083  help_texts.add () =  "build temporary_name    : generate a name for a temprary file";
2084  help_texts.add () =  "build triggers <constituent> : generate library trigger file";
2085  help_texts.add () =  "build windefs <library_name> : generate def file for Windows shared libraries";
2086  help_texts.add () =  "check <option>          : check actions. (Try cmt help check)";
2087  help_texts.add () =  "check configuration     : check configuration";
2088  help_texts.add () =  "check files <old> <new> : compare two files and overrides <old> by <new> if different";
2089  help_texts.add () =  "check version <name>    : check if a name follows a version tag syntax ";
2090  help_texts.add () =  "co | checkout           : perform a cvs checkout over a CMT package";
2091  help_texts.add () =  "cleanup [-csh|-sh|-bat] : generate a cleanup script";
2092  help_texts.add () =  "config                  : generate setup and cleanup scripts";
2093  help_texts.add () =  "create <package> <version> [<path>] : create and configure a new package";
2094  help_texts.add () =  "create_project <project> <name> [<path>] : create and configure a new project";
2095  help_texts.add () =  "cvsbranches <module>      : display the subdirectories for a module";
2096  help_texts.add () =  "cvssubpackages <module>   : display the subpackages for a module";
2097  help_texts.add () =  "cvssubprojects <module>   : display the subprojects for a module";
2098  help_texts.add () =  "cvstags <module>          : display the CVS tags for a module";
2099  help_texts.add () =  "do <action> [<param>=<value>] ... : Execute an action";
2100  help_texts.add () =  "expand model <model>    : ";
2101  help_texts.add () =  "filter <in> <out>       : filter a file against CMT macros and env. variables";
2102  help_texts.add () =  "help | -help | --help   : display this help";
2103  help_texts.add () =  "load";
2104  help_texts.add () =  "lock [<p> <v> [<path>]] : lock a package";
2105  help_texts.add () =  "remove <package> <version> [<path>] : remove a package version";
2106  help_texts.add () =  "remove library_links    : remove symbolic links towards all imported libraries";
2107  help_texts.add () =  "run '<command>'         : apply a command";
2108  help_texts.add () =  "run_sequence <sequence file> : execute a cmt equence file";
2109  help_texts.add () =  "set version <version>   : generate a version file in the current package";
2110  help_texts.add () =  "set versions            : generate version files into packages";
2111  help_texts.add () =  "setup [-csh|-sh|-bat]   : generate a setup script";
2112  help_texts.add () =  "show <option>           : query actions. (Try cmt help show)";
2113  help_texts.add () =  "show  action <name>     :  a formatted action definition";
2114  help_texts.add () =  "show  action_value <name> :  a raw action definition";
2115  help_texts.add () =  "show  action_names      :  all action names";
2116  help_texts.add () =  "show  actions           :  all action definitions";
2117  help_texts.add () =  "show  all_tags          :  all defined tags";
2118  help_texts.add () =  "show  applied_patterns  :  all patterns actually applied";
2119  help_texts.add () =  "show  author            :  package author";
2120  help_texts.add () =  "show  branches          :  added branches";
2121  help_texts.add () =  "show  clients           :  package clients";
2122  help_texts.add () =  "show  cmtpath_patterns  :  cmtpath_patterns";
2123  help_texts.add () =  "show  constituent <name>:  constituent definition";
2124  help_texts.add () =  "show  constituent_names :  constituent names";
2125  help_texts.add () =  "show  constituents      :  constituent definitions";
2126  help_texts.add () =  "show  cycles            :  cycles in the use graph";
2127  help_texts.add () =  "show  fragment <name>   :  one fragment definition";
2128  help_texts.add () =  "show  fragments         :  fragment definitions";
2129  help_texts.add () =  "show  groups            :  group definitions";
2130  help_texts.add () =  "show  include_dirs      :  ";
2131  help_texts.add () =  "show  language <name>   :  language definition";
2132  help_texts.add () =  "show  languages         :  language definitions";
2133  help_texts.add () =  "show  macro <name>      :  a formatted macro definition";
2134  help_texts.add () =  "show  macro_value <name>  :  a raw macro definition";
2135  help_texts.add () =  "show  macro_names       :  all macro names";
2136  help_texts.add () =  "show  macros            :  all macro definitions";
2137  help_texts.add () =  "show  manager           :  package manager";
2138  help_texts.add () =  "show  packages          :  packages reachable from the current context";
2139  help_texts.add () =  "show  path              :  the package search list";
2140  help_texts.add () =  "show  pattern <name>    :  the pattern definition and usages";
2141  help_texts.add () =  "show  pattern_names     :  pattern names";
2142  help_texts.add () =  "show  patterns          :  the pattern definitions";
2143  help_texts.add () =  "show  projects          :  project definitions";
2144  help_texts.add () =  "show  setup             :  setup definitions";
2145  help_texts.add () =  "show  pwd               :  filtered current directory";
2146  help_texts.add () =  "show  set <name>        :  a formatted set definition";
2147  help_texts.add () =  "show  set_names         :  set names";
2148  help_texts.add () =  "show  set_value <name>  :  a raw set definition";
2149  help_texts.add () =  "show  sets              :  set definitions";
2150  help_texts.add () =  "show  strategies        :  all strategies (build & version)";
2151  help_texts.add () =  "show  tags              :  all currently active tags";
2152  help_texts.add () =  "show  use_paths <pack>  :  all paths to the used package";
2153  help_texts.add () =  "show  uses              :  used packages";
2154  help_texts.add () =  "show  version           :  version of the current package";
2155  help_texts.add () =  "show  versions <name>   :  visible versions of the selected package";
2156  help_texts.add () =  "system                  : display the system tag";
2157  help_texts.add () =  "unlock [<p> <v> [<path>]] : unlock a package";
2158  help_texts.add () =  "version                 : version of CMT";
2159  help_texts.add () =  "";
2160
2161  //"build <key>             : build various components :"
2162  //"show <key>              : display various infos on :"
2163
2164  help.add (action_none, help_texts[action_none]);
2165  help.add (action_awk, help_texts[action_awk]);
2166  help.add (action_broadcast, help_texts[action_broadcast]);
2167  help.add (action_build, help_texts[action_build]);
2168  help.add (action_build_constituent_makefile, help_texts[action_build_constituent_makefile]);
2169  help.add (action_build_constituents_makefile, help_texts[action_build_constituents_makefile]);
2170  help.add (action_build_dependencies, help_texts[action_build_dependencies]);
2171  help.add (action_build_library_links, help_texts[action_build_library_links]);
2172  help.add (action_build_make_setup, help_texts[action_build_make_setup]);
2173  help.add (action_build_msdev, help_texts[action_build_msdev]);
2174  help.add (action_build_CMT_pacman, help_texts[action_build_CMT_pacman]);
2175  help.add (action_build_vsnet, help_texts[action_build_vsnet]);
2176  help.add (action_build_os9_makefile, help_texts[action_build_os9_makefile]);
2177  help.add (action_build_prototype, help_texts[action_build_prototype]);
2178  help.add (action_build_readme, help_texts[action_build_readme]);
2179  help.add (action_build_tag_makefile, help_texts[action_build_tag_makefile]);
2180  help.add (action_build_temporary_name, help_texts[action_build_temporary_name]);
2181  help.add (action_build_triggers, help_texts[action_build_triggers]);
2182  help.add (action_build_windefs, help_texts[action_build_windefs]);
2183  help.add (action_check_configuration, help_texts[action_check_configuration]);
2184  help.add (action_check_files, help_texts[action_check_files]);
2185  help.add (action_check_version, help_texts[action_check_version]);
2186  help.add (action_checkout, help_texts[action_checkout]);
2187  help.add (action_cleanup, help_texts[action_cleanup]);
2188  help.add (action_config, help_texts[action_config]);
2189  help.add (action_create, help_texts[action_create]);
2190  help.add (action_create_project, help_texts[action_create_project]);
2191  help.add (action_cvsbranches, help_texts[action_cvsbranches]);
2192  help.add (action_cvssubpackages, help_texts[action_cvssubpackages]);
2193  help.add (action_cvssubprojects, help_texts[action_cvssubprojects]);
2194  help.add (action_cvstags, help_texts[action_cvstags]);
2195  help.add (action_do, help_texts[action_do]);
2196  help.add (action_expand_model, help_texts[action_expand_model]);
2197  help.add (action_filter, help_texts[action_filter]);
2198  help.add (action_help, help_texts[action_help]);
2199  help.add (action_load, help_texts[action_load]);
2200  help.add (action_lock, help_texts[action_lock]);
2201  help.add (action_remove, help_texts[action_remove]);
2202  help.add (action_remove_library_links, help_texts[action_remove_library_links]);
2203  help.add (action_run, help_texts[action_run]);
2204  help.add (action_run_sequence, help_texts[action_run_sequence]);
2205  help.add (action_set_version, help_texts[action_set_version]);
2206  help.add (action_set_versions, help_texts[action_set_versions]);
2207  help.add (action_setup, help_texts[action_setup]);
2208  help.add (action_show, help_texts[action_show]);
2209  help.add (action_show_action, help_texts[action_show_action]);
2210  help.add (action_show_action_value, help_texts[action_show_action_value]);
2211  help.add (action_show_action_names, help_texts[action_show_action_names]);
2212  help.add (action_show_actions, help_texts[action_show_actions]);
2213  help.add (action_show_all_tags, help_texts[action_show_all_tags]);
2214  help.add (action_show_applied_patterns, help_texts[action_show_applied_patterns]);
2215  help.add (action_show_author, help_texts[action_show_author]);
2216  help.add (action_show_branches, help_texts[action_show_branches]);
2217  help.add (action_show_clients, help_texts[action_show_clients]);
2218  help.add (action_show_cmtpath_patterns, help_texts[action_show_cmtpath_patterns]);
2219  help.add (action_show_constituent, help_texts[action_show_constituent]);
2220  help.add (action_show_constituent_names, help_texts[action_show_constituent_names]);
2221  help.add (action_show_constituents, help_texts[action_show_constituents]);
2222  help.add (action_show_cycles, help_texts[action_show_cycles]);
2223  help.add (action_show_fragment, help_texts[action_show_fragment]);
2224  help.add (action_show_fragments, help_texts[action_show_fragments]);
2225  help.add (action_show_groups, help_texts[action_show_groups]);
2226  help.add (action_show_include_dirs, help_texts[action_show_include_dirs]);
2227  help.add (action_show_language, help_texts[action_show_language]);
2228  help.add (action_show_languages, help_texts[action_show_languages]);
2229  help.add (action_show_macro, help_texts[action_show_macro]);
2230  help.add (action_show_macro_value, help_texts[action_show_macro_value]);
2231  help.add (action_show_macro_names, help_texts[action_show_macro_names]);
2232  help.add (action_show_macros, help_texts[action_show_macros]);
2233  help.add (action_show_manager, help_texts[action_show_manager]);
2234  help.add (action_show_packages, help_texts[action_show_packages]);
2235  help.add (action_show_path, help_texts[action_show_path]);
2236  help.add (action_show_pattern, help_texts[action_show_pattern]);
2237  help.add (action_show_pattern_names, help_texts[action_show_pattern_names]);
2238  help.add (action_show_patterns, help_texts[action_show_patterns]);
2239  help.add (action_show_projects, help_texts[action_show_projects]);
2240  help.add (action_show_setup, help_texts[action_show_setup]);
2241  help.add (action_show_pwd, help_texts[action_show_pwd]);
2242  help.add (action_show_set, help_texts[action_show_set]);
2243  help.add (action_show_set_names, help_texts[action_show_set_names]);
2244  help.add (action_show_set_value, help_texts[action_show_set_value]);
2245  help.add (action_show_sets, help_texts[action_show_sets]);
2246  help.add (action_show_strategies, help_texts[action_show_strategies]);
2247  help.add (action_show_tags, help_texts[action_show_tags]);
2248  help.add (action_show_use_paths, help_texts[action_show_use_paths]);
2249  help.add (action_show_uses, help_texts[action_show_uses]);
2250  help.add (action_show_version, help_texts[action_show_version]);
2251  help.add (action_show_versions, help_texts[action_show_versions]);
2252  help.add (action_system, help_texts[action_system]);
2253  help.add (action_unlock, help_texts[action_unlock]);
2254  help.add (action_version, help_texts[action_version]);
2255}
2256
Note: See TracBrowser for help on using the repository browser.