Mercurial > hg > octave-lyh
changeset 16198:2c5c538be353
clean up input.cc and eliminate ff_instream global variable
* input.h, input.cc (gnu_readline): Now static. Handle only
interactive input. Delete optional force_readline argument. Delete
single argument version. Change all callers.
(interactive_input): Delete force_readline argument. Delete single
argument version. Change all callers.
(octave_base_reader::octave_gets): Handle only interactive input.
(get_input_from_file): Delete.
(ff_instream): Delete global variable.
* oct-parse.in.yy (parse_fcn_file): Open file directly here without
using get_input_from_file. Don't protect ff_instream.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 05 Mar 2013 17:43:00 -0500 |
parents | 576daea679fe |
children | 810a71122c25 |
files | libinterp/interpfcn/input.cc libinterp/interpfcn/input.h libinterp/parse-tree/oct-parse.in.yy |
diffstat | 3 files changed, 50 insertions(+), 125 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/interpfcn/input.cc +++ b/libinterp/interpfcn/input.cc @@ -116,9 +116,6 @@ // TRUE means we're parsing a script file. bool reading_script_file = false; -// If we are reading from an M-file, this is it. -FILE *ff_instream = 0; - // TRUE means this is an interactive shell. bool interactive = false; @@ -180,53 +177,25 @@ } } -std::string -gnu_readline (const std::string& s, bool& eof, bool force_readline) +static std::string +gnu_readline (const std::string& s, bool& eof) { octave_quit (); eof = false; - std::string retval; - - if (line_editing || force_readline) - { - retval = command_editor::readline (s, eof); + assert (line_editing); - if (! eof && retval.empty ()) - retval = "\n"; - } - else - { - if (! s.empty () && (interactive || forced_interactive)) - { - FILE *stream = command_editor::get_output_stream (); + std::string retval = command_editor::readline (s, eof); - gnulib::fputs (s.c_str (), stream); - gnulib::fflush (stream); - } - - FILE *curr_stream = command_editor::get_input_stream (); - - if (reading_fcn_file || reading_script_file || reading_classdef_file) - curr_stream = ff_instream; - - retval = octave_fgets (curr_stream, eof); - } + if (! eof && retval.empty ()) + retval = "\n"; return retval; } -extern std::string -gnu_readline (const std::string& s, bool force_readline) -{ - bool eof = false; - - return gnu_readline (s, eof, force_readline); -} - static inline std::string -interactive_input (const std::string& s, bool& eof, bool force_readline) +interactive_input (const std::string& s, bool& eof) { Vlast_prompt_time.stamp (); @@ -245,15 +214,7 @@ return "\n"; } - return gnu_readline (s, eof, force_readline); -} - -static inline std::string -interactive_input (const std::string& s, bool force_readline = false) -{ - bool eof = false; - - return interactive_input (s, eof, force_readline); + return gnu_readline (s, eof); } std::string @@ -267,95 +228,59 @@ bool history_skip_auto_repeated_debugging_command = false; - if ((interactive || forced_interactive) - && (! (reading_fcn_file - || reading_classdef_file - || reading_script_file - || input_from_startup_file - || input_from_command_line_file))) - { - std::string ps = (promptflag > 0) ? VPS1 : VPS2; + std::string ps = (promptflag > 0) ? VPS1 : VPS2; + + std::string prompt = command_editor::decode_prompt_string (ps); + + pipe_handler_error_count = 0; - std::string prompt = command_editor::decode_prompt_string (ps); - - pipe_handler_error_count = 0; + flush_octave_stdout (); - flush_octave_stdout (); + octave_pager_stream::reset (); + octave_diary_stream::reset (); - octave_pager_stream::reset (); - octave_diary_stream::reset (); + octave_diary << prompt; - octave_diary << prompt; + retval = interactive_input (prompt, eof); - retval = interactive_input (prompt, eof, false); - - // There is no need to update the load_path cache if there is no - // user input. - if (! retval.empty () - && retval.find_first_not_of (" \t\n\r") != std::string::npos) - { - load_path::update (); + // There is no need to update the load_path cache if there is no + // user input. + if (! retval.empty () + && retval.find_first_not_of (" \t\n\r") != std::string::npos) + { + load_path::update (); - if (Vdebugging) - last_debugging_command = retval; - else - last_debugging_command = std::string (); - } - else if (Vdebugging) - { - retval = last_debugging_command; - history_skip_auto_repeated_debugging_command = true; - } + if (Vdebugging) + last_debugging_command = retval; + else + last_debugging_command = std::string (); } - else - retval = gnu_readline ("", eof, false); + else if (Vdebugging) + { + retval = last_debugging_command; + history_skip_auto_repeated_debugging_command = true; + } current_input_line = retval; if (! current_input_line.empty ()) { - if (! (input_from_startup_file || input_from_command_line_file - || history_skip_auto_repeated_debugging_command)) + if (! history_skip_auto_repeated_debugging_command) command_history::add (current_input_line); - if (! (reading_fcn_file || reading_script_file || reading_classdef_file)) - { - octave_diary << current_input_line; + octave_diary << current_input_line; - if (current_input_line[current_input_line.length () - 1] != '\n') - octave_diary << "\n"; - } + if (current_input_line[current_input_line.length () - 1] != '\n') + octave_diary << "\n"; do_input_echo (current_input_line); } - else if (! (reading_fcn_file || reading_script_file || reading_classdef_file)) + else octave_diary << "\n"; return retval; } -// Fix things up so that input can come from file 'name', printing a -// warning if the file doesn't exist. - -FILE * -get_input_from_file (const std::string& name, int warn) -{ - FILE *instream = 0; - - if (name.length () > 0) - instream = gnulib::fopen (name.c_str (), "rb"); - - if (! instream && warn) - warning ("%s: no such file or directory", name.c_str ()); - - if (reading_fcn_file || reading_script_file || reading_classdef_file) - ff_instream = instream; - else - command_editor::set_input_stream (instream); - - return instream; -} - // Fix things up so that input can come from the standard input. This // may need to become much more complicated, which is why it's in a // separate function. @@ -748,7 +673,9 @@ octave_diary << prompt; - std::string input_buf = interactive_input (prompt.c_str (), true); + bool eof = false; + + std::string input_buf = interactive_input (prompt.c_str (), eof); if (! (error_state || input_buf.empty ())) { @@ -845,7 +772,9 @@ while (1) { - std::string input_buf = interactive_input (prompt_string, true); + bool eof = false; + + std::string input_buf = interactive_input (prompt_string, eof); if (input_buf == "yes") return true;
--- a/libinterp/interpfcn/input.h +++ b/libinterp/interpfcn/input.h @@ -35,9 +35,6 @@ class octave_value; -extern OCTINTERP_API FILE *get_input_from_file (const std::string& name, - int warn = 1); - extern OCTINTERP_API FILE *get_input_from_stdin (void); // TRUE means that input is coming from a file that was named on @@ -62,8 +59,8 @@ // TRUE means we're parsing a classdef file. extern bool reading_classdef_file; -// If we are reading from an M-file, this is it. -extern FILE *ff_instream; +// Fix things up so that input can come from file 'name', printing a +// warning if the file doesn't exist. // TRUE means this is an interactive shell. extern bool interactive; @@ -87,8 +84,6 @@ // TRUE if we are in debugging mode. extern OCTINTERP_API bool Vdebugging; -extern std::string gnu_readline (const std::string& s, bool force_readline = false); - extern void initialize_command_input (void); extern bool octave_yes_or_no (const std::string& prompt);
--- a/libinterp/parse-tree/oct-parse.in.yy +++ b/libinterp/parse-tree/oct-parse.in.yy @@ -3375,8 +3375,6 @@ frame.add_fcn (command_editor::set_input_stream, in_stream); - frame.protect_var (ff_instream); - frame.protect_var (reading_fcn_file); frame.protect_var (line_editing); @@ -3388,7 +3386,10 @@ command_history::ignore_entries (); - FILE *ffile = get_input_from_file (ff, 0); + FILE *ffile = 0; + + if (! ff.empty ()) + ffile = gnulib::fopen (ff.c_str (), "rb"); frame.add_fcn (safe_fclose, ffile);