Index: trunk/SophyaLib/SysTools/commander.cc
===================================================================
--- trunk/SophyaLib/SysTools/commander.cc	(revision 3579)
+++ trunk/SophyaLib/SysTools/commander.cc	(revision 3581)
@@ -21,17 +21,33 @@
 // Pour ecrire une valeur double sous forme de string 
 // sans perte de precision, et si possible de maniere 
-// lisible (%g, sinon %.17e)  
-static char cval_strbuff_[64];
+// lisible (%g, sinon format adapte jusqu'a %.17e)  
+static char cval_strbuff_[80];
+////1er essai binaire: char * cval_dble2str(double v)
+////1er essai binaire: {
+////1er essai binaire:   char* str1 = cval_strbuff_;  
+////1er essai binaire:   sprintf(str1,"%g",v);
+////1er essai binaire:   char* str2 = cval_strbuff_+32;       
+////1er essai binaire:   sprintf(str2,"%.17e",v);
+////1er essai binaire:   double x1 = atof(str1);
+////1er essai binaire:   double x2 = atof(str2);
+////1er essai binaire:   double fx = fabs(v);
+////1er essai binaire:   if (fx>0. && fabs(x2-x1)/fx>1e-12)  return str2;
+////1er essai binaire:   else return str1;
+////1er essai binaire: }
 char * cval_dble2str(double v)
 {
-  char* str1 = cval_strbuff_;  
-  sprintf(str1,"%g",v);
-  char* str2 = cval_strbuff_+32;       
-  sprintf(str2,"%.17e",v);
-  double x1 = atof(str1);
-  double x2 = atof(str2);
-  double fx = fabs(v);
-  if (fx>0. && fabs(x2-x1)/fx>1e-12)  return str2;
-  else return str1;
+ char* strgood = cval_strbuff_;        sprintf(strgood,"%g",v);
+ char* strfull = cval_strbuff_+32;     sprintf(strfull,"%.17e",v);
+ char* strform = cval_strbuff_+64;
+ double x1 = atof(strfull), fx = fabs(x1);
+ if(fx>0.) {
+   for(int i=7;i<=17;i+=2) {  // increment de 2 pour aller + vite
+     double x2 = atof(strgood);
+     if(fabs(x2-x1)/fx<1.e-16) break;
+     sprintf(strform,"%%.%de",i);
+     sprintf(strgood,strform,v);
+   }
+ }
+ return strgood;
 }
 //--------------------------------------------------
@@ -121,5 +137,5 @@
   if ( (args[1] == "(") && (args[args.size()-1] == ")") ) {
     // foreach varname ( w1 w2 w3 ... ) 
-    for(int kk=2; kk<args.size()-1; kk++) strlist.push_back(args[kk]);
+    for(unsigned int kk=2; kk<args.size()-1; kk++) strlist.push_back(args[kk]);
   }
   else {
@@ -170,5 +186,5 @@
 CommanderBloc::~CommanderBloc()
 {
-for(int k=0; k<blocs.size(); k++) delete blocs[k];
+for(unsigned int k=0; k<blocs.size(); k++) delete blocs[k];
 }
 
@@ -195,9 +211,6 @@
 if (typ == BT_ForeachLineInFile) {  // foreach line in file loop
   ifstream is(filename.c_str());
-  char buff[256];
   string line;
   while (!is.eof()) {
-    /* Reza, Juin 2005 : Remplace par getline(istream, string) - plus sur
-       is.getline(buff, 256); line += buff;  */
     rcc = 0;
     line = "";
@@ -211,5 +224,5 @@
 }
 else if (typ == BT_ForeachList) {  // foreach string loop
-  for(k=0; k<strlist.size(); k++) {
+  for(unsigned int k=0; k<strlist.size(); k++) {
     rcc = ExecuteOnce(strlist[k]);
     if (rcc == CMD_BREAKEXE_RC)  return rcc;
@@ -250,5 +263,5 @@
 int CommanderBloc::ExecuteOnce(string& lvv)
 {
-  int kj=0;
+  unsigned int kj=0;
   int kk=0;
   int rcc = 0;
@@ -341,8 +354,8 @@
 int CommanderScript::Execute(vector<string>& args)
 {
-  int rcc;
+  int rcc=-2;
   if (!CheckScript()) return(-1);
   cout << " CommanderScript::Execute() - Executing script " << Name() << endl;
-  for(int k=0; k<lines.size(); k++) {
+  for(unsigned int k=0; k<lines.size(); k++) {
     rcc = _commander->Interpret(lines[k]);
     if ( (rcc == CMD_BREAKEXE_RC) || (rcc == CMD_RETURN_RC) ) break; 
@@ -1067,5 +1080,5 @@
       if (tokens.size() > 2) {
 	string sex = tokens[1];
-	for(int js=2; js<tokens.size(); js++)  sex += tokens[js];
+	for(unsigned int js=2; js<tokens.size(); js++)  sex += tokens[js];
 	CExpressionEvaluator cex(sex);
 	res = cex.Value();
@@ -1331,5 +1344,5 @@
   }
   vv = ArgsStack.top()[0];
-  for(int ssk=1; ssk<ArgsStack.top().size(); ssk++)  vv += ArgsStack.top()[ssk];
+  for(unsigned int ssk=1; ssk<ArgsStack.top().size(); ssk++)  vv += ArgsStack.top()[ssk];
   return(true);
 }
@@ -1340,5 +1353,5 @@
     vv = ""; return(false);
   }
-  if ( (ka < 0) || (ka >= ArgsStack.top().size()) ) {
+  if ( (ka < 0) || (ka >= (int)ArgsStack.top().size()) ) {
     cerr << " Commander::Var2Str/Error: ArgsStack index <0 or >=args.size()  ! " 
 	 << " ($" << vn << ")" << endl;
@@ -1437,5 +1450,5 @@
   vv = (*it).second[0]; 
   if ((*it).second.size() > 1) {   
-    for(int k=1; k<(*it).second.size(); k++) {
+    for(unsigned int k=1; k<(*it).second.size(); k++) {
       vv += ' ';  vv += (*it).second[k];
     }
@@ -1450,5 +1463,5 @@
   CmdVarList::iterator it = variables.find(vn);
   if (it == variables.end())  return false;
-  if ((idx < 0) || (idx > (*it).second.size()-1))
+  if ((idx < 0) || (idx > (int)(*it).second.size()-1))
     return false;
   vv = (*it).second[idx];
@@ -1511,5 +1524,5 @@
   }
   else { 
-    if (idx >= (*it).second.size())
+    if (idx >= (int)(*it).second.size())
       for(int j=(*it).second.size(); j<=idx; j++)  (*it).second.push_back("");
     (*it).second[idx] = val;
@@ -1805,5 +1818,5 @@
   }
   string xx = tokens[1];
-  for (int kk=2; kk<tokens.size(); kk++)  xx += (' ' + tokens[kk]);
+  for (unsigned int kk=2; kk<tokens.size(); kk++)  xx += (' ' + tokens[kk]);
   mAliases[tokens[0]] = xx;
 }
@@ -1832,5 +1845,5 @@
 }
 else if (kw == "echo") {
-  for (int ii=0; ii<tokens.size(); ii++)
+  for (unsigned int ii=0; ii<tokens.size(); ii++)
     cout << tokens[ii] << " " ;
   cout << endl;
@@ -1842,5 +1855,5 @@
   }
   ofstream ofs(tokens[0].c_str(), ios::app);
-  for (int ii=1; ii<tokens.size(); ii++)
+  for (unsigned int ii=1; ii<tokens.size(); ii++)
     ofs << tokens[ii] << " " ;
   ofs << endl;
@@ -1948,5 +1961,5 @@
   if (tokens.size() < 1) { cout << "Commander::Interpret() Usage: shell cmdline" << endl;  return(0); }
   string cmd;
-  for (int ii=0; ii<tokens.size(); ii++)
+  for (unsigned int ii=0; ii<tokens.size(); ii++)
     cmd += (tokens[ii] + ' ');
   system(cmd.c_str());
@@ -1955,5 +1968,5 @@
   if(tokens.size()<1) {cout<<"Commander::Interpret() Usage: cshell cmdline"<<endl; return(0);}
   string cmd="";
-  for(int ii=0;ii<tokens.size();ii++) cmd+=(tokens[ii]+' ');
+  for(unsigned int ii=0;ii<tokens.size();ii++) cmd+=(tokens[ii]+' ');
   CShellExecute(cmd);
   }
@@ -2203,5 +2216,5 @@
 static void check_latex_reflabel(string & prl)
 {
-  for(int k=0; k<prl.length(); k++) 
+  for(unsigned int k=0; k<prl.length(); k++) 
     if (! isalnum(prl[k]) )  prl[k] = 'Z';
 }
@@ -2211,5 +2224,5 @@
 {
   string rs;
-  for(int k=0; k<mot.length(); k++) {
+  for(unsigned int k=0; k<mot.length(); k++) {
     if (mot[k] == '_')  rs += "\\_"; 
     else rs += mot[k];
