Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/menu.m @ 14626:f947d2922feb stable rc-3-6-2-0
3.6.2-rc0 release candidate
* configure.ac (AC_INIT): Version is now 3.6.2-rc0.
(OCTAVE_RELEASE_DATE): Now 2012-05-11.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 11 May 2012 13:46:18 -0400 |
parents | 72c96de7a403 |
children | ff4143d9fc05 |
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 | 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. | |
2313 | 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/>. | |
245 | 18 |
3381 | 19 ## -*- texinfo -*- |
3372 | 20 ## @deftypefn {Function File} {} menu (@var{title}, @var{opt1}, @dots{}) |
21 ## Print a title string followed by a series of options. Each option will | |
22 ## be printed along with a number. The return value is the number of the | |
23 ## option selected by the user. This function is useful for interactive | |
24 ## programs. There is no limit to the number of options that may be passed | |
25 ## in, but it may be confusing to present more than will fit easily on one | |
26 ## screen. | |
5642 | 27 ## @seealso{disp, printf, input} |
3372 | 28 ## @end deftypefn |
4 | 29 |
2314 | 30 ## Author: jwe |
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 | 33 |
211 | 34 if (nargin < 2) |
6046 | 35 print_usage (); |
4 | 36 endif |
37 | |
2303 | 38 ## Force pending output to appear before the menu. |
4 | 39 |
40 fflush (stdout); | |
41 | |
2303 | 42 ## Don't send the menu through the pager since doing that can cause |
43 ## major confusion. | |
4 | 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 | 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 | 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 | 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 | 68 |
69 endfunction | |
13952
acaf33ccc04f
Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
70 |