comparison src/input.cc @ 5640:426719471ac6

[project @ 2006-03-04 06:02:14 by jwe]
author jwe
date Sat, 04 Mar 2006 06:02:14 +0000
parents 7099eb9841b4
children a527e0f77aa5
comparison
equal deleted inserted replaced
5639:acbcb9f164ca 5640:426719471ac6
735 print_usage ("input"); 735 print_usage ("input");
736 736
737 return retval; 737 return retval;
738 } 738 }
739 739
740 bool
741 octave_yes_or_no (const std::string& prompt)
742 {
743 std::string prompt_string = prompt + "(yes or no) ";
744
745 while (1)
746 {
747 std::string input_buf = gnu_readline (prompt_string);
748
749 if (input_buf == "yes")
750 return true;
751 else if (input_buf == "no")
752 return false;
753 else
754 message (0, "Please answer yes or no.");
755 }
756 }
757
758 DEFUN (yes_or_no, args, ,
759 "-*- texinfo -*-\n\
760 @deftypefn {Built-in Function} {} yes_or_no (@var{prompt})\n\
761 Ask the user a yes-or-no question. Return 1 if the answer is yes.\n\
762 Takes one argument, which is the string to display to ask the\n\
763 question. It should end in a space; @samp{yes-or-no-p} adds\n\
764 @samp{(yes or no) } to it. The user must confirm the answer with\n\
765 RET and can edit it until it has been confirmed.\n\
766 @end deftypefn")
767 {
768 octave_value retval;
769
770 int nargin = args.length ();
771
772 if (nargin == 0 || nargin == 1)
773 {
774 std::string prompt;
775
776 if (nargin == 1)
777 {
778 prompt = args(0).string_value ();
779
780 if (error_state)
781 {
782 error ("yes_or_no: expecting argument to be character string");
783 return retval;
784 }
785 }
786
787 retval = octave_yes_or_no (prompt);
788 }
789 else
790 print_usage ("yes_or_no");
791
792 return retval;
793 }
794
740 static void 795 static void
741 restore_command_history (void *) 796 restore_command_history (void *)
742 { 797 {
743 command_history::ignore_entries (! Vsaving_history); 798 command_history::ignore_entries (! Vsaving_history);
744 } 799 }