changeset 16209:e7ff32e7cf82

move global promptflag variable to octave_reader class * input.h, input.cc (promptflag): Declare as member of octave_base_reader and rename to pflag. (octave_base_reader::reset, octave_base_reader::promptflag, octave_base_reader::increment_promptflag, octave_reader::decrement_promptflag, octave_reader::promptflag, octave_reader::increment_promptflag, octave_reader::decrement_promptflag): New functions. * lex.ll (octave_lexer::decrement_promptflag, octave_lexer::promptflag, octave_lexer::increment_promptflag, octave_lexer::decrement_promptflag): New functions. Use them instead of global promptflag variable. (octave_lexer::reset): Call input_reader.reset. * oct-parse.in.yy (input): Don't reset promptflag here.
author John W. Eaton <jwe@octave.org>
date Wed, 06 Mar 2013 20:20:35 -0500
parents ed91ab4d4515
children 78365c56a762
files libinterp/interpfcn/input.cc libinterp/interpfcn/input.h libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.in.yy
diffstat 5 files changed, 60 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interpfcn/input.cc	Wed Mar 06 19:45:53 2013 -0500
+++ b/libinterp/interpfcn/input.cc	Wed Mar 06 20:20:35 2013 -0500
@@ -100,9 +100,6 @@
 // TRUE means the user forced this shell to be interactive (-i).
 bool forced_interactive = false;
 
-// Should we issue a prompt?
-int promptflag = 1;
-
 // TRUE after a call to completion_matches.
 bool octave_completion_matches_called = false;
 
@@ -123,8 +120,8 @@
 // The filemarker used to separate filenames from subfunction names
 char Vfilemarker = '>';
 
-static void
-do_input_echo (const std::string& input_string)
+void
+octave_base_reader::do_input_echo (const std::string& input_string) const
 {
   int do_echo = CURR_LEXER->reading_script_file ?
     (Vecho_executing_commands & ECHO_SCRIPTS)
@@ -134,7 +131,7 @@
     {
       if (forced_interactive)
         {
-          if (promptflag > 0)
+          if (pflag > 0)
             octave_stdout << command_editor::decode_prompt_string (VPS1);
           else
             octave_stdout << command_editor::decode_prompt_string (VPS2);
@@ -203,7 +200,7 @@
 
   bool history_skip_auto_repeated_debugging_command = false;
 
-  std::string ps = (promptflag > 0) ? VPS1 : VPS2;
+  std::string ps = (pflag > 0) ? VPS1 : VPS2;
 
   std::string prompt = command_editor::decode_prompt_string (ps);
 
--- a/libinterp/interpfcn/input.h	Wed Mar 06 19:45:53 2013 -0500
+++ b/libinterp/interpfcn/input.h	Wed Mar 06 20:20:35 2013 -0500
@@ -43,9 +43,6 @@
 // TRUE means the user forced this shell to be interactive (-i).
 extern bool forced_interactive;
 
-// Should we issue a prompt?
-extern int promptflag;
-
 // TRUE after a call to completion_matches.
 extern bool octave_completion_matches_called;
 
@@ -85,7 +82,7 @@
 
   friend class octave_input_reader;
 
-  octave_base_reader (void) : count (1) { }
+  octave_base_reader (void) : count (1), pflag (0) { }
 
   octave_base_reader (const octave_base_reader&) : count (1) { }
 
@@ -95,12 +92,31 @@
 
   virtual std::string input_source (void) const { return in_src; }
 
+  void reset (void) { promptflag (1); }
+
+  void increment_promptflag (void) { pflag++; }
+
+  void decrement_promptflag (void) { pflag--; }
+
+  int promptflag (void) const { return pflag; }
+
+  int promptflag (int n)
+  {
+    int retval = pflag;
+    pflag = n;
+    return retval;
+  }
+
   std::string octave_gets (bool& eof);
 
 private:
 
   int count;
 
+  int pflag;
+
+  void do_input_echo (const std::string&) const;
+
   static const std::string in_src;
 };
 
@@ -198,6 +214,16 @@
       delete rep;
   }
 
+  void reset (void) { return rep->reset (); }
+
+  void increment_promptflag (void) { rep->increment_promptflag (); }
+
+  void decrement_promptflag (void) { rep->decrement_promptflag (); }
+
+  int promptflag (void) const { return rep->promptflag (); }
+
+  int promptflag (int n) { return rep->promptflag (n); }
+
   std::string get_input (bool& eof)
   {
     return rep->get_input (eof);
--- a/libinterp/parse-tree/lex.h	Wed Mar 06 19:45:53 2013 -0500
+++ b/libinterp/parse-tree/lex.h	Wed Mar 06 20:20:35 2013 -0500
@@ -496,6 +496,14 @@
 
   octave_input_reader input_reader;
 
+  void increment_promptflag (void) { input_reader.increment_promptflag (); }
+
+  void decrement_promptflag (void) { input_reader.decrement_promptflag (); }
+
+  int promptflag (void) const { return input_reader.promptflag (); }
+
+  int promptflag (int n) { return input_reader.promptflag (n); }
+
   std::string input_source (void) const
   {
     return input_reader.input_source ();
--- a/libinterp/parse-tree/lex.ll	Wed Mar 06 19:45:53 2013 -0500
+++ b/libinterp/parse-tree/lex.ll	Wed Mar 06 20:20:35 2013 -0500
@@ -538,7 +538,7 @@
     else
       curr_lexer->looking_at_matrix_or_assign_lhs = true;
 
-    promptflag--;
+    curr_lexer->decrement_promptflag ();
     curr_lexer->eat_whitespace ();
 
     curr_lexer->bracketflag++;
@@ -602,7 +602,7 @@
     if (yytext[0] == '\\')
       curr_lexer->gripe_matlab_incompatible_continuation ();
     curr_lexer->scan_for_comments (yytext);
-    promptflag--;
+    curr_lexer->decrement_promptflag ();
     curr_lexer->input_line_number++;
     curr_lexer->current_input_column = 1;
   }
@@ -781,7 +781,7 @@
     curr_lexer->input_line_number++;
     curr_lexer->current_input_column = 1;
     curr_lexer->block_comment_nesting_level++;
-    promptflag--;
+    curr_lexer->decrement_promptflag ();
 
     bool eof = false;
     curr_lexer->process_comment (true, eof);
@@ -852,7 +852,7 @@
     curr_lexer->at_beginning_of_statement = false;
 
     curr_lexer->nesting_level.paren ();
-    promptflag--;
+    curr_lexer->decrement_promptflag ();
 
     TOK_RETURN ('(');
   }
@@ -920,7 +920,7 @@
     curr_lexer->looking_for_object_index = false;
     curr_lexer->at_beginning_of_statement = false;
 
-    promptflag--;
+    curr_lexer->decrement_promptflag ();
     curr_lexer->eat_whitespace ();
 
     curr_lexer->braceflag++;
@@ -1446,7 +1446,7 @@
   parser_symtab_context.clear ();
 
   // We do want a prompt by default.
-  promptflag = 1;
+  promptflag (1);
 
   // Only ask for input from stdin if we are expecting interactive
   // input.
@@ -1459,6 +1459,8 @@
             || input_from_eval_string ()))
     yyrestart (stdin, scanner);
 
+  input_reader.reset ();
+
   lexical_feedback::reset ();
 }
 
@@ -1786,25 +1788,25 @@
         case for_kw:
         case parfor_kw:
         case while_kw:
-          promptflag--;
+          decrement_promptflag ();
           looping++;
           break;
 
         case do_kw:
           at_beginning_of_statement = true;
-          promptflag--;
+          decrement_promptflag ();
           looping++;
           break;
 
         case try_kw:
         case unwind_protect_kw:
           at_beginning_of_statement = true;
-          promptflag--;
+          decrement_promptflag ();
           break;
 
         case if_kw:
         case switch_kw:
-          promptflag--;
+          decrement_promptflag ();
           break;
 
         case get_kw:
@@ -1827,7 +1829,7 @@
 
         case classdef_kw:
           // 'classdef' is always a keyword.
-          promptflag--;
+          decrement_promptflag ();
 
           if (! force_script && token_count == 0 && input_from_file ())
             {
@@ -1837,7 +1839,7 @@
           break;
 
         case function_kw:
-          promptflag--;
+          decrement_promptflag ();
 
           defining_func++;
           parsed_function_name.push (false);
@@ -1940,12 +1942,12 @@
                         if (type == '{')
                           {
                             block_comment_nesting_level++;
-                            promptflag--;
+                            decrement_promptflag ();
                           }
                         else
                           {
                             block_comment_nesting_level--;
-                            promptflag++;
+                            increment_promptflag ();
 
                             if (block_comment_nesting_level == 0)
                               {
@@ -2048,7 +2050,7 @@
                         done = true;
 
                         block_comment_nesting_level++;
-                        promptflag--;
+                        decrement_promptflag ();
 
                         buf += grab_block_comment (reader, eof);
 
@@ -2648,7 +2650,7 @@
               octave_comment_buffer::append (comment_buf);
             }
           current_input_column = 0;
-          promptflag--;
+          decrement_promptflag ();
           gripe_matlab_incompatible_continuation ();
           return true;
 
--- a/libinterp/parse-tree/oct-parse.in.yy	Wed Mar 06 19:45:53 2013 -0500
+++ b/libinterp/parse-tree/oct-parse.in.yy	Wed Mar 06 20:20:35 2013 -0500
@@ -319,7 +319,6 @@
 input           : input1
                   {
                     curr_parser.stmt_list = $1;
-                    promptflag = 1;
                     YYACCEPT;
                   }
                 | simple_list parse_error