source: CMT/v1r19/source/cmt_commands.cxx @ 11

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

Changing eol-style property

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