Skip to content
Snippets Groups Projects
Commit e324a4b2 authored by Christoph Grüninger's avatar Christoph Grüninger
Browse files

Remove deprecated --param=value.

(reviewed by fetzer)


git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@13555 2fb0f335-1f38-0410-981e-8018bf24f1b0
parent ba8689bc
No related branches found
No related tags found
No related merge requests found
...@@ -69,97 +69,17 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree &paramTree) ...@@ -69,97 +69,17 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree &paramTree)
return oss.str(); return oss.str();
} }
std::string paramName, paramValue; // read a -MyOpt VALUE option
std::string paramName = argv[i] + 1;
// read a --my-opt=VALUE option. This gets transformed
// into the parameter "MyOpt" with the value being "VALUE"
if (argv[i][1] == '-') {
// the syntax --my-opt=VALUE is deprecated and will be removed after DuMuX 2.6
std::cout << std::endl
<< "Warning: the syntax --my-opt=VALUE is deprecated and will be removed after DuMuX 2.6"
<< std::endl << std::endl;
std::string s(argv[i] + 2);
// There is nothing after the '='
if (s.size() == 0 || s[0] == '=')
{
std::ostringstream oss;
oss << "\n -> Parameter name of argument " << i << " (='" << argv[i] << "')"
<< " is empty. <- \n\n\n\n";
return oss.str();
}
// capitalize the first character if (argc == i + 1 || argv[i+1][0] == '-') {
s[0] = toupper(s[0]); std::ostringstream oss;
oss << "\n -> No argument given for parameter '" << argv[i] << "'! <- \n\n\n\n";
// parse argument return oss.str();
unsigned int j = 0;
while (true) {
if (j >= s.size()) {
// encountered the end of the string, i.e. we
// have a parameter where the argument is empty
paramName = s;
paramValue = "";
break;
}
else if (s[j] == '=') {
// we encountered a '=' character. everything
// before is the name of the parameter,
// everything after is the value.
paramName = s.substr(0, j);
paramValue = s.substr(j+1);
break;
}
else if (s[j] == '.') {
// we encountered a '.' character, indicating
// the end of a group name, and need
// to captitalize the following character
if (s.size() == j)
{
std::ostringstream oss;
oss << "\n -> Parameter name of argument " << i << " ('" << argv[i] << "')"
<< " is invalid (ends with a '.' character). <- \n\n\n\n";
return oss.str();
}
s[j+1] = toupper(s[j+1]);
}
else if (s[j] == '-') {
// remove all "-" characters and capitalize the
// character after them
s.erase(j, 1);
if (s.size() == j)
{
std::ostringstream oss;
oss << "\n -> Parameter name of argument " << i << " ('" << argv[i] << "')"
<< " is invalid (ends with a '-' character). <- \n\n\n\n";
return oss.str();
}
else if (s[j] == '-')
{
std::ostringstream oss;
oss << "\n -> Malformed parameter name name in argument " << i << " ('" << argv[i] << "'): "
<< "'--' in parameter name. <- \n\n\n\n";
return oss.str();
}
s[j] = toupper(s[j]);
}
++j;
}
} }
else {
// read a -MyOpt VALUE option
paramName = argv[i] + 1;
if (argc == i + 1 || argv[i+1][0] == '-') {
std::ostringstream oss;
oss << "\n -> No argument given for parameter '" << argv[i] << "'! <- \n\n\n\n";
return oss.str();
}
paramValue = argv[i+1]; std::string paramValue = argv[i+1];
++i; // In the case of '-MyOpt VALUE' each pair counts as two arguments ++i; // In the case of '-MyOpt VALUE' each pair counts as two arguments
}
// Put the key=value pair into the parameter tree // Put the key=value pair into the parameter tree
paramTree[paramName] = paramValue; paramTree[paramName] = paramValue;
......
...@@ -59,98 +59,18 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree &paramTree) ...@@ -59,98 +59,18 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree &paramTree)
return oss.str(); return oss.str();
} }
std::string paramName, paramValue; // read a -MyOpt VALUE option
std::string paramName = argv[i] + 1;
// read a --my-opt=VALUE option. This gets transformed
// into the parameter "MyOpt" with the value being "VALUE" if (argc == i + 1 || argv[i+1][0] == '-') {
if (argv[i][1] == '-') { std::ostringstream oss;
// the syntax --my-opt=VALUE is deprecated and will be removed after DuMuX 2.6 oss << "\n -> No argument given for parameter '" << argv[i] << "'! <- \n\n\n\n";
std::cout << std::endl return oss.str();
<< "Warning: the syntax --my-opt=VALUE is deprecated and will be removed after DuMuX 2.6"
<< std::endl << std::endl;
std::string s(argv[i] + 2);
// There is nothing after the '='
if (s.size() == 0 || s[0] == '=')
{
std::ostringstream oss;
oss << "\n -> Parameter name of argument " << i << " (='" << argv[i] << "')"
<< " is empty. <- \n\n\n\n";
return oss.str();
}
// capitalize the first character
s[0] = toupper(s[0]);
// parse argument
unsigned int j = 0;
while (true) {
if (j >= s.size()) {
// encountered the end of the string, i.e. we
// have a parameter where the argument is empty
paramName = s;
paramValue = "";
break;
}
else if (s[j] == '=') {
// we encountered a '=' character. everything
// before is the name of the parameter,
// everything after is the value.
paramName = s.substr(0, j);
paramValue = s.substr(j+1);
break;
}
else if (s[j] == '.') {
// we encountered a '.' character, indicating
// the end of a group name, and need
// to captitalize the following character
if (s.size() == j)
{
std::ostringstream oss;
oss << "\n -> Parameter name of argument " << i << " ('" << argv[i] << "')"
<< " is invalid (ends with a '.' character). <- \n\n\n\n";
return oss.str();
}
s[j+1] = toupper(s[j+1]);
}
else if (s[j] == '-') {
// remove all "-" characters and capitalize the
// character after them
s.erase(j, 1);
if (s.size() == j)
{
std::ostringstream oss;
oss << "\n -> Parameter name of argument " << i << " ('" << argv[i] << "')"
<< " is invalid (ends with a '-' character). <- \n\n\n\n";
return oss.str();
}
else if (s[j] == '-')
{
std::ostringstream oss;
oss << "\n -> Malformed parameter name name in argument " << i << " ('" << argv[i] << "'): "
<< "'--' in parameter name. <- \n\n\n\n";
return oss.str();
}
s[j] = toupper(s[j]);
}
++j;
}
}
else {
// read a -MyOpt VALUE option
paramName = argv[i] + 1;
if (argc == i + 1 || argv[i+1][0] == '-') {
std::ostringstream oss;
oss << "\n -> No argument given for parameter '" << argv[i] << "'! <- \n\n\n\n";
return oss.str();
}
paramValue = argv[i+1];
++i; // In the case of '-MyOpt VALUE' each pair counts as two arguments
} }
std::string paramValue = argv[i+1];
++i; // In the case of '-MyOpt VALUE' each pair counts as two arguments
// Put the key=value pair into the parameter tree // Put the key=value pair into the parameter tree
paramTree[paramName] = paramValue; paramTree[paramName] = paramValue;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment