changeset 18267:bc139ccccef9 gui-release

Don't echo scripts not executed from the cmd line when using 'echo on'(bug #41202) * toplev.h (octave_call_stack::all_scripts): New function returns TRUE if all elements an the call stack are scripts. Add prototype for do_all_scripts(). toplev.cc (octave_call_stack::do_all_scripts): New function to search call stack scripts only. * pt-eval.cc (tree_evaluator::visit_statement): Check octave_call_stack::all_scripts() and don't echo scripts if script is called from a function.
author Rik <rik@octave.org>
date Sun, 12 Jan 2014 18:18:47 -0800
parents 545a77c3206e
children 7e297c293e4c
files libinterp/corefcn/toplev.cc libinterp/corefcn/toplev.h libinterp/parse-tree/pt-eval.cc
diffstat 3 files changed, 35 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/toplev.cc	Fri Jan 10 19:25:07 2014 -0500
+++ b/libinterp/corefcn/toplev.cc	Sun Jan 12 18:18:47 2014 -0800
@@ -263,6 +263,29 @@
   return retval;
 }
 
+bool
+octave_call_stack::do_all_scripts (void) const
+{
+  bool retval = true;
+
+  const_iterator p = cs.end ();
+
+  while (p != cs.begin ())
+    {
+      const call_stack_elt& elt = *(--p);
+
+      octave_function *f = elt.fcn;
+
+      if (f && ! f->is_user_script ())
+        {
+          retval = false;
+          break;
+        }
+    }
+
+  return retval;
+}
+
 // Use static fields for the best efficiency.
 // NOTE: C++0x will allow these two to be merged into one.
 static const char *bt_fieldnames[] = { "file", "name", "line",
--- a/libinterp/corefcn/toplev.h	Fri Jan 10 19:25:07 2014 -0500
+++ b/libinterp/corefcn/toplev.h	Sun Jan 12 18:18:47 2014 -0800
@@ -206,6 +206,12 @@
     return instance_ok () ? instance->do_caller_user_code (nskip) : 0;
   }
 
+  // Return TRUE if all elements on the call stack are scripts.
+  static bool all_scripts (void)
+  {
+    return instance_ok () ? instance->do_all_scripts () : false;
+  }
+
   static void
   push (octave_function *f,
         symbol_table::scope_id scope = symbol_table::current_scope (),
@@ -352,6 +358,8 @@
 
   octave_user_code *do_caller_user_code (size_t nskip) const;
 
+  bool do_all_scripts (void) const;
+
   void do_push (octave_function *f, symbol_table::scope_id scope,
                 symbol_table::context_id context)
   {
--- a/libinterp/parse-tree/pt-eval.cc	Fri Jan 10 19:25:07 2014 -0500
+++ b/libinterp/parse-tree/pt-eval.cc	Sun Jan 12 18:18:47 2014 -0800
@@ -705,13 +705,12 @@
           if (! Vdebugging)
             octave_call_stack::set_location (stmt.line (), stmt.column ());
 
-          // FIXME: we need to distinguish functions from scripts
-          //        to get this right.
           if ((statement_context == script
-               && ((Vecho_executing_commands & ECHO_SCRIPTS)
-                   || (Vecho_executing_commands & ECHO_FUNCTIONS)))
+               && ((Vecho_executing_commands & ECHO_SCRIPTS
+                   && octave_call_stack::all_scripts ())
+                   || Vecho_executing_commands & ECHO_FUNCTIONS))
               || (statement_context == function
-                  && (Vecho_executing_commands & ECHO_FUNCTIONS)))
+                  && Vecho_executing_commands & ECHO_FUNCTIONS))
             stmt.echo_code ();
         }