2303
|
1 ### Copyright (C) 1996 John W. Eaton |
|
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 |
|
7 ### the Free Software Foundation; either version 2, or (at your option) |
|
8 ### any later version. |
|
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 |
|
16 ### along with Octave; see the file COPYING. If not, write to the Free |
|
17 ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ### 02111-1307, USA. |
245
|
19 |
375
|
20 function num = menu (t, ...) |
4
|
21 |
2303
|
22 ## usage: menu (title, opt1, ...) |
|
23 ## |
|
24 ## See also: disp, printf, input |
4
|
25 |
211
|
26 if (nargin < 2) |
904
|
27 usage ("menu (title, opt1, ...)"); |
4
|
28 endif |
|
29 |
2303
|
30 ## Force pending output to appear before the menu. |
4
|
31 |
|
32 fflush (stdout); |
|
33 |
2303
|
34 ## Don't send the menu through the pager since doing that can cause |
|
35 ## major confusion. |
4
|
36 |
|
37 save_page_screen_output = page_screen_output; |
917
|
38 |
|
39 unwind_protect |
|
40 |
|
41 page_screen_output = "false"; |
4
|
42 |
917
|
43 if (! isempty (t)) |
|
44 disp (t); |
|
45 printf ("\n"); |
|
46 endif |
4
|
47 |
917
|
48 nopt = nargin - 1; |
4
|
49 |
917
|
50 while (1) |
|
51 va_start (); |
|
52 for i = 1:nopt |
|
53 printf (" [%2d] ", i); |
|
54 disp (va_arg ()); |
|
55 endfor |
375
|
56 printf ("\n"); |
917
|
57 s = ""; |
|
58 s = input ("pick a number, any number: ", "s"); |
|
59 if (strcmp (s, "")) |
|
60 printf ("\n"); |
|
61 continue; |
|
62 endif |
|
63 eval (sprintf ("num = %s;", s)); |
|
64 if (! is_scalar (num) || num < 1 || num > nopt) |
|
65 printf ("\nerror: input invalid or out of range\n\n"); |
|
66 else |
|
67 break; |
|
68 endif |
|
69 endwhile |
4
|
70 |
917
|
71 unwind_protect_cleanup |
|
72 |
|
73 page_screen_output = save_page_screen_output; |
|
74 |
|
75 end_unwind_protect |
4
|
76 |
|
77 endfunction |