Index: /trunk/SophyaPI/PIext/nobjmgr.cc
===================================================================
--- /trunk/SophyaPI/PIext/nobjmgr.cc	(revision 2217)
+++ /trunk/SophyaPI/PIext/nobjmgr.cc	(revision 2218)
@@ -218,4 +218,8 @@
 bool NamedObjMgr::SetVar(string const & key, string const & val)
 {
+  if ((key.length() < 1) || (! isalpha(key[0])) )   {
+    cout << "NamedObjMgr::SetVar( " << key << " ...) Bad VarName " << endl;
+    return(false);
+  }
 #ifdef SANS_EVOLPLANCK
   bool fg = true;
@@ -231,4 +235,8 @@
 bool NamedObjMgr::HasVar(string const & key)
 {
+  if ((key.length() < 1) || (! isalpha(key[0])) )   {
+    cout << "NamedObjMgr::HasVar( " << key << ") Bad VarName " << endl;
+    return(false);
+  }
 #ifdef SANS_EVOLPLANCK
   DVList::ValList::const_iterator it;
@@ -244,4 +252,8 @@
 bool NamedObjMgr::DeleteVar(string const & key)
 {
+  if ((key.length() < 1) || (! isalpha(key[0])) )   {
+    cout << "NamedObjMgr::DeleteVar( " << key << ") Bad VarName " << endl;
+    return(false);
+  }
 #ifdef SANS_EVOLPLANCK
   return(false);
@@ -254,4 +266,8 @@
 string NamedObjMgr::GetVar(string const & key)
 {
+  if ((key.length() < 1) || (! isalpha(key[0])) )   {
+    cout << "NamedObjMgr::GetVar( " << key << ") Bad VarName " << endl;
+    return("");
+  }
   //  cout << " DEBUG::GetVar " << *myVars << endl;
   return(myVars->GetS(key));
@@ -503,7 +519,9 @@
 
 myNObj++;
-if (nobj.length() < 1) { 
+if ((nobj.length() < 1) || (! isalpha(nobj[0]) ) ) {
+  cout << "NamedObjMgr::AddObj() bad object name " << nobj ;
   sprintf(buff,"O%d", myNObj);
   nobj = buff;
+  cout << " changed to " << nobj << endl;
   }
 
@@ -580,5 +598,5 @@
   cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
   return(false);
-  }
+}
 nom = '/' + r1 + '/' + n1;
 nomnew = '/' + r2 + '/' + n2;
@@ -587,5 +605,9 @@
   cout << "NamedObjMgr::RenameObj() Error -  No " << nom << " object !" << endl;
   return(false);
-  }
+}
+if ((n2.length() < 1) || (! isalpha(n2[0])) ) {
+  cout << "NamedObjMgr::RenameObj() Error -  bad new object name" << n2 << endl;
+  return(false);
+}
 NObjList::iterator it2 = myObjs->find(nomnew);
 if (it2 != myObjs->end()) {
@@ -1501,5 +1523,5 @@
 size_t p = nom.find('/');
 if (p < nom.length()) nom = nom.substr(0,p);
-if (nom.length() < 1)  return(false); 
+if ((nom.length() < 1) || (! isalpha(nom[0]) ) )  return(false); 
 return(true);
 }
Index: /trunk/SophyaPI/PIext/piacmd.cc
===================================================================
--- /trunk/SophyaPI/PIext/piacmd.cc	(revision 2217)
+++ /trunk/SophyaPI/PIext/piacmd.cc	(revision 2218)
@@ -889,4 +889,18 @@
       q3 = s.find_first_of("]",q2+1);
       string sia = s.substr(q2+1, q3-q2-1);
+      if (sia.length() < 1) {
+	cerr << " Syntax error - in $varname[index] : $"  
+	     << vn << "[" << sia <<"]" << endl;
+	return(4);
+      }
+      if (isalpha(sia[0])) {
+	string sia2;
+	if (!GetVar(sia, sia2) || (sia2.length() < 1)) {
+	  cerr << " Syntax error - in $varname[index] : $"  
+	       << vn << "[" << sia <<"]" << endl;
+	return(4);	  
+	}
+	sia = sia2;
+      }
       int rcdia = ctoi(sia.c_str(), &iarr);
       if (rcdia < 0) {
@@ -936,10 +950,10 @@
     cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! " 
 	 << " ($" << vn << ")" << endl;
-    vv = ""; return(false);
+    vv = "";  return(false);
   }
   char buff[32];
   long an = ArgsStack.top().size();
   sprintf(buff,"%ld", an);
-  vv = buff;
+  vv = buff;  return(true);
 }
 else if (ctoi(vn.c_str(), &ka) > 0) {  // $0 $1 $2 ...
@@ -954,16 +968,30 @@
     vv = ""; return(false);
   }
-  vv = ArgsStack.top()[ka];
-}
+  vv = ArgsStack.top()[ka];  return(true);
+}
+else if (vn[0] == '#') {  // Variable de type $#vname --> size(vname) 
+  vn = vn.substr(1);
+  if (!omg.HasVar(vn) ) {
+    cerr << " PIACmd::SubstituteVarError: Undefined variable " 
+	 << vn << " ! " << endl;
+    vv = "";  return(false);
+  }
+  vn = omg.GetVar(vn);
+  vector<string> vs;
+  FillVStringFrString(vn, vs);
+  char buff[32];
+  sprintf(buff,"%d", (int)vs.size());
+  vv = buff; return(true);
+  } 
 else {  // variable ordinaire geree par NamedObjMgr
   if ( (!omg.HasVar(vn)) )  {
     cerr << " PIACmd::SubstituteVarError: Undefined variable " 
 	 << vn << " ! " << endl;
-    vv = ""; return(false);
-  }
-  vv = omg.GetVar(vn);
-}
-
-return(true);
+    vv = "";  return(false);
+  }
+  vv = omg.GetVar(vn);  return(true);
+}
+
+return(false);
 }
 
