annotate scripts/prefs/rmpref.m @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents 03b9d17a2d95
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19627
diff changeset
1 ## Copyright (C) 2012-2015 John W. Eaton
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## your option) any later version.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
20195
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19731
diff changeset
20 ## @deftypefn {Function File} {} rmpref (@var{group}, @var{pref})
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19731
diff changeset
21 ## @deftypefnx {Function File} {} rmpref (@var{group})
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19731
diff changeset
22 ## Remove the named preference @var{pref} from the preference group @var{group}.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ## The named preference group must be a character string.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 ##
20195
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19731
diff changeset
26 ## The preference @var{pref} may be a character string or cell array of strings.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 ##
20195
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19731
diff changeset
28 ## If @var{pref} is not specified, remove the preference group @var{group}.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 ## It is an error to remove a nonexistent preference or group.
13943
5820f8ce683e doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents: 13929
diff changeset
31 ## @seealso{addpref, ispref, setpref, getpref}
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 ## @end deftypefn
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 ## Author: jwe
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 function retval = rmpref (group, pref)
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
38 if (nargin < 1 || nargin > 2)
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
39 print_usage ();
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
40 elseif (! ischar (group))
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
41 error ("rmpref: GROUP must be a string");
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
42 elseif (nargin == 2 && ! (ischar (pref) || iscellstr (pref)))
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
43 error ("rmpref: PREF must be a string or cell array of strings");
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
44 endif
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 if (nargin == 1)
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
47 if (ispref (group))
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
48 prefs = loadprefs ();
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
49 prefs = rmfield (prefs, group);
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
50 saveprefs (prefs);
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 else
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
52 error ("rmpref: group <%s> does not exist", group);
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 endif
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 else
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
55 valid = ispref (group, pref);
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
56 if (all (valid))
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
57 prefs = loadprefs ();
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
58 prefs.(group) = rmfield (prefs.(group), pref);
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
59 saveprefs (prefs);
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
60 else
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
61 if (! ispref (group))
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
62 error ("rmpref: group <%s> does not exist", group);
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
63 else
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
64 idx = find (! valid, 1);
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
65 error ("rmpref: pref <%s> does not exist", (cellstr (pref)){idx} );
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
66 endif
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
67 endif
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 endif
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 endfunction
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
72
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
73 ## Testing these functions will require some care to avoid wiping out
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
74 ## existing (or creating unwanted) preferences for the user running the
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
75 ## tests.
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
76
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
77 ## Test input validation
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
78 %!error rmpref ()
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
79 %!error rmpref (1,2,3)
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
80 %!error rmpref ({"__group1__"})
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
81 %!error rmpref ("__group1__", 1)
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
82