Mercurial > octave
annotate scripts/prefs/addpref.m @ 29358:0a5b15007766 stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 09:52:15 -0500 |
parents | bd51beb6205e |
children | 7854d5752dd2 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 ## Copyright (C) 2012-2021 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 ## |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
13261
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 ## 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
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 ## |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 ## 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
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20834
diff
changeset
|
27 ## @deftypefn {} {} addpref ("@var{group}", "@var{pref}", @var{val}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20834
diff
changeset
|
28 ## @deftypefnx {} {} addpref ("@var{group}", @{"@var{pref1}", "@var{pref2}", @dots{}@}, @{@var{val1}, @var{val2}, @dots{}@}) |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
29 ## Add the preference @var{pref} and associated value @var{val} to the named |
20160
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
30 ## preference group @var{group}. |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 ## |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
32 ## The named preference group must be a string. |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
33 ## |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
34 ## The preference @var{pref} may be a string or a cell array of strings. An |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
35 ## error will be issued if the preference already exists. |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 ## |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
37 ## The corresponding value @var{val} may be any Octave value, .e.g., double, |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
38 ## struct, cell array, object, etc. Or, if @var{pref} is a cell array of |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
39 ## strings then @var{val} must be a cell array of values with the same size as |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
40 ## @var{pref}. |
13943
5820f8ce683e
doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
13929
diff
changeset
|
41 ## @seealso{setpref, getpref, ispref, rmpref} |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 ## @end deftypefn |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 function addpref (group, pref, val) |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
46 if (nargin != 3) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
47 print_usage (); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
48 endif |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
49 |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
50 if (! ischar (group)) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
51 error ("addpref: GROUP must be a string"); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
52 elseif (! (ischar (pref) || iscellstr (pref))) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
53 error ("addpref: PREF must be a string or cellstr"); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
54 endif |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
55 |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
56 prefs = loadprefs (); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
57 |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
58 if (ischar (pref)) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
59 if (isfield (prefs, group) && isfield (prefs.(group), pref)) |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
60 error ("addpref: preference %s already exists in GROUP %s", pref, group); |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 else |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
62 prefs.(group).(pref) = val; |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 endif |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 else |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
65 if (! size_equal (pref, val)) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
66 error ("addpref: size mismatch for PREF and VAL"); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
67 endif |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
68 for i = 1:numel (pref) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
69 if (isfield (prefs, group) && isfield (prefs.(group), pref{i})) |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
70 error ("addpref: preference %s already exists in GROUP %s", |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
71 pref{i}, group); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
72 else |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
73 prefs.(group).(pref{i}) = val{i}; |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
74 endif |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
75 endfor |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 endif |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
78 saveprefs (prefs); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
79 |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 endfunction |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
82 |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
83 %!test |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
84 %! HOME = getenv ("HOME"); |
26698
63b5a17ba30f
Use save_default_options() to make BIST test suite robust against user configurations.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
85 %! save_default_options ("-binary", "local"); |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
86 %! unwind_protect |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
87 %! setenv ("HOME", P_tmpdir ()); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
88 %! |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
89 %! addpref ("group1", "pref1", [1 2 3]); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
90 %! assert (getpref ("group1", "pref1"), [1 2 3]); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
91 %! |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
92 %! addpref ("group2", {"prefA", "prefB"}, {"StringA", {"StringB"}}); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
93 %! assert (getpref ("group2", "prefA"), "StringA"); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
94 %! assert (getpref ("group2", "prefB"), {"StringB"}); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
95 %! |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
96 %! fail ('addpref ("group1", "pref1", 4)', ... |
22765
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22760
diff
changeset
|
97 %! "preference pref1 already exists in GROUP group1"); |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
98 %! fail ('setpref ("group1", {"p1", "p2"}, 1)', ... |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
99 %! "size mismatch for PREF and VAL"); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
100 %! fail ('addpref ("group2", {"prefC", "prefA"}, {1, 2})', |
22765
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22760
diff
changeset
|
101 %! "preference prefA already exists in GROUP group2"); |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
102 %! |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
103 %! unwind_protect_cleanup |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
104 %! unlink (fullfile (P_tmpdir (), ".octave_prefs")); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
105 %! if (isempty (HOME)) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
106 %! unsetenv ("HOME"); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
107 %! else |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
108 %! setenv ("HOME", HOME); |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
109 %! endif |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
110 %! end_unwind_protect |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
111 |
20834
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
112 %!error addpref () |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
113 %!error addpref (1) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
114 %!error addpref (1,2) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
115 %!error addpref (1,2,3,4) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
116 %!error <GROUP must be a string> addpref (1, "pref1", 2) |
27b333c88c8e
Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
117 %!error <PREF must be a string> addpref ("group1", 1, 2) |