changeset 19167:6f0290863d50

Add new function unsetenv from gnulib to Octave. * NEWS: Announce new function. * bootstrap.conf: Pull unsetenv from gnulib. * sysdep.cc (Fgetenv): Add seealso references to setenv, unsetenv. * sysdep.cc (Fsetenv): Rename from Fputenv. Change DEFALIAS to be from setenv to putenv. Redo docstring. Use unsetenv in BIST tests to get rid of temporary environment variable. * sysdep.cc (Funsetenv): New function. * system.txi: Add unsetenv to manual.
author Rik <rik@octave.org>
date Sat, 27 Sep 2014 12:26:57 -0700
parents 767103303974
children 9163a6e9b096
files NEWS bootstrap.conf doc/interpreter/system.txi libinterp/corefcn/sysdep.cc
diffstat 4 files changed, 57 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Sep 26 20:51:25 2014 -0700
+++ b/NEWS	Sat Sep 27 12:26:57 2014 -0700
@@ -93,6 +93,7 @@
       numfields
       rotate
       sylvester
+      unsetenv
       zoom
 
  ** inline() scheduled for eventual deprecation by Matlab
--- a/bootstrap.conf	Fri Sep 26 20:51:25 2014 -0700
+++ b/bootstrap.conf	Sat Sep 27 12:26:57 2014 -0700
@@ -101,6 +101,7 @@
   uname
   unistd
   unlink
+  unsetenv
   vasprintf
 "
 
--- a/doc/interpreter/system.txi	Fri Sep 26 20:51:25 2014 -0700
+++ b/doc/interpreter/system.txi	Sat Sep 27 12:26:57 2014 -0700
@@ -406,7 +406,9 @@
 
 @DOCSTRING(getenv)
 
-@DOCSTRING(putenv)
+@DOCSTRING(setenv)
+
+@DOCSTRING(unsetenv)
 
 @node Current Working Directory
 @section Current Working Directory
--- a/libinterp/corefcn/sysdep.cc	Fri Sep 26 20:51:25 2014 -0700
+++ b/libinterp/corefcn/sysdep.cc	Sat Sep 27 12:26:57 2014 -0700
@@ -555,6 +555,7 @@
 \n\
 @noindent\n\
 returns a string containing the value of your path.\n\
+@seealso{setenv, unsetenv}\n\
 @end deftypefn")
 {
   octave_value retval;
@@ -574,11 +575,20 @@
   return retval;
 }
 
-DEFUN (putenv, args, ,
+/*
+%!assert (ischar (getenv ("OCTAVE_HOME")))
+*/
+
+DEFUN (setenv, args, ,
        "-*- texinfo -*-\n\
-@deftypefn  {Built-in Function} {} putenv (@var{var}, @var{value})\n\
-@deftypefnx {Built-in Function} {} setenv (@var{var}, @var{value})\n\
+@deftypefn  {Built-in Function} {} setenv (@var{var}, @var{value})\n\
+@deftypefnx {Built-in Function} {} setenv (@var{var})\n\
+@deftypefnx {Built-in Function} {} putenv (@dots{})\n\
 Set the value of the environment variable @var{var} to @var{value}.\n\
+\n\
+If no @var{value} is specified then the variable will be assigned the null\n\
+string.\n\
+@seealso{unsetenv, getenv}\n\
 @end deftypefn")
 {
   octave_value_list retval;
@@ -597,10 +607,10 @@
           if (! error_state)
             octave_env::putenv (var, val);
           else
-            error ("putenv: VALUE must be a string");
+            error ("setenv: VALUE must be a string");
         }
       else
-        error ("putenv: VAR must be a string");
+        error ("setenv: VAR must be a string");
     }
   else
     print_usage ();
@@ -608,13 +618,48 @@
   return retval;
 }
 
-DEFALIAS (setenv, putenv);
+DEFALIAS (putenv, setenv);
 
 /*
-%!assert (ischar (getenv ("OCTAVE_HOME")))
 %!test
 %! setenv ("dummy_variable_that_cannot_matter", "foobar");
 %! assert (getenv ("dummy_variable_that_cannot_matter"), "foobar");
+%! unsetenv ("dummy_variable_that_cannot_matter");
+%! assert (getenv ("dummy_variable_that_cannot_matter"), "");
+*/
+
+DEFUN (unsetenv, args, ,
+       "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{status} =} unsetenv (@var{var})\n\
+Delete the environment variable @var{var}.\n\
+\n\
+Return 0 if the variable was deleted, or did not exist, and -1 if an error\n\
+occurred.\n\
+@seealso{setenv, getenv}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin == 1)
+    {
+      const char *var = args(0).string_value ().c_str ();
+
+      if (! error_state)
+        {
+          int status = gnulib::unsetenv (var);
+          retval = status;
+        }
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+## Test for unsetenv is in setenv test
 */
 
 // FIXME: perhaps kbhit should also be able to print a prompt?