Mercurial > octave
annotate libinterp/corefcn/input.cc @ 26376:00f796120a6d stable
maint: Update copyright dates in all source files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 02 Jan 2019 16:32:43 -0500 |
parents | d527c6111425 |
children | cf9e10ce3351 6c25c714bec4 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
26358
diff
changeset
|
3 Copyright (C) 1993-2019 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
1 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
1 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
1 | 20 |
21 */ | |
22 | |
2939 | 23 // Get command input interactively or from files. |
1 | 24 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21547
diff
changeset
|
25 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
26 # include "config.h" |
1 | 27 #endif |
28 | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
29 #include <cstdio> |
1343 | 30 #include <cstdlib> |
31 #include <cstring> | |
32 #include <cassert> | |
33 | |
3503 | 34 #include <iostream> |
5765 | 35 #include <sstream> |
1728 | 36 #include <string> |
37 | |
2927 | 38 #include "cmd-edit.h" |
3189 | 39 #include "file-ops.h" |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
40 #include "iconv-wrappers.h" |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
41 #include "localcharset-wrapper.h" |
4153 | 42 #include "quit.h" |
1755 | 43 #include "str-vec.h" |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
44 #include "uniconv-wrappers.h" |
1755 | 45 |
23129
35e3d199527c
Replace feval calls with direct call to C++ function (bug #50116).
Rik <rik@octave.org>
parents:
23127
diff
changeset
|
46 #include "builtin-defun-decls.h" |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
22089
diff
changeset
|
47 #include "call-stack.h" |
1352 | 48 #include "defun.h" |
49 #include "dirfns.h" | |
1 | 50 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
51 #include "errwarn.h" |
3016 | 52 #include "help.h" |
16381
f33dcbd6a005
move hook_function classes to separate file
John W. Eaton <jwe@octave.org>
parents:
16378
diff
changeset
|
53 #include "hook-fcn.h" |
1 | 54 #include "input.h" |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
55 #include "interpreter-private.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
56 #include "interpreter.h" |
9999
653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
John W. Eaton <jwe@octave.org>
parents:
9485
diff
changeset
|
57 #include "lex.h" |
5832 | 58 #include "load-path.h" |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
59 #include "octave.h" |
16416
169f71c9d9c8
use octave_link instead of hook functions in input.cc
John W. Eaton <jwe@octave.org>
parents:
16395
diff
changeset
|
60 #include "octave-link.h" |
1352 | 61 #include "oct-map.h" |
1742 | 62 #include "oct-hist.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
63 #include "interpreter.h" |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
64 #include "octave-link.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
65 #include "ovl.h" |
16347
bf8397caeff1
allow add_input_event_hook to accept function handles
John W. Eaton <jwe@octave.org>
parents:
16336
diff
changeset
|
66 #include "ov-fcn-handle.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
67 #include "ov-usr-fcn.h" |
1 | 68 #include "pager.h" |
529 | 69 #include "parse.h" |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
70 #include "pt-eval.h" |
3805 | 71 #include "pt-stmt.h" |
1352 | 72 #include "sighandlers.h" |
1114 | 73 #include "sysdep.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
74 #include "interpreter.h" |
3098 | 75 #include "unwind-prot.h" |
1352 | 76 #include "utils.h" |
77 #include "variables.h" | |
529 | 78 |
3165 | 79 // The time we last printed a prompt. |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
80 octave::sys::time Vlast_prompt_time = 0.0; |
3165 | 81 |
3804 | 82 // TRUE after a call to completion_matches. |
2299 | 83 bool octave_completion_matches_called = false; |
84 | |
6257 | 85 // TRUE if the plotting system has requested a call to drawnow at |
86 // the next user prompt. | |
7409 | 87 bool Vdrawnow_requested = false; |
6257 | 88 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
89 // TRUE if we are in debugging mode. |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
90 bool Vdebugging = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
91 |
22164
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
92 // TRUE if we are recording line numbers in a source file. |
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
93 // Always true except when debugging and taking input directly from |
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
94 // the terminal. |
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
95 bool Vtrack_line_num = true; |
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
96 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
97 static std::string |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
98 quoting_filename (const std::string& text, int, char quote) |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
99 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
100 if (quote) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
101 return text; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
102 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
103 return ("'" + text); |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
104 } |
8841
c74389115610
auto repeat for debugging commands
John W. Eaton <jwe@octave.org>
parents:
8749
diff
changeset
|
105 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
106 // Try to parse a partial command line in reverse, excluding trailing TEXT. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
107 // If it appears a variable has been indexed by () or {}, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
108 // return that expression, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
109 // to allow autocomplete of field names of arrays of structures. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
110 static std::string |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
111 find_indexed_expression (const std::string& text) |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
112 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
113 std::string line = octave::command_editor::get_line_buffer (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
114 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
115 int pos = line.length () - text.length (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
116 int curly_count = 0; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
117 int paren_count = 0; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
118 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
119 int last = --pos; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
120 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
121 while (pos >= 0 && (line[pos] == ')' || line[pos] == '}')) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
122 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
123 if (line[pos] == ')') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
124 paren_count++; |
26358
d527c6111425
input.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26193
diff
changeset
|
125 else |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
126 curly_count++; |
7294 | 127 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
128 while (curly_count + paren_count > 0 && --pos >= 0) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
129 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
130 if (line[pos] == ')') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
131 paren_count++; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
132 else if (line[pos] == '(') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
133 paren_count--; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
134 else if (line[pos] == '}') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
135 curly_count++; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
136 else if (line[pos] == '{') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
137 curly_count--; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
138 } |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
139 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
140 while (--pos >= 0 && line[pos] == ' ') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
141 ; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
142 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
143 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
144 while (pos >= 0 && (isalnum (line[pos]) || line[pos] == '_')) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
145 pos--; |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
146 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
147 if (++pos >= 0) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
148 return (line.substr (pos, last + 1 - pos)); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
149 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
150 return std::string (); |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
151 } |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
152 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
153 static inline bool |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
154 is_variable (octave::symbol_table& symtab, const std::string& name) |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
155 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
156 bool retval = false; |
5142 | 157 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
158 if (! name.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
159 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
160 octave::symbol_scope scope = symtab.current_scope (); |
16097
2f4fa62089b3
improve end of file handling for lexer input
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
161 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
162 octave_value val = scope ? scope.varval (name) : octave_value (); |
19595
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19379
diff
changeset
|
163 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
164 retval = val.is_defined (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
165 } |
1822 | 166 |
167 return retval; | |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
168 } |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
169 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
170 static string_vector |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
171 generate_struct_completions (const std::string& text, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
172 std::string& prefix, std::string& hint) |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
173 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
174 string_vector names; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
175 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
176 size_t pos = text.rfind ('.'); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
177 bool array = false; |
6257 | 178 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
179 if (pos != std::string::npos) |
6257 | 180 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
181 if (pos == text.length ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
182 hint = ""; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
183 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
184 hint = text.substr (pos+1); |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
185 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
186 prefix = text.substr (0, pos); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
187 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
188 if (prefix == "") |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
189 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
190 array = true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
191 prefix = find_indexed_expression (text); |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
192 } |
6257 | 193 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
194 std::string base_name = prefix; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
195 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
196 pos = base_name.find_first_of ("{(. "); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
197 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
198 if (pos != std::string::npos) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
199 base_name = base_name.substr (0, pos); |
6367 | 200 |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
201 octave::interpreter& interp |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
202 = octave::__get_interpreter__ ("generate_struct_completions"); |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
203 |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
204 octave::symbol_table& symtab = interp.get_symbol_table (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
205 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
206 if (is_variable (symtab, base_name)) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
207 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
208 int parse_status; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
209 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
210 octave::unwind_protect frame; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
211 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
212 frame.protect_var (discard_error_messages); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
213 frame.protect_var (discard_warning_messages); |
6305 | 214 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
215 discard_error_messages = true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
216 discard_warning_messages = true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
217 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
218 try |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
219 { |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
220 octave_value tmp |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
221 = interp.eval_string (prefix, true, parse_status); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
222 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
223 frame.run (); |
6305 | 224 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
225 if (tmp.is_defined () |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
226 && (tmp.isstruct () || tmp.isjava () || tmp.is_classdef_object ())) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
227 names = tmp.map_keys (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
228 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
229 catch (const octave::execution_exception&) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
230 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
231 octave::interpreter::recover_from_exception (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
232 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
233 } |
6257 | 234 } |
235 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
236 // Undo look-back that found the array expression, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
237 // but insert an extra "." to distinguish from the non-struct case. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
238 if (array) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
239 prefix = "."; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
240 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
241 return names; |
6257 | 242 } |
18037
708173343c50
use "octave" instead of "\\s" in default prompt
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
243 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
244 // FIXME: this will have to be much smarter to work "correctly". |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
245 static bool |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
246 looks_like_struct (const std::string& text, char prev_char) |
1 | 247 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
248 bool retval = (! text.empty () |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
249 && (text != "." || prev_char == ')' || prev_char == '}') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
250 && text.find_first_of (octave::sys::file_ops::dir_sep_chars ()) == std::string::npos |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
251 && text.find ("..") == std::string::npos |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
252 && text.rfind ('.') != std::string::npos); |
581 | 253 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
254 return retval; |
1 | 255 } |
256 | |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
257 // FIXME: make this generate filenames when appropriate. |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
258 |
2247 | 259 static string_vector |
3523 | 260 generate_possible_completions (const std::string& text, std::string& prefix, |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
261 std::string& hint, bool& deemed_struct) |
1280 | 262 { |
2247 | 263 string_vector names; |
1280 | 264 |
2921 | 265 prefix = ""; |
1280 | 266 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
267 char prev_char = octave::command_editor::get_prev_char (text.length ()); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
268 deemed_struct = looks_like_struct (text, prev_char); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
269 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
270 if (deemed_struct) |
1430 | 271 names = generate_struct_completions (text, prefix, hint); |
272 else | |
23721
b2d55b52ee51
new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
273 names = octave::make_name_list (); |
1280 | 274 |
2944 | 275 // Sort and remove duplicates. |
2348 | 276 |
8503
8ba2ee57c594
remove qsort in favor of sort
Jaroslav Hajek <highegg@gmail.com>
parents:
8447
diff
changeset
|
277 names.sort (true); |
2348 | 278 |
1280 | 279 return names; |
280 } | |
281 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
282 static bool |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
283 is_completing_dirfns (void) |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
284 { |
25786
b102a94cc3b2
complete only file names for isfile and isfolder commands
Mike Miller <mtmiller@octave.org>
parents:
25700
diff
changeset
|
285 static std::string dirfns_commands[] = {"cd", "isfile", "isfolder", "ls"}; |
b102a94cc3b2
complete only file names for isfile and isfolder commands
Mike Miller <mtmiller@octave.org>
parents:
25700
diff
changeset
|
286 static const size_t dirfns_commands_length = 4; |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
287 |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
288 bool retval = false; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
289 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
290 std::string line = octave::command_editor::get_line_buffer (); |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
291 |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
292 for (size_t i = 0; i < dirfns_commands_length; i++) |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
293 { |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23805
diff
changeset
|
294 int index = line.find (dirfns_commands[i] + ' '); |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
295 |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
296 if (index == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
297 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
298 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
299 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
300 } |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
301 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
302 |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
303 return retval; |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
304 } |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
305 |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
306 static std::string |
3523 | 307 generate_completion (const std::string& text, int state) |
1822 | 308 { |
3523 | 309 std::string retval; |
2944 | 310 |
3523 | 311 static std::string prefix; |
312 static std::string hint; | |
1280 | 313 |
2921 | 314 static size_t hint_len = 0; |
1280 | 315 |
1 | 316 static int list_index = 0; |
2921 | 317 static int name_list_len = 0; |
4604 | 318 static int name_list_total_len = 0; |
2247 | 319 static string_vector name_list; |
4604 | 320 static string_vector file_name_list; |
1 | 321 |
1280 | 322 static int matches = 0; |
1 | 323 |
324 if (state == 0) | |
325 { | |
326 list_index = 0; | |
327 | |
2921 | 328 prefix = ""; |
1280 | 329 |
2921 | 330 hint = text; |
1280 | 331 |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
332 // No reason to display symbols while completing a |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
333 // file/directory operation. |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
334 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
335 bool deemed_struct = false; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
336 |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
337 if (is_completing_dirfns ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
338 name_list = string_vector (); |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
339 else |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
340 name_list = generate_possible_completions (text, prefix, hint, |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
341 deemed_struct); |
1280 | 342 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20178
diff
changeset
|
343 name_list_len = name_list.numel (); |
2921 | 344 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
345 // If the line was something like "a{1}." then text = "." but |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
346 // we don't want to expand all the . files. |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
347 if (! deemed_struct) |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
348 { |
4604 | 349 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
350 file_name_list = octave::command_editor::generate_filename_completions (text); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
351 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
352 name_list.append (file_name_list); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
353 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
354 } |
5142 | 355 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20178
diff
changeset
|
356 name_list_total_len = name_list.numel (); |
4604 | 357 |
2921 | 358 hint_len = hint.length (); |
1280 | 359 |
360 matches = 0; | |
2247 | 361 |
2921 | 362 for (int i = 0; i < name_list_len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
363 if (hint == name_list[i].substr (0, hint_len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
364 matches++; |
1 | 365 } |
366 | |
4604 | 367 if (name_list_total_len > 0 && matches > 0) |
1 | 368 { |
4604 | 369 while (list_index < name_list_total_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
370 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
371 std::string name = name_list[list_index]; |
2247 | 372 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
373 list_index++; |
16097
2f4fa62089b3
improve end of file handling for lexer input
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
374 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
375 if (hint == name.substr (0, hint_len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
376 { |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
377 // Special case: array reference forces prefix="." |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
378 // in generate_struct_completions () |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
379 if (list_index <= name_list_len && ! prefix.empty ()) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23805
diff
changeset
|
380 retval = (prefix == "." ? "" : prefix) + '.' + name; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
381 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
382 retval = name; |
1280 | 383 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
384 char prev_char = octave::command_editor::get_prev_char |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
385 (text.length ()); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
386 if (matches == 1 && looks_like_struct (retval, prev_char)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
387 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
388 // Don't append anything, since we don't know |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
389 // whether it should be '(' or '.'. |
19595
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19379
diff
changeset
|
390 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
391 octave::command_editor::set_completion_append_character ('\0'); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
392 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
393 else |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
394 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
395 octave::input_system& input_sys |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
396 = octave::__get_input_system__ ("generate_completion"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
397 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
398 octave::command_editor::set_completion_append_character |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
399 (input_sys.completion_append_char ()); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
400 } |
1280 | 401 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
402 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
403 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
404 } |
1 | 405 } |
1822 | 406 |
407 return retval; | |
408 } | |
581 | 409 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
410 namespace octave |
6257 | 411 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
412 // Use literal "octave" in default setting for PS1 instead of |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
413 // "\\s" to avoid setting the prompt to "octave.exe" or |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
414 // "octave-gui", etc. |
6257 | 415 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
416 input_system::input_system (interpreter& interp) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
417 : m_interpreter (interp), m_PS1 (R"(octave:\#> )"), m_PS2 ("> "), |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
418 m_completion_append_char (' '), m_gud_mode (false), |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
419 m_mfile_encoding ("utf-8"), m_last_debugging_command ("\n"), |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
420 m_input_event_hook_functions () |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
421 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
422 #if defined (OCTAVE_USE_WINDOWS_API) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
423 m_mfile_encoding = "system"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
424 #endif |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
425 } |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
426 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
427 void input_system::initialize (bool line_editing) |
6257 | 428 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
429 // Force default line editor if we don't want readline editing. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
430 if (! line_editing) |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
431 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
432 command_editor::force_default_editor (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
433 return; |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
434 } |
6257 | 435 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
436 // If we are using readline, this allows conditional parsing of the |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
437 // .inputrc file. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
438 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
439 octave::command_editor::set_name ("Octave"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
440 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
441 // FIXME: this needs to include a comma too, but that |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
442 // causes trouble for the new struct element completion code. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
443 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
444 static const char *s = "\t\n !\"\'*+-/:;<=>(){}[\\]^`~"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
445 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
446 octave::command_editor::set_basic_word_break_characters (s); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
447 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
448 octave::command_editor::set_completer_word_break_characters (s); |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
449 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
450 octave::command_editor::set_basic_quote_characters (R"(")"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
451 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
452 octave::command_editor::set_filename_quote_characters (" \t\n\\\"'@<>=;|&()#$`?*[!:{"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
453 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
454 octave::command_editor::set_completer_quote_characters (R"('")"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
455 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
456 octave::command_editor::set_completion_function (generate_completion); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
457 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
458 octave::command_editor::set_quoting_function (quoting_filename); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
459 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
460 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
461 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
462 input_system::PS1 (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
463 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
464 return set_internal_variable (m_PS1, args, nargout, "PS1"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
465 } |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
466 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
467 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
468 input_system::PS2 (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
469 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
470 return set_internal_variable (m_PS2, args, nargout, "PS2"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
471 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
472 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
473 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
474 input_system::completion_append_char (const octave_value_list& args, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
475 int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
476 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
477 return set_internal_variable (m_completion_append_char, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
478 "completion_append_char"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
479 } |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
480 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
481 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
482 input_system::gud_mode (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
483 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
484 return set_internal_variable (m_gud_mode, args, nargout, "__gud_mode__"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
485 } |
269 | 486 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
487 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
488 input_system::mfile_encoding (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
489 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
490 // Save current value in case there is an error in the additional |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
491 // validation below. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
492 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
493 std::string saved_encoding = m_mfile_encoding; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
494 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
495 // We must pass the actual variable to change here for temporary |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
496 // "local" settings to work properly. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
497 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
498 octave_value retval |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
499 = set_internal_variable (m_mfile_encoding, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
500 "__mfile_encoding__"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
501 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
502 // Additional validation if the encoding has changed. |
1358 | 503 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
504 if (m_mfile_encoding != saved_encoding) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
505 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
506 if (m_mfile_encoding.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
507 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
508 #if defined (OCTAVE_USE_WINDOWS_API) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
509 m_mfile_encoding = "system"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
510 #else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
511 m_mfile_encoding = "utf-8"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
512 #endif |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
513 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
514 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
515 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
516 std::transform (m_mfile_encoding.begin (), |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
517 m_mfile_encoding.end (), |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
518 m_mfile_encoding.begin (), ::tolower); |
3933 | 519 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
520 std::string codepage = (m_mfile_encoding.compare ("system") == 0) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
521 ? octave_locale_charset_wrapper () : m_mfile_encoding; |
3933 | 522 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
523 // Check for valid codepage. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
524 void *codec |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
525 = octave_iconv_open_wrapper (codepage.c_str (), "utf-8"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
526 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
527 if (errno == EINVAL) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
528 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
529 m_mfile_encoding = saved_encoding; |
3933 | 530 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
531 error ("__mfile_encoding__: conversion from codepage '%s' not supported", |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
532 codepage.c_str ()); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
533 } |
3933 | 534 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
535 octave_iconv_close_wrapper (codec); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
536 } |
25700
ba8227df92ae
synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents:
25659
diff
changeset
|
537 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
538 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
539 |
25700
ba8227df92ae
synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents:
25659
diff
changeset
|
540 // Synchronize the related gui preference for editor encoding |
ba8227df92ae
synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents:
25659
diff
changeset
|
541 octave::feval ("__octave_link_gui_preference__", |
ba8227df92ae
synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents:
25659
diff
changeset
|
542 ovl ("editor/default_encoding", m_mfile_encoding)); |
ba8227df92ae
synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents:
25659
diff
changeset
|
543 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
544 return retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
545 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
546 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
547 bool input_system::yes_or_no (const std::string& prompt) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
548 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
549 std::string prompt_string = prompt + "(yes or no) "; |
6367 | 550 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
551 while (1) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
552 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
553 bool eof = false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
554 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
555 std::string input_buf = interactive_input (prompt_string, eof); |
6979 | 556 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
557 if (input_buf == "yes") |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
558 return true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
559 else if (input_buf == "no") |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
560 return false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
561 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
562 message (nullptr, "Please answer yes or no."); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
563 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
564 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
565 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
566 std::string input_system::interactive_input (const std::string& s, bool& eof) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
567 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
568 Vlast_prompt_time.stamp (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
569 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
570 if (Vdrawnow_requested && octave::application::interactive ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
571 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
572 bool eval_error = false; |
6979 | 573 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
574 try |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
575 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
576 Fdrawnow (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
577 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
578 catch (const octave::execution_exception& e) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
579 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
580 eval_error = true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
581 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
582 std::string stack_trace = e.info (); |
269 | 583 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
584 if (! stack_trace.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
585 std::cerr << stack_trace; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
586 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
587 if (octave::application::interactive ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
588 octave::interpreter::recover_from_exception (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
589 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
590 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
591 octave::flush_stdout (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
592 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
593 // We set Vdrawnow_requested to false even if there is an error in |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
594 // drawnow so that the error doesn't reappear at every prompt. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
595 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
596 Vdrawnow_requested = false; |
16419
16bfbf9136d3
avoid creating unnecessary octave_value objects for octave_link calls
John W. Eaton <jwe@octave.org>
parents:
16416
diff
changeset
|
597 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
598 if (eval_error) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
599 return "\n"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
600 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
601 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
602 return gnu_readline (s, eof); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
603 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
604 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
605 // If the user simply hits return, this will produce an empty matrix. |
6305 | 606 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
607 octave_value_list |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
608 input_system::get_user_input (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
609 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
610 octave_value_list retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
611 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
612 int read_as_string = 0; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
613 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
614 if (args.length () == 2) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
615 read_as_string++; |
16395
fc491da603f6
also provide a hook for exiting debugger
John W. Eaton <jwe@octave.org>
parents:
16386
diff
changeset
|
616 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
617 std::string prompt = args(0).xstring_value ("input: unrecognized argument"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
618 |
25435
a52e6fb674b1
eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents:
25407
diff
changeset
|
619 output_system& output_sys = __get_output_system__ ("do_sync"); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
620 |
25435
a52e6fb674b1
eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents:
25407
diff
changeset
|
621 output_sys.reset (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
622 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
623 octave_diary << prompt; |
25402
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
624 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
625 bool eof = false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
626 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
627 std::string input_buf = interactive_input (prompt.c_str (), eof); |
19595
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19379
diff
changeset
|
628 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
629 if (input_buf.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
630 error ("input: reading user-input failed!"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
631 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
632 size_t len = input_buf.length (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
633 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
634 octave_diary << input_buf; |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
635 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
636 if (input_buf[len - 1] != '\n') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
637 octave_diary << "\n"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
638 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
639 if (read_as_string) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
640 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
641 // FIXME: fix gnu_readline and octave_gets instead! |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
642 if (input_buf.length () == 1 && input_buf[0] == '\n') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
643 retval(0) = ""; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
644 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
645 retval(0) = input_buf; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
646 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
647 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
648 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
649 int parse_status = 0; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
650 |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
651 retval |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
652 = m_interpreter.eval_string (input_buf, true, parse_status, nargout); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
653 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
654 if (! Vdebugging && retval.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
655 retval(0) = Matrix (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
656 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
657 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
658 return retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
659 } |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7758
diff
changeset
|
660 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
661 octave_value input_system::keyboard (const octave_value_list& args) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
662 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
663 octave_value retval; |
6305 | 664 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
665 int nargin = args.length (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
666 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
667 assert (nargin == 0 || nargin == 1); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
668 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
669 octave::unwind_protect frame; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
670 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
671 frame.add_fcn (octave::command_history::ignore_entries, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
672 octave::command_history::ignoring_entries ()); |
18595
a87bdd302b1b
set editor cursor on error line when debug_on_error is true (bug #41532)
John W. Eaton <jwe@octave.org>
parents:
18037
diff
changeset
|
673 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
674 octave::command_history::ignore_entries (false); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
675 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
676 frame.protect_var (Vdebugging); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
677 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
678 octave::call_stack& cs = m_interpreter.get_call_stack (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
679 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
680 frame.add_method (cs, &octave::call_stack::restore_frame, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
681 cs.current_frame ()); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
682 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
683 // FIXME: probably we just want to print one line, not the |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
684 // entire statement, which might span many lines... |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
685 // |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
686 // tree_print_code tpc (octave_stdout); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
687 // stmt.accept (tpc); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
688 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
689 Vdebugging = true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
690 Vtrack_line_num = false; |
3180 | 691 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
692 std::string prompt = "debug> "; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
693 if (nargin > 0) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
694 prompt = args(0).string_value (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
695 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
696 get_debug_input (prompt); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
697 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
698 return retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
699 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
700 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
701 bool input_system::have_input_event_hooks (void) const |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
702 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
703 return ! m_input_event_hook_functions.empty (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
704 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
705 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
706 void input_system::add_input_event_hook (const hook_function& hook_fcn) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
707 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
708 m_input_event_hook_functions.insert (hook_fcn.id (), hook_fcn); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
709 } |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7758
diff
changeset
|
710 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
711 bool input_system::remove_input_event_hook (const std::string& hook_fcn_id) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
712 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
713 hook_function_list::iterator p |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
714 = m_input_event_hook_functions.find (hook_fcn_id); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
715 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
716 if (p == m_input_event_hook_functions.end ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
717 return false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
718 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
719 m_input_event_hook_functions.erase (p); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
720 return true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
721 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
722 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
723 void input_system::clear_input_event_hooks (void) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
724 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
725 m_input_event_hook_functions.clear (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
726 } |
269 | 727 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
728 void input_system::run_input_event_hooks (void) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
729 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
730 m_input_event_hook_functions.run (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
731 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
732 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
733 std::string |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
734 input_system::gnu_readline (const std::string& s, bool& eof) const |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
735 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
736 octave_quit (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
737 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
738 eof = false; |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
739 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
740 std::string retval = octave::command_editor::readline (s, eof); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
741 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
742 if (! eof && retval.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
743 retval = "\n"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
744 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
745 return retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
746 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
747 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
748 static void |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
749 execute_in_debugger_handler (const std::pair<std::string, int>& arg) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
750 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
751 octave_link::execute_in_debugger_event (arg.first, arg.second); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
752 } |
1 | 753 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
754 void input_system::get_debug_input (const std::string& prompt) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
755 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
756 octave::unwind_protect frame; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
757 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
758 octave::tree_evaluator& tw = m_interpreter.get_evaluator (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
759 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
760 bool silent = tw.quiet_breakpoint_flag (false); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
761 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
762 octave::call_stack& cs = m_interpreter.get_call_stack (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
763 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
764 octave_user_code *caller = cs.caller_user_code (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
765 std::string nm; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
766 int curr_debug_line; |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
767 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
768 if (caller) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
769 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
770 nm = caller->fcn_file_name (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
771 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
772 if (nm.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
773 nm = caller->name (); |
16395
fc491da603f6
also provide a hook for exiting debugger
John W. Eaton <jwe@octave.org>
parents:
16386
diff
changeset
|
774 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
775 curr_debug_line = cs.caller_user_code_line (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
776 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
777 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
778 curr_debug_line = cs.current_line (); |
6257 | 779 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
780 std::ostringstream buf; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
781 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
782 if (! nm.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
783 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
784 if (m_gud_mode) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
785 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
786 static char ctrl_z = 'Z' & 0x1f; |
16374
8b0a04cbdc9d
provide hook function for dbstop events
John W. Eaton <jwe@octave.org>
parents:
16373
diff
changeset
|
787 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
788 buf << ctrl_z << ctrl_z << nm << ':' << curr_debug_line; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
789 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
790 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
791 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
792 // FIXME: we should come up with a clean way to detect |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
793 // that we are stopped on the no-op command that marks the |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
794 // end of a function or script. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
795 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
796 if (! silent) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
797 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
798 buf << "stopped in " << nm; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
799 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
800 if (curr_debug_line > 0) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
801 buf << " at line " << curr_debug_line; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
802 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
803 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
804 octave_link::enter_debugger_event (nm, curr_debug_line); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
805 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
806 octave_link::set_workspace (); |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
807 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
808 frame.add_fcn (execute_in_debugger_handler, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
809 std::pair<std::string, int> (nm, curr_debug_line)); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
810 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
811 if (! silent) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
812 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
813 std::string line_buf; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
814 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
815 if (caller) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
816 line_buf = caller->get_code_line (curr_debug_line); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
817 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
818 if (! line_buf.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
819 buf << "\n" << curr_debug_line << ": " << line_buf; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
820 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
821 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
822 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
823 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
824 if (silent) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
825 octave::command_editor::erase_empty_line (true); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
826 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
827 std::string msg = buf.str (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
828 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
829 if (! msg.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
830 std::cerr << msg << std::endl; |
3180 | 831 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
832 frame.add_method (*this, &octave::input_system::set_PS1, m_PS1); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
833 m_PS1 = prompt; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
834 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
835 // FIXME: should debugging be possible in an embedded interpreter? |
6257 | 836 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
837 octave::application *app = octave::application::app (); |
19595
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19379
diff
changeset
|
838 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
839 if (! app->interactive ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
840 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
841 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
842 frame.add_method (app, &octave::application::interactive, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
843 app->interactive ()); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
844 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
845 frame.add_method (app, &octave::application::forced_interactive, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
846 app->forced_interactive ()); |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7758
diff
changeset
|
847 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
848 app->interactive (true); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
849 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
850 app->forced_interactive (true); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
851 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
852 |
25441
143007dad864
store reference instead of pointer to interpreter in lexer
John W. Eaton <jwe@octave.org>
parents:
25435
diff
changeset
|
853 octave::parser curr_parser (m_interpreter); |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7758
diff
changeset
|
854 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
855 while (Vdebugging) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
856 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
857 try |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
858 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
859 Vtrack_line_num = false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
860 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
861 reset_error_handler (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
862 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
863 curr_parser.reset (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
864 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
865 int retval = curr_parser.run (); |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7758
diff
changeset
|
866 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
867 if (octave::command_editor::interrupt (false)) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
868 break; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
869 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
870 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
871 if (retval == 0 && curr_parser.m_stmt_list) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
872 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
873 curr_parser.m_stmt_list->accept (tw); |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
874 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
875 if (octave_completion_matches_called) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
876 octave_completion_matches_called = false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
877 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
878 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
879 octave_quit (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
880 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
881 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
882 catch (const octave::execution_exception& e) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
883 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
884 std::string stack_trace = e.info (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
885 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
886 if (! stack_trace.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
887 std::cerr << stack_trace; |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
888 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
889 // Ignore errors when in debugging mode; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
890 octave::interpreter::recover_from_exception (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
891 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
892 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
893 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
894 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
895 std::string base_reader::octave_gets (bool& eof) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
896 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
897 octave_quit (); |
5142 | 898 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
899 eof = false; |
16097
2f4fa62089b3
improve end of file handling for lexer input
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
900 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
901 std::string retval; |
1 | 902 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
903 // Process pre input event hook function prior to flushing output and |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
904 // printing the prompt. |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
905 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
906 if (application::interactive ()) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
907 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
908 if (! Vdebugging) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
909 octave_link::exit_debugger_event (); |
16438
a971d8bdaadc
use signals instead of event queue for entering/leaving debug mode
John W. Eaton <jwe@octave.org>
parents:
16433
diff
changeset
|
910 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
911 octave_link::pre_input_event (); |
16468
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
16438
diff
changeset
|
912 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
913 octave_link::set_workspace (); |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
914 } |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
915 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
916 bool history_skip_auto_repeated_debugging_command = false; |
8841
c74389115610
auto repeat for debugging commands
John W. Eaton <jwe@octave.org>
parents:
8749
diff
changeset
|
917 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
918 input_system& input_sys = __get_input_system__ ("base_reader::octave_gets"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
919 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
920 std::string ps = (m_pflag > 0) ? input_sys.PS1 () : input_sys.PS2 (); |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
921 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
922 std::string prompt = command_editor::decode_prompt_string (ps); |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
923 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
924 pipe_handler_error_count = 0; |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
925 |
25435
a52e6fb674b1
eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents:
25407
diff
changeset
|
926 output_system& output_sys = __get_output_system__ ("do_sync"); |
1755 | 927 |
25435
a52e6fb674b1
eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents:
25407
diff
changeset
|
928 output_sys.reset (); |
2618 | 929 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
930 octave_diary << prompt; |
1 | 931 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
932 retval = input_sys.interactive_input (prompt, eof); |
581 | 933 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
934 // There is no need to update the load_path cache if there is no |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
935 // user input. |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
936 if (retval != "\n" |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
937 && retval.find_first_not_of (" \t\n\r") != std::string::npos) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
938 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
939 load_path& lp = __get_load_path__ ("base_reader::octave_gets"); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
940 |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
941 lp.update (); |
8841
c74389115610
auto repeat for debugging commands
John W. Eaton <jwe@octave.org>
parents:
8749
diff
changeset
|
942 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
943 if (Vdebugging) |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
944 input_sys.last_debugging_command (retval); |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
945 else |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
946 input_sys.last_debugging_command ("\n"); |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
947 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
948 else if (Vdebugging) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
949 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
950 retval = input_sys.last_debugging_command (); |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
951 history_skip_auto_repeated_debugging_command = true; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
952 } |
1 | 953 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
954 if (retval != "\n") |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
955 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
956 if (! history_skip_auto_repeated_debugging_command) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
957 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
958 if (command_history::add (retval)) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
959 octave_link::append_history (retval); |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
960 } |
1 | 961 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
962 octave_diary << retval; |
3176 | 963 |
26061
cb3ead3cf859
avoid assertion failure with -D_GLIBCXX_ASSERTIONS
Orion Poplawski <orion@cora.nwra.com>
parents:
25054
diff
changeset
|
964 if (! retval.empty () && retval.back () != '\n') |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
965 octave_diary << "\n"; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
966 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
967 else |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
968 octave_diary << "\n"; |
581 | 969 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
970 // Process post input event hook function after the internal history |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
971 // list has been updated. |
9476 | 972 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
973 if (application::interactive ()) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
974 octave_link::post_input_event (); |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
975 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
976 return retval; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
977 } |
1 | 978 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
979 bool base_reader::reading_fcn_file (void) const |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
980 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
981 return m_lexer ? m_lexer->m_reading_fcn_file : false; |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
982 } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
983 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
984 bool base_reader::reading_classdef_file (void) const |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
985 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
986 return m_lexer ? m_lexer->m_reading_classdef_file : false; |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
987 } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
988 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
989 bool base_reader::reading_script_file (void) const |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
990 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
991 return m_lexer ? m_lexer->m_reading_script_file : false; |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
992 } |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
993 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
994 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
995 terminal_reader : public base_reader |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
996 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
997 public: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
998 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
999 terminal_reader (base_lexer *lxr = nullptr) |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1000 : base_reader (lxr) |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1001 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1002 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1003 std::string get_input (bool& eof); |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1004 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1005 std::string input_source (void) const { return s_in_src; } |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1006 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1007 bool input_from_terminal (void) const { return true; } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1008 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1009 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1010 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1011 static const std::string s_in_src; |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1012 }; |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1013 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1014 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1015 file_reader : public base_reader |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1016 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1017 public: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1018 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1019 file_reader (FILE *f_arg, base_lexer *lxr = nullptr) |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1020 : base_reader (lxr), m_file (f_arg) { } |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1021 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1022 std::string get_input (bool& eof); |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1023 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1024 std::string input_source (void) const { return s_in_src; } |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1025 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1026 bool input_from_file (void) const { return true; } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1027 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1028 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1029 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1030 FILE *m_file; |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1031 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1032 static const std::string s_in_src; |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1033 }; |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1034 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1035 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1036 eval_string_reader : public base_reader |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1037 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1038 public: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1039 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1040 eval_string_reader (const std::string& str, base_lexer *lxr = nullptr) |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1041 : base_reader (lxr), m_eval_string (str) |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1042 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1043 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1044 std::string get_input (bool& eof); |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1045 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1046 std::string input_source (void) const { return s_in_src; } |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1047 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1048 bool input_from_eval_string (void) const { return true; } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1049 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1050 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1051 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1052 std::string m_eval_string; |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1053 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1054 static const std::string s_in_src; |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1055 }; |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1056 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1057 input_reader::input_reader (base_lexer *lxr) |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1058 : m_rep (new terminal_reader (lxr)) |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1059 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1060 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1061 input_reader::input_reader (FILE *file, base_lexer *lxr) |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1062 : m_rep (new file_reader (file, lxr)) |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1063 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1064 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1065 input_reader::input_reader (const std::string& str, base_lexer *lxr) |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1066 : m_rep (new eval_string_reader (str, lxr)) |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1067 { } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
1068 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1069 const std::string base_reader::s_in_src ("invalid"); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1070 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1071 const std::string terminal_reader::s_in_src ("terminal"); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1072 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1073 std::string |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1074 terminal_reader::get_input (bool& eof) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1075 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1076 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1077 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1078 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1079 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1080 return octave_gets (eof); |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1081 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1082 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1083 const std::string file_reader::s_in_src ("file"); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1084 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1085 std::string |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1086 file_reader::get_input (bool& eof) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1087 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1088 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1089 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1090 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1091 |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1092 std::string src_str = octave_fgets (m_file, eof); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1093 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1094 octave::input_system& input_sys |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1095 = octave::__get_input_system__ ("get_input"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1096 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1097 std::string mfile_encoding = input_sys.mfile_encoding (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1098 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1099 std::string encoding |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1100 = (mfile_encoding.compare ("system") == 0 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1101 ? octave_locale_charset_wrapper () : mfile_encoding); |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1102 |
25620
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1103 if (encoding.compare ("utf-8") == 0) |
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1104 { |
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1105 // Check for BOM and strip it |
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1106 if (src_str.compare (0, 3, "\xef\xbb\xbf") == 0) |
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1107 src_str.erase (0, 3); |
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1108 } |
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1109 else |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1110 { |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1111 // convert encoding to UTF-8 before returning string |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1112 const char *src = src_str.c_str (); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1113 size_t srclen = src_str.length (); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1114 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1115 size_t length; |
26358
d527c6111425
input.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26193
diff
changeset
|
1116 uint8_t *utf8_str; |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1117 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1118 utf8_str = octave_u8_conv_from_encoding (encoding.c_str (), src, srclen, |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1119 &length); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1120 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1121 if (! utf8_str) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1122 error ("file_reader::get_input: converting from codepage '%s' to UTF-8: %s", |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1123 encoding.c_str (), std::strerror (errno)); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1124 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1125 octave::unwind_protect frame; |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1126 frame.add_fcn (::free, static_cast<void *> (utf8_str)); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1127 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1128 src_str = std::string (reinterpret_cast<char *> (utf8_str), length); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1129 } |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1130 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1131 return src_str; |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1132 } |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1133 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1134 const std::string eval_string_reader::s_in_src ("eval_string"); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1135 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1136 std::string |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1137 eval_string_reader::get_input (bool& eof) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1138 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1139 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1140 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1141 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1142 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1143 std::string retval; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1144 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1145 retval = m_eval_string; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1146 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1147 // Clear the eval string so that the next call will return |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1148 // an empty character string with EOF = true. |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1149 m_eval_string = ""; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1150 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1151 if (retval.empty ()) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1152 eof = true; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1153 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1154 return retval; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1155 } |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1156 } |
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1157 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1158 DEFMETHOD (input, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1159 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1160 @deftypefn {} {@var{ans} =} input (@var{prompt}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1161 @deftypefnx {} {@var{ans} =} input (@var{prompt}, "s") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1162 Print @var{prompt} and wait for user input. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1163 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1164 For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1165 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1166 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1167 input ("Pick a number, any number! ") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1168 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1169 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1170 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1171 prints the prompt |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1172 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1173 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1174 Pick a number, any number! |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1175 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1176 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1177 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1178 and waits for the user to enter a value. The string entered by the user |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1179 is evaluated as an expression, so it may be a literal constant, a variable |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1180 name, or any other valid Octave code. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1181 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1182 The number of return arguments, their size, and their class depend on the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1183 expression entered. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1184 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1185 If you are only interested in getting a literal string value, you can call |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1186 @code{input} with the character string @qcode{"s"} as the second argument. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1187 This tells Octave to return the string entered by the user directly, without |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1188 evaluating it first. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1189 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1190 Because there may be output waiting to be displayed by the pager, it is a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1191 good idea to always call @code{fflush (stdout)} before calling @code{input}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1192 This will ensure that all pending output is written to the screen before |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1193 your prompt. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1194 @seealso{yes_or_no, kbhit, pause, menu, listdlg} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1195 @end deftypefn */) |
529 | 1196 { |
1197 int nargin = args.length (); | |
1198 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1199 if (nargin < 1 || nargin > 2) |
5823 | 1200 print_usage (); |
529 | 1201 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1202 octave::input_system& input_sys = interp.get_input_system (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1203 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1204 return input_sys.get_user_input (args, std::max (nargout, 1)); |
529 | 1205 } |
1206 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1207 DEFMETHOD (yes_or_no, interp, args, , |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1208 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1209 @deftypefn {} {@var{ans} =} yes_or_no ("@var{prompt}") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1210 Ask the user a yes-or-no question. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1211 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1212 Return logical true if the answer is yes or false if the answer is no. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1213 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1214 Takes one argument, @var{prompt}, which is the string to display when asking |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1215 the question. @var{prompt} should end in a space; @code{yes-or-no} adds the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1216 string @samp{(yes or no) } to it. The user must confirm the answer with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1217 @key{RET} and can edit it until it has been confirmed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1218 @seealso{input} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1219 @end deftypefn */) |
5640 | 1220 { |
1221 int nargin = args.length (); | |
1222 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1223 if (nargin > 1) |
5823 | 1224 print_usage (); |
5640 | 1225 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1226 octave::input_system& input_sys = interp.get_input_system (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1227 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1228 std::string prompt; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1229 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1230 if (nargin == 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1231 prompt = args(0).xstring_value ("yes_or_no: PROMPT must be a string"); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1232 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1233 return ovl (input_sys.yes_or_no (prompt)); |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1234 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1235 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1236 DEFMETHOD (keyboard, interp, args, , |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1237 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1238 @deftypefn {} {} keyboard () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1239 @deftypefnx {} {} keyboard ("@var{prompt}") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1240 Stop m-file execution and enter debug mode. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1241 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1242 When the @code{keyboard} function is executed, Octave prints a prompt and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1243 waits for user input. The input strings are then evaluated and the results |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1244 are printed. This makes it possible to examine the values of variables |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1245 within a function, and to assign new values if necessary. To leave the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1246 prompt and return to normal execution type @samp{return} or @samp{dbcont}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1247 The @code{keyboard} function does not return an exit status. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1248 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1249 If @code{keyboard} is invoked without arguments, a default prompt of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1250 @samp{debug> } is used. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1251 @seealso{dbstop, dbcont, dbquit} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1252 @end deftypefn */) |
529 | 1253 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
1254 if (args.length () > 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1255 print_usage (); |
10186
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1256 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
1257 octave::unwind_protect frame; |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9482
diff
changeset
|
1258 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1259 octave::call_stack& cs = interp.get_call_stack (); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1260 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1261 frame.add_method (cs, &octave::call_stack::restore_frame, |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1262 cs.current_frame ()); |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9482
diff
changeset
|
1263 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1264 // Skip the frame assigned to the keyboard function. |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1265 cs.goto_frame_relative (0); |
10186
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1266 |
25402
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
1267 octave::tree_evaluator& tw = interp.get_evaluator (); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1268 |
25402
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
1269 tw.debug_mode (true); |
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
1270 tw.quiet_breakpoint_flag (false); |
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
1271 tw.current_frame (cs.current_frame ()); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1272 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1273 octave::input_system& input_sys = interp.get_input_system (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1274 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1275 input_sys.keyboard (args); |
529 | 1276 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1277 return ovl (); |
529 | 1278 } |
1279 | |
2234 | 1280 DEFUN (completion_matches, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1281 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1282 @deftypefn {} {} completion_matches (@var{hint}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1283 Generate possible completions given @var{hint}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1284 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1285 This function is provided for the benefit of programs like Emacs which |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1286 might be controlling Octave and handling user input. The current |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1287 command number is not incremented when this function is called. This is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1288 a feature, not a bug. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1289 @end deftypefn */) |
2234 | 1290 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
1291 if (args.length () != 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1292 print_usage (); |
2234 | 1293 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1294 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1295 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1296 std::string hint = args(0).string_value (); |
2234 | 1297 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1298 int n = 32; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1299 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1300 string_vector list (n); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1301 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1302 int k = 0; |
2234 | 1303 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1304 for (;;) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1305 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1306 std::string cmd = generate_completion (hint, k); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1307 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1308 if (! cmd.empty ()) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1309 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1310 if (k == n) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
1311 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1312 n *= 2; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1313 list.resize (n); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
1314 } |
2234 | 1315 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1316 list[k++] = cmd; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1317 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1318 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1319 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1320 list.resize (k); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1321 break; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1322 } |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1323 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1324 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1325 if (nargout > 0) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1326 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1327 if (! list.empty ()) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1328 retval = list; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1329 else |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1330 retval = ""; |
2234 | 1331 } |
1332 else | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1333 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1334 // We don't use string_vector::list_in_columns here |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1335 // because it will be easier for Emacs if the names |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1336 // appear in a single column. |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1337 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1338 int len = list.numel (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1339 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1340 for (int i = 0; i < len; i++) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1341 octave_stdout << list[i] << "\n"; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1342 } |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1343 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1344 octave_completion_matches_called = true; |
2234 | 1345 |
1346 return retval; | |
1347 } | |
1348 | |
20239
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1349 /* |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1350 %!assert (ischar (completion_matches (""))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1351 %!assert (ischar (completion_matches ("a"))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1352 %!assert (ischar (completion_matches (" "))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1353 %!assert (isempty (completion_matches (" "))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1354 %!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("")))))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1355 %!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("a")))))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1356 %!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("ab")))))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1357 %!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("abs")))))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1358 %!assert (! any (strcmp ("abs", deblank (cellstr (completion_matches ("absa")))))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1359 |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1360 %!error completion_matches () |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1361 %!error completion_matches (1, 2) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1362 */ |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1363 |
16879
cc3743a91652
Rename read_readline_init_file to readline_read_init_file.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1364 DEFUN (readline_read_init_file, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1365 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1366 @deftypefn {} {} readline_read_init_file (@var{file}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1367 Read the readline library initialization file @var{file}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1368 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1369 If @var{file} is omitted, read the default initialization file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1370 (normally @file{~/.inputrc}). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1371 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1372 @xref{Readline Init File, , , readline, GNU Readline Library}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1373 for details. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1374 @seealso{readline_re_read_init_file} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1375 @end deftypefn */) |
3189 | 1376 { |
1377 int nargin = args.length (); | |
1378 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1379 if (nargin > 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1380 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1381 |
3189 | 1382 if (nargin == 0) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1383 octave::command_editor::read_init_file (); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1384 else |
3189 | 1385 { |
5872 | 1386 std::string file = args(0).string_value (); |
3189 | 1387 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1388 octave::command_editor::read_init_file (file); |
3189 | 1389 } |
1390 | |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1391 return ovl (); |
3189 | 1392 } |
1393 | |
16880
1aebb613a5ac
Rename re_read_readline_init_file to readline_re_read_init_file.
Rik <rik@octave.org>
parents:
16879
diff
changeset
|
1394 DEFUN (readline_re_read_init_file, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1395 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1396 @deftypefn {} {} readline_re_read_init_file () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1397 Re-read the last readline library initialization file that was read. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1398 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1399 @xref{Readline Init File, , , readline, GNU Readline Library}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1400 for details. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1401 @seealso{readline_read_init_file} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1402 @end deftypefn */) |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1403 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1404 if (args.length () != 0) |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1405 print_usage (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1406 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1407 octave::command_editor::re_read_init_file (); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1408 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1409 return ovl (); |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1410 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1411 |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1412 static int |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1413 internal_input_event_hook_fcn (void) |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1414 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1415 octave::input_system& input_sys |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1416 = octave::__get_input_system__ ("internal_input_event_hook_fcn"); |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1417 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1418 input_sys.run_input_event_hooks (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1419 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1420 if (! input_sys.have_input_event_hooks ()) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1421 octave::command_editor::remove_event_hook (internal_input_event_hook_fcn); |
16152
c48847a781d5
* input.cc (input_event_hook): Return 0.
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
1422 |
c48847a781d5
* input.cc (input_event_hook): Return 0.
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
1423 return 0; |
3498 | 1424 } |
1425 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1426 DEFMETHOD (add_input_event_hook, interp, args, , |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1427 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1428 @deftypefn {} {@var{id} =} add_input_event_hook (@var{fcn}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1429 @deftypefnx {} {@var{id} =} add_input_event_hook (@var{fcn}, @var{data}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1430 Add the named function or function handle @var{fcn} to the list of functions |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1431 to call periodically when Octave is waiting for input. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1432 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1433 The function should have the form |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1434 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1435 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1436 @var{fcn} (@var{data}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1437 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1438 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1439 If @var{data} is omitted, Octave calls the function without any arguments. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1440 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1441 The returned identifier may be used to remove the function handle from the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1442 list of input hook functions. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1443 @seealso{remove_input_event_hook} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1444 @end deftypefn */) |
3498 | 1445 { |
1446 int nargin = args.length (); | |
1447 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1448 if (nargin < 1 || nargin > 2) |
9215
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1449 print_usage (); |
3498 | 1450 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1451 octave_value user_data; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1452 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1453 if (nargin == 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1454 user_data = args(1); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1455 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1456 octave::input_system& input_sys = interp.get_input_system (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1457 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1458 hook_function hook_fcn (args(0), user_data); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1459 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1460 if (! input_sys.have_input_event_hooks ()) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1461 octave::command_editor::add_event_hook (internal_input_event_hook_fcn); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1462 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1463 input_sys.add_input_event_hook (hook_fcn); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1464 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1465 return ovl (hook_fcn.id ()); |
9215
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1466 } |
3498 | 1467 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1468 DEFMETHOD (remove_input_event_hook, interp, args, , |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1469 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1470 @deftypefn {} {} remove_input_event_hook (@var{name}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1471 @deftypefnx {} {} remove_input_event_hook (@var{fcn_id}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1472 Remove the named function or function handle with the given identifier |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1473 from the list of functions to call periodically when Octave is waiting |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1474 for input. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1475 @seealso{add_input_event_hook} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1476 @end deftypefn */) |
9215
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1477 { |
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1478 int nargin = args.length (); |
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1479 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1480 if (nargin < 1 || nargin > 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1481 print_usage (); |
16347
bf8397caeff1
allow add_input_event_hook to accept function handles
John W. Eaton <jwe@octave.org>
parents:
16336
diff
changeset
|
1482 |
26358
d527c6111425
input.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26193
diff
changeset
|
1483 std::string hook_fcn_id = args(0).xstring_value ("remove_input_event_hook: argument not valid as a hook function name or id"); |
3498 | 1484 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1485 bool warn = (nargin < 2); |
3498 | 1486 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1487 octave::input_system& input_sys = interp.get_input_system (); |
3498 | 1488 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1489 if (! input_sys.remove_input_event_hook (hook_fcn_id) && warn) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1490 warning ("remove_input_event_hook: %s not found in list", |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1491 hook_fcn_id.c_str ()); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1492 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1493 if (! input_sys.have_input_event_hooks ()) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1494 octave::command_editor::remove_event_hook (internal_input_event_hook_fcn); |
3498 | 1495 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1496 return ovl (); |
3498 | 1497 } |
1498 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1499 DEFMETHOD (PS1, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1500 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1501 @deftypefn {} {@var{val} =} PS1 () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1502 @deftypefnx {} {@var{old_val} =} PS1 (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1503 @deftypefnx {} {} PS1 (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1504 Query or set the primary prompt string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1505 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1506 When executing interactively, Octave displays the primary prompt when it is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1507 ready to read a command. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1508 |
24595
5ed2e9248ee9
doc: Tweaks to use single quotes instead of double quotes (bug #52870).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
1509 The default value of the primary prompt string is @qcode{'octave:\#> '}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1510 To change it, use a command like |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1511 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1512 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1513 PS1 ("\\u@@\\H> ") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1514 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1515 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1516 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1517 which will result in the prompt @samp{boris@@kremvax> } for the user |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1518 @samp{boris} logged in on the host @samp{kremvax.kgb.su}. Note that two |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1519 backslashes are required to enter a backslash into a double-quoted |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1520 character string. @xref{Strings}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1521 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1522 You can also use ANSI escape sequences if your terminal supports them. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1523 This can be useful for coloring the prompt. For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1524 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1525 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1526 PS1 ('\[\033[01;31m\]\s:\#> \[\033[0m\]') |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1527 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1528 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1529 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1530 will give the default Octave prompt a red coloring. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1531 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1532 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1533 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1534 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1535 @seealso{PS2, PS4} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1536 @end deftypefn */) |
5794 | 1537 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1538 octave::input_system& input_sys = interp.get_input_system (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1539 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1540 return input_sys.PS1 (args, nargout); |
5794 | 1541 } |
2181 | 1542 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1543 DEFMETHOD (PS2, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1544 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1545 @deftypefn {} {@var{val} =} PS2 () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1546 @deftypefnx {} {@var{old_val} =} PS2 (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1547 @deftypefnx {} {} PS2 (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1548 Query or set the secondary prompt string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1549 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1550 The secondary prompt is printed when Octave is expecting additional input to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1551 complete a command. For example, if you are typing a @code{for} loop that |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1552 spans several lines, Octave will print the secondary prompt at the beginning |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1553 of each line after the first. The default value of the secondary prompt |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1554 string is @qcode{"> "}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1555 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1556 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1557 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1558 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1559 @seealso{PS1, PS4} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1560 @end deftypefn */) |
5794 | 1561 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1562 octave::input_system& input_sys = interp.get_input_system (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1563 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1564 return input_sys.PS2 (args, nargout); |
5794 | 1565 } |
2181 | 1566 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1567 DEFMETHOD (completion_append_char, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1568 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1569 @deftypefn {} {@var{val} =} completion_append_char () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1570 @deftypefnx {} {@var{old_val} =} completion_append_char (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1571 @deftypefnx {} {} completion_append_char (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1572 Query or set the internal character variable that is appended to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1573 successful command-line completion attempts. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1574 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1575 The default value is @qcode{" "} (a single space). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1576 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1577 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1578 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1579 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1580 @end deftypefn */) |
5794 | 1581 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1582 octave::input_system& input_sys = interp.get_input_system (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1583 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1584 return input_sys.completion_append_char (args, nargout); |
5794 | 1585 } |
3019 | 1586 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1587 DEFMETHOD (__request_drawnow__, , args, , |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1588 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1589 @deftypefn {} {} __request_drawnow__ () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1590 @deftypefnx {} {} __request_drawnow__ (@var{flag}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1591 Undocumented internal function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1592 @end deftypefn */) |
6257 | 1593 { |
1594 int nargin = args.length (); | |
1595 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1596 if (nargin > 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1597 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1598 |
6257 | 1599 if (nargin == 0) |
1600 Vdrawnow_requested = true; | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1601 else |
6257 | 1602 Vdrawnow_requested = args(0).bool_value (); |
1603 | |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1604 return ovl (); |
6257 | 1605 } |
1606 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1607 DEFMETHOD (__gud_mode__, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1608 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1609 @deftypefn {} {} __gud_mode__ () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1610 Undocumented internal function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1611 @end deftypefn */) |
7294 | 1612 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1613 octave::input_system& input_sys = interp.get_input_system (); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1614 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1615 return input_sys.gud_mode (args, nargout); |
7294 | 1616 } |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1617 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1618 DEFMETHOD (__mfile_encoding__, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1619 doc: /* -*- texinfo -*- |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1620 @deftypefn {} {@var{current_encoding} =} __mfile_encoding__ (@var{new_encoding}) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1621 Set and query the codepage that is used for reading .m files. |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1622 @end deftypefn */) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1623 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1624 octave::input_system& input_sys = interp.get_input_system (); |
7294 | 1625 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1626 return input_sys.mfile_encoding (args, nargout); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1627 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1628 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1629 // Always define these functions. The macro is intended to allow the |
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1630 // declarations to be hidden, not so that Octave will not provide the |
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1631 // functions if they are requested. |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1632 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1633 // #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1634 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1635 bool |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1636 octave_yes_or_no (const std::string& prompt) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1637 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1638 octave::input_system& input_sys |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1639 = octave::__get_input_system__ ("set_default_prompts"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1640 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1641 return input_sys.yes_or_no (prompt); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1642 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1643 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1644 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1645 do_keyboard (const octave_value_list& args) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1646 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1647 octave::input_system& input_sys |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1648 = octave::__get_input_system__ ("do_keyboard"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1649 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1650 return input_sys.keyboard (args); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1651 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1652 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1653 void |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1654 remove_input_event_hook_functions (void) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1655 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1656 octave::input_system& input_sys |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1657 = octave::__get_input_system__ ("remove_input_event_hook_functions"); |
7294 | 1658 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1659 input_sys.clear_input_event_hooks (); |
7294 | 1660 } |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1661 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1662 // Fix things up so that input can come from the standard input. This |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1663 // may need to become much more complicated, which is why it's in a |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1664 // separate function. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1665 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1666 FILE * |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1667 get_input_from_stdin (void) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1668 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1669 octave::command_editor::set_input_stream (stdin); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1670 return octave::command_editor::get_input_stream (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1671 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1672 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1673 // #endif |