]> Creatis software - CreaPhase.git/blob - octave_packages/m/miscellaneous/recycle.m
update packages
[CreaPhase.git] / octave_packages / m / miscellaneous / recycle.m
1 ## Copyright (C) 2012 John W. Eaton
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {@var{current_state}} recycle ()
21 ## @deftypefnx {Function File} {@var{old_state}} recycle (@var{new_state})
22 ## Query or set the preference for recycling deleted files.
23 ##
24 ## Recycling files instead of permanently deleting them is currently not
25 ## implemented in Octave.  To help avoid accidental data loss it
26 ## is an error to attempt enable file recycling.
27 ## @seealso{delete}
28 ## @end deftypefn
29
30 ## Author: jwe
31
32 function retval = recycle (state)
33
34   persistent current_state = "off";
35
36   if (nargin > 1)
37     print_usage ();
38   endif
39
40   if (nargin == 0 || nargout > 0)
41     retval = current_state;
42   endif
43
44   if (nargin == 1)
45     if (ischar (state))
46       if (strcmpi (state, "on"))
47         error ("recycle: recycling files is not implemented");
48       elseif (strcmpi (state, "off"))
49         current_state = "off";
50       else
51         error ("recycle: invalid value of STATE = `%s'", state);
52       endif
53     else
54       error ("recycle: expecting STATE to be a character string");
55     endif
56   endif
57
58 endfunction
59
60 %!error recycle ("on");
61 %!error recycle ("on", "and I mean it");
62 %!error recycle (1);
63
64 %!test
65 %! recycle ("off");
66 %! assert (recycle ("off"), "off");