375
|
1 # Copyright (C) 1993, 1994 John W. Eaton |
245
|
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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
375
|
19 function num = menu (t, ...) |
4
|
20 |
211
|
21 # usage: menu (title, opt1, ...) |
4
|
22 # |
|
23 # See also: disp, printf, input |
|
24 |
211
|
25 if (nargin < 2) |
904
|
26 usage ("menu (title, opt1, ...)"); |
4
|
27 endif |
|
28 |
|
29 # Force pending output to appear before the menu. |
|
30 |
|
31 fflush (stdout); |
|
32 |
|
33 # Don't send the menu through the pager since doing that can cause |
|
34 # major confusion. |
|
35 |
|
36 save_page_screen_output = page_screen_output; |
917
|
37 |
|
38 unwind_protect |
|
39 |
|
40 page_screen_output = "false"; |
4
|
41 |
917
|
42 if (! isempty (t)) |
|
43 disp (t); |
|
44 printf ("\n"); |
|
45 endif |
4
|
46 |
917
|
47 nopt = nargin - 1; |
4
|
48 |
917
|
49 while (1) |
|
50 va_start (); |
|
51 for i = 1:nopt |
|
52 printf (" [%2d] ", i); |
|
53 disp (va_arg ()); |
|
54 endfor |
375
|
55 printf ("\n"); |
917
|
56 s = ""; |
|
57 s = input ("pick a number, any number: ", "s"); |
|
58 if (strcmp (s, "")) |
|
59 printf ("\n"); |
|
60 continue; |
|
61 endif |
|
62 eval (sprintf ("num = %s;", s)); |
|
63 if (! is_scalar (num) || num < 1 || num > nopt) |
|
64 printf ("\nerror: input invalid or out of range\n\n"); |
|
65 else |
|
66 break; |
|
67 endif |
|
68 endwhile |
4
|
69 |
917
|
70 unwind_protect_cleanup |
|
71 |
|
72 page_screen_output = save_page_screen_output; |
|
73 |
|
74 end_unwind_protect |
4
|
75 |
|
76 endfunction |