X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fcore%2Futil%2FCommandLine.cpp;fp=source%2Fcore%2Futil%2FCommandLine.cpp;h=39f2cdb8f62fbda1a0a8e195c3683a7b0d777c31;hb=c377f6f51a72b35d5d0b341c624e8bad55baeea4;hp=74c34e1461cde32c1cd9d8f0263c217577203ae0;hpb=2032c82d206dd40e35d118242272417431094823;p=anna.git diff --git a/source/core/util/CommandLine.cpp b/source/core/util/CommandLine.cpp index 74c34e1..39f2cdb 100644 --- a/source/core/util/CommandLine.cpp +++ b/source/core/util/CommandLine.cpp @@ -89,6 +89,17 @@ throw() { a_arguments.push_back(new Variable(arg1, arg2, type, comment, needValue)); } +void CommandLine::initialize(const char** argv, const int argc, int positionalArguments) +throw(RuntimeException) { + if (argc < 1) throw RuntimeException("Provided argc < 1 as command-line argv size !", ANNA_FILE_LOCATION); + if (positionalArguments < 0) throw RuntimeException("Provided negative number of positional arguments as command-line initializer", ANNA_FILE_LOCATION); + if (positionalArguments > (argc-1)) throw RuntimeException("Provided positional arguments > (argc - 1) as command-line initializer", ANNA_FILE_LOCATION); + a_positionalArguments = positionalArguments; + a_argv = argv; + a_argc = argc; + a_wasParsed = false; +} + //-------------------------------------------------------------------------------- // Verifica que todos los argumentos declarados como obligatorios estan en la // linea de comandos. @@ -189,7 +200,7 @@ bool CommandLine::analize() throw() { Variable* variable; bool result = true; - int i = 1; + int i = a_positionalArguments + 1; string aux; if(a_wasParsed == true) // already analyzed @@ -315,6 +326,9 @@ throw() { vector ::const_iterator ii, maxii; const char *value; + for(int pos = 1; pos <= a_positionalArguments; pos++) + result += anna::functions::asString("Positional argument [%d]: %s\n", pos, getPositional(pos)); + for(ii = a_arguments.begin(), maxii = a_arguments.end(); ii != maxii; ii ++) { value = (*ii)->getValue(); @@ -334,6 +348,9 @@ xml::Node* CommandLine::asXML(xml::Node* parent) const throw() { vector ::const_iterator ii, maxii; const char *value; + for(int pos = 1; pos <= a_positionalArguments; pos++) + result->createAttribute(anna::functions::asString("PositionalArgument_%d", pos).c_str(), getPositional(pos)); + for(ii = a_arguments.begin(), maxii = a_arguments.end(); ii != maxii; ii ++) { value = (*ii)->getValue();