7017
|
1 ## Copyright (C) 2005, 2006, 2007 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 ## |
|
38 ## @table @samp |
|
39 ## @item "enable" |
|
40 ## Future tests for the specified license of @var{feature} are conducted |
|
41 ## as usual. |
|
42 ## @item "disable" |
|
43 ## Future tests for the specified license of @var{feature} return 0. |
|
44 ## @end table |
|
45 ## |
6547
|
46 ## @deftypefnx {Function File} {@var{retval} =} license ("checkout", @var{feature}) |
5548
|
47 ## Check out a license for @var{feature}, returning 1 on success and 0 |
|
48 ## on failure. |
5546
|
49 ## |
5548
|
50 ## This function is provided for compatibility with @sc{Matlab}. |
5642
|
51 ## @seealso{ver, version} |
5546
|
52 ## @end deftypefn |
|
53 |
|
54 ## Author: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> |
|
55 |
|
56 function retval = license (varargin) |
|
57 |
5548
|
58 persistent __octave_licenses__; |
5546
|
59 |
|
60 if (isempty (__octave_licenses__)) |
|
61 __octave_licenses__ = cell (); |
|
62 __octave_licenses__{1,1} = "Octave"; |
6555
|
63 __octave_licenses__{1,2} = "GNU General Public License"; |
5546
|
64 __octave_licenses__{1,3} = true; |
|
65 if (exist ("OCTAVE_FORGE_VERSION")) |
|
66 __octave_licenses__{2,1} = "octave-forge"; |
|
67 __octave_licenses__{2,2} = "<various licenses>"; |
|
68 __octave_licenses__{2,3} = true; |
|
69 endif |
|
70 endif |
|
71 |
|
72 nout = nargout; |
|
73 nin = nargin; |
|
74 nr_licenses = rows (__octave_licenses__); |
|
75 |
|
76 if (nout > 1 || nin > 3) |
|
77 error ("type `help license' for usage info"); |
|
78 endif |
|
79 |
|
80 if (nin == 0) |
|
81 |
5548
|
82 found = false; |
|
83 for p = 1:nr_licenses |
|
84 if (strcmp (__octave_licenses__{p,1}, "Octave")) |
|
85 found = true; |
|
86 break; |
|
87 endif |
|
88 endfor |
5546
|
89 |
5548
|
90 if (found) |
|
91 result = __octave_licenses__{p,2}; |
|
92 else |
|
93 result = "unknown"; |
|
94 endif |
5546
|
95 |
5548
|
96 if (nout == 0) |
|
97 printf ("%s\n", result); |
5546
|
98 else |
5548
|
99 retval = result; |
5546
|
100 endif |
|
101 |
|
102 elseif (nin == 1) |
|
103 |
|
104 if (nout == 0) |
|
105 |
|
106 if (! strcmp (varargin{1}, "inuse")) |
|
107 usage ("license (\"inuse\")"); |
|
108 endif |
|
109 |
|
110 for p = 1:nr_licenses |
5548
|
111 printf ("%s\n", __octave_licenses__{p,1}); |
5546
|
112 endfor |
|
113 |
|
114 else |
|
115 |
|
116 if (! strcmp (varargin{1}, "inuse")) |
|
117 usage ("retval = license (\"inuse\")"); |
|
118 endif |
|
119 |
5548
|
120 pw = getpwuid (getuid ()); |
|
121 if (isstruct (pw)) |
|
122 username = pw.name; |
5546
|
123 else |
5548
|
124 username = "octave_user"; |
5546
|
125 endif |
|
126 |
|
127 retval(1:nr_licenses) = struct ("feature", "", "user", ""); |
|
128 for p = 1:nr_licenses |
|
129 retval(p).feature = __octave_licenses__{p,1}; |
|
130 retval(p).user = username; |
|
131 endfor |
|
132 |
|
133 endif |
|
134 |
|
135 else |
|
136 |
|
137 feature = varargin{2}(1:(min ([(length (varargin{2})), 27]))); |
|
138 |
|
139 if (strcmp (varargin{1}, "test")) |
|
140 |
|
141 found = false; |
|
142 for p = 1:nr_licenses |
|
143 if (strcmpi (feature, __octave_licenses__{p,1})) |
|
144 found = true; |
|
145 break; |
|
146 endif |
|
147 endfor |
|
148 |
|
149 if (nin == 2) |
|
150 retval = found && __octave_licenses__{p,3}; |
|
151 else |
|
152 if (found) |
|
153 if (strcmp (varargin{3}, "enable")) |
|
154 __octave_licenses__{p,3} = true; |
|
155 elseif (strcmp (varargin{3}, "disable")) |
|
156 __octave_licenses__{p,3} = false; |
|
157 else |
|
158 error ("toggle must be either `enable' of `disable'"); |
|
159 endif |
|
160 else |
|
161 error ("feature `%s' not found", feature); |
|
162 endif |
|
163 endif |
|
164 |
|
165 elseif (strcmp (varargin{1}, "checkout")) |
|
166 |
|
167 if (nin != 2) |
|
168 usage ("retval = license (\"checkout\", feature)"); |
|
169 endif |
|
170 |
|
171 found = false; |
|
172 for p = 1:nr_licenses |
|
173 if (strcmpi (feature, __octave_licenses__{p,1})) |
|
174 found = true; |
|
175 break; |
|
176 endif |
|
177 endfor |
|
178 |
|
179 retval = found && __octave_licenses__{p,3}; |
|
180 |
|
181 else |
|
182 |
|
183 error ("type `help license' for usage info"); |
|
184 |
|
185 endif |
|
186 |
|
187 endif |
|
188 |
|
189 endfunction |