From 01900207ab36712506dee38ecb1623ad4b5357bd Mon Sep 17 00:00:00 2001
From: Francois Henrotte <francois.henrotte@ulg.ac.be>
Date: Thu, 6 Dec 2012 09:09:46 +0000
Subject: [PATCH]

---
 contrib/onelab/OnelabClients.cpp | 30 ++++++++++------
 contrib/onelab/OnelabMessage.cpp |  2 +-
 contrib/onelab/OnelabParser.cpp  | 59 ++++++++++++++++++++------------
 3 files changed, 58 insertions(+), 33 deletions(-)

diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp
index ba839c14bd..bb2c8c08b3 100644
--- a/contrib/onelab/OnelabClients.cpp
+++ b/contrib/onelab/OnelabClients.cpp
@@ -741,7 +741,8 @@ void InterfacedClient::analyze() {
     split = SplitOLFileName(choices[i]);
     if(split[2].size()){ // if .ol file
       std::string fileName = getWorkingDir() + split[1] + split[2];
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
       OLMsg::Info("Parse file <%s> %s", fileName.c_str(), 
 		  parse_onefile(fileName)?"done":"failed");
     }
@@ -758,7 +759,8 @@ void InterfacedClient::convert() {
     if(split[2].size()){ // if .ol file
       std::string fileName = getWorkingDir() + split[1] + split[2];
       std::string ofileName = getWorkingDir() + split[1] ;
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
       std::ofstream outfile(ofileName.c_str());
       if (outfile.is_open())
 	convert_onefile(fileName,outfile);
@@ -781,7 +783,8 @@ void InterfacedClient::compute(){
     for(unsigned int i = 0; i < choices.size(); i++){
       split = SplitOLFileName(choices[i]);
       std::string fileName = getWorkingDir() + split[1];
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
     }
   }
 
@@ -800,7 +803,8 @@ void InterfacedClient::compute(){
     for(unsigned int i = 0; i < choices.size(); i++){
       split = SplitOLFileName(choices[i]);
       std::string fileName = getWorkingDir() + split[1];
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
     }
   }
 }
@@ -828,7 +832,8 @@ void NativeClient::compute() {
     for(unsigned int i = 0; i < choices.size(); i++){
       split = SplitOLFileName(choices[i]);
       std::string fileName = getWorkingDir() + split[1];
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
     }
   }
 
@@ -847,7 +852,8 @@ void NativeClient::compute() {
     for(unsigned int i = 0; i < choices.size(); i++){
       split = SplitOLFileName(choices[i]);
       std::string fileName = getWorkingDir() + split[1];
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
     }
   }
 }
@@ -868,7 +874,8 @@ void EncapsulatedClient::analyze() {
     split = SplitOLFileName(choices[i]);
     if(split[2].size()){ // if .ol file
       std::string fileName = getWorkingDir() + split[1] + split[2];
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
       OLMsg::Info("Parse file <%s> %s", fileName.c_str(), 
 		  parse_onefile(fileName)?"done":"failed");
     }
@@ -885,7 +892,8 @@ void EncapsulatedClient::convert() {
     if(split[2].size()){ // if .ol file
       std::string fileName = getWorkingDir() + split[1] + split[2];
       std::string ofileName = getWorkingDir() + split[1] ;
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
       std::ofstream outfile(ofileName.c_str());
       if (outfile.is_open())
 	convert_onefile(fileName, outfile);
@@ -914,7 +922,8 @@ void EncapsulatedClient::compute(){
     for(unsigned int i = 0; i < choices.size(); i++){
      split = SplitOLFileName(choices[i]);
       std::string fileName = getWorkingDir() + split[1];
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
     }
   }
 
@@ -941,7 +950,8 @@ void EncapsulatedClient::compute(){
     for(unsigned int i = 0; i < choices.size(); i++){
       split = SplitOLFileName(choices[i]);
       std::string fileName = getWorkingDir() + split[1];
-      checkIfPresent(fileName);
+      if(!checkIfPresent(fileName))
+	OLMsg::Error("The file <%s> is not present",fileName.c_str());
     }
   }
 }
diff --git a/contrib/onelab/OnelabMessage.cpp b/contrib/onelab/OnelabMessage.cpp
index 524100baa4..d1fa7a08a2 100644
--- a/contrib/onelab/OnelabMessage.cpp
+++ b/contrib/onelab/OnelabMessage.cpp
@@ -18,7 +18,7 @@
 
 int OLMsg::_commRank = 0;
 int OLMsg::_commSize = 1;
-int OLMsg::_verbosity = 4;
+int OLMsg::_verbosity = 1;
 // int OLMsg::_progressMeterStep = 10;
 // int OLMsg::_progressMeterCurrent = 0;
 // std::map<std::string, double> OLMsg::_timers;
diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp
index f4d4096319..008cbfc805 100644
--- a/contrib/onelab/OnelabParser.cpp
+++ b/contrib/onelab/OnelabParser.cpp
@@ -133,12 +133,13 @@ int enclosed(const std::string &in, std::vector<std::string> &arguments,
   size_t pos, cursor;
   arguments.resize(0);
   cursor=0;
-  if ( (pos=in.find("(",cursor)) == std::string::npos )
+  if ( (pos=in.find("(",cursor)) == std::string::npos ){
      OLMsg::Error("Syntax error: <%s>",in.c_str());
-
+     return 0;
+  }
   if (pos>0){
     std::cout << pos << in << std::endl;
-     OLMsg::Error("Syntax error: <%s>",in.c_str());
+    OLMsg::Error("Syntax error: <%s>",in.c_str());
   }
   unsigned int count=1;
   pos++; // skips '('
@@ -173,13 +174,17 @@ int extract(const std::string &in, std::string &paramName,
   // syntax: paramName.action( arg1, arg2, ... )
   size_t pos, cursor;
   cursor=0;
-  if ( (pos=in.find(".",cursor)) == std::string::npos )
+  if ( (pos=in.find(".",cursor)) == std::string::npos ){
      OLMsg::Error("Syntax error: <%s>",in.c_str());
+     return 0;
+  }
   else
     paramName.assign(sanitize(in.substr(cursor,pos-cursor)));
   cursor = pos+1; // skips '.'
-  if ( (pos=in.find("(",cursor)) == std::string::npos )
+  if ( (pos=in.find("(",cursor)) == std::string::npos ){
      OLMsg::Error("Syntax error: <%s>",in.c_str());
+     return 0;
+  }
   else
     action.assign(sanitize(in.substr(cursor,pos-cursor)));
   cursor = pos;
@@ -191,8 +196,10 @@ int extractLogic(const std::string &in, std::vector<std::string> &arguments){
   size_t pos, cursor;
   arguments.resize(0);
   cursor=0;
-  if ( (pos=in.find("(",cursor)) == std::string::npos )
+  if ( (pos=in.find("(",cursor)) == std::string::npos ){
      OLMsg::Error("Syntax error: <%s>",in.c_str());
+     return 0;
+  }
 
   unsigned int count=1;
   pos++; // skips '('
@@ -478,8 +485,10 @@ bool localSolverClient::resolveRange(const std::string &in, std::vector<double>
   size_t pos, cursor;
   arguments.resize(0);
   cursor=0;
-  if ( (pos=in.find(":",cursor)) == std::string::npos )
+  if ( (pos=in.find(":",cursor)) == std::string::npos ){
      OLMsg::Error("Syntax error in range <%s>",in.c_str());
+     return 0;
+  }
   else{
     val=atof(resolveGetVal(in.substr(cursor,pos-cursor)).c_str());
     arguments.push_back(val);
@@ -965,9 +974,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::include.c_str(),line.c_str());
-    else
-      OLMsg::Info("Parse file <%s> %s", arguments[0].c_str(), 
-	      parse_onefile(getWorkingDir() + arguments[0])?"done":"failed");
+    else{
+      std::string filename = getWorkingDir() + resolveGetVal(arguments[0]);
+      OLMsg::Info("Parse file <%s> %s", filename.c_str(), 
+		  parse_onefile(filename)?"done":"failed");
+    }
   }
   else if ( (pos=line.find(olkey::message)) != std::string::npos) { 
     // onelab.message
@@ -1072,7 +1083,8 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
     if(NbLines>=10)
       OLMsg::Error("Command <%s> should not span over more than 10 lines",
 		 cmds.c_str());
-    parse_sentence(cmds);
+    else
+      parse_sentence(cmds);
   }
   else if ( (pos=line.find(olkey::getValue)) != std::string::npos) {
     // onelab.getValue: nothing to do
@@ -1225,14 +1237,15 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
     else{
       get(strings,longName(arguments[0]));
       if (strings.size())
-	condition= true;
+	condition = strings[0].getValue().size();
       else{
 	get(numbers,longName(arguments[0]));
 	if (numbers.size())
 	  condition = (bool) numbers[0].getValue();
-	else
-	  OLMsg::Error("Unknown parameter <%s> in <%s> statement",
-		       arguments[0].c_str(),olkey::iftrue.c_str());
+      	else{
+      	  OLMsg::Warning("Unknown parameter <%s> in <%s> statement",
+			 arguments[0].c_str(),olkey::iftrue.c_str());
+      	}
       }
       if (!convert_ifstatement(infile,outfile,condition))
 	OLMsg::Error("Misformed <%s> statement: %s",
@@ -1249,15 +1262,14 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
     else{
       get(strings,longName(arguments[0]));
       if (strings.size())
-	condition= true;
+	condition =  strings[0].getValue().size();
       else{
 	get(numbers,longName(arguments[0]));
 	if (numbers.size())
 	  condition = (bool) numbers[0].getValue();
 	else{
-	  condition=false;
-	  // OLMsg::Error("Unknown parameter <%s> in <%s> statement",
-	  // 	       arguments[0].c_str(),olkey::ifntrue.c_str());
+	  OLMsg::Warning("Unknown parameter <%s> in <%s> statement",
+			 arguments[0].c_str(),olkey::ifntrue.c_str());
 	}
       }
       if (!convert_ifstatement(infile,outfile,!condition))
@@ -1271,7 +1283,8 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
     extractLogic(line.substr(cursor),arguments);
     bool condition= resolveLogicExpr(arguments);
     if (!convert_ifstatement(infile,outfile,condition))
-      OLMsg::Error("Misformed %s statement: <%s>", line.c_str());
+      OLMsg::Error("Misformed %s statement: <%s>", 
+		   olkey::ifcond.c_str(),line.c_str());
   }
   else if ( (pos=line.find(olkey::include)) != std::string::npos) {
     // onelab.include
@@ -1279,8 +1292,10 @@ 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(getWorkingDir() + arguments[0], outfile);
+    else{
+      std::string filename = getWorkingDir() + resolveGetVal(arguments[0]);
+      convert_onefile(filename, outfile);
+    }
   }
   else if ( (pos=line.find(olkey::message)) != std::string::npos) { 
     // onelab.message
-- 
GitLab