GNU Octave  3.8.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-2013 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.
42 extern bool interactive;
43 
44 // TRUE means the user forced this shell to be interactive (-i).
45 extern bool forced_interactive;
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 extern void initialize_command_input (void);
58 
59 extern bool octave_yes_or_no (const std::string& prompt);
60 
61 extern octave_value do_keyboard (const octave_value_list& args
62  = octave_value_list ());
63 
64 extern void remove_input_event_hook_functions (void);
65 
66 extern void set_default_prompts (void);
67 
68 extern std::string VPS4;
69 
70 extern char Vfilemarker;
71 
73 {
74  ECHO_OFF = 0,
78 };
79 
80 extern int Vecho_executing_commands;
81 
83 
84 class
86 {
87 public:
88 
89  friend class octave_input_reader;
90 
92  : count (1), pflag (0), lexer (lxr)
93  { }
94 
96  : count (1), pflag (x.pflag), lexer (x.lexer)
97  { }
98 
99  virtual ~octave_base_reader (void) { }
100 
101  virtual std::string get_input (bool& eof) = 0;
102 
103  virtual std::string input_source (void) const { return in_src; }
104 
105  void reset (void) { promptflag (1); }
106 
107  void increment_promptflag (void) { pflag++; }
108 
109  void decrement_promptflag (void) { pflag--; }
110 
111  int promptflag (void) const { return pflag; }
112 
113  int promptflag (int n)
114  {
115  int retval = pflag;
116  pflag = n;
117  return retval;
118  }
119 
120  std::string octave_gets (bool& eof);
121 
122  virtual bool reading_fcn_file (void) const;
123 
124  virtual bool reading_classdef_file (void) const;
125 
126  virtual bool reading_script_file (void) const;
127 
128  virtual bool input_from_terminal (void) const { return false; }
129 
130  virtual bool input_from_file (void) const { return false; }
131 
132  virtual bool input_from_eval_string (void) const { return false; }
133 
134 private:
135 
136  int count;
137 
138  int pflag;
139 
141 
142  void do_input_echo (const std::string&) const;
143 
144  static const std::string in_src;
145 };
146 
147 class
149 {
150 public:
151 
153  : octave_base_reader (lxr)
154  { }
155 
156  std::string get_input (bool& eof);
157 
158  std::string input_source (void) const { return in_src; }
159 
160  bool input_from_terminal (void) const { return true; }
161 
162 private:
163 
164  static const std::string in_src;
165 };
166 
167 class
169 {
170 public:
171 
172  octave_file_reader (FILE *f_arg, octave_base_lexer *lxr = 0)
173  : octave_base_reader (lxr), file (f_arg) { }
174 
175  std::string get_input (bool& eof);
176 
177  std::string input_source (void) const { return in_src; }
178 
179  bool input_from_file (void) const { return true; }
180 
181 private:
182 
183  FILE *file;
184 
185  static const std::string in_src;
186 };
187 
188 class
190 {
191 public:
192 
193  octave_eval_string_reader (const std::string& str,
194  octave_base_lexer *lxr = 0)
195  : octave_base_reader (lxr), eval_string (str)
196  { }
197 
198  std::string get_input (bool& eof);
199 
200  std::string input_source (void) const { return in_src; }
201 
202  bool input_from_eval_string (void) const { return true; }
203 
204 private:
205 
206  std::string eval_string;
207 
208  static const std::string in_src;
209 };
210 
211 class
213 {
214 public:
216  : rep (new octave_terminal_reader (lxr))
217  { }
218 
219  octave_input_reader (FILE *file, octave_base_lexer *lxr = 0)
220  : rep (new octave_file_reader (file, lxr))
221  { }
222 
223  octave_input_reader (const std::string& str, octave_base_lexer *lxr = 0)
224  : rep (new octave_eval_string_reader (str, lxr))
225  { }
226 
228  {
229  rep = ir.rep;
230  rep->count++;
231  }
232 
234  {
235  if (&ir != this)
236  {
237  rep = ir.rep;
238  rep->count++;
239  }
240 
241  return *this;
242  }
243 
245  {
246  if (--rep->count == 0)
247  delete rep;
248  }
249 
250  void reset (void) { return rep->reset (); }
251 
253 
255 
256  int promptflag (void) const { return rep->promptflag (); }
257 
258  int promptflag (int n) { return rep->promptflag (n); }
259 
260  std::string get_input (bool& eof)
261  {
262  return rep->get_input (eof);
263  }
264 
265  std::string input_source (void) const
266  {
267  return rep->input_source ();
268  }
269 
270  bool input_from_terminal (void) const
271  {
272  return rep->input_from_terminal ();
273  }
274 
275  bool input_from_file (void) const
276  {
277  return rep->input_from_file ();
278  }
279 
280  bool input_from_eval_string (void) const
281  {
282  return rep->input_from_eval_string ();
283  }
284 
285 private:
286 
288 };
289 
290 #endif