5546
|
1 ## Copyright (C) 2005 William Poetra Yoga Hadisoeseno |
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} license |
|
22 ## Display the license of Octave. |
|
23 ## |
5548
|
24 ## @deftypefnx {Function File} {} license ("inuse") |
|
25 ## Display a list of packages currently being used. |
5546
|
26 ## |
6547
|
27 ## @deftypefnx {Function File} {@var{retval} =} license ("inuse") |
5548
|
28 ## Return a structure containing the fields @code{feature} and @code{user}. |
5546
|
29 ## |
6547
|
30 ## @deftypefnx {Function File} {@var{retval} =} license ("test", @var{feature}) |
5548
|
31 ## Return 1 if a license exists for the product identified by the string |
|
32 ## @var{feature} and 0 otherwise. The argument @var{feature} is case |
|
33 ## insensitive and only the first 27 characters are checked. |
5546
|
34 ## |
5548
|
35 ## @deftypefnx {Function File} {} license ("test", @var{feature}, @var{toggle}) |
|
36 ## Enable or disable license testing for @var{feature}, depending on |
|
37 ## @var{toggle}, which may be one of: |
5546
|
38 ## |
|
39 ## @table @samp |
|
40 ## @item "enable" |
|
41 ## Future tests for the specified license of @var{feature} are conducted |
|
42 ## as usual. |
|
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 ## |
5548
|
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"; |
|
64 __octave_licenses__{1,2} = "GNU General Public License, Version 2"; |
|
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)) |
|
123 username = pw.name; |
5546
|
124 else |
5548
|
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 |
|
159 error ("toggle must be either `enable' of `disable'"); |
|
160 endif |
|
161 else |
|
162 error ("feature `%s' not found", feature); |
|
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 |