1########################################################################
2##
3## Copyright (C) 2012-2021 The Octave Project Developers
4##
5## See the file COPYRIGHT.md in the top-level directory of this
6## distribution or <https://octave.org/copyright/>.
7##
8## This file is part of Octave.
9##
10## Octave is free software: you can redistribute it and/or modify it
11## under the terms of the GNU General Public License as published by
12## the Free Software Foundation, either version 3 of the License, or
13## (at your option) any later version.
14##
15## Octave is distributed in the hope that it will be useful, but
16## WITHOUT ANY WARRANTY; without even the implied warranty of
17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18## GNU General Public License for more details.
19##
20## You should have received a copy of the GNU General Public License
21## along with Octave; see the file COPYING.  If not, see
22## <https://www.gnu.org/licenses/>.
23##
24########################################################################
25
26## -*- texinfo -*-
27## @deftypefn  {} {@var{val} =} recycle ()
28## @deftypefnx {} {@var{old_val} =} recycle (@var{new_val})
29## Query or set the preference for recycling deleted files.
30##
31## When recycling is enabled, commands which would permanently erase files
32## instead move them to a temporary location (such as the directory labeled
33## Trash).
34##
35## Programming Note: This function is provided for @sc{matlab} compatibility,
36## but recycling is not implemented in Octave.  To help avoid accidental data
37## loss an error will be raised if an attempt is made to enable file recycling.
38## @seealso{delete, rmdir}
39## @end deftypefn
40
41function val = recycle (new_val)
42
43  persistent current_state = "off";
44
45  if (nargin > 1)
46    print_usage ();
47  endif
48
49  if (nargin == 0 || nargout > 0)
50    val = current_state;
51  endif
52
53  if (nargin == 1)
54    if (! ischar (new_val))
55      error ("recycle: NEW_VAL must be a character string");
56    endif
57
58    if (strcmpi (new_val, "on"))
59      error ("recycle: recycling files is not implemented");
60    elseif (strcmpi (new_val, "off"))
61      current_state = "off";
62    else
63      error ("recycle: invalid value '%s'", new_val);
64    endif
65  endif
66
67endfunction
68
69
70%!test
71%! recycle ("off");
72%! assert (recycle ("off"), "off");
73
74%!error recycle ("on", "and I mean it")
75%!error <NEW_VAL must be a character string> recycle (1)
76%!error <recycling files is not implemented> recycle ("on")
77%!error <invalid value 'foobar'> recycle ("foobar")
78