0024510: Remove unused local variables
[occt.git] / src / Draw / Draw_VariableCommands.cxx
old mode 100755 (executable)
new mode 100644 (file)
index f2def5a..97da0ed
@@ -1,8 +1,18 @@
-// File:       Draw_VariableCommands.cxx
-// Created:    Thu Feb 23 18:28:40 1995
-// Author:     Remi LEQUETTE
-//             <rle@bravox>
-
+// Created on: 1995-02-23
+// Created by: Remi LEQUETTE
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and / or modify it
+// under the terms of the GNU Lesser General Public version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #include <Draw.ixx>
 #ifdef HAVE_CONFIG_H
@@ -39,6 +49,7 @@ extern Draw_Viewer dout;
 #include <tcl.h>
 #include <errno.h>
 
+#include <OSD_Environment.hxx>
 
 Standard_Boolean Draw_ParseFailed;
 
@@ -383,12 +394,12 @@ static Standard_Integer erase(Draw_Interpretor& di, Standard_Integer n, const ch
 static Standard_Integer draw(Draw_Interpretor& , Standard_Integer n, const char** a)
 {
   if (n < 3) return 1;
-  Standard_Integer id = atoi(a[1]);
+  Standard_Integer id = Draw::Atoi(a[1]);
   if (!dout.HasView(id)) {
     cout << "bad view number in draw"<<endl;
     return 1;
   }
-  Standard_Integer mo = atoi(a[2]);
+  Standard_Integer mo = Draw::Atoi(a[2]);
   Draw_Display d = dout.MakeDisplay(id);
   d.SetMode(mo);
   Standard_Integer i;
@@ -462,7 +473,7 @@ static Standard_Integer whatis(Draw_Interpretor& di, Standard_Integer n, const c
 static Standard_Integer value(Draw_Interpretor& di, Standard_Integer n, const char** a)
 {
   if (n != 2) return 1;
-  di << atof(a[1]);
+  di << Draw::Atof(a[1]);
 
   return 0;
 }
@@ -569,13 +580,53 @@ static Standard_Integer set(Draw_Interpretor& di, Standard_Integer n, const char
   Standard_Real val=0;
   for (i = 1; i < n; i += 2) {
     val = 0;
-    if (i+1 < n) val = atof(a[i+1]);
+    if (i+1 < n) val = Draw::Atof(a[i+1]);
     Draw::Set(a[i],val);
   }
   di << val;
   return 0;
 }
 
+//=======================================================================
+//function : dsetenv
+//purpose  : 
+//=======================================================================
+
+static Standard_Integer dsetenv(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
+{
+  if (argc < 2) {
+    cout << "Use: " << argv[0] << " {varname} [value]" << endl;
+    return 1;
+  }
+
+  OSD_Environment env (argv[1]);
+  if (argc > 2 && argv[2][0] != '\0')
+  {
+    env.SetValue (argv[2]);
+    env.Build();
+  }
+  else
+    env.Remove();
+  return env.Failed();
+}
+
+//=======================================================================
+//function : dgetenv
+//purpose  : 
+//=======================================================================
+
+static Standard_Integer dgetenv(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+  if (argc < 2) {
+    cout << "Use: " << argv[0] << " {varname}" << endl;
+    return 1;
+  }
+
+  const char* val = getenv (argv[1]);
+  di << ( val ? val : "" );
+  return 0;
+}
+
 //=======================================================================
 //function : isdraw
 //purpose  : 
@@ -624,7 +675,7 @@ static Standard_Integer pick(Draw_Interpretor& , Standard_Integer n, const char*
   Standard_Integer id;
   Standard_Integer X,Y,b;
   Standard_Boolean wait = (n == 6);
-  if (!wait) id = atoi(a[1]);
+  if (!wait) id = Draw::Atoi(a[1]);
   dout.Select(id,X,Y,b,wait);
   Standard_Real z = dout.Zoom(id);
   gp_Pnt P((Standard_Real)X /z,(Standard_Real)Y /z,0);
@@ -791,9 +842,10 @@ void Draw::Set(const Standard_CString Name, const Standard_Real val)
 Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name, 
                                  const Standard_Boolean )
 {
+#if !((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) || defined(USE_NON_CONST)
   Standard_PCharacter pName;
-  //
   pName=(Standard_PCharacter)name;
+#endif
   //
   Standard_Boolean pick = ((name[0] == '.') && (name[1] == '\0'));
   Handle(Draw_Drawable3D) D;
@@ -888,7 +940,7 @@ void  Draw::Repaint()
 static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer , const char** a)
 {
 
-  Standard_Real x = atof(a[1]);
+  Standard_Real x = Draw::Atof(a[1]);
 
   if (!strcasecmp(a[0],"cos"))
     di << Cos(x);
@@ -903,7 +955,7 @@ static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer , const ch
   else if (!strcasecmp(a[0],"asin"))
     di << ASin(x);
   else if (!strcasecmp(a[0],"atan2"))
-    di << ATan2(x,atof(a[2]));
+    di << ATan2(x,Draw::Atof(a[2]));
 
   return 0;
 }
@@ -913,9 +965,6 @@ static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer , const ch
 // Atof and Atoi
 //=======================================================================
 
-#undef atof
-#undef atoi
-
 static Standard_Boolean Numeric(char c)
 {
   return (c == '.' || (c >= '0' && c <= '9'));
@@ -971,7 +1020,7 @@ static Standard_Real ParseValue(char*& name)
        *p = '\0';
        
        if (Numeric(*name))   // numeric litteral
-         x = atof(name);
+         x = Atof(name);
        else if (!Draw::Get((Standard_CString) name,x)) {  // variable
          
          // search for a function ...
@@ -979,7 +1028,7 @@ static Standard_Real ParseValue(char*& name)
          // count arguments
          Standard_Integer argc = 1;
          char* q = p;
-         while ((*q == ' ') && (*q == '\t')) q++;
+         while ((*q == ' ') || (*q == '\t')) q++;
          if (*q == '(') {
            Standard_Integer pc = 1;
            argc = 2;
@@ -1029,7 +1078,7 @@ static Standard_Real ParseValue(char*& name)
                  x = 0;
                }
                else
-                 x = atof(theCommands.Result());
+                 x = Atof(theCommands.Result());
                theCommands.Reset();
                if (sv) {
                  theCommands << sv;
@@ -1056,7 +1105,7 @@ static Standard_Real ParseFactor(char*& name)
 {
   Standard_Real x = ParseValue(name);
 
-  while (1) {
+  for(;;) {
     char c = *name;
     if (c == '\0') return x;
     name++;
@@ -1082,7 +1131,7 @@ static Standard_Real Parse(char*& name)
 {
   Standard_Real x = ParseFactor(name);
 
-  while (1) {
+  for(;;) {
     char c = *name;
     if (c == '\0') return x;
     name++;
@@ -1169,7 +1218,7 @@ extern void (*Draw_AfterCommand)(Standard_Integer);
 //function : Commands
 //purpose  : 
 //=======================================================================
-void  Draw::VariableCommands(Draw_Interpretor& theCommands)
+void  Draw::VariableCommands(Draw_Interpretor& theCommandsArg)
 {
   static Standard_Boolean Done = Standard_False;
   if (Done) return;
@@ -1214,46 +1263,49 @@ void  Draw::VariableCommands(Draw_Interpretor& theCommands)
 
   g = "DRAW Numeric functions";
 
-  theCommands.Add("cos" ,"cos(x)" ,__FILE__,trigo,g);
-  theCommands.Add("sin" ,"sin(x)" ,__FILE__,trigo,g);
-  theCommands.Add("tan" ,"tan(x)" ,__FILE__,trigo,g);
-  theCommands.Add("acos" ,"acos(x)" ,__FILE__,trigo,g);
-  theCommands.Add("asin" ,"asin(x)" ,__FILE__,trigo,g);
-  theCommands.Add("atan2" ,"atan2(x,y)" ,__FILE__,trigo,g);
-  theCommands.Add("sqrt","sqrt(x)",__FILE__,trigo,g);
+  theCommandsArg.Add("cos" ,"cos(x)" ,__FILE__,trigo,g);
+  theCommandsArg.Add("sin" ,"sin(x)" ,__FILE__,trigo,g);
+  theCommandsArg.Add("tan" ,"tan(x)" ,__FILE__,trigo,g);
+  theCommandsArg.Add("acos" ,"acos(x)" ,__FILE__,trigo,g);
+  theCommandsArg.Add("asin" ,"asin(x)" ,__FILE__,trigo,g);
+  theCommandsArg.Add("atan2" ,"atan2(x,y)" ,__FILE__,trigo,g);
+  theCommandsArg.Add("sqrt","sqrt(x)",__FILE__,trigo,g);
 
   g = "DRAW Variables management";
 
-  theCommands.Add("protect","protect name ...",__FILE__,protect,g);
-  theCommands.Add("unprotect","unprotect name ...",__FILE__,protect,g);
+  theCommandsArg.Add("protect","protect name ...",__FILE__,protect,g);
+  theCommandsArg.Add("unprotect","unprotect name ...",__FILE__,protect,g);
 
-  theCommands.Add("bsave","bsave name filename",__FILE__,save,g);
-  theCommands.Add("brestore","brestore filename name",__FILE__,restore,g);
+  theCommandsArg.Add("bsave","bsave name filename",__FILE__,save,g);
+  theCommandsArg.Add("brestore","brestore filename name",__FILE__,restore,g);
 
-  theCommands.Add("isdraw","isdraw var, return 1 if Draw value",__FILE__,isdraw,g);
-  theCommands.Add("isprot","isprot var, return 1 if Draw var is protected",__FILE__,isprot,g);
+  theCommandsArg.Add("isdraw","isdraw var, return 1 if Draw value",__FILE__,isdraw,g);
+  theCommandsArg.Add("isprot","isprot var, return 1 if Draw var is protected",__FILE__,isprot,g);
   
-  theCommands.Add("autodisplay","toggle autodisplay [0/1]",__FILE__,autodisplay,g);
-  theCommands.Add("display","display [name1 name2 ...], no names display all",__FILE__,display,g);
-  theCommands.Add("donly","donly [name1 name2 ...], erase and display",__FILE__,erase,g);
-  theCommands.Add("erase","erase [name1 name2 ...], no names erase all",__FILE__,erase,g);
-  theCommands.Add("draw","draw view mode [name1 name2 ...], draw on view with mode",__FILE__,draw,g);
-  theCommands.Add("clear","clear display",__FILE__,erase,g);
-  theCommands.Add("2dclear","clear display (2d objects)",__FILE__,erase,g);
-  theCommands.Add("repaint","repaint, force redraw",__FILE__,repaintall,g);
-
-  theCommands.Add("dtyp", "dtyp name1 name2",__FILE__,whatis,g);
-  theCommands.Add("dval", "dval name, return value",__FILE__,value,g);
-  theCommands.Add("dname", "dname name, print name",__FILE__,dname,g);
-  theCommands.Add("dump", "dump name1 name2 ...",__FILE__,dump,g);
-  theCommands.Add("copy",  "copy name1 toname1 name2 toname2 ...",__FILE__,copy,g);
+  theCommandsArg.Add("autodisplay","toggle autodisplay [0/1]",__FILE__,autodisplay,g);
+  theCommandsArg.Add("display","display [name1 name2 ...], no names display all",__FILE__,display,g);
+  theCommandsArg.Add("donly","donly [name1 name2 ...], erase and display",__FILE__,erase,g);
+  theCommandsArg.Add("erase","erase [name1 name2 ...], no names erase all",__FILE__,erase,g);
+  theCommandsArg.Add("draw","draw view mode [name1 name2 ...], draw on view with mode",__FILE__,draw,g);
+  theCommandsArg.Add("clear","clear display",__FILE__,erase,g);
+  theCommandsArg.Add("2dclear","clear display (2d objects)",__FILE__,erase,g);
+  theCommandsArg.Add("repaint","repaint, force redraw",__FILE__,repaintall,g);
+
+  theCommandsArg.Add("dtyp", "dtyp name1 name2",__FILE__,whatis,g);
+  theCommandsArg.Add("dval", "dval name, return value",__FILE__,value,g);
+  theCommandsArg.Add("dname", "dname name, print name",__FILE__,dname,g);
+  theCommandsArg.Add("dump", "dump name1 name2 ...",__FILE__,dump,g);
+  theCommandsArg.Add("copy",  "copy name1 toname1 name2 toname2 ...",__FILE__,copy,g);
   // san - 02/08/2002 - `rename` command changed to `renamevar` since it conflicts with 
   // the built-in Tcl command `rename`
   //theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,copy,g);
-  theCommands.Add("renamevar","renamevar name1 toname1 name2 toname2 ...",__FILE__,copy,g);
-  theCommands.Add("dset","var1 value1 vr2 value2 ...",__FILE__,set,g);
+  theCommandsArg.Add("renamevar","renamevar name1 toname1 name2 toname2 ...",__FILE__,copy,g);
+  theCommandsArg.Add("dset","var1 value1 vr2 value2 ...",__FILE__,set,g);
 
-  theCommands.Add("pick","pick id X Y Z b [nowait]",__FILE__,pick,g);
-  theCommands.Add("lastrep","lastrep id X Y [Z] b, return name",__FILE__,lastrep,g);
+  // commands to access C environment variables; see Mantis issue #23197
+  theCommandsArg.Add("dgetenv","var : get value of environment variable in C subsystem",__FILE__,dgetenv,g);
+  theCommandsArg.Add("dsetenv","var [value] : set (unset if value is empty) environment variable in C subsystem",__FILE__,dsetenv,g);
 
+  theCommandsArg.Add("pick","pick id X Y Z b [nowait]",__FILE__,pick,g);
+  theCommandsArg.Add("lastrep","lastrep id X Y [Z] b, return name",__FILE__,lastrep,g);
 }