From 6a2fa5f7f8109816ff7006dbc60a1b4701409e0d Mon Sep 17 00:00:00 2001
From: Francois Henrotte <francois.henrotte@ulg.ac.be>
Date: Mon, 12 Nov 2012 21:38:54 +0000
Subject: [PATCH]

---
 contrib/onelab/OnelabClients.cpp | 34 +++++++++-------
 contrib/onelab/OnelabParser.cpp  | 67 ++++++++++++++++++++++++++++----
 2 files changed, 79 insertions(+), 22 deletions(-)

diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp
index 3f9fc5839f..3080208a30 100644
--- a/contrib/onelab/OnelabClients.cpp
+++ b/contrib/onelab/OnelabClients.cpp
@@ -460,6 +460,7 @@ bool localSolverClient::checkCommandLine(){
   }
   else{
     //setCommandLine("");
+    OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), true);
     OLMsg::Error("Invalid command line <%s> for client <%s>",
 		 getCommandLine().c_str(), getName().c_str());
   }
@@ -606,9 +607,8 @@ bool remoteClient::syncInputFile(const std::string &wdir, const std::string &fil
 	cmd.assign("rsync -e ssh -auv " + localName + " " + _remoteHost +":");
 	if(_remoteDir.size())
 	  cmd.append(_remoteDir);
-	cmd.append(fileName);
+	cmd.append(split[1]);
 
-	//OLMsg::Info("System call <%s>", cmd.c_str());
 	SleepInSeconds(OLMsg::GetOnelabNumber("RSYNCDELAY"));
 	return mySystem(cmd);
       }
@@ -673,8 +673,8 @@ void MetaModel::analyze() {
   OLMsg::Info("Metamodel now ANALYZING");
   std::string fileName = genericNameFromArgs + onelabExtension;
   openOnelabBlock();
-  OLMsg::Info("Parse file <%s> success=%d", fileName.c_str(), 
-	      parse_onefile(fileName));
+  OLMsg::Info("Parse file <%s> %s", fileName.c_str(), 
+	      parse_onefile(fileName)?"ok":"ko");
   closeOnelabBlock();
 }
 
@@ -682,8 +682,8 @@ void MetaModel::compute() {
   OLMsg::Info("Metamodel now COMPUTING");
   std::string fileName = genericNameFromArgs + onelabExtension;
   openOnelabBlock();
-  OLMsg::Info("Parse file <%s> success=%d", fileName.c_str(), 
-	      parse_onefile(fileName));
+  OLMsg::Info("Parse file <%s> %s", fileName.c_str(), 
+	      parse_onefile(fileName)?"ok":"ko");
   closeOnelabBlock();
   onelab::server::instance()->setChanged(false);
 }
@@ -693,9 +693,9 @@ 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)
+  // A working (relative) subdir (useful to organize submodels)
   // can be defined with the command: client.workingSubdir(subdir) 
-  if(host.empty() || rdir.empty()){ //local client
+  if(host.empty()){ //local client
     if(!type.compare(0,6,"interf"))
       c= new InterfacedClient(name,cmdl,getWorkingDir());
     else if(!type.compare(0,6,"native"))
@@ -968,6 +968,7 @@ bool RemoteInterfacedClient::checkCommandLine(){
   }
   else{
     //setCommandLine("");
+    OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), true);
     OLMsg::Error("Invalid command line <%s> for client <%s>",
 		 getCommandLine().c_str(), getName().c_str());
   }
@@ -1043,6 +1044,7 @@ bool RemoteNativeClient::checkCommandLine(){
   }
   else{
     //setCommandLine("");
+    OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), true);
     OLMsg::Error("Invalid command line <%s> for client <%s>",
 		 getCommandLine().c_str(), getName().c_str());
   }
@@ -1129,6 +1131,7 @@ bool RemoteEncapsulatedClient::checkCommandLine(){
   }
   else{
   //   setCommandLine("");
+    OLMsg::SetOnelabString(getName() + "/CommandLine", getCommandLine(), true);
     OLMsg::Error("Invalid command line <%s> for client <%s>",
 		 getCommandLine().c_str(), getName().c_str());
   }
@@ -1209,7 +1212,9 @@ std::string ftoa(const double x){
 }
 
 int mySystem(std::string commandLine){
-  OLMsg::Info("Calling <%s>",commandLine.c_str());
+  //Don't use OLMsg::Info here otherwise the message appears twice
+  //in the Gmsh message window.
+  std::cout << "Onelab: Calling <" << commandLine << ">" << std::endl;
   return SystemCall(commandLine.c_str(), true);
 }
 
@@ -1274,10 +1279,11 @@ 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);
+  if( (pos0 != std::string::npos) && (!in.compare(pos0,1,"\"")))
+    pos0++;
+  if( (pos != std::string::npos) && (!in.compare(pos,1,"\"")))
+    pos--;
+  return in.substr(pos0,pos-pos0+1);
 }
 
 std::string FixWindowsQuotes(const std::string &in)
@@ -1357,7 +1363,7 @@ double find_in_array(int lin, int col, const std::vector <std::vector <double> >
 	return data[lin][col];
     }
   }
-  OLMsg::Error("The value has not been calculated: (%d,%d) out of range",lin,col);
+  OLMsg::Error("Find in array: (%d,%d) out of range",lin,col);
   return(0);
 }
 
diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp
index ab873af9e0..acb71fc4c8 100644
--- a/contrib/onelab/OnelabParser.cpp
+++ b/contrib/onelab/OnelabParser.cpp
@@ -66,7 +66,17 @@ int extractLogic(const std::string &in, std::vector<std::string> &arguments){
   return arguments.size();
 }
 
-// Client member function moved here because it uses parser commands 
+// Client member functions defined here because they use parser commands 
+
+// std::string localSolverClient::toChar(){
+//   std::ostringstream sstream;
+//   if(getCommandLine().size()){
+//     sstream << getName() << "." << "commandLine("
+// 	    << getCommandLine() << ");\n";
+//   }
+//   return sstream.str();
+// }
+
 void MetaModel::saveCommandLines(const std::string fileName){
   std::vector<std::string> arguments, buffer;
   std::string loaderPathName=OLMsg::GetOnelabString("LoaderPathName");
@@ -107,7 +117,6 @@ void MetaModel::saveCommandLines(const std::string fileName){
     // outfile << "(LoaderPathName) == ";
     // outfile << loaderPathName << ")" << std::endl;
     for(citer it = _clients.begin(); it != _clients.end(); it++){
-      //if((*it)->checkCommandLine())
 	 outfile << (*it)->toChar();
     }
     //outfile << olkey::olendif << std::endl;
@@ -489,7 +498,7 @@ void localSolverClient::parse_sentence(std::string line) {
       // if(arguments[0].empty()) numbers[0].setReadOnly(1);
 
       if(arguments.size()>2)
-	numbers[0].setLabel(arguments[2]);
+	numbers[0].setLabel(unquote(arguments[2]));
       if(arguments.size()>3){
 	std::vector<double> bounds;
 	if (resolveRange(arguments[3],bounds)){
@@ -521,7 +530,7 @@ void localSolverClient::parse_sentence(std::string line) {
       std::vector<std::string> choices;
       strings[0].setChoices(choices);
 
-      if(arguments.size()>2) strings[0].setLabel(arguments[2]);
+      if(arguments.size()>2) strings[0].setLabel(unquote(arguments[2]));
       set(strings[0]);
     }
     else if(!action.compare("radioButton")) { 
@@ -545,7 +554,7 @@ void localSolverClient::parse_sentence(std::string line) {
 	numbers[0].setValue(val);
       }
       if(arguments.size()>2)
-	numbers[0].setLabel(arguments[2]);
+	numbers[0].setLabel(unquote(arguments[2]));
       std::vector<double> choices;
       choices.push_back(0);
       choices.push_back(1);
@@ -575,11 +584,26 @@ void localSolverClient::parse_sentence(std::string line) {
 	    numbers[0].setStep(atof(arguments[2].c_str()));
 	  }
 	  else
-	    OLMsg::Error("Wrong number of arguments for MinMax <%s>",name.c_str());
+	    OLMsg::Error("Wrong number of arguments for range <%s>",
+			 name.c_str());
 	}
 	set(numbers[0]);
       }
     }
+    else if(!action.compare("withinRange")){ 
+      // ensure the value is in the prescribed range
+      name.assign(longName(name));
+      get(numbers,name);
+      if(numbers.size()){ // parameter must exist
+	if( (numbers[0].getMin() != -onelab::parameter::maxNumber()) &&
+	    (numbers[0].getValue() < numbers[0].getMin()) )
+	  numbers[0].setValue(numbers[0].getMin());
+	if( (numbers[0].getMax() != onelab::parameter::maxNumber()) &&
+	    (numbers[0].getValue() > numbers[0].getMax()) )
+	  numbers[0].setValue(numbers[0].getMax());
+	set(numbers[0]);
+      }
+    }
     else if(!action.compare("resetChoices")){
       name.assign(longName(name));
       get(numbers,name);
@@ -644,7 +668,7 @@ void localSolverClient::parse_sentence(std::string line) {
 	  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,arguments[i+1]);
+	  numbers[0].setValueLabel(val,unquote(arguments[i+1]));
 	}
 	numbers[0].setChoices(choices);
 	set(numbers[0]);
@@ -1356,12 +1380,39 @@ void MetaModel::client_sentence(const std::string &name,
 	    set(str);
 	  }
 	}
+	if(host.empty()) {
+	  host=OLMsg::GetOnelabString(name + "/remoteHost");
+	}
+	if(rdir.empty()) {
+	  rdir=OLMsg::GetOnelabString(name + "/remoteWork");
+	}
+
 	registerClient(name,type,cmdl,host,rdir);
       }
       else
 	OLMsg::Error("Redefinition of client <%s>", name.c_str());
     }
   }
+  else if(!action.compare("remote")){
+    if(isTodo(REGISTER)){
+      if(arguments.size()>0)
+	OLMsg::SetOnelabString(name + "/remoteHost", arguments[0], false);
+      else{
+	onelab::string str;
+	str.setName(name + "/remoteHost");
+	str.setAttribute("Highlight","Ivory");
+	set(str);
+      }
+      if(arguments.size()>1)
+	OLMsg::SetOnelabString(name + "/remoteDir", arguments[1], false);
+      else{
+	onelab::string str;
+	str.setName(name + "/remoteDir");
+	str.setAttribute("Highlight","Ivory");
+	set(str);
+      }
+    }
+  }
   else if(!action.compare("commandLine")){
     if(isTodo(REGISTER)){
       if(arguments[0].size())
@@ -1373,7 +1424,7 @@ void MetaModel::client_sentence(const std::string &name,
   else if(!action.compare("workingSubdir")){
     localSolverClient *c;
     if((c=findClientByName(name)))
-      c->setWorkingDir(c->getWorkingDir()+arguments[0]);
+      c->setWorkingDir(c->getWorkingDir() + arguments[0]);
     else
       OLMsg::Error("Unknown client <%s>", name.c_str());
   }
-- 
GitLab