GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
input.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 // Use the GNU readline library for command line editing and hisory.
24 
25 #if ! defined (octave_input_h)
26 #define octave_input_h 1
27 
28 #include "octave-config.h"
29 
30 #include <cstdio>
31 
32 #include <string>
33 
34 #include "oct-refcount.h"
35 #include "oct-time.h"
36 #include "ovl.h"
37 #include "pager.h"
38 
39 class octave_value;
40 namespace octave
41 {
42  class base_lexer;
43 }
44 
45 extern OCTINTERP_API FILE * get_input_from_stdin (void);
46 
47 // TRUE after a call to completion_matches.
49 
50 // TRUE if the plotting system has requested a call to drawnow at
51 // the next user prompt.
52 extern OCTINTERP_API bool Vdrawnow_requested;
53 
54 // TRUE if we are in debugging mode.
55 extern OCTINTERP_API bool Vdebugging;
56 
57 // TRUE if we are not executing a command direct from debug> prompt.
58 extern OCTINTERP_API bool Vtrack_line_num;
59 
61 
62 extern void initialize_command_input (void);
63 
64 extern bool octave_yes_or_no (const std::string& prompt);
65 
66 extern octave_value do_keyboard (const octave_value_list& args
67  = octave_value_list ());
68 
69 extern void remove_input_event_hook_functions (void);
70 
71 extern void set_default_prompts (void);
72 
74 
75 namespace octave
76 {
77  class
79  {
80  public:
81 
82  friend class input_reader;
83 
85  : m_count (1), m_pflag (0), m_lexer (lxr)
86  { }
87 
89  : m_count (1), m_pflag (x.m_pflag), m_lexer (x.m_lexer)
90  { }
91 
92  virtual ~base_reader (void) = default;
93 
94  virtual std::string get_input (bool& eof) = 0;
95 
96  virtual std::string input_source (void) const { return s_in_src; }
97 
98  void reset (void) { promptflag (1); }
99 
100  void increment_promptflag (void) { m_pflag++; }
101 
102  void decrement_promptflag (void) { m_pflag--; }
103 
104  int promptflag (void) const { return m_pflag; }
105 
106  int promptflag (int n)
107  {
108  int retval = m_pflag;
109  m_pflag = n;
110  return retval;
111  }
112 
113  std::string octave_gets (bool& eof);
114 
115  virtual bool reading_fcn_file (void) const;
116 
117  virtual bool reading_classdef_file (void) const;
118 
119  virtual bool reading_script_file (void) const;
120 
121  virtual bool input_from_terminal (void) const { return false; }
122 
123  virtual bool input_from_file (void) const { return false; }
124 
125  virtual bool input_from_eval_string (void) const { return false; }
126 
127  private:
128 
130 
131  int m_pflag;
132 
134 
135  static const std::string s_in_src;
136  };
137 
138  class
140  {
141  public:
142 
143  input_reader (base_lexer *lxr = nullptr);
144 
145  input_reader (FILE *file, base_lexer *lxr = nullptr);
146 
147  input_reader (const std::string& str, base_lexer *lxr = nullptr);
148 
150  {
151  m_rep = ir.m_rep;
152  m_rep->m_count++;
153  }
154 
155  input_reader& operator = (const input_reader& ir)
156  {
157  if (&ir != this)
158  {
159  m_rep = ir.m_rep;
160  m_rep->m_count++;
161  }
162 
163  return *this;
164  }
165 
167  {
168  if (--m_rep->m_count == 0)
169  delete m_rep;
170  }
171 
172  void reset (void) { return m_rep->reset (); }
173 
174  void increment_promptflag (void) { m_rep->increment_promptflag (); }
175 
176  void decrement_promptflag (void) { m_rep->decrement_promptflag (); }
177 
178  int promptflag (void) const { return m_rep->promptflag (); }
179 
180  int promptflag (int n) { return m_rep->promptflag (n); }
181 
182  std::string get_input (bool& eof)
183  {
184  return m_rep->get_input (eof);
185  }
186 
188  {
189  return m_rep->input_source ();
190  }
191 
192  bool input_from_terminal (void) const
193  {
194  return m_rep->input_from_terminal ();
195  }
196 
197  bool input_from_file (void) const
198  {
199  return m_rep->input_from_file ();
200  }
201 
202  bool input_from_eval_string (void) const
203  {
204  return m_rep->input_from_eval_string ();
205  }
206 
207  private:
208 
210  };
211 }
212 
213 #endif
OCTINTERP_API bool Vdebugging
Definition: input.cc:97
virtual bool input_from_terminal(void) const
Definition: input.h:121
std::string find_indexed_expression(const std::string &text)
Definition: input.cc:537
bool input_from_eval_string(void) const
Definition: input.h:202
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
static const std::string s_in_src
Definition: input.h:135
bool input_from_terminal(void) const
Definition: input.h:192
void remove_input_event_hook_functions(void)
Definition: input.cc:115
OCTINTERP_API bool Vdrawnow_requested
Definition: input.cc:94
OCTINTERP_API bool Vtrack_line_num
Definition: input.cc:102
void reset(void)
Definition: input.h:98
~input_reader(void)
Definition: input.h:166
void decrement_promptflag(void)
Definition: input.h:176
base_reader * m_rep
Definition: input.h:209
int promptflag(int n)
Definition: input.h:106
void set_default_prompts(void)
Definition: input.cc:121
base_reader(const base_reader &x)
Definition: input.h:88
void decrement_promptflag(void)
Definition: input.h:102
int promptflag(void) const
Definition: input.h:178
std::string str
Definition: hash.cc:118
octave_value retval
Definition: data.cc:6246
base_reader(base_lexer *lxr)
Definition: input.h:84
void increment_promptflag(void)
Definition: input.h:100
void reset(void)
Definition: input.h:172
virtual bool input_from_eval_string(void) const
Definition: input.h:125
bool input_from_file(void) const
Definition: input.h:197
void initialize_command_input(void)
Definition: input.cc:580
int promptflag(void) const
Definition: input.h:104
base_lexer * m_lexer
Definition: input.h:133
octave::sys::time Vlast_prompt_time
Definition: input.cc:84
input_reader(const input_reader &ir)
Definition: input.h:149
bool octave_yes_or_no(const std::string &prompt)
int promptflag(int n)
Definition: input.h:180
octave_value do_keyboard(const octave_value_list &args=octave_value_list())
std::string input_source(void) const
Definition: input.h:187
bool octave_completion_matches_called
Definition: input.cc:90
refcount< int > m_count
Definition: input.h:129
OCTINTERP_API FILE * get_input_from_stdin(void)
Definition: input.cc:369
void increment_promptflag(void)
Definition: input.h:174
virtual std::string input_source(void) const
Definition: input.h:96
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
std::string get_input(bool &eof)
Definition: input.h:182
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
virtual bool input_from_file(void) const
Definition: input.h:123