changeset 19883:1c9ed5b4c73d

input.h: change meaning of interactive and forced_interactive global variables. * libinterp/corefcn/input.h, libinterp/corefcn/input.cc: the interactive var is set at the start of Octave session if the session would be interactive. The forced_interactive is set only by the "--interactive" option. This means that in a forced interactive session, interactive is false, and that in a not forced interactive session with the "--interactive" option, forced_interactive is true. This is a bit counter-intuitive. Also when it matters if a session is interactive or not, it should not matter if it was forced not, only whether is interactive. Change this logic. Interactive means we are running a interactive session, forced interactive means the interactive session needed to be forced. * libinterp/octave.cc: during Octave initialization, as soon as we identify if this would be an interactive session, check with forced_interactive to adjust the value of this variables. * libinterp/corefcn/error.cc, libinterp/corefcn/oct-stream.cc, libinterp/corefcn/pager.cc, libinterp/corefcn/dirfns.cc, libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sysdep.cc, libinterp/corefcn/toplev.cc, libinterp/parse-tree/lex.ll, libinterp/parse-tree/oct-parse.in.yy: replace all checks for "(interactive || forced_interactive)" with simply interactive. On the few cases where forced_interactive was not checked, it was replaced with "(interactive && ! forced_interactive)", just like "! interactive" got replaced by "(! interactive || forced_interactive)", only to conserve the logic. I am uncertain if such checks are not actually bugs though.
author Carnë Draug <carandraug@octave.org>
date Tue, 24 Feb 2015 17:09:42 +0000
parents 9b7ca334a104
children f81a1da191e4
files libinterp/corefcn/dirfns.cc libinterp/corefcn/error.cc libinterp/corefcn/input.cc libinterp/corefcn/input.h libinterp/corefcn/oct-stream.cc libinterp/corefcn/pager.cc libinterp/corefcn/sighandlers.cc libinterp/corefcn/sysdep.cc libinterp/corefcn/toplev.cc libinterp/octave.cc libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.in.yy
diffstat 12 files changed, 43 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/dirfns.cc	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/corefcn/dirfns.cc	Tue Feb 24 17:09:42 2015 +0000
@@ -346,7 +346,8 @@
                 {
                   bool doit = true;
 
-                  if (interactive && Vconfirm_recursive_rmdir)
+                  if (interactive && ! forced_interactive
+                      && Vconfirm_recursive_rmdir)
                     {
                       std::string prompt
                         = "remove entire contents of " + fulldir + "? ";
--- a/libinterp/corefcn/error.cc	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/corefcn/error.cc	Tue Feb 24 17:09:42 2015 +0000
@@ -451,7 +451,7 @@
       && ! discard_error_messages)
     pr_where ("error");
 
-  if ((interactive || forced_interactive)
+  if (interactive
       && Vdebug_on_error && init_state == 0
       && octave_call_stack::caller_user_code ())
     {
--- a/libinterp/corefcn/input.cc	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/corefcn/input.cc	Tue Feb 24 17:09:42 2015 +0000
@@ -99,10 +99,11 @@
 // Character to append after successful command-line completion attempts.
 static char Vcompletion_append_char = ' ';
 
-// TRUE means this is an interactive shell.
+// TRUE means this is an interactive shell (either forced or not)
 bool interactive = false;
 
 // TRUE means the user forced this shell to be interactive (-i).
+// FALSE means the shell would be interactive, independent of user settings.
 bool forced_interactive = false;
 
 // TRUE after a call to completion_matches.
@@ -196,7 +197,7 @@
 {
   Vlast_prompt_time.stamp ();
 
-  if (Vdrawnow_requested && (interactive || forced_interactive))
+  if (Vdrawnow_requested && interactive)
     {
       feval ("drawnow");
 
@@ -226,7 +227,7 @@
   // Process pre input event hook function prior to flushing output and
   // printing the prompt.
 
-  if (interactive || forced_interactive)
+  if (interactive)
     {
       if (! Vdebugging)
         octave_link::exit_debugger_event ();
@@ -292,7 +293,7 @@
   // Process post input event hook function after the internal history
   // list has been updated.
 
-  if (interactive || forced_interactive)
+  if (interactive)
     octave_link::post_input_event ();
 
   return retval;
@@ -587,8 +588,10 @@
   frame.protect_var (VPS1);
   VPS1 = prompt;
 
-  if (! (interactive || forced_interactive))
+  if (! interactive)
     {
+      frame.protect_var (interactive);
+      interactive = true;
       frame.protect_var (forced_interactive);
       forced_interactive = true;
     }
--- a/libinterp/corefcn/input.h	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/corefcn/input.h	Tue Feb 24 17:09:42 2015 +0000
@@ -38,10 +38,11 @@
 
 extern OCTINTERP_API FILE *get_input_from_stdin (void);
 
-// TRUE means this is an interactive shell.
+// TRUE means this is an interactive shell (forced or not)
 extern bool interactive;
 
 // TRUE means the user forced this shell to be interactive (-i).
+// FALSE means the shell would be interactive, independent of user settings.
 extern bool forced_interactive;
 
 // TRUE after a call to completion_matches.
--- a/libinterp/corefcn/oct-stream.cc	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/corefcn/oct-stream.cc	Tue Feb 24 17:09:42 2015 +0000
@@ -931,7 +931,7 @@
 {
   std::string retval;
 
-  if ((interactive || forced_interactive) && file_number () == 0)
+  if (interactive && file_number () == 0)
     {
       ::error ("%s: unable to read from stdin while running interactively",
                who.c_str ());
@@ -1047,7 +1047,7 @@
 {
   off_t cnt = -1;
 
-  if ((interactive || forced_interactive) && file_number () == 0)
+  if (interactive && file_number () == 0)
     {
       ::error ("%s: unable to read from stdin while running interactively",
                who.c_str ());
@@ -1496,7 +1496,7 @@
 {
   octave_value retval = Matrix ();
 
-  if ((interactive || forced_interactive) && file_number () == 0)
+  if (interactive && file_number () == 0)
     {
       ::error ("%s: unable to read from stdin while running interactively",
                who.c_str ());
@@ -1824,7 +1824,7 @@
 
                   // FIXME: is this the right thing to do?
 
-                  if (interactive && name () == "stdin")
+                  if (interactive && ! forced_interactive && name () == "stdin")
                     {
                       is.clear ();
 
@@ -2049,7 +2049,7 @@
 
           // FIXME: is this the right thing to do?
 
-          if (interactive && name () == "stdin")
+          if (interactive && ! forced_interactive && name () == "stdin")
             {
               // Skip to end of line.
 
--- a/libinterp/corefcn/pager.cc	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/corefcn/pager.cc	Tue Feb 24 17:09:42 2015 +0000
@@ -231,7 +231,7 @@
 int
 octave_pager_buf::sync (void)
 {
-  if (! interactive
+  if (! interactive || forced_interactive
       || really_flush_to_pager
       || (Vpage_screen_output && Vpage_output_immediately)
       || ! Vpage_screen_output)
@@ -240,7 +240,7 @@
 
       int len = pptr () - buf;
 
-      bool bypass_pager = (! interactive
+      bool bypass_pager = (! interactive || forced_interactive
                            || ! Vpage_screen_output
                            || (really_flush_to_pager
                                && Vpage_screen_output
--- a/libinterp/corefcn/sighandlers.cc	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/corefcn/sighandlers.cc	Tue Feb 24 17:09:42 2015 +0000
@@ -523,7 +523,8 @@
           octave_signal_caught = 1;
           octave_interrupt_state++;
 
-          if (interactive && octave_interrupt_state == 2)
+          if (interactive && ! forced_interactive
+              && octave_interrupt_state == 2)
             std::cerr << "Press Control-C again to abort." << std::endl;
 
           if (octave_interrupt_state >= 3)
--- a/libinterp/corefcn/sysdep.cc	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/corefcn/sysdep.cc	Tue Feb 24 17:09:42 2015 +0000
@@ -343,7 +343,7 @@
   int tty_fd = STDIN_FILENO;
   if (! gnulib::isatty (tty_fd))
     {
-      if (interactive)
+      if (interactive && ! forced_interactive)
         error ("stdin is not a tty!");
       return;
     }
@@ -745,7 +745,7 @@
 
   // FIXME: add timeout and default value args?
 
-  if (interactive || forced_interactive)
+  if (interactive)
     {
       Fdrawnow ();
 
--- a/libinterp/corefcn/toplev.cc	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/corefcn/toplev.cc	Tue Feb 24 17:09:42 2015 +0000
@@ -572,7 +572,7 @@
 
   // The big loop.
 
-  octave_lexer *lxr = ((interactive || forced_interactive)
+  octave_lexer *lxr = (interactive
                        ? new octave_lexer ()
                        : new octave_lexer (stdin));
 
@@ -600,7 +600,7 @@
 
                   octave_quit ();
 
-                  if (! (interactive || forced_interactive))
+                  if (! interactive)
                     {
                       bool quit = (tree_return_command::returning
                                    || tree_break_command::breaking);
@@ -617,7 +617,7 @@
 
                   if (error_state)
                     {
-                      if (! (interactive || forced_interactive))
+                      if (! interactive)
                         {
                           // We should exit with a nonzero status.
                           retval = 1;
@@ -730,7 +730,7 @@
 
       OCTAVE_SAFE_CALL (flush_octave_stdout, ());
 
-      if (! quitting_gracefully && (interactive || forced_interactive))
+      if (! quitting_gracefully && interactive)
         {
           octave_stdout << "\n";
 
--- a/libinterp/octave.cc	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/octave.cc	Tue Feb 24 17:09:42 2015 +0000
@@ -791,11 +791,21 @@
   interactive = (! embedded && stdin_is_tty
                  && gnulib::isatty (fileno (stdout)));
 
-  if (! interactive && ! forced_line_editing)
+  // Check if the user forced an interactive session.  If he
+  // unnecessarily did so, reset forced_interactive to false.
+  if (forced_interactive)
+    {
+      if (interactive)
+        forced_interactive = false;
+      else
+        interactive = true;
+    }
+
+  if ((! interactive || forced_interactive) && ! forced_line_editing)
     line_editing = false;
 
   // Also skip start-up message unless session is interactive.
-  if (! (interactive || forced_interactive))
+  if (! interactive)
     inhibit_startup_message = true;
 
   // Force default line editor if we don't want readline editing.
@@ -881,7 +891,7 @@
   // Force input to be echoed if not really interactive,
   // but the user has forced interactive behavior.
 
-  if (! interactive && forced_interactive)
+  if (forced_interactive)
     {
       command_editor::blink_matching_paren (false);
 
--- a/libinterp/parse-tree/lex.ll	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/parse-tree/lex.ll	Tue Feb 24 17:09:42 2015 +0000
@@ -2236,7 +2236,7 @@
   // input.
 
   if (! quitting_gracefully
-      && (interactive || forced_interactive)
+      && interactive
       && ! (reading_fcn_file
             || reading_classdef_file
             || reading_script_file
--- a/libinterp/parse-tree/oct-parse.in.yy	Tue Feb 24 10:41:57 2015 -0800
+++ b/libinterp/parse-tree/oct-parse.in.yy	Tue Feb 24 17:09:42 2015 +0000
@@ -111,8 +111,7 @@
   do \
     { \
       yyerrok; \
-      if ((interactive || forced_interactive) \
-          && ! lexer.input_from_eval_string ()) \
+      if (interactive && ! lexer.input_from_eval_string ()) \
         YYACCEPT; \
       else \
         YYABORT; \