home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / miscellaneous / menu.m < prev    next >
Text File  |  1998-11-10  |  2KB  |  75 lines

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