GNU Octave 7.1.0
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-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26// Use the GNU readline library for command line editing and history.
27
28#if ! defined (octave_input_h)
29#define octave_input_h 1
30
31#include "octave-config.h"
32
33#include <cstdio>
34
35#include <memory>
36#include <string>
37#include <unordered_map>
38
39#include "hook-fcn.h"
40#include "oct-time.h"
41#include "ovl.h"
42#include "pager.h"
43
44// TRUE after a call to completion_matches.
46
47// TRUE if the plotting system has requested a call to drawnow at
48// the next user prompt.
49extern OCTINTERP_API bool Vdrawnow_requested;
50
51#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
52OCTAVE_DEPRECATED (6, "'Vtrack_line_num' is an obsolete internal variable; any uses should be removed")
53extern OCTINTERP_API bool Vtrack_line_num;
54#endif
55
56extern OCTINTERP_API octave::sys::time Vlast_prompt_time;
57
58class octave_value;
59
60OCTAVE_NAMESPACE_BEGIN
61
62 class interpreter;
63
65 {
66 public:
67
68 input_system (interpreter& interp);
69
70 void initialize (bool line_editing);
71
72 octave_value PS1 (const octave_value_list& args, int nargout);
73
74 std::string PS1 (void) const { return m_PS1; }
75
76 std::string PS1 (const std::string& s)
77 {
78 std::string val = m_PS1;
79 m_PS1 = s;
80 return val;
81 }
82
83 void set_PS1 (const std::string& s) { m_PS1 = s; }
84
85 octave_value PS2 (const octave_value_list& args, int nargout);
86
87 std::string PS2 (void) const { return m_PS2; }
88
89 std::string PS2 (const std::string& s)
90 {
91 std::string val = m_PS2;
92 m_PS2 = s;
93 return val;
94 }
95
96 void set_PS2 (const std::string& s) { m_PS2 = s; }
97
98 std::string last_debugging_command (void) const
99 {
101 }
102
103 std::string last_debugging_command (const std::string& s)
104 {
105 std::string val = m_last_debugging_command;
107 return val;
108 }
109
111 completion_append_char (const octave_value_list& args, int nargout);
112
113 char completion_append_char (void) const
114 {
116 }
117
119 {
120 char val = m_completion_append_char;
122 return val;
123 }
124
126
127 octave_value gud_mode (const octave_value_list& args, int nargout);
128
129 bool gud_mode (void) const { return m_gud_mode; }
130
131 bool gud_mode (bool flag)
132 {
133 bool val = m_gud_mode;
134 m_gud_mode = flag;
135 return val;
136 }
137
138 void set_gud_mode (bool flag) { m_gud_mode = flag; }
139
141
142 std::string mfile_encoding (void) const { return m_mfile_encoding; }
143
144 std::string mfile_encoding (const std::string& s)
145 {
146 std::string val = m_mfile_encoding;
148 return val;
149 }
150
151 void set_mfile_encoding (const std::string& s) { m_mfile_encoding = s; }
152
153 std::string dir_encoding (const std::string& dir);
154
155 void set_dir_encoding (const std::string& dir, std::string& enc);
156
159
161 {
163 }
164
166 {
167 bool old_val = m_auto_repeat_debug_command;
169 return old_val;
170 }
171
172 bool yes_or_no (const std::string& prompt);
173
174 std::string interactive_input (const std::string& s, bool& eof);
175
177 get_user_input (const octave_value_list& args, int nargout);
178
179 bool have_input_event_hooks (void) const;
180
181 void add_input_event_hook (const hook_function& hook_fcn);
182
183 bool remove_input_event_hook (const std::string& hook_fcn_id);
184
186
188
189 private:
190
192
193 // Primary prompt string.
194 std::string m_PS1;
195
196 // Secondary prompt string.
197 std::string m_PS2;
198
199 // Character to append after successful command-line completion
200 // attempts.
202
203 // TRUE if we are running in the Emacs GUD mode.
205
206 // Codepage which is used to read .m files
207 std::string m_mfile_encoding;
208
209 // map of directories -> used mfile encoding
210 std::unordered_map<std::string, std::string> m_dir_encoding;
211
212 // TRUE means repeat last debug command if the user just types RET.
214
215 // If we are in debugging mode, this is the last command entered,
216 // so that we can repeat the previous command if the user just
217 // types RET.
219
221
223
224 std::string gnu_readline (const std::string& s, bool& eof) const;
225 };
226
228 {
229 public:
230
231 friend class input_reader;
232
234 : m_interpreter (interp)
235 { }
236
239 { }
240
241 virtual ~base_reader (void) = default;
242
243 virtual std::string get_input (const std::string& prompt, bool& eof) = 0;
244
245 virtual std::string input_source (void) const { return s_in_src; }
246
247 std::string octave_gets (const std::string& prompt, bool& eof);
248
249 virtual bool input_from_terminal (void) const { return false; }
250
251 virtual bool input_from_file (void) const { return false; }
252
253 virtual bool input_from_eval_string (void) const { return false; }
254
255 protected:
256
258
259 private:
260
261 static const std::string s_in_src;
262 };
263
265 {
266 public:
267
269
270 input_reader (interpreter& interp, FILE *file);
271
272 input_reader (interpreter& interp, FILE *file, const std::string& enc);
273
274 input_reader (interpreter& interp, const std::string& str);
275
276 input_reader (const input_reader& ir) = default;
277
278 input_reader& operator = (const input_reader& ir) = default;
279
280 ~input_reader (void) = default;
281
282 std::string get_input (const std::string& prompt, bool& eof)
283 {
284 return m_rep->get_input (prompt, eof);
285 }
286
287 std::string input_source (void) const
288 {
289 return m_rep->input_source ();
290 }
291
292 bool input_from_terminal (void) const
293 {
294 return m_rep->input_from_terminal ();
295 }
296
297 bool input_from_file (void) const
298 {
299 return m_rep->input_from_file ();
300 }
301
302 bool input_from_eval_string (void) const
303 {
304 return m_rep->input_from_eval_string ();
305 }
306
307 private:
308
309 std::shared_ptr<base_reader> m_rep;
310 };
311
312OCTAVE_NAMESPACE_END
313
314#endif
base_reader(const base_reader &x)
Definition: input.h:237
virtual std::string input_source(void) const
Definition: input.h:245
virtual bool input_from_eval_string(void) const
Definition: input.h:253
virtual bool input_from_terminal(void) const
Definition: input.h:249
std::string octave_gets(const std::string &prompt, bool &eof)
virtual ~base_reader(void)=default
base_reader(interpreter &interp)
Definition: input.h:233
virtual bool input_from_file(void) const
Definition: input.h:251
virtual std::string get_input(const std::string &prompt, bool &eof)=0
static const std::string s_in_src
Definition: input.h:261
interpreter & m_interpreter
Definition: input.h:257
bool input_from_terminal(void) const
Definition: input.h:292
input_reader(interpreter &interp, const std::string &str)
std::string get_input(const std::string &prompt, bool &eof)
Definition: input.h:282
input_reader(interpreter &interp, FILE *file)
std::string input_source(void) const
Definition: input.h:287
input_reader(const input_reader &ir)=default
bool input_from_eval_string(void) const
Definition: input.h:302
input_reader(interpreter &interp)
bool input_from_file(void) const
Definition: input.h:297
input_reader(interpreter &interp, FILE *file, const std::string &enc)
input_reader & operator=(const input_reader &ir)=default
std::shared_ptr< base_reader > m_rep
Definition: input.h:309
~input_reader(void)=default
bool remove_input_event_hook(const std::string &hook_fcn_id)
octave_value auto_repeat_debug_command(const octave_value_list &args, int nargout)
interpreter & m_interpreter
Definition: input.h:191
bool m_auto_repeat_debug_command
Definition: input.h:213
char completion_append_char(char c)
Definition: input.h:118
input_system(interpreter &interp)
Definition: input.cc:411
void initialize(bool line_editing)
Definition: input.cc:419
std::string PS1(const std::string &s)
Definition: input.h:76
std::string m_mfile_encoding
Definition: input.h:207
bool yes_or_no(const std::string &prompt)
std::string PS2(void) const
Definition: input.h:87
std::string m_PS1
Definition: input.h:194
std::string last_debugging_command(void) const
Definition: input.h:98
void set_gud_mode(bool flag)
Definition: input.h:138
bool have_input_event_hooks(void) const
std::string m_last_debugging_command
Definition: input.h:218
octave_value gud_mode(const octave_value_list &args, int nargout)
std::string PS2(const std::string &s)
Definition: input.h:89
void clear_input_event_hooks(void)
bool m_gud_mode
Definition: input.h:204
void set_completion_append_char(char c)
Definition: input.h:125
std::string mfile_encoding(const std::string &s)
Definition: input.h:144
void set_PS2(const std::string &s)
Definition: input.h:96
void add_input_event_hook(const hook_function &hook_fcn)
void run_input_event_hooks(void)
std::string PS1(void) const
Definition: input.h:74
void set_dir_encoding(const std::string &dir, std::string &enc)
bool m_initialized
Definition: input.h:222
octave_value completion_append_char(const octave_value_list &args, int nargout)
bool gud_mode(bool flag)
Definition: input.h:131
bool gud_mode(void) const
Definition: input.h:129
bool auto_repeat_debug_command(bool val)
Definition: input.h:165
std::string m_PS2
Definition: input.h:197
void set_PS1(const std::string &s)
Definition: input.h:83
octave_value_list get_user_input(const octave_value_list &args, int nargout)
std::string gnu_readline(const std::string &s, bool &eof) const
octave_value PS2(const octave_value_list &args, int nargout)
std::string dir_encoding(const std::string &dir)
hook_function_list m_input_event_hook_functions
Definition: input.h:220
std::string interactive_input(const std::string &s, bool &eof)
octave_value PS1(const octave_value_list &args, int nargout)
std::unordered_map< std::string, std::string > m_dir_encoding
Definition: input.h:210
void set_mfile_encoding(const std::string &s)
Definition: input.h:151
char m_completion_append_char
Definition: input.h:201
char completion_append_char(void) const
Definition: input.h:113
octave_value mfile_encoding(const octave_value_list &args, int nargout)
bool auto_repeat_debug_command(void) const
Definition: input.h:160
std::string last_debugging_command(const std::string &s)
Definition: input.h:103
std::string mfile_encoding(void) const
Definition: input.h:142
bool Vtrack_line_num
Definition: input.cc:95
OCTINTERP_API octave::sys::time Vlast_prompt_time
Definition: input.cc:83
OCTINTERP_API bool Vdrawnow_requested
Definition: input.cc:90
bool octave_completion_matches_called
Definition: input.cc:86
F77_RET_T const F77_DBLE * x