Mercurial > octave
annotate libinterp/corefcn/input.cc @ 26193:9aff537a5704
* input.cc (looks_like_struct): Delete obsolete commented code.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 10 Dec 2018 16:33:48 -0500 |
parents | 8a15f3bace49 |
children | d527c6111425 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25034
diff
changeset
|
3 Copyright (C) 1993-2018 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++; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
125 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
|
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 (len < 1) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
640 return read_as_string ? octave_value ("") : octave_value (Matrix ()); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
641 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
642 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
|
643 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
644 // 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
|
645 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
|
646 retval(0) = ""; |
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 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
|
649 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
650 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
651 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
652 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
|
653 |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
654 retval |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
655 = 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
|
656 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
657 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
|
658 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
|
659 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
660 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
661 return retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
662 } |
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
|
663 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
664 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
|
665 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
666 octave_value retval; |
6305 | 667 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
668 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
|
669 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
670 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
|
671 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
672 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
|
673 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
674 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
|
675 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
|
676 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
677 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
|
678 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
679 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
|
680 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
681 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
|
682 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
683 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
|
684 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
|
685 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
686 // 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
|
687 // 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
|
688 // |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
689 // 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
|
690 // 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
|
691 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
692 Vdebugging = true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
693 Vtrack_line_num = false; |
3180 | 694 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
695 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
|
696 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
|
697 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
|
698 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
699 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
|
700 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
701 return retval; |
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 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
704 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
|
705 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
706 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
|
707 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
708 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
709 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
|
710 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
711 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
|
712 } |
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
|
713 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
714 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
|
715 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
716 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
|
717 = 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
|
718 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
719 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
|
720 return false; |
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 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
|
723 return true; |
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 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
726 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
|
727 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
728 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
|
729 } |
269 | 730 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
731 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
|
732 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
733 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
|
734 } |
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 std::string |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
737 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
|
738 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
739 octave_quit (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
740 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
741 eof = false; |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
742 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
743 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
|
744 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
745 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
|
746 retval = "\n"; |
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 return retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
749 } |
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 static void |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
752 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
|
753 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
754 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
|
755 } |
1 | 756 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
757 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
|
758 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
759 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
|
760 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
761 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
|
762 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
763 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
|
764 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
765 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
|
766 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
767 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
|
768 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
|
769 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
|
770 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
771 if (caller) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
772 { |
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->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
|
774 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
775 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
|
776 nm = caller->name (); |
16395
fc491da603f6
also provide a hook for exiting debugger
John W. Eaton <jwe@octave.org>
parents:
16386
diff
changeset
|
777 |
25407
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.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
|
779 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
780 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
781 curr_debug_line = cs.current_line (); |
6257 | 782 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
783 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
|
784 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
785 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
|
786 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
787 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
|
788 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
789 static char ctrl_z = 'Z' & 0x1f; |
16374
8b0a04cbdc9d
provide hook function for dbstop events
John W. Eaton <jwe@octave.org>
parents:
16373
diff
changeset
|
790 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
791 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
|
792 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
793 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
794 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
795 // 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
|
796 // 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
|
797 // 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
|
798 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
799 if (! silent) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
800 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
801 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
|
802 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
803 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
|
804 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
|
805 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
806 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
807 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
|
808 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
809 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
|
810 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
811 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
|
812 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
|
813 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
814 if (! silent) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
815 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
816 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
|
817 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
818 if (caller) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
819 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
|
820 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
821 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
|
822 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
|
823 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
824 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
825 } |
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 if (silent) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
828 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
|
829 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
830 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
|
831 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
832 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
|
833 std::cerr << msg << std::endl; |
3180 | 834 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
835 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
|
836 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
|
837 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
838 // FIXME: should debugging be possible in an embedded interpreter? |
6257 | 839 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
840 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
|
841 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
842 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
|
843 { |
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::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->interactive ()); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
847 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
848 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
|
849 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
|
850 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
851 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
|
852 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
853 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
|
854 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
855 |
25441
143007dad864
store reference instead of pointer to interpreter in lexer
John W. Eaton <jwe@octave.org>
parents:
25435
diff
changeset
|
856 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
|
857 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
858 while (Vdebugging) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
859 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
860 try |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
861 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
862 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
|
863 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
864 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
|
865 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
866 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
|
867 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
868 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
|
869 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
870 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
|
871 break; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
872 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
873 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
874 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
|
875 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
876 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
|
877 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
878 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
|
879 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
|
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 octave_quit (); |
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 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
885 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
|
886 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
887 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
|
888 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
889 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
|
890 std::cerr << stack_trace; |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
891 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
892 // 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
|
893 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
|
894 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
895 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
896 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
897 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
898 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
|
899 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
900 octave_quit (); |
5142 | 901 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
902 eof = false; |
16097
2f4fa62089b3
improve end of file handling for lexer input
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
903 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
904 std::string retval; |
1 | 905 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
906 // 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
|
907 // printing the prompt. |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
908 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
909 if (application::interactive ()) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
910 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
911 if (! Vdebugging) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
912 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
|
913 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
914 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
|
915 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
916 octave_link::set_workspace (); |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
917 } |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
918 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
919 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
|
920 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
921 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
|
922 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
923 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
|
924 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
925 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
|
926 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
927 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
|
928 |
25435
a52e6fb674b1
eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents:
25407
diff
changeset
|
929 output_system& output_sys = __get_output_system__ ("do_sync"); |
1755 | 930 |
25435
a52e6fb674b1
eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents:
25407
diff
changeset
|
931 output_sys.reset (); |
2618 | 932 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
933 octave_diary << prompt; |
1 | 934 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
935 retval = input_sys.interactive_input (prompt, eof); |
581 | 936 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
937 // 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
|
938 // user input. |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
939 if (retval != "\n" |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
940 && 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
|
941 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
942 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
|
943 |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
944 lp.update (); |
8841
c74389115610
auto repeat for debugging commands
John W. Eaton <jwe@octave.org>
parents:
8749
diff
changeset
|
945 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
946 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
|
947 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
|
948 else |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
949 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
|
950 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
951 else if (Vdebugging) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
952 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
953 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
|
954 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
|
955 } |
1 | 956 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
957 if (retval != "\n") |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
958 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
959 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
|
960 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
961 if (command_history::add (retval)) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
962 octave_link::append_history (retval); |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
963 } |
1 | 964 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
965 octave_diary << retval; |
3176 | 966 |
26061
cb3ead3cf859
avoid assertion failure with -D_GLIBCXX_ASSERTIONS
Orion Poplawski <orion@cora.nwra.com>
parents:
25054
diff
changeset
|
967 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
|
968 octave_diary << "\n"; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
969 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
970 else |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
971 octave_diary << "\n"; |
581 | 972 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
973 // 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
|
974 // list has been updated. |
9476 | 975 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
976 if (application::interactive ()) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
977 octave_link::post_input_event (); |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
978 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
979 return retval; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
980 } |
1 | 981 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
982 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
|
983 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
984 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
|
985 } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
986 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
987 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
|
988 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
989 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
|
990 } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
991 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
992 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
|
993 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
994 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
|
995 } |
24732
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 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
998 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
|
999 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1000 public: |
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 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
|
1003 : base_reader (lxr) |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1004 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1005 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1006 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
|
1007 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1008 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
|
1009 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1010 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
|
1011 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1012 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1013 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1014 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
|
1015 }; |
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 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1018 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
|
1019 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1020 public: |
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 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
|
1023 : 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
|
1024 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1025 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
|
1026 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1027 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
|
1028 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1029 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
|
1030 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1031 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1032 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1033 FILE *m_file; |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1034 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1035 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
|
1036 }; |
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 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1039 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
|
1040 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1041 public: |
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 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
|
1044 : 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
|
1045 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1046 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1047 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
|
1048 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1049 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
|
1050 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1051 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
|
1052 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1053 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1054 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1055 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
|
1056 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1057 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
|
1058 }; |
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 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
|
1061 : 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
|
1062 { } |
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 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
|
1065 : 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
|
1066 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1067 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
1068 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
|
1069 : 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
|
1070 { } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
1071 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1072 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
|
1073 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1074 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
|
1075 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1076 std::string |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1077 terminal_reader::get_input (bool& eof) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1078 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1079 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1080 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1081 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1082 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1083 return octave_gets (eof); |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1084 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1085 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1086 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
|
1087 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1088 std::string |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1089 file_reader::get_input (bool& eof) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1090 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1091 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1092 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1093 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1094 |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1095 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
|
1096 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1097 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
|
1098 = 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
|
1099 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1100 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
|
1101 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1102 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
|
1103 = (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
|
1104 ? 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
|
1105 |
25620
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1106 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
|
1107 { |
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1108 // 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
|
1109 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
|
1110 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
|
1111 } |
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1112 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
|
1113 { |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1114 // 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
|
1115 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
|
1116 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
|
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 size_t length; |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1119 uint8_t *utf8_str = nullptr; |
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 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
|
1122 &length); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1123 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1124 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
|
1125 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
|
1126 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
|
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 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
|
1129 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
|
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 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
|
1132 } |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1133 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1134 return src_str; |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1135 } |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1136 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1137 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
|
1138 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1139 std::string |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1140 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
|
1141 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1142 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1143 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1144 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1145 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1146 std::string retval; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1147 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1148 retval = m_eval_string; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1149 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1150 // 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
|
1151 // 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
|
1152 m_eval_string = ""; |
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 if (retval.empty ()) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1155 eof = true; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1156 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1157 return retval; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1158 } |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1159 } |
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1160 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1161 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
|
1162 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
|
1163 @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
|
1164 @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
|
1165 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
|
1166 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1167 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
|
1168 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1169 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1170 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
|
1171 @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
|
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 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1174 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
|
1175 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1176 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1177 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
|
1178 @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
|
1179 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1180 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1181 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
|
1182 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
|
1183 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
|
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 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
|
1186 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
|
1187 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1188 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
|
1189 @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
|
1190 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
|
1191 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
|
1192 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1193 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
|
1194 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
|
1195 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
|
1196 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
|
1197 @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
|
1198 @end deftypefn */) |
529 | 1199 { |
1200 int nargin = args.length (); | |
1201 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1202 if (nargin < 1 || nargin > 2) |
5823 | 1203 print_usage (); |
529 | 1204 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1205 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
|
1206 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1207 return input_sys.get_user_input (args, std::max (nargout, 1)); |
529 | 1208 } |
1209 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1210 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
|
1211 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
|
1212 @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
|
1213 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
|
1214 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1215 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
|
1216 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1217 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
|
1218 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
|
1219 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
|
1220 @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
|
1221 @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
|
1222 @end deftypefn */) |
5640 | 1223 { |
1224 int nargin = args.length (); | |
1225 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1226 if (nargin > 1) |
5823 | 1227 print_usage (); |
5640 | 1228 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1229 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
|
1230 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1231 std::string prompt; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1232 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1233 if (nargin == 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1234 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
|
1235 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1236 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
|
1237 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1238 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1239 DEFMETHOD (keyboard, interp, args, , |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1240 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
|
1241 @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
|
1242 @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
|
1243 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
|
1244 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1245 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
|
1246 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
|
1247 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
|
1248 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
|
1249 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
|
1250 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
|
1251 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1252 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
|
1253 @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
|
1254 @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
|
1255 @end deftypefn */) |
529 | 1256 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
1257 if (args.length () > 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1258 print_usage (); |
10186
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1259 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
1260 octave::unwind_protect frame; |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9482
diff
changeset
|
1261 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1262 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
|
1263 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1264 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
|
1265 cs.current_frame ()); |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9482
diff
changeset
|
1266 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1267 // 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
|
1268 cs.goto_frame_relative (0); |
10186
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1269 |
25402
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
1270 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
|
1271 |
25402
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
1272 tw.debug_mode (true); |
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
1273 tw.quiet_breakpoint_flag (false); |
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
1274 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
|
1275 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1276 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
|
1277 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1278 input_sys.keyboard (args); |
529 | 1279 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1280 return ovl (); |
529 | 1281 } |
1282 | |
2234 | 1283 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
|
1284 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
|
1285 @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
|
1286 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
|
1287 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1288 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
|
1289 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
|
1290 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
|
1291 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
|
1292 @end deftypefn */) |
2234 | 1293 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
1294 if (args.length () != 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1295 print_usage (); |
2234 | 1296 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1297 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1298 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1299 std::string hint = args(0).string_value (); |
2234 | 1300 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1301 int n = 32; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1302 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1303 string_vector list (n); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1304 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1305 int k = 0; |
2234 | 1306 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1307 for (;;) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1308 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1309 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
|
1310 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1311 if (! cmd.empty ()) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1312 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1313 if (k == n) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
1314 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1315 n *= 2; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1316 list.resize (n); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
1317 } |
2234 | 1318 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1319 list[k++] = cmd; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1320 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1321 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1322 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1323 list.resize (k); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1324 break; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1325 } |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1326 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1327 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1328 if (nargout > 0) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1329 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1330 if (! list.empty ()) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1331 retval = list; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1332 else |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1333 retval = ""; |
2234 | 1334 } |
1335 else | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1336 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1337 // 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
|
1338 // 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
|
1339 // appear in a single column. |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1340 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1341 int len = list.numel (); |
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 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
|
1344 octave_stdout << list[i] << "\n"; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1345 } |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1346 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1347 octave_completion_matches_called = true; |
2234 | 1348 |
1349 return retval; | |
1350 } | |
1351 | |
20239
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1352 /* |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1353 %!assert (ischar (completion_matches (""))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1354 %!assert (ischar (completion_matches ("a"))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1355 %!assert (ischar (completion_matches (" "))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1356 %!assert (isempty (completion_matches (" "))) |
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 ("")))))) |
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 ("a")))))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1359 %!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
|
1360 %!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
|
1361 %!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
|
1362 |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1363 %!error completion_matches () |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1364 %!error completion_matches (1, 2) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1365 */ |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1366 |
16879
cc3743a91652
Rename read_readline_init_file to readline_read_init_file.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1367 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
|
1368 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
|
1369 @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
|
1370 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
|
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 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
|
1373 (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
|
1374 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1375 @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
|
1376 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
|
1377 @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
|
1378 @end deftypefn */) |
3189 | 1379 { |
1380 int nargin = args.length (); | |
1381 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1382 if (nargin > 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1383 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1384 |
3189 | 1385 if (nargin == 0) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1386 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
|
1387 else |
3189 | 1388 { |
5872 | 1389 std::string file = args(0).string_value (); |
3189 | 1390 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1391 octave::command_editor::read_init_file (file); |
3189 | 1392 } |
1393 | |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1394 return ovl (); |
3189 | 1395 } |
1396 | |
16880
1aebb613a5ac
Rename re_read_readline_init_file to readline_re_read_init_file.
Rik <rik@octave.org>
parents:
16879
diff
changeset
|
1397 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
|
1398 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
|
1399 @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
|
1400 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
|
1401 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1402 @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
|
1403 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
|
1404 @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
|
1405 @end deftypefn */) |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1406 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1407 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
|
1408 print_usage (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1409 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1410 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
|
1411 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1412 return ovl (); |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1413 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1414 |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1415 static int |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1416 internal_input_event_hook_fcn (void) |
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 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
|
1419 = 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
|
1420 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1421 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
|
1422 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1423 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
|
1424 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
|
1425 |
c48847a781d5
* input.cc (input_event_hook): Return 0.
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
1426 return 0; |
3498 | 1427 } |
1428 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1429 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
|
1430 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
|
1431 @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
|
1432 @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
|
1433 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
|
1434 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
|
1435 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1436 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
|
1437 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1438 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1439 @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
|
1440 @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
|
1441 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1442 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
|
1443 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1444 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
|
1445 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
|
1446 @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
|
1447 @end deftypefn */) |
3498 | 1448 { |
1449 int nargin = args.length (); | |
1450 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1451 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
|
1452 print_usage (); |
3498 | 1453 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1454 octave_value user_data; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1455 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1456 if (nargin == 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1457 user_data = args(1); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1458 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1459 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
|
1460 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1461 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
|
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 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
|
1464 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
|
1465 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1466 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
|
1467 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1468 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
|
1469 } |
3498 | 1470 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1471 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
|
1472 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
|
1473 @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
|
1474 @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
|
1475 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
|
1476 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
|
1477 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
|
1478 @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
|
1479 @end deftypefn */) |
9215
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1480 { |
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1481 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
|
1482 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1483 if (nargin < 1 || nargin > 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1484 print_usage (); |
16347
bf8397caeff1
allow add_input_event_hook to accept function handles
John W. Eaton <jwe@octave.org>
parents:
16336
diff
changeset
|
1485 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1486 std::string hook_fcn_id = args(0).string_value ("remove_input_event_hook: argument not valid as a hook function name or id"); |
3498 | 1487 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1488 bool warn = (nargin < 2); |
3498 | 1489 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1490 octave::input_system& input_sys = interp.get_input_system (); |
3498 | 1491 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1492 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
|
1493 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
|
1494 hook_fcn_id.c_str ()); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1495 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1496 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
|
1497 octave::command_editor::remove_event_hook (internal_input_event_hook_fcn); |
3498 | 1498 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1499 return ovl (); |
3498 | 1500 } |
1501 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1502 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
|
1503 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
|
1504 @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
|
1505 @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
|
1506 @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
|
1507 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
|
1508 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1509 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
|
1510 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
|
1511 |
24595
5ed2e9248ee9
doc: Tweaks to use single quotes instead of double quotes (bug #52870).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
1512 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
|
1513 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
|
1514 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1515 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1516 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
|
1517 @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
|
1518 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1519 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1520 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
|
1521 @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
|
1522 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
|
1523 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
|
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 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
|
1526 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
|
1527 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1528 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1529 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
|
1530 @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
|
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 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1533 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
|
1534 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1535 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
|
1536 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
|
1537 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
|
1538 @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
|
1539 @end deftypefn */) |
5794 | 1540 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1541 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
|
1542 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1543 return input_sys.PS1 (args, nargout); |
5794 | 1544 } |
2181 | 1545 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1546 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
|
1547 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
|
1548 @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
|
1549 @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
|
1550 @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
|
1551 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
|
1552 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1553 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
|
1554 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
|
1555 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
|
1556 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
|
1557 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
|
1558 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1559 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
|
1560 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
|
1561 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
|
1562 @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
|
1563 @end deftypefn */) |
5794 | 1564 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1565 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
|
1566 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1567 return input_sys.PS2 (args, nargout); |
5794 | 1568 } |
2181 | 1569 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1570 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
|
1571 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
|
1572 @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
|
1573 @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
|
1574 @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
|
1575 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
|
1576 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
|
1577 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1578 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
|
1579 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1580 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
|
1581 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
|
1582 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
|
1583 @end deftypefn */) |
5794 | 1584 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1585 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
|
1586 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1587 return input_sys.completion_append_char (args, nargout); |
5794 | 1588 } |
3019 | 1589 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1590 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
|
1591 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
|
1592 @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
|
1593 @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
|
1594 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
|
1595 @end deftypefn */) |
6257 | 1596 { |
1597 int nargin = args.length (); | |
1598 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1599 if (nargin > 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1600 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1601 |
6257 | 1602 if (nargin == 0) |
1603 Vdrawnow_requested = true; | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1604 else |
6257 | 1605 Vdrawnow_requested = args(0).bool_value (); |
1606 | |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1607 return ovl (); |
6257 | 1608 } |
1609 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1610 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
|
1611 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
|
1612 @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
|
1613 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
|
1614 @end deftypefn */) |
7294 | 1615 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1616 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
|
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 return input_sys.gud_mode (args, nargout); |
7294 | 1619 } |
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 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1621 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
|
1622 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
|
1623 @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
|
1624 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
|
1625 @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
|
1626 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1627 octave::input_system& input_sys = interp.get_input_system (); |
7294 | 1628 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1629 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
|
1630 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1631 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1632 // 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
|
1633 // 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
|
1634 // 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
|
1635 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1636 // #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
|
1637 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1638 bool |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1639 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
|
1640 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1641 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
|
1642 = 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
|
1643 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1644 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
|
1645 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1646 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1647 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1648 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
|
1649 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1650 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
|
1651 = 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
|
1652 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1653 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
|
1654 } |
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 void |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1657 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
|
1658 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1659 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
|
1660 = octave::__get_input_system__ ("remove_input_event_hook_functions"); |
7294 | 1661 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1662 input_sys.clear_input_event_hooks (); |
7294 | 1663 } |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1664 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1665 // 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
|
1666 // 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
|
1667 // separate function. |
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 FILE * |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1670 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
|
1671 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1672 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
|
1673 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
|
1674 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1675 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25620
diff
changeset
|
1676 // #endif |