From 86c421378fada27d27c72dd4f081c5355f80fe7b Mon Sep 17 00:00:00 2001 From: Francois Henrotte <francois.henrotte@ulg.ac.be> Date: Wed, 31 Oct 2012 10:19:25 +0000 Subject: [PATCH] --- Fltk/onelabWindow.cpp | 1 + contrib/onelab/Makefile | 55 ++++++++++++++ contrib/onelab/OnelabClients.cpp | 4 +- contrib/onelab/OnelabParser.cpp | 122 ++++++++++++++++++++----------- contrib/onelab/loader.cpp | 3 +- 5 files changed, 138 insertions(+), 47 deletions(-) create mode 100644 contrib/onelab/Makefile diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp index 5358c17b40..40f58dc914 100644 --- a/Fltk/onelabWindow.cpp +++ b/Fltk/onelabWindow.cpp @@ -560,6 +560,7 @@ void onelab_cb(Fl_Widget *w, void *data) #if defined(HAVE_ONELAB_METAMODEL) if(metamodel(action)) geometry_reload_cb(0, 0); + Msg::ResetErrorCounter(); #endif } else{ diff --git a/contrib/onelab/Makefile b/contrib/onelab/Makefile new file mode 100644 index 0000000000..ad88b101e7 --- /dev/null +++ b/contrib/onelab/Makefile @@ -0,0 +1,55 @@ +SOLVERS=loader +SOURCES=myOS StringUtils mathex OnelabClients OnelabMessage OnelabParser metamodel + +COMMON_DIR=$(GMSH_DIR)/Common +ONELAB_DIR=$(GMSH_DIR)/projects/onelab +MATHEX_DIR=$(GMSH_DIR)/contrib/MathEx + +OBJDIR=objects + +ifeq ($(STATICLINUX), 32) + LDFLAGS+=-static-libgcc -static-libstdc++ -static -m32 + CPPFLAGS+= -m32 + OBJDIR=objects-static-linux32 + EXESUFFIX=32 +endif +ifeq ($(STATICLINUX), 64) + LDFLAGS+=-static-libgcc -static-libstdc++ -static + OBJDIR=objects-static-linux64 + EXESUFFIX=64 +endif +ifeq ($(MINGW), 32) + CXX=i686-w64-mingw32-g++ + LDFLAGS+=-static-libgcc -static-libstdc++ -static -lws2_32 + OBJDIR=objects-mingw32 + EXESUFFIX=32.exe +endif +ifeq ($(MINGW), 64) + CXX=x86_64-w64-mingw32-g++ + LDFLAGS+=-static-libgcc -static-libstdc++ -static -lws2_32 + OBJDIR=objects-mingw64 + EXESUFFIX=64.exe +endif + +TARGETS=$(SOLVERS:=_onelab$(EXESUFFIX)) +all : $(TARGETS) +ifndef GMSH_DIR + @echo '"The environment variable GMSH_DIR is not set."' + @exit +endif + +CPPFLAGS+=-I$(COMMON_DIR) -I$(ONELAB_DIR) -I$(MATHEX_DIR) -g +VPATH=$(ONELAB_DIR):$(COMMON_DIR):$(MATHEX_DIR) + +OBJECTS=$(foreach OBJ, $(SOURCES), $(OBJDIR)/$(OBJ).o) +$(OBJDIR)/%.o : %.cpp $(ONELAB_DIR)/*.h + @mkdir -p $(OBJDIR) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ + +%_onelab$(EXESUFFIX) : $(OBJDIR)/%.o $(OBJECTS) + $(CXX) $< $(OBJECTS) $(LDFLAGS) -o $@ + +clean : + $(RM) $(TARGETS) $(OBJDIR)/*.o + +.PRECIOUS: $(OBJDIR)/%.o diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index f72d2d8882..1b115740af 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -678,6 +678,8 @@ void MetaModel::registerClient(const std::string &name, const std::string &type, // Clients are assigned by default the same working dir as the MetaModel // i.e. the working dir from args + // A working subdir (useful to organize submodels in a metamodel) + // can be defined with the command: client.workingSubdir(subdir) if(host.empty() || rdir.empty()){ //local client if(!type.compare(0,6,"interf")) c= new InterfacedClient(name,cmdl,getWorkingDir()); @@ -1218,7 +1220,7 @@ std::string FixWindowsQuotes(const std::string &in) std::string FixExecPath(const std::string &in) { std::string cmd,split0,split1,split2; - std::cout << "in=<" << in << ">" << std::endl; + //std::cout << "in=<" << in << ">" << std::endl; cmd.assign(removeBlanks(in)); cmd.assign(FixWindowsPath(cmd)); diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index 3f2e6a35cf..0618a0a7a0 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -24,19 +24,94 @@ namespace olkey{ static std::string getRegion(label+"region"); } +int extractLogic(const std::string &in, std::vector<std::string> &arguments){ + // syntax: ( argument[0], argument[1]\in{<,>,<=,>=,==,!=}, arguments[2]) + size_t pos, cursor; + arguments.resize(0); + cursor=0; + if ( (pos=in.find("(",cursor)) == std::string::npos ) + OLMsg::Error("Syntax error: <%s>",in.c_str()); + + unsigned int count=1; + pos++; // skips '(' + cursor=pos; + do{ + if(in[pos]=='(') count++; + if(in[pos]==')') count--; + if( (in[pos]=='<') || (in[pos]=='=') || (in[pos]=='>') || (in[pos]=='!') ){ + arguments.push_back(removeBlanks(in.substr(cursor,pos-cursor))); + if(count!=1) + OLMsg::Error("Syntax error: <%s>",in.c_str()); + cursor=pos; + if(in[pos+1]=='='){ + arguments.push_back(in.substr(cursor,2)); + pos++; + } + else{ + arguments.push_back(in.substr(cursor,1)); + } + cursor=pos+1; + } + pos++; + } while( count && (pos!=std::string::npos) ); + // count is 0 when the closing brace is found. + + if(count) + OLMsg::Error("Syntax error: mismatched parenthesis in <%s>",in.c_str()); + else + arguments.push_back(removeBlanks(in.substr(cursor,pos-1-cursor))); + + if((arguments.size()!=1) && (arguments.size()!=3)) + OLMsg::Error("Syntax error: <%s>",in.c_str()); + return arguments.size(); +} + // Client member function moved here because it uses parser commands void MetaModel::saveCommandLines(const std::string fileName){ - //save client command lines + std::vector<std::string> arguments, buffer; + size_t cursor, pos; + std::string loaderPathName=OLMsg::GetOnelabString("LoaderPathName"); + std::string fileNameSave = getWorkingDir()+fileName+onelabExtension+".save"; + std::ifstream infile(fileNameSave.c_str()); + if (infile.is_open()){ + while (infile.good()){ + std::string line; + getline(infile,line); + if ( (pos=line.find(olkey::ifcond)) != std::string::npos) { + cursor = pos+olkey::ifcond.length(); + extractLogic(line.substr(cursor),arguments); + if(arguments.size() >= 2){ + bool keep = arguments[2].compare(loaderPathName); + if(keep) buffer.push_back(line); + do{ + getline (infile,line); + if(keep) buffer.push_back(line); + } while ((pos=line.find(olkey::olendif)) != std::string::npos); + } + else + OLMsg::Error("Incorrect statement <%s> in <%s>", + line.c_str(), fileNameSave.c_str()); + } + } + } + infile.close(); + + //save client command lines std::ofstream outfile(fileNameSave.c_str()); if (outfile.is_open()){ outfile << olkey::ifcond << "(" << olkey::getValue ; outfile << "(LoaderPathName) == "; - outfile << OLMsg::GetOnelabString("LoaderPathName") << ")" << std::endl; + outfile << loaderPathName << ")" << std::endl; for(citer it = _clients.begin(); it != _clients.end(); it++) if((*it)->checkCommandLine()) outfile << (*it)->toChar(); outfile << olkey::olendif << std::endl; + + for(std::vector<std::string>::const_iterator it = buffer.begin(); + it != buffer.end(); it++){ + outfile << (*it) << std::endl; + } } else OLMsg::Error("The file <%s> cannot be opened",fileNameSave.c_str()); @@ -84,47 +159,6 @@ int enclosed(const std::string &in, std::vector<std::string> &arguments, return arguments.size(); } -int extractLogic(const std::string &in, std::vector<std::string> &arguments){ - // syntax: ( argument[0], argument[1]\in{<,>,<=,>=,==,!=}, arguments[2]) - size_t pos, cursor; - arguments.resize(0); - cursor=0; - if ( (pos=in.find("(",cursor)) == std::string::npos ) - OLMsg::Error("Syntax error: <%s>",in.c_str()); - - unsigned int count=1; - pos++; // skips '(' - cursor=pos; - do{ - if(in[pos]=='(') count++; - if(in[pos]==')') count--; - if( (in[pos]=='<') || (in[pos]=='=') || (in[pos]=='>') || (in[pos]=='!') ){ - arguments.push_back(removeBlanks(in.substr(cursor,pos-cursor))); - if(count!=1) - OLMsg::Error("Syntax error: <%s>",in.c_str()); - cursor=pos; - if(in[pos+1]=='='){ - arguments.push_back(in.substr(cursor,2)); - pos++; - } - else{ - arguments.push_back(in.substr(cursor,1)); - } - cursor=pos+1; - } - pos++; - } while( count && (pos!=std::string::npos) ); - // count is 0 when the closing brace is found. - - if(count) - OLMsg::Error("Syntax error: mismatched parenthesis in <%s>",in.c_str()); - else - arguments.push_back(removeBlanks(in.substr(cursor,pos-1-cursor))); - - if((arguments.size()!=1) && (arguments.size()!=3)) - OLMsg::Error("Syntax error: <%s>",in.c_str()); - return arguments.size(); -} int extract(const std::string &in, std::string ¶mName, std::string &action, std::vector<std::string> &arguments){ @@ -1332,7 +1366,7 @@ void MetaModel::client_sentence(const std::string &name, OLMsg::Error("No pathname given for client <%s>", name.c_str()); } } - else if(!action.compare("workingDir")){ + else if(!action.compare("workingSubdir")){ localSolverClient *c; if((c=findClientByName(name))) c->setWorkingDir(c->getWorkingDir()+arguments[0]); diff --git a/contrib/onelab/loader.cpp b/contrib/onelab/loader.cpp index 14072372e1..6ced543660 100644 --- a/contrib/onelab/loader.cpp +++ b/contrib/onelab/loader.cpp @@ -227,8 +227,6 @@ int main(int argc, char *argv[]){ std::string caseName="", todo="compute", modelName="", workingDir=""; onelab::remoteNetworkClient *client = 0; - //if(argc) OLMsg::SetExecutableName(argv[0]); - while(i < argc) { if(argv[i][0] == '-') { if(!strcmp(argv[i] + 1, "a")) { @@ -282,6 +280,7 @@ int main(int argc, char *argv[]){ OLMsg::Fatal("No valid input model name <%s>.", caseName.c_str()); OLMsg::InitializeOnelab("onelab"); + if(argc) OLMsg::SetOnelabString("LoaderPathName",argv[0]); OLMsg::SetOnelabString("Arguments/FileName",modelName); OLMsg::SetOnelabString("Arguments/WorkingDir",workingDir); -- GitLab