Mercurial > octave
comparison src/input.cc @ 9999:653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 18 Dec 2009 03:05:06 -0500 |
parents | 3cee58bf4acf |
children | 2cd940306a06 |
comparison
equal
deleted
inserted
replaced
9998:46493feaab7f | 9999:653716f3d976 |
---|---|
53 #include "dirfns.h" | 53 #include "dirfns.h" |
54 #include "error.h" | 54 #include "error.h" |
55 #include "gripes.h" | 55 #include "gripes.h" |
56 #include "help.h" | 56 #include "help.h" |
57 #include "input.h" | 57 #include "input.h" |
58 #include "lex.h" | |
58 #include "load-path.h" | 59 #include "load-path.h" |
59 #include "oct-map.h" | 60 #include "oct-map.h" |
60 #include "oct-hist.h" | 61 #include "oct-hist.h" |
61 #include "toplev.h" | 62 #include "toplev.h" |
62 #include "oct-obj.h" | 63 #include "oct-obj.h" |
110 | 111 |
111 // TRUE means that input is coming from a file that was named on | 112 // TRUE means that input is coming from a file that was named on |
112 // the command line. | 113 // the command line. |
113 bool input_from_command_line_file = false; | 114 bool input_from_command_line_file = false; |
114 | 115 |
116 // TRUE means that stdin is a terminal, not a pipe or redirected file. | |
117 bool stdin_is_tty = false; | |
118 | |
115 // TRUE means we're parsing a function file. | 119 // TRUE means we're parsing a function file. |
116 bool reading_fcn_file = false; | 120 bool reading_fcn_file = false; |
117 | 121 |
118 // TRUE means we're parsing a classdef file. | 122 // TRUE means we're parsing a classdef file. |
119 bool reading_classdef_file = false; | 123 bool reading_classdef_file = false; |
262 | 266 |
263 if ((interactive || forced_interactive) | 267 if ((interactive || forced_interactive) |
264 && (! (reading_fcn_file | 268 && (! (reading_fcn_file |
265 || reading_classdef_file | 269 || reading_classdef_file |
266 || reading_script_file | 270 || reading_script_file |
271 || get_input_from_eval_string | |
267 || input_from_startup_file | 272 || input_from_startup_file |
268 || input_from_command_line_file))) | 273 || input_from_command_line_file))) |
269 { | 274 { |
270 std::string ps = (promptflag > 0) ? VPS1 : VPS2; | 275 std::string ps = (promptflag > 0) ? VPS1 : VPS2; |
271 | 276 |
684 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); | 689 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
685 | 690 |
686 unwind_protect::protect_var (VPS1); | 691 unwind_protect::protect_var (VPS1); |
687 VPS1 = prompt; | 692 VPS1 = prompt; |
688 | 693 |
689 while (Vdebugging) | 694 if (stdin_is_tty) |
690 { | 695 { |
691 reset_error_handler (); | 696 if (! (interactive || forced_interactive) |
692 | 697 || (reading_fcn_file |
693 reset_parser (); | 698 || reading_classdef_file |
694 | 699 || reading_script_file |
695 // Save current value of global_command. | 700 || get_input_from_eval_string |
696 unwind_protect::protect_var (global_command); | 701 || input_from_startup_file |
697 | 702 || input_from_command_line_file)) |
698 // Do this with an unwind-protect cleanup function so that the | 703 { |
699 // forced variables will be unmarked in the event of an interrupt. | 704 unwind_protect::protect_var (forced_interactive); |
700 symbol_table::scope_id scope = symbol_table::top_scope (); | 705 forced_interactive = true; |
701 unwind_protect::add_fcn (symbol_table::unmark_forced_variables, scope); | 706 |
702 | 707 unwind_protect::protect_var (reading_fcn_file); |
703 // This is the same as yyparse in parse.y. | 708 reading_fcn_file = false; |
704 int retval = octave_parse (); | 709 |
705 | 710 unwind_protect::protect_var (reading_classdef_file); |
706 if (retval == 0 && global_command) | 711 reading_classdef_file = false; |
707 { | 712 |
708 global_command->accept (*current_evaluator); | 713 unwind_protect::protect_var (reading_script_file); |
709 | 714 reading_script_file = false; |
710 // FIXME -- To avoid a memory leak, global_command should be | 715 |
711 // deleted, I think. But doing that here causes trouble if | 716 unwind_protect::protect_var (input_from_startup_file); |
712 // an error occurs while executing a debugging command | 717 input_from_startup_file = false; |
713 // (dbstep, for example). It's not clear to me why that | 718 |
714 // happens. | 719 unwind_protect::protect_var (input_from_command_line_file); |
715 // | 720 input_from_command_line_file = false; |
716 // delete global_command; | 721 |
717 // | 722 unwind_protect::protect_var (get_input_from_eval_string); |
718 // global_command = 0; | 723 get_input_from_eval_string = false; |
719 | 724 |
720 if (octave_completion_matches_called) | 725 YY_BUFFER_STATE old_buf = current_buffer (); |
721 octave_completion_matches_called = false; | 726 YY_BUFFER_STATE new_buf = create_buffer (get_input_from_stdin ()); |
722 } | 727 |
723 | 728 unwind_protect::add_fcn (switch_to_buffer, old_buf); |
724 // Unmark forced variables. | 729 unwind_protect::add_fcn (delete_buffer, new_buf); |
725 unwind_protect::run (); | 730 |
726 | 731 switch_to_buffer (new_buf); |
727 // Restore previous value of global_command. | 732 } |
728 unwind_protect::run (); | 733 |
729 | 734 while (Vdebugging) |
730 OCTAVE_QUIT; | 735 { |
731 } | 736 reset_error_handler (); |
737 | |
738 reset_parser (); | |
739 | |
740 // Save current value of global_command. | |
741 unwind_protect::protect_var (global_command); | |
742 | |
743 // Do this with an unwind-protect cleanup function so that the | |
744 // forced variables will be unmarked in the event of an interrupt. | |
745 symbol_table::scope_id scope = symbol_table::top_scope (); | |
746 unwind_protect::add_fcn (symbol_table::unmark_forced_variables, scope); | |
747 | |
748 // This is the same as yyparse in parse.y. | |
749 int retval = octave_parse (); | |
750 | |
751 if (retval == 0 && global_command) | |
752 { | |
753 global_command->accept (*current_evaluator); | |
754 | |
755 // FIXME -- To avoid a memory leak, global_command should be | |
756 // deleted, I think. But doing that here causes trouble if | |
757 // an error occurs while executing a debugging command | |
758 // (dbstep, for example). It's not clear to me why that | |
759 // happens. | |
760 // | |
761 // delete global_command; | |
762 // | |
763 // global_command = 0; | |
764 | |
765 if (octave_completion_matches_called) | |
766 octave_completion_matches_called = false; | |
767 } | |
768 | |
769 // Unmark forced variables. | |
770 unwind_protect::run (); | |
771 | |
772 // Restore previous value of global_command. | |
773 unwind_protect::run (); | |
774 | |
775 OCTAVE_QUIT; | |
776 } | |
777 } | |
778 else | |
779 warning ("invalid attempt to debug script read from stdin"); | |
732 | 780 |
733 unwind_protect::run_frame (uwp_frame); | 781 unwind_protect::run_frame (uwp_frame); |
734 } | 782 } |
735 | 783 |
736 // If the user simply hits return, this will produce an empty matrix. | 784 // If the user simply hits return, this will produce an empty matrix. |