1 ## Copyright (C) 2012 John W. Eaton
3 ## This file is part of Octave.
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.
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.
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/>.
20 ## @deftypefn {Function File} {} getpref (@var{group}, @var{pref}, @var{default})
21 ## Return the preference value corresponding to the named preference
22 ## @var{pref} in the preference group @var{group}.
24 ## The named preference group must be a character string.
26 ## If @var{pref} does not exist in @var{group} and @var{default} is
27 ## specified, return @var{default}.
29 ## The preference @var{pref} may be a character string or a cell array
30 ## of character strings. The corresponding default value @var{default}
31 ## may be any value, or, if @var{pref} is a cell array of strings,
32 ## @var{default} must be a cell array of values with the same size as
35 ## If neither @var{pref} nor @var{default} are specified, return a
36 ## structure of preferences for the preference group @var{group}.
38 ## If no arguments are specified, return a structure containing all
39 ## groups of preferences and their values.
40 ## @seealso{addpref, setpref, ispref, rmpref}
45 function retval = getpref (group, pref, default)
48 retval = loadprefs ();
52 if (isfield (prefs, group))
53 retval = prefs.(group);
58 error ("expecting group to be a character string");
60 elseif (nargin == 2 || nargin == 3)
61 grp = getpref (group);
63 if (isfield (grp, pref))
68 error ("preference %s does not exist in group %s", pref, group);
70 elseif (iscellstr (pref))
71 if (nargin == 2 || size_equal (pref, default))
73 if (isfield (grp, pref{i}))
74 retval.(pref) = grp.(pref{i});
76 retval.(pref) = default{i};
78 error ("preference %s does not exist in group %s", pref{i}, group);
82 error ("size mismatch for pref and default");
85 error ("expecting pref to be a character string or cellstr");
93 %% Testing these functions will require some care to avoid wiping out
94 %% existing (or creating unwanted) preferences for the user running the