diff --git a/contrib/onelab/Makefile b/contrib/onelab/OLMakefile similarity index 100% rename from contrib/onelab/Makefile rename to contrib/onelab/OLMakefile diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index bb2c8c08b3913fd5ab8808d00d4252ac94f21f8d..b606ac933db533571d51e844a4632f57234bb8d9 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -141,7 +141,7 @@ bool localNetworkSolverClient::run() while(1) { if(_pid < 0) break; - int stop = server->NonBlockingWait(sock, 0.001, 0.); + int stop = server->NonBlockingWait(sock, 0.0001, 0.); if(stop || _pid < 0) { OLMsg::Info("Stop=%d _pid=%d",stop, _pid); break; @@ -504,7 +504,7 @@ void localSolverClient::PostArray(std::vector<std::string> choices) std::string fileName = getWorkingDir()+choices[4*i]; //checkIfPresent or make available locally double val=find_in_array(lin,col,read_array(fileName,' ')); - addNumberChoice(choices[4*i+3],val,true); + addNumberChoice(longName(choices[4*i+3]),val,true); OLMsg::Info("Upload parameter <%s>=%e from file <%s>", choices[4*i+3].c_str(),val,fileName.c_str()); i++; diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index 008cbfc80529b6bf2cc7440f1218bc09e9cf1301..3a1efdd6248e29ad7e828dae43f7d8d3c1c2eb2d 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -153,9 +153,6 @@ int enclosed(const std::string &in, std::vector<std::string> &arguments, OLMsg::Error("Syntax error: mismatched parenthesis <%s>",in.c_str()); cursor=pos+1; // skips ',' } - else if(in[pos]==';') - OLMsg::Error("Syntax error: unterminated sentence <%s>",in.c_str()); - pos++; } while( count && (pos!=std::string::npos) ); // count is 0 when the closing brace is found. @@ -188,7 +185,14 @@ int extract(const std::string &in, std::string ¶mName, else action.assign(sanitize(in.substr(cursor,pos-cursor))); cursor = pos; - return enclosed(in.substr(cursor),arguments,pos); + + int NumArg = enclosed(in.substr(cursor),arguments,pos); + //std::cout << "FHF=" << in.substr(cursor+pos) << std::endl; + if((in.find_first_not_of(" \t",cursor+pos)) != std::string::npos){ + OLMsg::Error("Ghost command in <%s> (forgot a %s ?)", + in.c_str(),olkey::separator.c_str()); + } + return NumArg; } int extractLogic(const std::string &in, std::vector<std::string> &arguments){ @@ -735,18 +739,21 @@ void localSolverClient::parse_sentence(std::string line) { name.assign(longName(name)); get(numbers,name); if(numbers.size()){ // parameter must exist - if(arguments.size() % 2) + if(arguments.size() % 2){ OLMsg::Error("Nb of labels does not match nb of choices for <%s>", - name.c_str()); - std::vector<double> choices=numbers[0].getChoices(); - for(unsigned int i = 0; i < arguments.size(); i=i+2){ - double val=atof(resolveGetVal(arguments[i]).c_str()); - if(std::find(choices.begin(),choices.end(),val)==choices.end()) - choices.push_back(val); - numbers[0].setValueLabel(val,unquote(arguments[i+1])); + name.c_str()); + } + else{ + std::vector<double> choices=numbers[0].getChoices(); + for(unsigned int i = 0; i < arguments.size(); i=i+2){ + double val=atof(resolveGetVal(arguments[i]).c_str()); + if(std::find(choices.begin(),choices.end(),val)==choices.end()) + choices.push_back(val); + numbers[0].setValueLabel(val,unquote(arguments[i+1])); + } + numbers[0].setChoices(choices); + set(numbers[0]); } - numbers[0].setChoices(choices); - set(numbers[0]); } else OLMsg::Error("The number <%s> does not exist",name.c_str()); @@ -903,7 +910,7 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) { OLMsg::Error("Misformed <%s> statement", olkey::deflabel.c_str()); } else if( (pos=line.find(olkey::begin)) != std::string::npos) { - // onelab.begin + // onelab.block if (!parse_block(infile)) OLMsg::Error("Misformed <%s> block <%s>", olkey::begin.c_str(),olkey::end.c_str()); @@ -1039,52 +1046,57 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) { else if( isOnelabBlock() || ( !isOnelabBlock() && ((pos=line.find(olkey::line)) != std::string::npos)) ){ - // either any other line within a onelabBlock or a line + // either any line with no "OL." within a onelabBlock or a line // introduced by a "onelab.line" tag not within a onelabBlock std::string cmds="",cmd; size_t posa, posb; - int NbLines=1; + int NbLines = 1; + bool err = false, terminated = false; do{ + // skip tag 'olkey::line' if any if( (pos=line.find(olkey::line)) != std::string::npos) posa=pos + olkey::line.size(); else - posa=0; // skip tag 'olkey::line' if any + posa=0; - posb=line.find(olkey::comment); // skip trailing comments if any + // skip trailing comments if any + posb=line.find(olkey::comment); if(posb==std::string::npos) cmd.assign(line.substr(posa)); else cmd.assign(line.substr(posa,posb-posa)); - cmds.append(cmd); + cmds.append(cmd); //std::cout << "cmds=<" << cmds << ">" << std::endl; // check whether "cmd" ends now with "olkey::separator" posb=cmd.find_last_not_of(" \t")-olkey::separator.length()+1; if(posb<0) posb=0; - if(cmd.compare(posb,olkey::separator.length(),olkey::separator)){ - // append the next line + terminated = !cmd.compare(posb,olkey::separator.length(),olkey::separator); + + if(!terminated){ + // not found olkey::separator => append the next line getline (infile,line); - if((pos=line.find_first_not_of(" \t"))==std::string::npos){ - OLMsg::Error("Empty line not allowed within a command <%s>", - cmds.c_str()); - break; - } - else if(!line.compare(pos,olkey::comment.size(),olkey::comment)){ - OLMsg::Error("Comment lines not allowed within a command <%s>", - cmds.c_str()); - break; + NbLines++; // command should not span over more than 20 lines + if((pos=line.find_first_not_of(" \t")) == std::string::npos) + getline (infile,line); + else if(!line.compare(pos,olkey::comment.size(),olkey::comment)) + getline (infile,line); + else if(!line.compare(pos,olkey::end.size(),olkey::end)){ + err = true; + closeOnelabBlock(); } - NbLines++; // command should not span over more than 10 lines } - else - break; - } while (infile.good() && NbLines<=10); - if(NbLines>=10) - OLMsg::Error("Command <%s> should not span over more than 10 lines", - cmds.c_str()); - else + } while (infile.good() && !err && !terminated && NbLines <= 20); + + if(terminated) parse_sentence(cmds); + else if(err) + OLMsg::Error("Block ended within multiline command <%s>", + cmds.c_str()); + else if(NbLines >= 20) + OLMsg::Error("Command <%s> should not span over more than 20 lines", + cmds.c_str()); } else if ( (pos=line.find(olkey::getValue)) != std::string::npos) { // onelab.getValue: nothing to do diff --git a/contrib/onelab/metamodel.cpp b/contrib/onelab/metamodel.cpp index 71fb77e8f395e2a1aeee03cb04d1ca9a3a6422f9..ff339bbdd2a8b83e7deea586d02e45b84d516527 100644 --- a/contrib/onelab/metamodel.cpp +++ b/contrib/onelab/metamodel.cpp @@ -26,7 +26,7 @@ std::string getString(const std::string &name){ /* Interface Gmsh - Metamodels */ -void initializeMetamodel(const std::string &loaderName, onelab::client *olclient, void (*gui_wait_fct)(double time)) +void initializeMetamodel(const std::string &loaderName, onelab::client *olclient, void (*gui_wait_fct)(double time), const int verbosity) { //called by "metamodel_cb" //copies the Msg::_onelabClient to OLMsg::_onelabClient @@ -37,6 +37,7 @@ void initializeMetamodel(const std::string &loaderName, onelab::client *olclient OLMsg::SetOnelabClient(olclient); OLMsg::SetOnelabString("LoaderPathName",loaderName,false); OLMsg::SetGuiWaitFunction(gui_wait_fct); + OLMsg::SetVerbosity(verbosity); } int metamodel(const std::string &action){ diff --git a/contrib/onelab/metamodel.h b/contrib/onelab/metamodel.h index 701f3368f0f98427d590dc8ca14f2b8b92f2d9a2..54bff8a70b8d499cee225472e0d17dcecd26488b 100644 --- a/contrib/onelab/metamodel.h +++ b/contrib/onelab/metamodel.h @@ -8,7 +8,7 @@ namespace onelab{ class client; } int metamodel(const std::string &todo); -void initializeMetamodel(const std::string &, onelab::client *, void (*wait)(double time)); +void initializeMetamodel(const std::string &, onelab::client *, void (*wait)(double time), const int verbosity); /* PYTHON functions */ diff --git a/contrib/onelab/onelab.i b/contrib/onelab/onelab.i new file mode 100644 index 0000000000000000000000000000000000000000..ae601f09c8b1783f1d0545d74d720c86554c61a3 --- /dev/null +++ b/contrib/onelab/onelab.i @@ -0,0 +1,23 @@ +%module onelab +%{ +#include "onelab.h" +onelab::server *onelab::server::_server = 0; +void modelName(const std::string &name, const std::string &wdir=""); +int metamodel(const std::string &todo); +void setNumber(const std::string &name, const double value); +void setString(const std::string &name, const std::string &value); +double getNumber(const std::string &name); +std::string getString(const std::string &name); + +%} + +%include std_string.i + +extern void modelName(const std::string &name, const std::string &wdir=""); +extern int metamodel(const std::string &todo); +extern void setNumber(const std::string &name, const double value); +extern void setString(const std::string &name, const std::string &value); +extern double getNumber(const std::string &name); +extern std::string getString(const std::string &name); + +