Index: tol/contrib/cint/tolCint.cpp
===================================================================
--- tol/contrib/cint/tolCint.cpp	(revision a29d86c40f5ed9bc0daa581054b24415dbeb331a)
+++ tol/contrib/cint/tolCint.cpp	(revision 297c5f5a849ef82b8dd68ef3287d14ebc813f007)
@@ -31,7 +31,8 @@
 #include <tol/tol_bdtegra.h>
 #include <tol/tol_btxtgra.h>
+#include <tol/tol_bsetgra.h>
 
 //#pragma pack(16)
-//#include <Api.h>
+#include <Api.h>
 #include <G__ci.h>
 //#pragma pack(4)
@@ -69,18 +70,94 @@
 }
 
-
-//--------------------------------------------------------------------
-int Cint_initialize()
-//--------------------------------------------------------------------
-{
-  int G__init_cint_ = G__init_cint("cint");
-  G__set_errmsgcallback(reinterpret_cast<void*>(Cint_errmsgcallback));
-  G__setautoconsole(1);
-  return(G__init_cint_);
-}
-
-//--------------------------------------------------------------------
-static int G__init_cint__ = Cint_initialize();
-//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+int& Cint_is_initialized()
+//--------------------------------------------------------------------
+{
+  static int _Cint__initialized_ = false;
+  return(_Cint__initialized_);
+}
+
+//--------------------------------------------------------------------
+int Cint_initialize(const BText& filePath)
+//--------------------------------------------------------------------
+{
+  if(Cint_is_initialized())
+  {
+    return(G__INIT_CINT_SUCCESS);
+  }
+  else
+  {
+    Cint_is_initialized() = true; 
+    BText order = "cint";
+    if(filePath.HasName()) { order += BText(" ")+filePath; }
+    int G__init_cint_ = G__init_cint(order);
+    switch(G__init_cint_) {
+    case G__INIT_CINT_SUCCESS_MAIN:
+      Error("Cint called out of main should never happen G__INIT_CINT_SUCCESS_MAIN.\n");
+      /* Should never happen */
+      break;
+    case G__INIT_CINT_SUCCESS:
+      Std("\nCint has been succesfully initialized.\n");
+      break;
+    case G__INIT_CINT_FAILURE:
+    default:
+      Error("Cint initialization failed G__INIT_CINT_FAILURE.\n");
+    }
+    G__set_errmsgcallback(Cint_errmsgcallback);
+    return(G__init_cint_);
+  }
+}
+
+//--------------------------------------------------------------------
+int Cint_scratch_all()
+//--------------------------------------------------------------------
+{
+  if(Cint_is_initialized())
+  {
+    return(false);
+  }
+  else
+  {
+    Cint_is_initialized() = false;
+    return(Cint_scratch_all());
+  }
+}
+
+//--------------------------------------------------------------------
+  DeclareContensClass(BDat, BDatTemporary, BDatCint_initialize);
+  DefExtOpr(1, BDatCint_initialize, "Cint.initialize", 1, 1, "Text",
+  "(Text filePath)",
+  I2("Initializes the CINT environment with an optional C/C++ file.",
+     "Inicilaliza el entorno de CINT con un fichero C/C++ opcional.")+
+     cint_url_link(),
+     BOperClassify::Conversion_);
+  void BDatCint_initialize::CalcContens()
+//--------------------------------------------------------------------
+{
+  if(CheckNonDeclarativeAction("Cint.initialize")) { return; }
+  BText& filePath = Text(Arg(1));
+  contens_ = Cint_initialize(filePath);
+}
+
+
+//--------------------------------------------------------------------
+  DeclareContensClass(BDat, BDatTemporary, BDatCint_scratch_all);
+  DefExtOpr(1, BDatCint_scratch_all, "Cint.scratch_all", 1, 1, "Real",
+  "(Real unused)",
+  I2("Terminates the interpreter and frees heap memory used by it."
+     "The interpreter should not be used after call this function."
+     "To resume the interpreter, user needs to call function Cint.initialize.",
+     "Termina el intérprete y libera memoria heap usada por él."
+     "El intérprete no debe utilizarse después de llamar a esta función."
+     "Para continuar con el intérprete, el usuario debe llamar a la "
+     "función Cint.initialize.")+
+     cint_url_link(),
+     BOperClassify::Conversion_);
+  void BDatCint_scratch_all::CalcContens()
+//--------------------------------------------------------------------
+{
+  if(CheckNonDeclarativeAction("Cint.scratch_all")) { return; }
+  contens_ = Cint_scratch_all();
+}
 
 
@@ -121,5 +198,31 @@
 //--------------------------------------------------------------------
   DeclareContensClass(BDat, BDatTemporary, BDatCINT_exec_tempfile);
-  DefExtOpr(1, BDatCINT_exec_tempfile, "Cint.exec_text", 1, 1, "Text",
+  DefExtOpr(1, BDatCINT_exec_tempfile, "Cint.exec_tempfile", 1, 1, "Text",
+  "(Text filePath)",
+  I2("Opens temporary source file and execute it in the current context. "
+     "The tempfile can contain variable declaration, struct, union, "
+     "enum definitions, conditional expressions, loop and control "
+     "statements but cannot contain function nor class definitions, "
+     "wich can be loaded just calling Cint.loadfile",
+     "Abre un archivo temporal de código fuente, que se ejecuta en el "
+     "contexto actual. El archivo temporal puede contener declaración "
+     "de variables, definiones de struct, union, enum, expresiones "
+     "condicionales, órdenes de control y bucles, pero no puede "
+     "contener definiciones de función ni de clase, las cuales "
+     "sólo pueden cargarse con Cint.loadfile"),
+     BOperClassify::Conversion_);
+  void BDatCINT_exec_tempfile::CalcContens()
+//--------------------------------------------------------------------
+{
+  if(CheckNonDeclarativeAction("Cint.exec_tempfile")) { return; }
+  BText& filePath = Text(Arg(1));
+  G__exec_tempfile(filePath.String());
+  contens_ = true;
+}
+
+
+//--------------------------------------------------------------------
+  DeclareContensClass(BDat, BDatTemporary, BDatCINT_exec_text);
+  DefExtOpr(1, BDatCINT_exec_text, "Cint.exec_text", 1, 1, "Text",
   "(Text expression)",
     I2("Executes any C/C++ expression or set of expressions.\n"
@@ -136,5 +239,5 @@
      cint_url_link(),
      BOperClassify::Conversion_);
-  void BDatCINT_exec_tempfile::CalcContens()
+  void BDatCINT_exec_text::CalcContens()
 //--------------------------------------------------------------------
 {
@@ -166,27 +269,29 @@
   if(CheckNonDeclarativeAction("Cint.calc")) { return; }
   BText& expression = Text(Arg(1));
-  G__value g = G__calc(expression.String());
+  contens_ = G__double(G__calc(expression));
+/*
+  G__value g = G__calc(expression);
   switch (g.type) 
   {
     case 100: contens_ = g.obj.d; break;
     case 105: contens_ = g.obj.i; break;
-    default: Error(I2("Unknown CINT type ",
-                      "Tipo CINT desconocido ")<<g.type);
-  }
-}
-
-
-
-//--------------------------------------------------------------------
-  DeclareContensClass(BDat, BDatTemporary, BDatCINT_import_from_tol);
-  DefExtOpr(1, BDatCINT_import_from_tol, 
-  "Cint.import_from_tol", 1, 0, "Anything Anything",
-  "(Anything var1 [, Anything var2, ...])",
+    default: Error(BText("[Cint.calc] ")+
+     I2("Unknown CINT numerical type ",
+                      "Tipo CINT numérico desconocido ")<<g.type);
+  }
+*/
+}
+
+//--------------------------------------------------------------------
+  DeclareContensClass(BSet, BSetTemporary, BSetCINT_import_from_tol);
+  DefExtOpr(1, BSetCINT_import_from_tol, 
+  "Cint.import_from_tol", 1, 4, "Set Text Text Text",
+  "(Set vars [, Text prefix=\"\", Text suffix=\"\", Text namespace=\"\"])",
   I2("Imports TOL variables, global or local, into CINT global scope.\n"
-     "Returns the number of imported variables\n"
+     "Returns the names of imported CINT variables.\n"
      "TOL variables must have a valid name in TOL and C languages.\n"
      "At this moment these are the available TOL types :\n",    
      "Importa variables TOL, globales o locales, al ámbito global de CINT\n"
-     "Devuelve el número total de variables correctamen te importadas.\n" 
+     "Devuelve los nombres de las variables CINT correctamente importadas.\n" 
      "Las variables TOL deben tener un nombre válido en los lenguajes "
      "TOL y C\n"
@@ -199,16 +304,28 @@
      "Puede ver la declaración de los correspondientes tipos C/C++ en ")+
      "\nhttps://www.tol-project.org/browser/tolp/trunk/tol/"
-     "stdlib/general/TolCint/tol_cint_casting.cpp"+
+     "stdlib/general/TolCint/tol_cint_casting.cpp\n"+
   I2("Imported variables can be modified by CINT routines but memory "
      "allocation and the internal structure cannot be altered. "
      "For example, you can change the elements of a Matrix but cannot "
-     "change the number of cells, rows nor columns.",
+     "change the number of cells, rows nor columns.\n",
      "Las variables importadas pueden ser modificadas por rutinas CINT "
      "pero el alojo de memoria no puede ser alterado. "
      "Por ejemplo, es posible cambiar los elementos de una matriz pero "
-     "no el número de celdas, filas o columnas")+
+     "no el número de celdas, filas o columnas.\n")+
+  I2("If argument prefix is not empty then it will added before each TOL name to "
+     "create transformed CINT names.\n",
+     "Si el argumento prefix no es vacío se añadirá por delante de cada nombre TOL "
+     "para crear los nombres CINT transformados.\n")+
+  I2("If argument suffix is not empty then it will added after each TOL name to "
+     "create transformed CINT names.\n",
+     "Si el argumento suffix no es vacío se añadirá por detrás de cada nombre TOL "
+     "para crear los nombres CINT transformados.\n") +
+  I2("If argument namespace is not empty then CINT variables will be created in "
+     "in the speciefied and pre-existant namespace instead of global scope.\n",
+     "Si el argumento namespace no es vacío se crearán las variables dentro "
+     "de dicho namespace preexistente, en lugar de en el ámbito global.\n")+
     cint_url_link(),
   BOperClassify::Conversion_);
-  void BDatCINT_import_from_tol::CalcContens()
+  void BSetCINT_import_from_tol::CalcContens()
 //--------------------------------------------------------------------
 {
@@ -216,10 +333,26 @@
   
   BSyntaxObject* var = NULL;
+  BGrammar* gra = NULL;
   int numArg; 
-  contens_ = 0;
-  
-  for(numArg = 1; var=Arg(numArg); numArg++)
-  {
-    BGrammar* gra = var->Grammar();
+  BSet& arg = Set(Arg(1));
+  BText prefix_ = "";
+  BText sufix_ = "";
+  BText namespace_ = "";
+  if(Arg(2)) { prefix_ = Text(Arg(2)); }
+  if(Arg(3)) { sufix_ = Text(Arg(3)); }
+  if(Arg(4)) { namespace_ = Text(Arg(4)); }
+  BText expression = "";
+  if(namespace_.HasName())
+  {
+    expression = BText("namespace ") + namespace_ + " {\n";
+  };
+  int c = arg.Card();
+  contens_.PrepareStore(c);
+  for(numArg = 1; numArg<=c; numArg++)
+  {
+    var = arg[numArg];
+    if(!var) { continue; }
+    gra = var->Grammar();
+    BText pns = prefix_+var->Name()+sufix_;
     if(gra==GraReal())
     {
@@ -227,8 +360,7 @@
       double* ptr = (double*)(&dat);
       int ptrNum = (int)ptr;
-      BText expression = BText("double& ")+var->Name()+" = *((double *)("<<ptrNum<<"))";
+      expression += BText("double& ")+pns+" = *((double *)("<<ptrNum<<"));\n";
     //Std(BText("TRACE [Cint.import_from_tol] ")+expression);
-      G__exec_text(expression);
-      contens_ += 1;
+      contens_.AddElement(new BContensText("",pns,""));
     }
     else if(gra==GraMatrix())
@@ -237,11 +369,10 @@
       double* ptr = (double*)(mat.GetData().GetBuffer());
       int ptrNum = (int)ptr;
-      BText expression = BText("Matrix ")+var->Name()+" ( "<<
+      expression += BText("Matrix ")+pns+" ( "<<
         mat.Rows()<<","<<
         mat.Columns()<<","<<
-        " ((double *)("<<ptrNum<<")) ); 0;";
+        " ((double *)("<<ptrNum<<")) );\n";
     //Std(BText("TRACE [Cint.import_from_tol] ")+expression);
-      G__exec_text(expression);
-      contens_ += 1;
+      contens_.AddElement(new BContensText("",pns,""));
     }
     else if(gra==GraText())
@@ -250,17 +381,75 @@
       char* ptr = (char*)(txt.Buffer());
       int ptrNum = (int)ptr;
-      BText expression = BText("Text ")+var->Name()+" ( "<<
+      expression += BText("Text ")+pns+" ( "<<
         txt.Length()<<","<<
-        " ((char *)("<<ptrNum<<")) ); 0;";
+        " ((char *)("<<ptrNum<<")) );\n";
     //Std(BText("TRACE [Cint.import_from_tol] ")+expression);
-      G__exec_text(expression);
-      contens_ += 1;
+      contens_.AddElement(new BContensText("",pns,""));
     }
     else 
     {
       Warning(BText("[Cint.import_from_tol] ")+
-        "Cannot import TOL variables of type "<<gra->Name());
-    }
-  }
-}
-
+        I2("Cannot import TOL variable ",
+           "No se puede importar la variable TOL ")<<
+           gra->Name()+" "+var->Name());
+    }
+  }
+  if(namespace_.HasName())
+  {
+    expression += "\n};";
+  };
+//Std(BText("\nTRACE [Cint.import_from_tol] expression=[\n")+expression+"\n]\n");
+  G__exec_text(expression);
+}
+
+
+//--------------------------------------------------------------------
+  DeclareContensClass(BDat, BDatTemporary, BDatCINT_delete_variables);
+  DefExtOpr(1, BDatCINT_delete_variables, 
+  "Cint.delete_variables", 1, 3, 
+  "Set Text Text",
+  "(Set varNames [, Text prefix=\"\", Text suffix=\"\"] )",
+  I2("Deletes  from CINT global scope the variables which names are in "
+     "specified set varNames.\n"
+     "Returns the number of deleted variables.\n",    
+     "Borra del ámbito global de CINT las variables cuyos nombres se "
+     "especifican en el conjunto varNames\n"
+     "Devuelve el número total de variables realmente borradas.\n")+
+  I2("If argument prefix is not empty then it will added before each TOL name to "
+     "create transformed CINT names.\n",
+     "Si el argumento prefix no es vacío se añadirá por delante de cada nombre TOL "
+     "para crear los nombres CINT transformados.\n")+
+  I2("If argument suffix is not empty then it will added after each TOL name to "
+     "create transformed CINT names.\n",
+     "Si el argumento suffix no es vacío se añadirá por detrás de cada nombre TOL "
+     "para crear los nombres CINT transformados.\n") +
+     cint_url_link(),
+  BOperClassify::Conversion_);
+  void BDatCINT_delete_variables::CalcContens()
+//--------------------------------------------------------------------
+{
+  if(CheckNonDeclarativeAction("Cint.delete_variables")) { return; }
+  
+  BSyntaxObject* var = NULL;
+  BGrammar* gra = NULL;
+  int numArg; 
+  contens_ = 0;
+  BSet& arg = Set(Arg(1));
+  BText prefix_ = "";
+  BText sufix_ = "";
+  if(Arg(2)) { prefix_ = Text(Arg(2)); }
+  if(Arg(3)) { sufix_ = Text(Arg(3)); }
+
+  for(numArg = 1; numArg<=arg.Card(); numArg++)
+  {
+    var = arg[numArg];
+    if(!var) { continue; }
+    gra = var->Grammar();
+    if(gra==GraText())
+    {
+      BText pns = prefix_+var->Name()+sufix_;
+      contens_ += G__deletevariable(pns);
+    }
+  }
+}
+
