annotate scripts/miscellaneous/menu.m @ 14138:72c96de7a403 stable

maint: update copyright notices for 2012
author John W. Eaton <jwe@octave.org>
date Mon, 02 Jan 2012 14:25:41 -0500
parents acaf33ccc04f
children ff4143d9fc05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13952
diff changeset
1 ## Copyright (C) 1993-2012 John W. Eaton
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: 6521
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: 6521
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: 6521
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: 6521
diff changeset
17 ## <http://www.gnu.org/licenses/>.
245
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 211
diff changeset
18
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3372
diff changeset
19 ## -*- texinfo -*-
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3180
diff changeset
20 ## @deftypefn {Function File} {} menu (@var{title}, @var{opt1}, @dots{})
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3180
diff changeset
21 ## Print a title string followed by a series of options. Each option will
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3180
diff changeset
22 ## be printed along with a number. The return value is the number of the
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3180
diff changeset
23 ## option selected by the user. This function is useful for interactive
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3180
diff changeset
24 ## programs. There is no limit to the number of options that may be passed
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3180
diff changeset
25 ## in, but it may be confusing to present more than will fit easily on one
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3180
diff changeset
26 ## screen.
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
27 ## @seealso{disp, printf, input}
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3180
diff changeset
28 ## @end deftypefn
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
29
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
30 ## Author: jwe
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
31
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10281
diff changeset
32 function num = menu (title, varargin)
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
33
211
4adbab9c31cd [project @ 1993-11-12 14:12:22 by jwe]
jwe
parents: 4
diff changeset
34 if (nargin < 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
35 print_usage ();
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
36 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
37
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1887
diff changeset
38 ## Force pending output to appear before the menu.
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
39
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
40 fflush (stdout);
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
41
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1887
diff changeset
42 ## Don't send the menu through the pager since doing that can cause
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1887
diff changeset
43 ## major confusion.
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
44
13952
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
45 page_screen_output (0, "local");
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
46
13952
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
47 if (! isempty (title))
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
48 disp (title);
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
49 printf ("\n");
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
50 endif
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
51
13952
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
52 nopt = nargin - 1;
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
53
13952
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
54 while (1)
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
55 for i = 1:nopt
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
56 printf (" [%2d] ", i);
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
57 disp (varargin{i});
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
58 endfor
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
59 printf ("\n");
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
60 s = input ("pick a number, any number: ", "s");
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
61 num = sscanf (s, "%d");
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
62 if (! isscalar (num) || num < 1 || num > nopt)
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
63 printf ("\nerror: input invalid or out of range\n\n");
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
64 else
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
65 break;
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
66 endif
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
67 endwhile
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
68
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
69 endfunction
13952
acaf33ccc04f Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
70