Skip to content
Snippets Groups Projects
Commit a8d718ac authored by Francois Henrotte's avatar Francois Henrotte
Browse files

Windows quoting

parent 7427a729
No related branches found
No related tags found
No related merge requests found
......@@ -721,15 +721,17 @@ void Msg::LoadOnelabClient(const std::string &clientName, const std::string &soc
if(ps.size() && ps[0].getValue().size())
action.assign(ps[0].getValue());
cmd.assign("");
//cmd.assign("");
if(!action.compare("compute")){
std::vector<onelab::string> ps;
client->get(ps,clientName+"/FullCmdLine");
if(ps.size() && ps[0].getValue().size())
cmd.append(" " + ps[0].getValue());
cmd.assign(ps[0].getValue());
if(cmd.size()){
Msg::Info("Loader calls <%s>",cmd.c_str());
//client->sendInfo(strcat("Loader calls",cmd.c_str()));
std::cout << "Loader calls " << cmd << std::endl;
SystemCall(cmd.c_str(),true); //true->blocking
}
else
......
......@@ -407,10 +407,6 @@ const bool localSolverClient::getList(const std::string type, std::vector<std::s
bool localSolverClient::checkCommandLine(){
OLMsg::Info("Check command line for <%s>",getName().c_str());
if(getCommandLine().empty())
OLMsg::Warning("No commandline for client <%s>", getName().c_str());
if(!isActive()) return true;
if(!getCommandLine().empty()){
......@@ -418,13 +414,9 @@ bool localSolverClient::checkCommandLine(){
run(); // does nothing for Interfaced clients, initializes native clients
}
else{
OLMsg::Error("No commandline for client <%s>", getName().c_str());
if(OLMsg::hasGmsh) {
// exits metamodel and restores control to the onelab window
OLMsg::Error("The command line of client <%s> is undefined.",
getName().c_str());
std::cout << "\n\nBrowse for executable in the ONELAB window.\n\n"
<< std::endl;
return false;
return false; // exits metamodel and restores control to gmsh
}
else{ // asks the user in console mode
std::cout << "\nONELAB:Enter the command line (with path) of the executable file of <" << getName() << ">" << std::endl;
......@@ -645,6 +637,7 @@ void MetaModel::construct()
parse_onefile( genericNameFromArgs + onelabExtension + ".save",false);
parse_onefile( genericNameFromArgs + onelabExtension);
closeOnelabBlock();
saveCommandLines(genericNameFromArgs);
}
void MetaModel::analyze() {
......@@ -862,7 +855,7 @@ void EncapsulatedClient::convert() {
}
std::string EncapsulatedClient::buildCommandLine(){
return OLMsg::GetLoaderName();
return FixWindowsQuote(OLMsg::GetLoaderName());
}
void EncapsulatedClient::compute(){
......@@ -893,6 +886,7 @@ void EncapsulatedClient::compute(){
OLMsg::SetOnelabString(getName()+"/FullCmdLine",cmd,false);
// the encapsulating localNetworkClient is called
OLMsg::Info("Command line=<%s>",cmd.c_str());
run();
if(getList("OutputFiles",choices)){
......@@ -977,7 +971,7 @@ void RemoteNativeClient::compute(){
analyze();
if(OLMsg::GetErrorNum()) return;
OLMsg::Info("Analyze <%s> changed=%d", getName().c_str());
OLMsg::Info("Computes <%s> changed=%d", getName().c_str());
setAction("compute");
if(getList("InputFiles",choices)){
......@@ -1035,6 +1029,7 @@ void RemoteEncapsulatedClient::compute(){
OLMsg::SetOnelabString(getName()+"/FullCmdLine",cmd,false);
// the encapsulating localNetworkClient is called
OLMsg::Info("Command line=<%s>",cmd.c_str());
run();
if(getList("OutputFiles",choices)){
......@@ -1128,6 +1123,7 @@ bool checkIfPresent(std::string fileName){
#include <sys/types.h>
#if not defined WIN32
#include <unistd.h>
#include <pwd.h>
......@@ -1162,6 +1158,26 @@ std::string sanitize(const std::string &in)
out.push_back(in[i]);
return out;
}
std::string FixWindowQuotes(const std::string &in)
{
#if defined(WIN32)
return "\"" + in + "\"";
#else
return in;
#endif
}
std::string unquote(const std::string &in)
{
size_t pos0=in.find_first_not_of(" ");
size_t pos=in.find_last_not_of(" ");
if( (pos0 != std::string::npos) && (pos != std::string::npos))
if(in.compare(pos0,1,"\"")) pos0++;
if(in.compare(pos,1,"\"")) pos--;
return in.substr(pos0,pos-pos0+1);
}
std::string removeBlanks(const std::string &in)
{
size_t pos0=in.find_first_not_of(" ");
......@@ -1175,7 +1191,7 @@ bool isPath(const std::string &in)
{
size_t pos=in.find_last_not_of(" 0123456789");
if(in.compare(pos,1,"/"))
OLMsg::Error("The argument <%s> is not a valid path (must end with '/')",in.c_str());
OLMsg::Error("The argument <%s> is not a valid parameter path (must end with '/')",in.c_str());
return true;
}
......
......@@ -39,6 +39,8 @@ std::string getUserHomedir();
std::string sanitize(const std::string &in);
std::string removeBlanks(const std::string &in);
bool isPath(const std::string &in);
std::string FixWindowQuotes(const std::string &in);
std::string unquote(const std::string &in);
// Parser TOOLS
int enclosed(const std::string &in, std::vector<std::string> &arguments, size_t &end);
......
......@@ -160,9 +160,11 @@ std::string localSolverClient::resolveGetVal(std::string line) {
pos0=pos; // for further use
cursor = pos+olkey::getValue.length();
int NumArg=enclosed(line.substr(cursor),arguments,pos);
if(NumArg<1)
if(NumArg<1){
OLMsg::Error("Misformed %s statement: <%s>",
olkey::getValue.c_str(),line.c_str());
return "??";
}
std::string paramName=longName(arguments[0]);
get(numbers,paramName);
if (numbers.size()){
......@@ -246,8 +248,10 @@ std::string localSolverClient::resolveGetVal(std::string line) {
get(strings,longName(paramName));
if (strings.size())
buff.assign(strings[0].getValue());
else
else{
OLMsg::Error("resolveGetVal: unknown variable: <%s>",paramName.c_str());
return "??";
}
}
line.replace(pos0,cursor+pos-pos0,buff);
cursor=pos0+buff.length();
......@@ -258,9 +262,11 @@ std::string localSolverClient::resolveGetVal(std::string line) {
while ( (pos=line.find(olkey::mathex,cursor)) != std::string::npos){
size_t pos0=pos;
cursor=pos+olkey::mathex.length();
if(enclosed(line.substr(cursor),arguments,pos) != 1)
if(enclosed(line.substr(cursor),arguments,pos) != 1){
OLMsg::Error("Misformed %s statement: <%s>",
olkey::mathex.c_str(),line.c_str());
return "??";
}
//std::cout << "MathEx evaluates now <"<< arguments[0]<< "> " << std::endl;
smlib::mathex* mathExp = new smlib::mathex();
mathExp->expression(arguments[0]);
......@@ -401,9 +407,11 @@ void localSolverClient::parse_sentence(std::string line) {
}
else if(!action.compare("radioButton")) {
// syntax: paramName.radioButton(val,path,label)
double val=0;
if(arguments[0].empty())
OLMsg::Error("No value given for param <%s>",name.c_str());
double val=atof(arguments[0].c_str());
else
val=atof(arguments[0].c_str());
if((arguments.size()>1) && isPath(arguments[1]))
name.assign(arguments[1] + name);
_parameters.insert(name);
......@@ -430,12 +438,13 @@ void localSolverClient::parse_sentence(std::string line) {
// syntax: paramName.range({a:b:c|a:b#n|min,max,step})
if(arguments[0].empty())
OLMsg::Error("No argument given for MinMax <%s>",name.c_str());
else{
name.assign(longName(name));
get(numbers,name);
if(numbers.size()){ // parameter must exist
if(arguments.size()==1){
std::vector<double> bounds;
if (extractRange(arguments[1],bounds)){
if (extractRange(arguments[0],bounds)){
numbers[0].setMin(bounds[0]);
numbers[0].setMax(bounds[1]);
numbers[0].setStep(bounds[2]);
......@@ -451,6 +460,7 @@ void localSolverClient::parse_sentence(std::string line) {
}
set(numbers[0]);
}
}
else if(!action.compare("resetChoices")){
name.assign(longName(name));
get(numbers,name);
......@@ -550,6 +560,7 @@ void localSolverClient::parse_sentence(std::string line) {
else if(!action.compare("setVisible")){
if(arguments[0].empty())
OLMsg::Error("Missing argument SetVisible <%s>",name.c_str());
else{
name.assign(longName(name));
get(numbers,name);
if(numbers.size()){
......@@ -567,9 +578,11 @@ void localSolverClient::parse_sentence(std::string line) {
}
}
}
}
else if(!action.compare("setReadOnly")){
if(arguments[0].empty())
OLMsg::Error("Missing argument SetReadOnly <%s>",name.c_str());
else{
name.assign(longName(name));
get(numbers,name);
if(numbers.size()){
......@@ -587,6 +600,7 @@ void localSolverClient::parse_sentence(std::string line) {
}
}
}
}
else if(!action.compare("layout")){
name.assign(longName(name));
get(numbers,name);
......@@ -611,6 +625,7 @@ void localSolverClient::parse_sentence(std::string line) {
if(arguments.size() !=2 )
OLMsg::Error("SetAttribute <%s> needs two arguments %d",
name.c_str(), arguments.size());
else{
name.assign(longName(name));
get(numbers,name);
if(numbers.size()){
......@@ -629,6 +644,7 @@ void localSolverClient::parse_sentence(std::string line) {
}
}
}
}
else{
client_sentence(name,action,arguments);
}
......@@ -701,10 +717,11 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
else if ( (pos=line.find(olkey::iftrue)) != std::string::npos) {
// onelab.iftrue
cursor = pos+olkey::iftrue.length();
bool condition = false;
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::iftrue.c_str(),line.c_str());
bool condition = false;
else{
get(strings,longName(arguments[0]));
if (strings.size())
condition= true;
......@@ -720,13 +737,15 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
OLMsg::Error("Misformed <%s> statement: <%s>",
olkey::iftrue.c_str(),arguments[0].c_str());
}
}
else if ( (pos=line.find(olkey::ifntrue)) != std::string::npos) {
// onelab.ifntrue
cursor = pos+olkey::ifntrue.length();
bool condition = false;
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::ifntrue.c_str(),line.c_str());
bool condition = false;
else{
get(strings,longName(arguments[0]));
if (strings.size())
condition= true;
......@@ -743,6 +762,7 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
OLMsg::Error("Misformed <%s> statement: <%s>",
olkey::ifntrue.c_str(),arguments[0].c_str());
}
}
else if ( (pos=line.find(olkey::ifcond)) != std::string::npos) {
// onelab.ifcond
cursor = pos+olkey::ifcond.length();
......@@ -759,6 +779,7 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::include.c_str(),line.c_str());
else
parse_onefile(arguments[0]);
}
else if ( (pos=line.find(olkey::message)) != std::string::npos) {
......@@ -767,9 +788,11 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::message.c_str(),line.c_str());
else{
std::string msg = resolveGetVal(arguments[0]);
OLMsg::Info("%s",msg.c_str());
}
}
else if ( (pos=line.find(olkey::showParam)) != std::string::npos) {
// onelab.showParam
cursor = pos+olkey::showParam.length();
......@@ -801,15 +824,18 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::showGmsh.c_str(),line.c_str());
else{
std::string fileName=resolveGetVal(arguments[0]);
OLMsg::MergeFile(fileName);
}
}
else if ( (pos=line.find(olkey::dump)) != std::string::npos) {
// onelab.dump
cursor = pos+olkey::dump.length();
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::dump.c_str(),line.c_str());
else
onelab::server::instance()->toFile(resolveGetVal(arguments[0]));
}
else if( isOnelabBlock() ||
......@@ -935,7 +961,7 @@ void localSolverClient::parse_onefile(std::string fileName, bool mandatory) {
if(mandatory)
OLMsg::Error("The file <%s> does not exist",fullName.c_str());
else
OLMsg::Info("The file <%s> does not exist",fullName.c_str());
OLMsg::Warning("The file <%s> does not exist",fullName.c_str());
}
bool localSolverClient::convert_ifstatement(std::ifstream &infile, std::ofstream &outfile, bool condition) {
......@@ -1002,12 +1028,11 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
else if ( (pos=line.find(olkey::iftrue)) != std::string::npos) {
// onelab.iftrue
cursor = pos+olkey::iftrue.length();
// pos=line.find_first_of(')',cursor)+1;
// if(enclosed(line.substr(cursor,pos-cursor),arguments)<1)
bool condition = false;
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::iftrue.c_str(),line.c_str());
bool condition = false;
else{
get(strings,longName(arguments[0]));
if (strings.size())
condition= true;
......@@ -1023,15 +1048,15 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
OLMsg::Error("Misformed <%s> statement: %s",
olkey::iftrue.c_str(),arguments[0].c_str());
}
}
else if ( (pos=line.find(olkey::ifntrue)) != std::string::npos) {
// onelab.ifntrue
cursor = pos+olkey::ifntrue.length();
// pos=line.find_first_of(')',cursor)+1;
// if(enclosed(line.substr(cursor,pos-cursor),arguments)<1)
bool condition = false;
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::ifntrue.c_str(),line.c_str());
bool condition = false;
else{
get(strings,longName(arguments[0]));
if (strings.size())
condition= true;
......@@ -1047,6 +1072,7 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
OLMsg::Error("Misformed <%s> statement: %s",
olkey::ifntrue.c_str(),arguments[0].c_str());
}
}
else if ( (pos=line.find(olkey::ifcond)) != std::string::npos) {
// onelab.ifcond
cursor = pos+olkey::ifcond.length();
......@@ -1061,6 +1087,7 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::include.c_str(),line.c_str());
else
convert_onefile(arguments[0],outfile);
}
else if ( (pos=line.find(olkey::message)) != std::string::npos) {
......@@ -1069,9 +1096,11 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Error("Misformed <%s> statement: (%s)",
olkey::message.c_str(),line.c_str());
else{
std::string msg = resolveGetVal(arguments[0]);
OLMsg::Info("%s",msg.c_str());
}
}
else if ( (pos=line.find(olkey::getValue)) != std::string::npos) {
outfile << resolveGetVal(line) << std::endl;
}
......@@ -1200,9 +1229,8 @@ void MetaModel::client_sentence(const std::string &name,
}
else if(!action.compare("commandLine")){
if(isTodo(REGISTER)){
if(arguments[0].size()){
if(arguments[0].size())
OLMsg::SetOnelabString(name + "/CommandLine",arguments[0],false);
}
else
OLMsg::Error("No pathname given for client <%s>", name.c_str());
}
......@@ -1283,7 +1311,7 @@ void MetaModel::client_sentence(const std::string &name,
}
localSolverClient *c;
if((c=findClientByName(name))){
c->checkCommandLine(); // initialize client if native
if(c->checkCommandLine() && !OLMsg::GetErrorNum())
c->analyze();
}
}
......@@ -1356,10 +1384,10 @@ void MetaModel::client_sentence(const std::string &name,
c->compute();
onelab::server::instance()->setChanged(false, c->getName());
}
}
else
OLMsg::Error("Unknown client <%s>", name.c_str());
}
}
else if(!action.compare("merge")){
if(isTodo(COMPUTE)){
std::vector<std::string> choices;
......@@ -1371,6 +1399,8 @@ void MetaModel::client_sentence(const std::string &name,
OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",1,false);
c->GmshMerge(choices);
}
else
OLMsg::Error("Unknown client <%s>", name.c_str());
}
}
else if(!action.compare("frontPage")){
......@@ -1380,15 +1410,16 @@ void MetaModel::client_sentence(const std::string &name,
}
localSolverClient *c;
if((c=findClientByName(name))) {
//c->checkCommandLine();
if(isTodo(ANALYZE) || isTodo(COMPUTE))
if(isTodo(REGISTER))
if(onelab::server::instance()->getChanged(c->getName())){
c->compute();
c->GmshMerge(choices);
OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",1,false);
onelab::server::instance()->setChanged(false, c->getName());
//onelab::server::instance()->setChanged(false, c->getName());
}
}
else
OLMsg::Error("Unknown client <%s>", name.c_str());
}
else
OLMsg::Error("Unknown action <%s>",action.c_str());
......
......@@ -16,6 +16,8 @@ void initializeMetamodel(const std::string &loaderName, onelab::client *olclient
}
int metamodel(const std::string &action){
int errors;
OLMsg::Info("Start metamodel");
OLMsg::hasGmsh = OLMsg::GetOnelabNumber("IsMetamodel");
OLMsg::ResetErrorNum();
......@@ -37,44 +39,48 @@ int metamodel(const std::string &action){
std::string workingDir = OLMsg::GetOnelabString("Arguments/WorkingDir");
std::string clientName = "meta";
MetaModel *myModel =
new MetaModel(clientName, workingDir, clientName, modelName);
myModel->setTodo(todo);
if(OLMsg::GetOnelabNumber("LOGFILES")){
if(workingDir.size()) workingDir.append(dirSep);
std::string mystdout = workingDir + "stdout.txt";
std::string mystderr = workingDir + "stderr.txt";
std::string mystdout = FixWindowsQuotes(workingDir + "stdout.txt");
std::string mystderr = FixWindowsQuotes(workingDir + "stderr.txt");
freopen(mystdout.c_str(),"w",stdout);
freopen(mystderr.c_str(),"w",stderr);
OLMsg::Info("Redirecting stdout into <%s>",mystdout.c_str());
OLMsg::Info("Redirecting stderr into <%s>",mystderr.c_str());
}
MetaModel *myModel =
new MetaModel("meta", workingDir, "meta", modelName);
myModel->setTodo(todo);
//if not all clients have valid commandlines -> exit metamodel
if(!myModel->checkCommandLines())
myModel->setTodo(EXIT);
// if(!myModel->checkCommandLines())
// myModel->setTodo(EXIT);
if( myModel->isTodo(EXIT)){
// exit metamodel
}
else if( myModel->isTodo(ANALYZE)){
if(OLMsg::GetErrorNum()) myModel->setTodo(EXIT);
if( myModel->isTodo(ANALYZE)){
myModel->analyze();
}
else if( myModel->isTodo(COMPUTE)){
myModel->compute();
}
else if( myModel->isTodo(EXIT)){
}
else
OLMsg::Error("Main: Unknown Action <%d>", todo);
delete myModel;
if((errors=OLMsg::GetErrorNum())){
OLMsg::Error("Leave metamodel - %d errors",errors);
OLMsg::Info("==============================================");
return 0;
}
int reload=OLMsg::GetOnelabNumber("Gmsh/NeedReloadGeom");
int errors=OLMsg::GetErrorNum();
OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",0,false);
if(errors)
OLMsg::Error("Leave metamodel - %d errors",errors);
else
OLMsg::Info("Leave metamodel - need reload=%d", reload);
OLMsg::Info("==============================================");
return reload;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment