Mercurial > hg > octave-nkf
annotate scripts/miscellaneous/license.m @ 12597:e12a7c0a1fc5 stable
getappdata.m: If no property name is provided, return a structure representing the appdata.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Tue, 12 Apr 2011 18:50:20 -0400 |
parents | 139f993936af |
children | 45f4ff9a6247 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2005-2011 William Poetra Yoga Hadisoeseno |
5546 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5546 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5546 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} license | |
21 ## Display the license of Octave. | |
22 ## | |
5548 | 23 ## @deftypefnx {Function File} {} license ("inuse") |
24 ## Display a list of packages currently being used. | |
5546 | 25 ## |
6547 | 26 ## @deftypefnx {Function File} {@var{retval} =} license ("inuse") |
5548 | 27 ## Return a structure containing the fields @code{feature} and @code{user}. |
5546 | 28 ## |
6547 | 29 ## @deftypefnx {Function File} {@var{retval} =} license ("test", @var{feature}) |
5548 | 30 ## Return 1 if a license exists for the product identified by the string |
31 ## @var{feature} and 0 otherwise. The argument @var{feature} is case | |
32 ## insensitive and only the first 27 characters are checked. | |
5546 | 33 ## |
5548 | 34 ## @deftypefnx {Function File} {} license ("test", @var{feature}, @var{toggle}) |
35 ## Enable or disable license testing for @var{feature}, depending on | |
36 ## @var{toggle}, which may be one of: | |
5546 | 37 ## |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
38 ## @table @asis |
5546 | 39 ## @item "enable" |
40 ## Future tests for the specified license of @var{feature} are conducted | |
41 ## as usual. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
42 ## |
5546 | 43 ## @item "disable" |
44 ## Future tests for the specified license of @var{feature} return 0. | |
45 ## @end table | |
46 ## | |
6547 | 47 ## @deftypefnx {Function File} {@var{retval} =} license ("checkout", @var{feature}) |
5548 | 48 ## Check out a license for @var{feature}, returning 1 on success and 0 |
49 ## on failure. | |
5546 | 50 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
51 ## This function is provided for compatibility with @sc{matlab}. |
5642 | 52 ## @seealso{ver, version} |
5546 | 53 ## @end deftypefn |
54 | |
55 ## Author: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> | |
56 | |
57 function retval = license (varargin) | |
58 | |
5548 | 59 persistent __octave_licenses__; |
5546 | 60 |
61 if (isempty (__octave_licenses__)) | |
62 __octave_licenses__ = cell (); | |
63 __octave_licenses__{1,1} = "Octave"; | |
6555 | 64 __octave_licenses__{1,2} = "GNU General Public License"; |
5546 | 65 __octave_licenses__{1,3} = true; |
66 if (exist ("OCTAVE_FORGE_VERSION")) | |
67 __octave_licenses__{2,1} = "octave-forge"; | |
68 __octave_licenses__{2,2} = "<various licenses>"; | |
69 __octave_licenses__{2,3} = true; | |
70 endif | |
71 endif | |
72 | |
73 nout = nargout; | |
74 nin = nargin; | |
75 nr_licenses = rows (__octave_licenses__); | |
76 | |
77 if (nout > 1 || nin > 3) | |
78 error ("type `help license' for usage info"); | |
79 endif | |
80 | |
81 if (nin == 0) | |
82 | |
5548 | 83 found = false; |
84 for p = 1:nr_licenses | |
85 if (strcmp (__octave_licenses__{p,1}, "Octave")) | |
86 found = true; | |
87 break; | |
88 endif | |
89 endfor | |
5546 | 90 |
5548 | 91 if (found) |
92 result = __octave_licenses__{p,2}; | |
93 else | |
94 result = "unknown"; | |
95 endif | |
5546 | 96 |
5548 | 97 if (nout == 0) |
98 printf ("%s\n", result); | |
5546 | 99 else |
5548 | 100 retval = result; |
5546 | 101 endif |
102 | |
103 elseif (nin == 1) | |
104 | |
105 if (nout == 0) | |
106 | |
107 if (! strcmp (varargin{1}, "inuse")) | |
108 usage ("license (\"inuse\")"); | |
109 endif | |
110 | |
111 for p = 1:nr_licenses | |
5548 | 112 printf ("%s\n", __octave_licenses__{p,1}); |
5546 | 113 endfor |
114 | |
115 else | |
116 | |
117 if (! strcmp (varargin{1}, "inuse")) | |
118 usage ("retval = license (\"inuse\")"); | |
119 endif | |
120 | |
5548 | 121 pw = getpwuid (getuid ()); |
122 if (isstruct (pw)) | |
10549 | 123 username = pw.name; |
5546 | 124 else |
10549 | 125 username = "octave_user"; |
5546 | 126 endif |
127 | |
128 retval(1:nr_licenses) = struct ("feature", "", "user", ""); | |
129 for p = 1:nr_licenses | |
130 retval(p).feature = __octave_licenses__{p,1}; | |
131 retval(p).user = username; | |
132 endfor | |
133 | |
134 endif | |
135 | |
136 else | |
137 | |
138 feature = varargin{2}(1:(min ([(length (varargin{2})), 27]))); | |
139 | |
140 if (strcmp (varargin{1}, "test")) | |
141 | |
142 found = false; | |
143 for p = 1:nr_licenses | |
144 if (strcmpi (feature, __octave_licenses__{p,1})) | |
145 found = true; | |
146 break; | |
147 endif | |
148 endfor | |
149 | |
150 if (nin == 2) | |
151 retval = found && __octave_licenses__{p,3}; | |
152 else | |
153 if (found) | |
154 if (strcmp (varargin{3}, "enable")) | |
155 __octave_licenses__{p,3} = true; | |
156 elseif (strcmp (varargin{3}, "disable")) | |
157 __octave_licenses__{p,3} = false; | |
158 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
159 error ("TOGGLE must be either `enable' of `disable'"); |
5546 | 160 endif |
161 else | |
12480
139f993936af
Uppercase variables in script error strings.
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
162 error ("FEATURE `%s' not found", feature); |
5546 | 163 endif |
164 endif | |
165 | |
166 elseif (strcmp (varargin{1}, "checkout")) | |
167 | |
168 if (nin != 2) | |
169 usage ("retval = license (\"checkout\", feature)"); | |
170 endif | |
171 | |
172 found = false; | |
173 for p = 1:nr_licenses | |
174 if (strcmpi (feature, __octave_licenses__{p,1})) | |
175 found = true; | |
176 break; | |
177 endif | |
178 endfor | |
179 | |
180 retval = found && __octave_licenses__{p,3}; | |
181 | |
182 else | |
183 | |
184 error ("type `help license' for usage info"); | |
185 | |
186 endif | |
187 | |
188 endif | |
189 | |
190 endfunction |