annotate scripts/prefs/rmpref.m @ 20170:af2b7695f1c4 draft default tip @

gallery.m: clean and vectorize part of qmult. * scripts/special-matrix/gallery.m: make qmult() follow Octave guidelines, vectorize last for loop in qmult().
author Antonio Pino Robles <data.script93@gmail.com>
date Thu, 28 May 2015 18:32:47 +0200
parents 4197fc428c7d
children 03b9d17a2d95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19593
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 -*-
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
20 ## @deftypefn {Function File} {} rmpref (@var{group})
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
21 ## @deftypefnx {Function File} {} rmpref (@var{group}, @var{pref})
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 ## Remove the named preference @var{pref} from the preference group
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 ## @var{group}.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 ## The named preference group must be a character string.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 ##
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
27 ## The preference @var{pref} may be a character string or cell array
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
28 ## of strings.
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 ## If @var{pref} is not specified, remove the preference group
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 ## @var{group}.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 ## 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
34 ## @seealso{addpref, ispref, setpref, getpref}
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 ## @end deftypefn
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 ## Author: jwe
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 function retval = rmpref (group, pref)
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
41 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
42 print_usage ();
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
43 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
44 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
45 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
46 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
47 endif
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 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
50 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
51 prefs = loadprefs ();
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
52 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
53 saveprefs (prefs);
13261
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 error ("rmpref: group <%s> does not exist", group);
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 endif
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 else
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
58 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
59 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
60 prefs = loadprefs ();
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
61 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
62 saveprefs (prefs);
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
63 else
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
64 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
65 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
66 else
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
67 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
68 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
69 endif
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
70 endif
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 endif
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 endfunction
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
75
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
76 ## 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
77 ## 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
78 ## tests.
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
79
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
80 ## 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
81 %!error rmpref ()
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
82 %!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
83 %!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
84 %!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
85