annotate scripts/general/nargchk.m @ 20305:c164cfc24bdd

QtHandles: add annotations dialog * libgui/graphics/annotation-dialog.h: new file * libgui/graphics/annotation-dialog.cc: new file * libgui/graphics/annotation-dialog.ui: new file * libgui/graphics/Canvas.cc (canvasMousePressEvent): call annotation_dialog when in TextMode. * libgui/graphics/module.mk: add annotation-dialog to build
author John Donoghue <john.donoghue@ieee.org>
date Sun, 19 Apr 2015 09:54:54 -0400
parents 4197fc428c7d
children 7503499a252b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19898
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19304
diff changeset
1 ## Copyright (C) 2008-2015 Bill Denney
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
710
60af453e3f67 [project @ 1994-09-17 14:29:26 by jwe]
jwe
parents:
diff changeset
18
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 2847
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 9204
diff changeset
20 ## @deftypefn {Function File} {@var{msgstr} =} nargchk (@var{minargs}, @var{maxargs}, @var{nargs})
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
21 ## @deftypefnx {Function File} {@var{msgstr} =} nargchk (@var{minargs}, @var{maxargs}, @var{nargs}, "string")
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
22 ## @deftypefnx {Function File} {@var{msgstruct} =} nargchk (@var{minargs}, @var{maxargs}, @var{nargs}, "struct")
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
23 ## Return an appropriate error message string (or structure) if the
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
24 ## number of inputs requested is invalid.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3371
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 input arguments
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
27 ## supplied to a function is within an acceptable range.
19304
bc640d4678fb Undeprecate nargchk, but add note that narginchk is preferred.
Rik <rik@octave.org>
parents: 17744
diff changeset
28 ##
bc640d4678fb Undeprecate nargchk, but add note that narginchk is preferred.
Rik <rik@octave.org>
parents: 17744
diff changeset
29 ## @strong{Caution}: @code{nargchk} is scheduled for deprecation. Use
bc640d4678fb Undeprecate nargchk, but add note that narginchk is preferred.
Rik <rik@octave.org>
parents: 17744
diff changeset
30 ## @code{narginchk} in all new code.
13852
e36817e2ee60 New function narginchk
Carnë Draug <carandraug+dev@gmail.com>
parents: 12881
diff changeset
31 ## @seealso{nargoutchk, narginchk, error, nargin, nargout}
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 2847
diff changeset
32 ## @end deftypefn
710
60af453e3f67 [project @ 1994-09-17 14:29:26 by jwe]
jwe
parents:
diff changeset
33
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
34 ## Author: Bill Denney <bill@denney.ws>
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
35
12881
49553ea11764 Return 0x1 empty struct when nargchk, nargoutcheck passes for ML compatability (bug #33808)
Rik <octave@nomad.inbox5.com>
parents: 12865
diff changeset
36 function msg = nargchk (minargs, maxargs, nargs, outtype = "string")
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
37
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
38 if (nargin < 3 || nargin > 4)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5307
diff changeset
39 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
40 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
41 error ("nargchk: MINARGS must be <= MAXARGS");
9204
1f47a9404d93 nargchk.m: don't generate error if output is struct
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
42 elseif (! any (strcmpi (outtype, {"string", "struct"})))
12881
49553ea11764 Return 0x1 empty struct when nargchk, nargoutcheck passes for ML compatability (bug #33808)
Rik <octave@nomad.inbox5.com>
parents: 12865
diff changeset
43 error ('nargchk: 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
44 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
45 error ("nargchk: MINARGS, MAXARGS, and NARGS must be scalars");
710
60af453e3f67 [project @ 1994-09-17 14:29:26 by jwe]
jwe
parents:
diff changeset
46 endif
60af453e3f67 [project @ 1994-09-17 14:29:26 by jwe]
jwe
parents:
diff changeset
47
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
48 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
49 if (nargs < minargs)
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
50 msg.message = "not enough input arguments";
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
51 msg.identifier = "Octave:nargchk:not-enough-inputs";
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
52 elseif (nargs > maxargs)
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
53 msg.message = "too many input arguments";
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
54 msg.identifier = "Octave:nargchk:too-many-inputs";
710
60af453e3f67 [project @ 1994-09-17 14:29:26 by jwe]
jwe
parents:
diff changeset
55 endif
60af453e3f67 [project @ 1994-09-17 14:29:26 by jwe]
jwe
parents:
diff changeset
56
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
57 if (strcmpi (outtype, "string"))
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
58 msg = msg.message;
12881
49553ea11764 Return 0x1 empty struct when nargchk, nargoutcheck passes for ML compatability (bug #33808)
Rik <octave@nomad.inbox5.com>
parents: 12865
diff changeset
59 elseif (isempty (msg.message))
49553ea11764 Return 0x1 empty struct when nargchk, nargoutcheck passes for ML compatability (bug #33808)
Rik <octave@nomad.inbox5.com>
parents: 12865
diff changeset
60 ## Compatability: Matlab returns a 0x1 empty struct when nargchk passes
49553ea11764 Return 0x1 empty struct when nargchk, nargoutcheck passes for ML compatability (bug #33808)
Rik <octave@nomad.inbox5.com>
parents: 12865
diff changeset
61 msg = resize (msg, 0, 1);
710
60af453e3f67 [project @ 1994-09-17 14:29:26 by jwe]
jwe
parents:
diff changeset
62 endif
60af453e3f67 [project @ 1994-09-17 14:29:26 by jwe]
jwe
parents:
diff changeset
63
60af453e3f67 [project @ 1994-09-17 14:29:26 by jwe]
jwe
parents:
diff changeset
64 endfunction
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
65
12705
4972eb61c6d6 Fix bug with error() not accepting an empty struct input (Bug #33428).
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
66
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
67 ## Tests
12865
a4d1581f9e72 Return correct struct for nargchk, nargoutchk (Bug #33808).
Rik <octave@nomad.inbox5.com>
parents: 12705
diff changeset
68 %!shared stnul, stmin, stmax
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
69 %! stnul = resize (struct ("message", "", "identifier", ""), 0, 1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
70 %! stmin = struct ("message", "not enough input arguments",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
71 %! "identifier", "Octave:nargchk:not-enough-inputs");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
72 %! stmax = struct ("message", "too many input arguments",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
73 %! "identifier", "Octave:nargchk:too-many-inputs");
8522
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
74 %!assert (nargchk (0, 1, 0), "")
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
75 %!assert (nargchk (0, 1, 1), "")
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
76 %!assert (nargchk (1, 1, 0), "not enough input arguments")
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
77 %!assert (nargchk (0, 1, 2), "too many input arguments")
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
78 %!assert (nargchk (0, 1, 2, "string"), "too many input arguments")
d65b33e55d40 nargchk.m: improve compatibility; new tests
Peter L. Sondergaard <peter@sonderport.dk>
parents: 7658
diff changeset
79 ## Struct outputs
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
80 %!assert (nargchk (0, 1, 0, "struct"), stnul)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
81 %!assert (nargchk (0, 1, 1, "struct"), stnul)
9204
1f47a9404d93 nargchk.m: don't generate error if output is struct
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
82 %!assert (nargchk (1, 1, 0, "struct"), stmin)
1f47a9404d93 nargchk.m: don't generate error if output is struct
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
83 %!assert (nargchk (0, 1, 2, "struct"), stmax)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
84