GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
input.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2015 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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 <cstdio>
29 
30 #include <string>
31 
32 #include "oct-time.h"
33 #include "oct-obj.h"
34 #include "pager.h"
35 
36 class octave_value;
37 class octave_base_lexer;
38 
39 extern OCTINTERP_API FILE *get_input_from_stdin (void);
40 
41 // TRUE means this is an interactive shell (forced or not)
42 extern bool interactive;
43 
44 // TRUE means the user forced this shell to be interactive (-i).
45 // FALSE means the shell would be interactive, independent of user settings.
46 extern bool forced_interactive;
47 
48 // TRUE after a call to completion_matches.
50 
51 // TRUE if the plotting system has requested a call to drawnow at
52 // the next user prompt.
54 
55 // TRUE if we are in debugging mode.
56 extern OCTINTERP_API bool Vdebugging;
57 
58 extern void initialize_command_input (void);
59 
60 extern bool octave_yes_or_no (const std::string& prompt);
61 
62 extern octave_value do_keyboard (const octave_value_list& args
63  = octave_value_list ());
64 
65 extern void remove_input_event_hook_functions (void);
66 
67 extern void set_default_prompts (void);
68 
69 extern std::string VPS4;
70 
71 extern char Vfilemarker;
72 
74 {
75  ECHO_OFF = 0,
79 };
80 
81 extern int Vecho_executing_commands;
82 
84 
85 class
87 {
88 public:
89 
90  friend class octave_input_reader;
91 
93  : count (1), pflag (0), lexer (lxr)
94  { }
95 
97  : count (1), pflag (x.pflag), lexer (x.lexer)
98  { }
99 
100  virtual ~octave_base_reader (void) { }
101 
102  virtual std::string get_input (bool& eof) = 0;
103 
104  virtual std::string input_source (void) const { return in_src; }
105 
106  void reset (void) { promptflag (1); }
107 
108  void increment_promptflag (void) { pflag++; }
109 
110  void decrement_promptflag (void) { pflag--; }
111 
112  int promptflag (void) const { return pflag; }
113 
114  int promptflag (int n)
115  {
116  int retval = pflag;
117  pflag = n;
118  return retval;
119  }
120 
121  std::string octave_gets (bool& eof);
122 
123  virtual bool reading_fcn_file (void) const;
124 
125  virtual bool reading_classdef_file (void) const;
126 
127  virtual bool reading_script_file (void) const;
128 
129  virtual bool input_from_terminal (void) const { return false; }
130 
131  virtual bool input_from_file (void) const { return false; }
132 
133  virtual bool input_from_eval_string (void) const { return false; }
134 
135 private:
136 
137  int count;
138 
139  int pflag;
140 
142 
143  void do_input_echo (const std::string&) const;
144 
145  static const std::string in_src;
146 };
147 
148 class
150 {
151 public:
152 
154  : octave_base_reader (lxr)
155  { }
156 
157  std::string get_input (bool& eof);
158 
159  std::string input_source (void) const { return in_src; }
160 
161  bool input_from_terminal (void) const { return true; }
162 
163 private:
164 
165  static const std::string in_src;
166 };
167 
168 class
170 {
171 public:
172 
173  octave_file_reader (FILE *f_arg, octave_base_lexer *lxr = 0)
174  : octave_base_reader (lxr), file (f_arg) { }
175 
176  std::string get_input (bool& eof);
177 
178  std::string input_source (void) const { return in_src; }
179 
180  bool input_from_file (void) const { return true; }
181 
182 private:
183 
184  FILE *file;
185 
186  static const std::string in_src;
187 };
188 
189 class
191 {
192 public:
193 
194  octave_eval_string_reader (const std::string& str,
195  octave_base_lexer *lxr = 0)
196  : octave_base_reader (lxr), eval_string (str)
197  { }
198 
199  std::string get_input (bool& eof);
200 
201  std::string input_source (void) const { return in_src; }
202 
203  bool input_from_eval_string (void) const { return true; }
204 
205 private:
206 
207  std::string eval_string;
208 
209  static const std::string in_src;
210 };
211 
212 class
214 {
215 public:
217  : rep (new octave_terminal_reader (lxr))
218  { }
219 
220  octave_input_reader (FILE *file, octave_base_lexer *lxr = 0)
221  : rep (new octave_file_reader (file, lxr))
222  { }
223 
224  octave_input_reader (const std::string& str, octave_base_lexer *lxr = 0)
225  : rep (new octave_eval_string_reader (str, lxr))
226  { }
227 
229  {
230  rep = ir.rep;
231  rep->count++;
232  }
233 
235  {
236  if (&ir != this)
237  {
238  rep = ir.rep;
239  rep->count++;
240  }
241 
242  return *this;
243  }
244 
246  {
247  if (--rep->count == 0)
248  delete rep;
249  }
250 
251  void reset (void) { return rep->reset (); }
252 
254 
256 
257  int promptflag (void) const { return rep->promptflag (); }
258 
259  int promptflag (int n) { return rep->promptflag (n); }
260 
261  std::string get_input (bool& eof)
262  {
263  return rep->get_input (eof);
264  }
265 
266  std::string input_source (void) const
267  {
268  return rep->input_source ();
269  }
270 
271  bool input_from_terminal (void) const
272  {
273  return rep->input_from_terminal ();
274  }
275 
276  bool input_from_file (void) const
277  {
278  return rep->input_from_file ();
279  }
280 
281  bool input_from_eval_string (void) const
282  {
283  return rep->input_from_eval_string ();
284  }
285 
286 private:
287 
289 };
290 
291 #endif
void reset(void)
Definition: input.h:106
OCTINTERP_API bool Vdebugging
Definition: input.cc:117
octave_base_reader * rep
Definition: input.h:288
octave_terminal_reader(octave_base_lexer *lxr=0)
Definition: input.h:153
virtual ~octave_base_reader(void)
Definition: input.h:100
static const std::string in_src
Definition: input.h:186
Definition: input.h:75
bool input_from_file(void) const
Definition: input.h:180
void remove_input_event_hook_functions(void)
Definition: input.cc:133
octave_input_reader(octave_base_lexer *lxr=0)
Definition: input.h:216
std::string input_source(void) const
Definition: input.h:178
OCTINTERP_API bool Vdrawnow_requested
Definition: input.cc:114
virtual std::string input_source(void) const
Definition: input.h:104
void increment_promptflag(void)
Definition: input.h:253
std::string input_source(void) const
Definition: input.h:159
octave_input_reader(const std::string &str, octave_base_lexer *lxr=0)
Definition: input.h:224
~octave_input_reader(void)
Definition: input.h:245
void reset(void)
Definition: input.h:251
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
Definition: oct-parse.cc:8810
int Vecho_executing_commands
Definition: input.cc:94
std::string eval_string
Definition: input.h:207
bool input_from_eval_string(void) const
Definition: input.h:203
void decrement_promptflag(void)
Definition: input.h:110
virtual bool input_from_file(void) const
Definition: input.h:131
octave_input_reader & operator=(const octave_input_reader &ir)
Definition: input.h:234
int promptflag(void) const
Definition: input.h:112
static const std::string in_src
Definition: input.h:165
octave_base_lexer * lexer
Definition: input.h:141
int promptflag(int n)
Definition: input.h:114
void set_default_prompts(void)
Definition: input.cc:139
char Vfilemarker
Definition: input.cc:127
std::string input_source(void) const
Definition: input.h:266
bool input_from_terminal(void) const
Definition: input.h:161
#define OCTINTERP_API
Definition: mexproto.h:66
int promptflag(void) const
Definition: input.h:257
#define lexer
Definition: oct-parse.cc:170
virtual bool input_from_eval_string(void) const
Definition: input.h:133
virtual bool input_from_terminal(void) const
Definition: input.h:129
octave_input_reader(const octave_input_reader &ir)
Definition: input.h:228
bool forced_interactive
Definition: input.cc:107
octave_file_reader(FILE *f_arg, octave_base_lexer *lxr=0)
Definition: input.h:173
bool input_from_file(void) const
Definition: input.h:276
octave_input_reader(FILE *file, octave_base_lexer *lxr=0)
Definition: input.h:220
void initialize_command_input(void)
Definition: input.cc:475
void increment_promptflag(void)
Definition: input.h:108
static const std::string in_src
Definition: input.h:145
bool octave_yes_or_no(const std::string &prompt)
Definition: input.cc:798
static const std::string in_src
Definition: input.h:209
int promptflag(int n)
Definition: input.h:259
octave_value do_keyboard(const octave_value_list &args=octave_value_list())
Definition: input.cc:859
void decrement_promptflag(void)
Definition: input.h:255
std::string input_source(void) const
Definition: input.h:201
bool input_from_eval_string(void) const
Definition: input.h:281
bool octave_completion_matches_called
Definition: input.cc:110
virtual std::string get_input(bool &eof)=0
OCTINTERP_API FILE * get_input_from_stdin(void)
Definition: input.cc:325
std::string get_input(bool &eof)
Definition: input.h:261
octave_eval_string_reader(const std::string &str, octave_base_lexer *lxr=0)
Definition: input.h:194
octave_time Vlast_prompt_time
Definition: input.cc:97
octave_base_reader(const octave_base_reader &x)
Definition: input.h:96
bool input_from_terminal(void) const
Definition: input.h:271
bool interactive
Definition: input.cc:103
echo_state
Definition: input.h:73
std::string VPS4
Definition: input.cc:85
octave_base_reader(octave_base_lexer *lxr)
Definition: input.h:92
F77_RET_T const double * x