summaryrefslogtreecommitdiff
path: root/TAO/CIAO/CCF/CCF/CodeGenerationKit/CommandLineParser.cpp
blob: 0394f89566925c312f6352459ddf7249f00d6b2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// File   : CommandLineParser.cpp
// Author : Boris Kolpackov <boris@dre.vanderbilt.edu>
// $Id$

#include "CCF/CodeGenerationKit/CommandLineParser.hpp"
#include "CCF/CodeGenerationKit/CommandLineGrammar.hpp"

#include <iostream>

using std::cerr;
using std::endl;

bool parse (int argc, char* argv[], CommandLine& cl) throw ()
{
  typedef vector<string> Argv;

  Argv v;

  for (int i = 0; i < argc; i++)
  {
    v.push_back (argv[i]);
  }

  Argv::iterator first = v.begin ();
  Argv::iterator last  = v.end ();

  scanner<Argv::iterator, scanner_policies <> > scan(first, last);

  CLineGrammar g (cl);

  match<nil_t> hit = g.parse(scan);

  bool result = hit.length() == v.size ();

  // some semantic analisys
  if (!cl.separator)
  {
    CommandLine::Options::reverse_iterator r = cl.options.rbegin ();

    if (r != cl.options.rend () &&
        r->value_ != "" &&
        r->type_ == CommandLine::Option::COMPOSITE)
    {

      cerr << "command line: assuming <" << r->value_
           << "> to be a value of option <" << r->name_
           << "> and not the first argument" << endl;

      cerr  << "command line: write ... --" << r->name_ << " -- "
            << r->value_ << " ... to indicate otherwise" << endl;
    }
  }

  return result;
}