GNU Octave  4.2.1
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-2017 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 "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.
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 
67  = octave_value_list ());
68 
69 extern void remove_input_event_hook_functions (void);
70 
71 extern void set_default_prompts (void);
72 
73 extern std::string VPS4;
74 
75 extern char Vfilemarker;
76 
78 {
79  ECHO_OFF = 0,
83 };
84 
85 extern int Vecho_executing_commands;
86 
88 
89 class
91 {
92 public:
93 
94  friend class octave_input_reader;
95 
97  : count (1), pflag (0), lexer (lxr)
98  { }
99 
101  : count (1), pflag (x.pflag), lexer (x.lexer)
102  { }
103 
104  virtual ~octave_base_reader (void) { }
105 
106  virtual std::string get_input (bool& eof) = 0;
107 
108  virtual std::string input_source (void) const { return in_src; }
109 
110  void reset (void) { promptflag (1); }
111 
112  void increment_promptflag (void) { pflag++; }
113 
114  void decrement_promptflag (void) { pflag--; }
115 
116  int promptflag (void) const { return pflag; }
117 
118  int promptflag (int n)
119  {
120  int retval = pflag;
121  pflag = n;
122  return retval;
123  }
124 
125  std::string octave_gets (bool& eof);
126 
127  virtual bool reading_fcn_file (void) const;
128 
129  virtual bool reading_classdef_file (void) const;
130 
131  virtual bool reading_script_file (void) const;
132 
133  virtual bool input_from_terminal (void) const { return false; }
134 
135  virtual bool input_from_file (void) const { return false; }
136 
137  virtual bool input_from_eval_string (void) const { return false; }
138 
139 private:
140 
142 
143  int pflag;
144 
146 
147  void do_input_echo (const std::string&) const;
148 
149  static const std::string in_src;
150 };
151 
152 class
154 {
155 public:
156 
158  : octave_base_reader (lxr)
159  { }
160 
161  std::string get_input (bool& eof);
162 
163  std::string input_source (void) const { return in_src; }
164 
165  bool input_from_terminal (void) const { return true; }
166 
167 private:
168 
169  static const std::string in_src;
170 };
171 
172 class
174 {
175 public:
176 
177  octave_file_reader (FILE *f_arg, octave::base_lexer *lxr = 0)
178  : octave_base_reader (lxr), file (f_arg) { }
179 
180  std::string get_input (bool& eof);
181 
182  std::string input_source (void) const { return in_src; }
183 
184  bool input_from_file (void) const { return true; }
185 
186 private:
187 
188  FILE *file;
189 
190  static const std::string in_src;
191 };
192 
193 class
195 {
196 public:
197 
199  octave::base_lexer *lxr = 0)
200  : octave_base_reader (lxr), eval_string (str)
201  { }
202 
203  std::string get_input (bool& eof);
204 
205  std::string input_source (void) const { return in_src; }
206 
207  bool input_from_eval_string (void) const { return true; }
208 
209 private:
210 
212 
213  static const std::string in_src;
214 };
215 
216 class
218 {
219 public:
221  : rep (new octave_terminal_reader (lxr))
222  { }
223 
225  : rep (new octave_file_reader (file, lxr))
226  { }
227 
229  : rep (new octave_eval_string_reader (str, lxr))
230  { }
231 
233  {
234  rep = ir.rep;
235  rep->count++;
236  }
237 
239  {
240  if (&ir != this)
241  {
242  rep = ir.rep;
243  rep->count++;
244  }
245 
246  return *this;
247  }
248 
250  {
251  if (--rep->count == 0)
252  delete rep;
253  }
254 
255  void reset (void) { return rep->reset (); }
256 
258 
260 
261  int promptflag (void) const { return rep->promptflag (); }
262 
263  int promptflag (int n) { return rep->promptflag (n); }
264 
265  std::string get_input (bool& eof)
266  {
267  return rep->get_input (eof);
268  }
269 
271  {
272  return rep->input_source ();
273  }
274 
275  bool input_from_terminal (void) const
276  {
277  return rep->input_from_terminal ();
278  }
279 
280  bool input_from_file (void) const
281  {
282  return rep->input_from_file ();
283  }
284 
285  bool input_from_eval_string (void) const
286  {
287  return rep->input_from_eval_string ();
288  }
289 
290 private:
291 
293 };
294 
295 #endif
void reset(void)
Definition: input.h:110
OCTINTERP_API bool Vdebugging
Definition: input.cc:109
octave_base_reader * rep
Definition: input.h:292
std::string find_indexed_expression(const std::string &text)
Definition: input.cc:509
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
virtual ~octave_base_reader(void)
Definition: input.h:104
static const std::string in_src
Definition: input.h:190
octave_input_reader(const std::string &str, octave::base_lexer *lxr=0)
Definition: input.h:228
Definition: input.h:79
bool input_from_file(void) const
Definition: input.h:184
void remove_input_event_hook_functions(void)
Definition: input.cc:130
octave_base_reader(octave::base_lexer *lxr)
Definition: input.h:96
octave_refcount< int > count
Definition: input.h:141
std::string input_source(void) const
Definition: input.h:182
OCTINTERP_API bool Vdrawnow_requested
Definition: input.cc:106
virtual std::string input_source(void) const
Definition: input.h:108
void increment_promptflag(void)
Definition: input.h:257
OCTINTERP_API bool Vtrack_line_num
Definition: input.cc:114
std::string input_source(void) const
Definition: input.h:163
~octave_input_reader(void)
Definition: input.h:249
void reset(void)
Definition: input.h:255
int Vecho_executing_commands
Definition: input.cc:93
std::string eval_string
Definition: input.h:211
bool input_from_eval_string(void) const
Definition: input.h:207
void decrement_promptflag(void)
Definition: input.h:114
octave_eval_string_reader(const std::string &str, octave::base_lexer *lxr=0)
Definition: input.h:198
virtual bool input_from_file(void) const
Definition: input.h:135
octave_input_reader & operator=(const octave_input_reader &ir)
Definition: input.h:238
JNIEnv void * args
Definition: ov-java.cc:67
int promptflag(void) const
Definition: input.h:116
static const std::string in_src
Definition: input.h:169
int promptflag(int n)
Definition: input.h:118
void set_default_prompts(void)
Definition: input.cc:136
char Vfilemarker
Definition: input.cc:124
std::string input_source(void) const
Definition: input.h:270
bool input_from_terminal(void) const
Definition: input.h:165
#define OCTINTERP_API
Definition: mexproto.h:69
int promptflag(void) const
Definition: input.h:261
#define lexer
Definition: oct-parse.cc:152
virtual bool input_from_eval_string(void) const
Definition: input.h:137
virtual bool input_from_terminal(void) const
Definition: input.h:133
std::string str
Definition: hash.cc:118
octave_file_reader(FILE *f_arg, octave::base_lexer *lxr=0)
Definition: input.h:177
octave_input_reader(const octave_input_reader &ir)
Definition: input.h:232
octave_value retval
Definition: data.cc:6294
octave_input_reader(FILE *file, octave::base_lexer *lxr=0)
Definition: input.h:224
bool input_from_file(void) const
Definition: input.h:280
void initialize_command_input(void)
Definition: input.cc:552
void increment_promptflag(void)
Definition: input.h:112
octave::sys::time Vlast_prompt_time
Definition: input.cc:96
static const std::string in_src
Definition: input.h:149
bool octave_yes_or_no(const std::string &prompt)
static const std::string in_src
Definition: input.h:213
int promptflag(int n)
Definition: input.h:263
octave_value do_keyboard(const octave_value_list &args=octave_value_list())
octave_input_reader(octave::base_lexer *lxr=0)
Definition: input.h:220
void decrement_promptflag(void)
Definition: input.h:259
std::string input_source(void) const
Definition: input.h:205
bool input_from_eval_string(void) const
Definition: input.h:285
bool octave_completion_matches_called
Definition: input.cc:102
virtual std::string get_input(bool &eof)=0
OCTINTERP_API FILE * get_input_from_stdin(void)
Definition: input.cc:341
std::string get_input(bool &eof)
Definition: input.h:265
octave_base_reader(const octave_base_reader &x)
Definition: input.h:100
OCTINTERP_API octave_value_list eval_string(const std::string &, bool silent, int &parse_status, int nargout)
bool input_from_terminal(void) const
Definition: input.h:275
echo_state
Definition: input.h:77
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:854
octave::base_lexer * lexer
Definition: input.h:145
std::string VPS4
Definition: input.cc:84
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
octave_terminal_reader(octave::base_lexer *lxr=0)
Definition: input.h:157