// file : CCF/CodeGenerationKit/CommandLineParser.cpp // author : Boris Kolpackov // cvs-id : $Id$ #include "CCF/CodeGenerationKit/CommandLineParser.hpp" #include "CCF/CodeGenerationKit/CommandLineGrammar.hpp" #include #include #include using std::cerr; using std::endl; bool parse (int argc, char* argv[], CommandLine& cl) throw () { typedef std::vector 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 > scan(first, last); CLineGrammar g (cl); match hit = g.parse(scan); bool result = static_cast(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; }