Mercurial > hg > octave-lyh
annotate scripts/general/nargoutchk.m @ 11563:3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 18 Jan 2011 20:55:01 -0800 |
parents | fd0a3ac60b0e |
children | 4972eb61c6d6 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2008-2011 Bill Denney |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
2 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
3 ## This file is part of Octave. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
4 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
8 ## your option) any later version. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
9 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
13 ## General Public License for more details. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
14 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
18 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
20 ## @deftypefn {Function File} {@var{msgstr} =} nargoutchk (@var{minargs}, @var{maxargs}, @var{nargs}) |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{msgstr} =} nargoutchk (@var{minargs}, @var{maxargs}, @var{nargs}, "string") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{msgstruct} =} nargoutchk (@var{minargs}, @var{maxargs}, @var{nargs}, "struct") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
23 ## Return an appropriate error message string (or structure) if the |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
24 ## number of outputs requested is invalid. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
25 ## |
8522
d65b33e55d40
nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents:
7658
diff
changeset
|
26 ## This is useful for checking to see that the number of output |
d65b33e55d40
nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents:
7658
diff
changeset
|
27 ## arguments supplied to a function is within an acceptable range. |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
28 ## @seealso{nargchk, error, nargout, nargin} |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
29 ## @end deftypefn |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
30 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
31 ## Author: Bill Denney <bill@denney.ws> |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
32 |
11470
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
33 function msg = nargoutchk (minargs, maxargs, nargs, outtype) |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
34 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
35 if (nargin < 3 || nargin > 4) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
36 print_usage (); |
11470
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
37 elseif (minargs > maxargs) |
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
38 error ("nargoutchk: MINARGS must be <= MAXARGS"); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
39 elseif (nargin == 3) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
40 outtype = "string"; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
41 elseif (! any (strcmpi (outtype, {"string" "struct"}))) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
42 error ("nargoutchk: output type must be either string or struct"); |
11470
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
43 elseif (! (isscalar (minargs) && isscalar (maxargs) && isscalar (nargs))) |
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
44 error ("nargoutchk: MINARGS, MAXARGS, and NARGS must be scalars"); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
45 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
46 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
47 msg = struct ("message", "", "identifier", ""); |
11470
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
48 if (nargs < minargs) |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
49 msg.message = "not enough output arguments"; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
50 msg.identifier = "Octave:nargoutchk:not-enough-outputs"; |
11470
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
51 elseif (nargs > maxargs) |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
52 msg.message = "too many output arguments"; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
53 msg.identifier = "Octave:nargoutchk:too-many-outputs"; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
54 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
55 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
56 if (strcmpi (outtype, "string")) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
57 msg = msg.message; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
58 else |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
59 if (isempty (msg.message)) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
60 msg = struct ([]); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
61 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
62 ## FIXME: remove the error below if error is modified to accept |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
63 ## struct inputs |
8664 | 64 error ("nargoutchk: error does not yet support struct inputs"); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
65 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
66 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
67 endfunction |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
68 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
69 ## Tests |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
70 %!shared stmin, stmax |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
71 %! stmin = struct ("message", "not enough output arguments", |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
72 %! "identifier", "Octave:nargoutchk:not-enough-outputs"); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
73 %! stmax = struct ("message", "too many output arguments", |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
74 %! "identifier", "Octave:nargoutchk:too-many-outputs"); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
75 %!assert (nargoutchk (0, 1, 0), "") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
76 %!assert (nargoutchk (0, 1, 1), "") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
77 %!assert (nargoutchk (1, 1, 0), "not enough output arguments") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
78 %!assert (nargoutchk (0, 1, 2), "too many output arguments") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
79 %!assert (nargoutchk (0, 1, 2, "string"), "too many output arguments") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
80 ## Struct outputs |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
81 #%!assert (nargoutchk (0, 1, 0, "struct"), struct([])) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
82 #%!assert (nargoutchk (0, 1, 1, "struct"), struct([])) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
83 #%!assert (nargoutchk (1, 1, 0, "struct"), stmin) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
84 #%!assert (nargoutchk (0, 1, 2, "struct"), stmax) |