0023347: Expression '(* q == ' ') && (* q == '\t')' is always false. Probably the...
[occt.git] / src / Draw / Draw_VariableCommands.cxx
index 7f425f5..95728f7 100755 (executable)
@@ -55,6 +55,7 @@ extern Draw_Viewer dout;
 #include <tcl.h>
 #include <errno.h>
 
+#include <OSD_Environment.hxx>
 
 Standard_Boolean Draw_ParseFailed;
 
@@ -592,6 +593,46 @@ static Standard_Integer set(Draw_Interpretor& di, Standard_Integer n, const char
   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  : 
@@ -995,7 +1036,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;
@@ -1269,6 +1310,10 @@ void  Draw::VariableCommands(Draw_Interpretor& theCommands)
   theCommands.Add("renamevar","renamevar name1 toname1 name2 toname2 ...",__FILE__,copy,g);
   theCommands.Add("dset","var1 value1 vr2 value2 ...",__FILE__,set,g);
 
+  // commands to access C environment variables; see Mantis issue #23197
+  theCommands.Add("dgetenv","var : get value of environment variable in C subsystem",__FILE__,dgetenv,g);
+  theCommands.Add("dsetenv","var [value] : set (unset if value is empty) environment variable in C subsystem",__FILE__,dsetenv,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);