2847
|
1 ## Copyright (C) 1996, 1997 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 |
|
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 |
2311
|
20 ## usage: menu (title, opt1, ...) |
|
21 ## |
|
22 ## See also: disp, printf, input |
4
|
23 |
2314
|
24 ## Author: jwe |
|
25 |
2311
|
26 function num = menu (t, ...) |
4
|
27 |
211
|
28 if (nargin < 2) |
904
|
29 usage ("menu (title, opt1, ...)"); |
4
|
30 endif |
|
31 |
2303
|
32 ## Force pending output to appear before the menu. |
4
|
33 |
|
34 fflush (stdout); |
|
35 |
2303
|
36 ## Don't send the menu through the pager since doing that can cause |
|
37 ## major confusion. |
4
|
38 |
|
39 save_page_screen_output = page_screen_output; |
917
|
40 |
|
41 unwind_protect |
|
42 |
2360
|
43 page_screen_output = 0; |
4
|
44 |
917
|
45 if (! isempty (t)) |
|
46 disp (t); |
|
47 printf ("\n"); |
|
48 endif |
4
|
49 |
917
|
50 nopt = nargin - 1; |
4
|
51 |
917
|
52 while (1) |
|
53 va_start (); |
|
54 for i = 1:nopt |
|
55 printf (" [%2d] ", i); |
|
56 disp (va_arg ()); |
|
57 endfor |
375
|
58 printf ("\n"); |
917
|
59 s = ""; |
|
60 s = input ("pick a number, any number: ", "s"); |
|
61 if (strcmp (s, "")) |
|
62 printf ("\n"); |
|
63 continue; |
|
64 endif |
|
65 eval (sprintf ("num = %s;", s)); |
|
66 if (! is_scalar (num) || num < 1 || num > nopt) |
|
67 printf ("\nerror: input invalid or out of range\n\n"); |
|
68 else |
|
69 break; |
|
70 endif |
|
71 endwhile |
4
|
72 |
917
|
73 unwind_protect_cleanup |
|
74 |
|
75 page_screen_output = save_page_screen_output; |
|
76 |
|
77 end_unwind_protect |
4
|
78 |
|
79 endfunction |