Mercurial > hg > octave-lyh
comparison src/input.cc @ 7752:40c428ea3408
initial implementation of dbup and dbdown
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 04 May 2008 03:42:19 -0400 |
parents | 2dee19385d32 |
children | 8e14a01ffe9f |
comparison
equal
deleted
inserted
replaced
7751:7c020c067a60 | 7752:40c428ea3408 |
---|---|
65 #include "pt.h" | 65 #include "pt.h" |
66 #include "pt-const.h" | 66 #include "pt-const.h" |
67 #include "pt-stmt.h" | 67 #include "pt-stmt.h" |
68 #include "sighandlers.h" | 68 #include "sighandlers.h" |
69 #include "sysdep.h" | 69 #include "sysdep.h" |
70 #include "toplev.h" | |
70 #include "unwind-prot.h" | 71 #include "unwind-prot.h" |
71 #include "utils.h" | 72 #include "utils.h" |
72 #include "variables.h" | 73 #include "variables.h" |
73 | 74 |
74 // Primary prompt string. | 75 // Primary prompt string. |
140 bool octave_completion_matches_called = false; | 141 bool octave_completion_matches_called = false; |
141 | 142 |
142 // TRUE if the plotting system has requested a call to drawnow at | 143 // TRUE if the plotting system has requested a call to drawnow at |
143 // the next user prompt. | 144 // the next user prompt. |
144 bool Vdrawnow_requested = false; | 145 bool Vdrawnow_requested = false; |
146 | |
147 // TRUE if we are in debugging mode. | |
148 bool Vdebugging = false; | |
145 | 149 |
146 // TRUE if we are running in the Emacs GUD mode. | 150 // TRUE if we are running in the Emacs GUD mode. |
147 static bool Vgud_mode = false; | 151 static bool Vgud_mode = false; |
148 | 152 |
149 static void | 153 static void |
580 } | 584 } |
581 | 585 |
582 // If the user simply hits return, this will produce an empty matrix. | 586 // If the user simply hits return, this will produce an empty matrix. |
583 | 587 |
584 static octave_value_list | 588 static octave_value_list |
585 get_user_input (const octave_value_list& args, bool debug, int nargout) | 589 get_user_input (const octave_value_list& args, int nargout) |
586 { | 590 { |
587 octave_value_list retval; | 591 octave_value_list retval; |
588 | 592 |
589 int nargin = args.length (); | 593 int nargin = args.length (); |
590 | 594 |
594 read_as_string++; | 598 read_as_string++; |
595 | 599 |
596 std::string nm; | 600 std::string nm; |
597 int line = -1; | 601 int line = -1; |
598 | 602 |
599 if (debug) | 603 if (Vdebugging) |
600 { | 604 { |
601 octave_user_code *caller = octave_call_stack::caller_user_code (); | 605 octave_user_code *caller = octave_call_stack::caller_user_code (); |
602 | 606 |
603 if (caller) | 607 if (caller) |
604 { | 608 { |
668 if (input_buf[len - 1] != '\n') | 672 if (input_buf[len - 1] != '\n') |
669 octave_diary << "\n"; | 673 octave_diary << "\n"; |
670 | 674 |
671 if (len < 1) | 675 if (len < 1) |
672 { | 676 { |
673 if (debug) | 677 if (Vdebugging) |
674 goto again; | 678 goto again; |
675 else | 679 else |
676 return read_as_string ? octave_value ("") : octave_value (Matrix ()); | 680 return read_as_string ? octave_value ("") : octave_value (Matrix ()); |
677 } | 681 } |
678 | 682 |
679 if (debug) | 683 if (Vdebugging) |
680 { | 684 { |
681 if (match_sans_spaces_semi ("exit", input_buf) | 685 if (match_sans_spaces_semi ("exit", input_buf) |
682 || match_sans_spaces_semi ("quit", input_buf) | 686 || match_sans_spaces_semi ("quit", input_buf) |
683 || match_sans_spaces_semi ("return", input_buf) | 687 || match_sans_spaces_semi ("return", input_buf) |
684 || match_sans_spaces_semi ("dbcont", input_buf)) | 688 || match_sans_spaces_semi ("dbcont", input_buf)) |
717 } | 721 } |
718 else | 722 else |
719 { | 723 { |
720 int parse_status = 0; | 724 int parse_status = 0; |
721 | 725 |
722 bool silent = ! debug; | 726 bool silent = ! Vdebugging; |
723 | 727 |
724 retval = eval_string (input_buf, silent, parse_status, nargout); | 728 retval = eval_string (input_buf, silent, parse_status, nargout); |
725 | 729 |
726 if (! debug && retval.length () == 0) | 730 if (! Vdebugging && retval.length () == 0) |
727 retval(0) = Matrix (); | 731 retval(0) = Matrix (); |
728 } | 732 } |
729 } | 733 } |
730 else | 734 else |
731 error ("input: reading user-input failed!"); | 735 error ("input: reading user-input failed!"); |
732 | 736 |
733 if (debug) | 737 if (Vdebugging) |
734 { | 738 { |
735 // Clear error_state so that if errors were encountered while | 739 // Clear error_state so that if errors were encountered while |
736 // evaluating user input, extra error messages will not be | 740 // evaluating user input, extra error messages will not be |
737 // printed after we return. | 741 // printed after we return. |
738 | 742 |
785 octave_value_list retval; | 789 octave_value_list retval; |
786 | 790 |
787 int nargin = args.length (); | 791 int nargin = args.length (); |
788 | 792 |
789 if (nargin == 1 || nargin == 2) | 793 if (nargin == 1 || nargin == 2) |
790 retval = get_user_input (args, false, nargout); | 794 retval = get_user_input (args, nargout); |
791 else | 795 else |
792 print_usage (); | 796 print_usage (); |
793 | 797 |
794 return retval; | 798 return retval; |
795 } | 799 } |
853 restore_command_history (void *) | 857 restore_command_history (void *) |
854 { | 858 { |
855 command_history::ignore_entries (! Vsaving_history); | 859 command_history::ignore_entries (! Vsaving_history); |
856 } | 860 } |
857 | 861 |
862 static size_t saved_frame = 0; | |
863 | |
864 static void | |
865 restore_frame (void *) | |
866 { | |
867 octave_call_stack::goto_frame (saved_frame); | |
868 } | |
869 | |
858 octave_value | 870 octave_value |
859 do_keyboard (const octave_value_list& args) | 871 do_keyboard (const octave_value_list& args) |
860 { | 872 { |
861 octave_value retval; | 873 octave_value retval; |
862 | 874 |
872 command_history::ignore_entries (false); | 884 command_history::ignore_entries (false); |
873 | 885 |
874 unwind_protect::add (restore_command_history, 0); | 886 unwind_protect::add (restore_command_history, 0); |
875 | 887 |
876 unwind_protect_bool (Vsaving_history); | 888 unwind_protect_bool (Vsaving_history); |
889 unwind_protect_bool (Vdebugging); | |
890 | |
891 saved_frame = octave_call_stack::current_frame (); | |
892 unwind_protect::add (restore_frame); | |
893 unwind_protect_size_t (saved_frame); | |
877 | 894 |
878 Vsaving_history = true; | 895 Vsaving_history = true; |
879 | 896 Vdebugging = true; |
880 octave_value_list tmp = get_user_input (args, true, 0); | 897 |
898 octave_value_list tmp = get_user_input (args, 0); | |
881 | 899 |
882 retval = tmp(0); | 900 retval = tmp(0); |
883 | 901 |
884 unwind_protect::run_frame ("do_keyboard"); | 902 unwind_protect::run_frame ("do_keyboard"); |
885 | 903 |
904 octave_value_list retval; | 922 octave_value_list retval; |
905 | 923 |
906 int nargin = args.length (); | 924 int nargin = args.length (); |
907 | 925 |
908 if (nargin == 0 || nargin == 1) | 926 if (nargin == 0 || nargin == 1) |
909 do_keyboard (args); | 927 { |
928 saved_frame = octave_call_stack::current_frame (); | |
929 unwind_protect::add (restore_frame); | |
930 unwind_protect_size_t (saved_frame); | |
931 | |
932 // Skip the frame assigned to the keyboard function. | |
933 octave_call_stack::goto_frame (1); | |
934 | |
935 do_keyboard (args); | |
936 | |
937 unwind_protect::run (); | |
938 } | |
910 else | 939 else |
911 print_usage (); | 940 print_usage (); |
912 | 941 |
913 return retval; | 942 return retval; |
914 } | 943 } |