Mercurial > octave
annotate libinterp/corefcn/input.cc @ 25392:55047ed5419b
eliminate some unnecessary parser includes in source files
* help.cc, input.cc, interpreter.cc, load-save.cc, ls-hdf5.cc,
ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc,
ls-oct-text.cc, sighandlers.cc, ov-str-mat.cc, pt-mat.cc:
Don't include parse tree headers that are not needed.
* interpreter.h: Delete forward declaration of tree_evluator since
pt-eval.h is included.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 16 May 2018 12:17:25 -0400 |
parents | 9cc1ca6538e3 |
children | ef2b9d4abf4a |
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 |
2181 | 79 // Primary prompt string. |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
80 static std::string VPS1; |
2181 | 81 |
82 // Secondary prompt string. | |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
83 static std::string VPS2; |
2181 | 84 |
3165 | 85 // 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
|
86 octave::sys::time Vlast_prompt_time = 0.0; |
3165 | 87 |
2181 | 88 // Character to append after successful command-line completion attempts. |
5794 | 89 static char Vcompletion_append_char = ' '; |
2181 | 90 |
3804 | 91 // TRUE after a call to completion_matches. |
2299 | 92 bool octave_completion_matches_called = false; |
93 | |
6257 | 94 // TRUE if the plotting system has requested a call to drawnow at |
95 // the next user prompt. | |
7409 | 96 bool Vdrawnow_requested = false; |
6257 | 97 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
98 // TRUE if we are in debugging mode. |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
99 bool Vdebugging = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
100 |
22164
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
101 // 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
|
102 // 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
|
103 // the terminal. |
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
104 bool Vtrack_line_num = true; |
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
105 |
8841
c74389115610
auto repeat for debugging commands
John W. Eaton <jwe@octave.org>
parents:
8749
diff
changeset
|
106 // If we are in debugging mode, this is the last command entered, so |
c74389115610
auto repeat for debugging commands
John W. Eaton <jwe@octave.org>
parents:
8749
diff
changeset
|
107 // that we can repeat the previous command if the user just types RET. |
16336
0ce49f9fb171
"\n" is the new empty string (bug #38552)
John W. Eaton <jwe@octave.org>
parents:
16288
diff
changeset
|
108 static std::string last_debugging_command = "\n"; |
8841
c74389115610
auto repeat for debugging commands
John W. Eaton <jwe@octave.org>
parents:
8749
diff
changeset
|
109 |
7294 | 110 // TRUE if we are running in the Emacs GUD mode. |
111 static bool Vgud_mode = false; | |
112 | |
16378
b28ae106e316
use class for lists of input hook functions
John W. Eaton <jwe@octave.org>
parents:
16374
diff
changeset
|
113 static hook_function_list input_event_hook_functions; |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
114 |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
115 // Codepage which is used to read .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
|
116 #if defined (OCTAVE_USE_WINDOWS_API) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
117 static std::string Vmfile_encoding = "system"; |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
118 #else |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
119 static std::string Vmfile_encoding = "utf-8"; |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
120 #endif |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
121 |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
122 // For octave_quit. |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
123 void |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
124 remove_input_event_hook_functions (void) |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
125 { |
16378
b28ae106e316
use class for lists of input hook functions
John W. Eaton <jwe@octave.org>
parents:
16374
diff
changeset
|
126 input_event_hook_functions.clear (); |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
127 } |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
128 |
16209
e7ff32e7cf82
move global promptflag variable to octave_reader class
John W. Eaton <jwe@octave.org>
parents:
16208
diff
changeset
|
129 void |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
130 set_default_prompts (void) |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
131 { |
18037
708173343c50
use "octave" instead of "\\s" in default prompt
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
132 // Use literal "octave" instead of "\\s" to avoid setting the prompt |
708173343c50
use "octave" instead of "\\s" in default prompt
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
133 // to "octave.exe" or "octave-gui", etc. |
708173343c50
use "octave" instead of "\\s" in default prompt
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
134 |
23804
8057d3f0673d
Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
135 VPS1 = R"(octave:\#> )"; |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
136 VPS2 = "> "; |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23721
diff
changeset
|
137 std::string VPS4 = "+ "; |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
138 |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
139 octave_link::set_default_prompts (VPS1, VPS2, VPS4); |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
140 } |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16524
diff
changeset
|
141 |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
142 static std::string |
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
143 gnu_readline (const std::string& s, bool& eof) |
1822 | 144 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
145 octave_quit (); |
5142 | 146 |
16097
2f4fa62089b3
improve end of file handling for lexer input
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
147 eof = false; |
2f4fa62089b3
improve end of file handling for lexer input
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
148 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
149 std::string retval = octave::command_editor::readline (s, eof); |
19595
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19379
diff
changeset
|
150 |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
151 if (! eof && retval.empty ()) |
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
152 retval = "\n"; |
1822 | 153 |
154 return retval; | |
155 } | |
581 | 156 |
6257 | 157 static inline std::string |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
158 interactive_input (const std::string& s, bool& eof) |
6257 | 159 { |
160 Vlast_prompt_time.stamp (); | |
161 | |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
162 if (Vdrawnow_requested && octave::application::interactive ()) |
6257 | 163 { |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
164 bool eval_error = false; |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
165 |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
166 try |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
167 { |
23129
35e3d199527c
Replace feval calls with direct call to C++ function (bug #50116).
Rik <rik@octave.org>
parents:
23127
diff
changeset
|
168 Fdrawnow (); |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
169 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
170 catch (const octave::execution_exception& e) |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
171 { |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
172 eval_error = true; |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
173 |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
174 std::string stack_trace = e.info (); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
175 |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
176 if (! stack_trace.empty ()) |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
177 std::cerr << stack_trace; |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
178 |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
179 if (octave::application::interactive ()) |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
180 octave::interpreter::recover_from_exception (); |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
181 } |
6257 | 182 |
23060
baf03cdb28b5
move pager and diary classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
183 octave::flush_stdout (); |
6367 | 184 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
185 // We set Vdrawnow_requested to false even if there is an error in |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
186 // drawnow so that the error doesn't reappear at every prompt. |
6305 | 187 |
6257 | 188 Vdrawnow_requested = false; |
6305 | 189 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
190 if (eval_error) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
191 return "\n"; |
6257 | 192 } |
193 | |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
194 return gnu_readline (s, eof); |
6257 | 195 } |
196 | |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
197 namespace octave |
1 | 198 { |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
199 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
|
200 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
201 octave_quit (); |
5142 | 202 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
203 eof = false; |
16097
2f4fa62089b3
improve end of file handling for lexer input
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
204 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
205 std::string retval; |
1 | 206 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
207 // 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
|
208 // printing the prompt. |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
209 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
210 if (application::interactive ()) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
211 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
212 if (! Vdebugging) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
213 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
|
214 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
215 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
|
216 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
217 octave_link::set_workspace (); |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
218 } |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
219 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
220 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
|
221 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
222 std::string ps = (m_pflag > 0) ? VPS1 : VPS2; |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
223 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
224 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
|
225 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
226 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
|
227 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
228 flush_stdout (); |
1755 | 229 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
230 pager_stream::reset (); |
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
231 diary_stream::reset (); |
2618 | 232 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
233 octave_diary << prompt; |
1 | 234 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
235 retval = interactive_input (prompt, eof); |
581 | 236 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
237 // 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
|
238 // user input. |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
239 if (retval != "\n" |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
240 && 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
|
241 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
242 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
|
243 |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
244 lp.update (); |
8841
c74389115610
auto repeat for debugging commands
John W. Eaton <jwe@octave.org>
parents:
8749
diff
changeset
|
245 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
246 if (Vdebugging) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
247 last_debugging_command = retval; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
248 else |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
249 last_debugging_command = "\n"; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
250 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
251 else if (Vdebugging) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
252 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
253 retval = last_debugging_command; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
254 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
|
255 } |
1 | 256 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
257 if (retval != "\n") |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
258 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
259 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
|
260 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
261 if (command_history::add (retval)) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
262 octave_link::append_history (retval); |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
263 } |
1 | 264 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
265 octave_diary << retval; |
3176 | 266 |
23812
057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
267 if (retval.back () != '\n') |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
268 octave_diary << "\n"; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
269 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
270 else |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
271 octave_diary << "\n"; |
581 | 272 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
273 // 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
|
274 // list has been updated. |
9476 | 275 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
276 if (application::interactive ()) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
277 octave_link::post_input_event (); |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
278 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
279 return retval; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
280 } |
1 | 281 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
282 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
|
283 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
284 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
|
285 } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
286 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
287 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
|
288 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
289 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
|
290 } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
291 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
292 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
|
293 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
294 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
|
295 } |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
296 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
297 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
298 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
|
299 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
300 public: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
301 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
302 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
|
303 : base_reader (lxr) |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
304 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
305 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
306 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
|
307 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
308 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
|
309 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
310 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
|
311 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
312 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
313 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
314 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
|
315 }; |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
316 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
317 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
318 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
|
319 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
320 public: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
321 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
322 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
|
323 : 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
|
324 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
325 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
|
326 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
327 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
|
328 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
329 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
|
330 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
331 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
332 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
333 FILE *m_file; |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
334 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
335 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
|
336 }; |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
337 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
338 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
339 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
|
340 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
341 public: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
342 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
343 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
|
344 : 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
|
345 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
346 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
347 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
|
348 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
349 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
|
350 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
351 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
|
352 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
353 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
354 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
355 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
|
356 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
357 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
|
358 }; |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
359 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
360 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
|
361 : 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
|
362 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
363 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
364 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
|
365 : 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
|
366 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
367 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
368 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
|
369 : 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
|
370 { } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
371 } |
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
372 |
581 | 373 // Fix things up so that input can come from the standard input. This |
374 // may need to become much more complicated, which is why it's in a | |
375 // separate function. | |
376 | |
1 | 377 FILE * |
378 get_input_from_stdin (void) | |
379 { | |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
380 octave::command_editor::set_input_stream (stdin); |
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
381 return octave::command_editor::get_input_stream (); |
1 | 382 } |
383 | |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
384 // FIXME: make this generate filenames when appropriate. |
2921 | 385 |
2247 | 386 static string_vector |
3523 | 387 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
|
388 std::string& hint, bool& deemed_struct) |
1280 | 389 { |
2247 | 390 string_vector names; |
1280 | 391 |
2921 | 392 prefix = ""; |
1280 | 393 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
394 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
|
395 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
|
396 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
397 if (deemed_struct) |
1430 | 398 names = generate_struct_completions (text, prefix, hint); |
399 else | |
23721
b2d55b52ee51
new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
400 names = octave::make_name_list (); |
1280 | 401 |
2944 | 402 // Sort and remove duplicates. |
2348 | 403 |
8503
8ba2ee57c594
remove qsort in favor of sort
Jaroslav Hajek <highegg@gmail.com>
parents:
8447
diff
changeset
|
404 names.sort (true); |
2348 | 405 |
1280 | 406 return names; |
407 } | |
408 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
409 static bool |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
410 is_completing_dirfns (void) |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
411 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
412 static std::string dirfns_commands[] = {"cd", "ls"}; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
413 static const size_t dirfns_commands_length = 2; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
414 |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
415 bool retval = false; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
416 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
417 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
|
418 |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
419 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
|
420 { |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23805
diff
changeset
|
421 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
|
422 |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
423 if (index == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
424 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
425 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
426 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
427 } |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
428 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
429 |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
430 return retval; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
431 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
432 |
3536 | 433 static std::string |
3523 | 434 generate_completion (const std::string& text, int state) |
1280 | 435 { |
3523 | 436 std::string retval; |
2944 | 437 |
3523 | 438 static std::string prefix; |
439 static std::string hint; | |
1280 | 440 |
2921 | 441 static size_t hint_len = 0; |
1280 | 442 |
1 | 443 static int list_index = 0; |
2921 | 444 static int name_list_len = 0; |
4604 | 445 static int name_list_total_len = 0; |
2247 | 446 static string_vector name_list; |
4604 | 447 static string_vector file_name_list; |
1 | 448 |
1280 | 449 static int matches = 0; |
1 | 450 |
451 if (state == 0) | |
452 { | |
453 list_index = 0; | |
454 | |
2921 | 455 prefix = ""; |
1280 | 456 |
2921 | 457 hint = text; |
1280 | 458 |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
459 // 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
|
460 // file/directory operation. |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
461 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
462 bool deemed_struct = false; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
463 |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
464 if (is_completing_dirfns ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
465 name_list = string_vector (); |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9484
diff
changeset
|
466 else |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
467 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
|
468 deemed_struct); |
1280 | 469 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20178
diff
changeset
|
470 name_list_len = name_list.numel (); |
2921 | 471 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
472 // 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
|
473 // 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
|
474 if (! deemed_struct) |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
475 { |
4604 | 476 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
477 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
|
478 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
479 name_list.append (file_name_list); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
480 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
481 } |
4604 | 482 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20178
diff
changeset
|
483 name_list_total_len = name_list.numel (); |
4604 | 484 |
2921 | 485 hint_len = hint.length (); |
1280 | 486 |
487 matches = 0; | |
2247 | 488 |
2921 | 489 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
|
490 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
|
491 matches++; |
1 | 492 } |
493 | |
4604 | 494 if (name_list_total_len > 0 && matches > 0) |
1 | 495 { |
4604 | 496 while (list_index < name_list_total_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
497 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
498 std::string name = name_list[list_index]; |
2247 | 499 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
500 list_index++; |
2247 | 501 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
502 if (hint == name.substr (0, hint_len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
503 { |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
504 // Special case: array reference forces prefix="." |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
505 // in generate_struct_completions () |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
506 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
|
507 retval = (prefix == "." ? "" : prefix) + '.' + name; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
508 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
509 retval = name; |
1280 | 510 |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
511 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
|
512 (text.length ()); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
513 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
|
514 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
515 // 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
|
516 // whether it should be '(' or '.'. |
4179 | 517 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
518 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
|
519 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
520 else |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
521 octave::command_editor::set_completion_append_character |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
522 (Vcompletion_append_char); |
1280 | 523 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
524 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
525 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
526 } |
1 | 527 } |
528 | |
2944 | 529 return retval; |
1 | 530 } |
531 | |
6979 | 532 static std::string |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
533 quoting_filename (const std::string& text, int, char quote) |
6979 | 534 { |
535 if (quote) | |
536 return text; | |
537 else | |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23805
diff
changeset
|
538 return ("'" + text); |
6979 | 539 } |
540 | |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
541 // Try to parse a partial command line in reverse, excluding trailing TEXT. |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
542 // If it appears a variable has been indexed by () or {}, |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
543 // return that expression, |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
544 // to allow autocomplete of field names of arrays of structures. |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
545 std::string |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
546 find_indexed_expression (const std::string& text) |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
547 { |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
548 std::string line = octave::command_editor::get_line_buffer (); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
549 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
550 int pos = line.length () - text.length (); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
551 int curly_count = 0; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
552 int paren_count = 0; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
553 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
554 int last = --pos; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
555 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
556 while (pos >= 0 && (line[pos] == ')' || line[pos] == '}')) |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
557 { |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
558 if (line[pos] == ')') |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
559 paren_count++; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
560 else if (line[pos] == '}') |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
561 curly_count++; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
562 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
563 while (curly_count + paren_count > 0 && --pos >= 0) |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
564 { |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
565 if (line[pos] == ')') |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
566 paren_count++; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
567 else if (line[pos] == '(') |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
568 paren_count--; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
569 else if (line[pos] == '}') |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
570 curly_count++; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
571 else if (line[pos] == '{') |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
572 curly_count--; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
573 } |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
574 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
575 while (--pos >= 0 && line[pos] == ' ') |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
576 ; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
577 } |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
578 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
579 while (pos >= 0 && (isalnum (line[pos]) || line[pos] == '_')) |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
580 pos--; |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
581 |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
582 if (++pos >= 0) |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
583 return (line.substr (pos, last + 1 - pos)); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
584 else |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
585 return std::string (); |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
586 } |
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
587 |
2927 | 588 void |
589 initialize_command_input (void) | |
590 { | |
591 // If we are using readline, this allows conditional parsing of the | |
592 // .inputrc file. | |
269 | 593 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
594 octave::command_editor::set_name ("Octave"); |
1358 | 595 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
596 // FIXME: this needs to include a comma too, but that |
3933 | 597 // causes trouble for the new struct element completion code. |
598 | |
4272 | 599 static const char *s = "\t\n !\"\'*+-/:;<=>(){}[\\]^`~"; |
3933 | 600 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
601 octave::command_editor::set_basic_word_break_characters (s); |
3933 | 602 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
603 octave::command_editor::set_completer_word_break_characters (s); |
3933 | 604 |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
605 octave::command_editor::set_basic_quote_characters (R"(")"); |
2944 | 606 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
607 octave::command_editor::set_filename_quote_characters (" \t\n\\\"'@<>=;|&()#$`?*[!:{"); |
23805
bf061a189af9
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23804
diff
changeset
|
608 octave::command_editor::set_completer_quote_characters (R"('")"); |
6979 | 609 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
610 octave::command_editor::set_completion_function (generate_completion); |
6979 | 611 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
612 octave::command_editor::set_quoting_function (quoting_filename); |
269 | 613 } |
614 | |
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
|
615 static void |
16438
a971d8bdaadc
use signals instead of event queue for entering/leaving debug mode
John W. Eaton <jwe@octave.org>
parents:
16433
diff
changeset
|
616 execute_in_debugger_handler (const std::pair<std::string, int>& arg) |
16419
16bfbf9136d3
avoid creating unnecessary octave_value objects for octave_link calls
John W. Eaton <jwe@octave.org>
parents:
16416
diff
changeset
|
617 { |
16438
a971d8bdaadc
use signals instead of event queue for entering/leaving debug mode
John W. Eaton <jwe@octave.org>
parents:
16433
diff
changeset
|
618 octave_link::execute_in_debugger_event (arg.first, arg.second); |
16419
16bfbf9136d3
avoid creating unnecessary octave_value objects for octave_link calls
John W. Eaton <jwe@octave.org>
parents:
16416
diff
changeset
|
619 } |
16bfbf9136d3
avoid creating unnecessary octave_value objects for octave_link calls
John W. Eaton <jwe@octave.org>
parents:
16416
diff
changeset
|
620 |
16bfbf9136d3
avoid creating unnecessary octave_value objects for octave_link calls
John W. Eaton <jwe@octave.org>
parents:
16416
diff
changeset
|
621 static void |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
622 get_debug_input (octave::interpreter& interp, const std::string& prompt) |
269 | 623 { |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
624 octave::unwind_protect frame; |
16395
fc491da603f6
also provide a hook for exiting debugger
John W. Eaton <jwe@octave.org>
parents:
16386
diff
changeset
|
625 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22171
diff
changeset
|
626 bool silent = octave::tree_evaluator::quiet_breakpoint_flag; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22171
diff
changeset
|
627 octave::tree_evaluator::quiet_breakpoint_flag = false; |
19595
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19379
diff
changeset
|
628 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
629 octave::call_stack& cs = interp.get_call_stack (); |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
630 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
631 octave_user_code *caller = cs.caller_user_code (); |
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
|
632 std::string nm; |
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
|
633 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
|
634 |
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
|
635 if (caller) |
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
|
636 { |
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
|
637 nm = caller->fcn_file_name (); |
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
|
638 |
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
|
639 if (nm.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
640 nm = caller->name (); |
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
|
641 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
642 curr_debug_line = cs.caller_user_code_line (); |
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
|
643 } |
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
|
644 else |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
645 curr_debug_line = cs.current_line (); |
3180 | 646 |
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
|
647 std::ostringstream buf; |
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
|
648 |
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
|
649 if (! nm.empty ()) |
3180 | 650 { |
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
|
651 if (Vgud_mode) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
652 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
653 static char ctrl_z = 'Z' & 0x1f; |
269 | 654 |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23805
diff
changeset
|
655 buf << ctrl_z << ctrl_z << nm << ':' << curr_debug_line; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
656 } |
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
|
657 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
658 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
659 // FIXME: we should come up with a clean way to detect |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
660 // that we are stopped on the no-op command that marks the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
661 // end of a function or script. |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
662 |
19379
c1ce43276b86
avoid printing debug location in cmd window when using GUI to step
John W. Eaton <jwe@octave.org>
parents:
18694
diff
changeset
|
663 if (! silent) |
c1ce43276b86
avoid printing debug location in cmd window when using GUI to step
John W. Eaton <jwe@octave.org>
parents:
18694
diff
changeset
|
664 { |
c1ce43276b86
avoid printing debug location in cmd window when using GUI to step
John W. Eaton <jwe@octave.org>
parents:
18694
diff
changeset
|
665 buf << "stopped in " << nm; |
1 | 666 |
19379
c1ce43276b86
avoid printing debug location in cmd window when using GUI to step
John W. Eaton <jwe@octave.org>
parents:
18694
diff
changeset
|
667 if (curr_debug_line > 0) |
c1ce43276b86
avoid printing debug location in cmd window when using GUI to step
John W. Eaton <jwe@octave.org>
parents:
18694
diff
changeset
|
668 buf << " at line " << curr_debug_line; |
c1ce43276b86
avoid printing debug location in cmd window when using GUI to step
John W. Eaton <jwe@octave.org>
parents:
18694
diff
changeset
|
669 } |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
670 |
25034
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
671 octave_link::enter_debugger_event (nm, curr_debug_line); |
16395
fc491da603f6
also provide a hook for exiting debugger
John W. Eaton <jwe@octave.org>
parents:
16386
diff
changeset
|
672 |
25034
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
673 octave_link::set_workspace (); |
16468
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
16438
diff
changeset
|
674 |
25034
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
675 frame.add_fcn (execute_in_debugger_handler, |
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
676 std::pair<std::string, int> (nm, curr_debug_line)); |
16374
8b0a04cbdc9d
provide hook function for dbstop events
John W. Eaton <jwe@octave.org>
parents:
16373
diff
changeset
|
677 |
25034
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
678 if (! silent) |
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
679 { |
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
680 std::string line_buf; |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
681 |
25034
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
682 if (caller) |
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
683 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
|
684 |
25034
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
685 if (! line_buf.empty ()) |
6e4121c39957
enable debugging flag and code echo for command-line functions
John W. Eaton <jwe@octave.org>
parents:
24833
diff
changeset
|
686 buf << "\n" << curr_debug_line << ": " << line_buf; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
687 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
688 } |
3180 | 689 } |
690 | |
19379
c1ce43276b86
avoid printing debug location in cmd window when using GUI to step
John W. Eaton <jwe@octave.org>
parents:
18694
diff
changeset
|
691 if (silent) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
692 octave::command_editor::erase_empty_line (true); |
19595
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19379
diff
changeset
|
693 |
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
|
694 std::string msg = buf.str (); |
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
|
695 |
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
|
696 if (! msg.empty ()) |
9484
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
697 std::cerr << msg << std::endl; |
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
|
698 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
699 frame.protect_var (VPS1); |
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
|
700 VPS1 = prompt; |
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
|
701 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
702 // FIXME: should debugging be possible in an embedded interpreter? |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
703 |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
704 octave::application *app = octave::application::app (); |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
705 |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
706 if (! app->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
|
707 { |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
708 |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
709 frame.add_method (app, &octave::application::interactive, |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
710 app->interactive ()); |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
711 |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
712 frame.add_method (app, &octave::application::forced_interactive, |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
713 app->forced_interactive ()); |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
714 |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
715 app->interactive (true); |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
716 |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
717 app->forced_interactive (true); |
12907
6e1b9f079e0f
allow debugging when input is not coming from a tty
John W. Eaton <jwe@octave.org>
parents:
12573
diff
changeset
|
718 } |
6e1b9f079e0f
allow debugging when input is not coming from a tty
John W. Eaton <jwe@octave.org>
parents:
12573
diff
changeset
|
719 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22171
diff
changeset
|
720 octave::parser curr_parser; |
16151 | 721 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
722 octave::tree_evaluator& tw = interp.get_evaluator (); |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23438
diff
changeset
|
723 |
12907
6e1b9f079e0f
allow debugging when input is not coming from a tty
John W. Eaton <jwe@octave.org>
parents:
12573
diff
changeset
|
724 while (Vdebugging) |
6e1b9f079e0f
allow debugging when input is not coming from a tty
John W. Eaton <jwe@octave.org>
parents:
12573
diff
changeset
|
725 { |
20639
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
726 try |
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
727 { |
22164
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
728 Vtrack_line_num = false; |
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
729 |
20639
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
730 reset_error_handler (); |
12907
6e1b9f079e0f
allow debugging when input is not coming from a tty
John W. Eaton <jwe@octave.org>
parents:
12573
diff
changeset
|
731 |
20639
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
732 curr_parser.reset (); |
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
|
733 |
20639
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
734 int retval = curr_parser.run (); |
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
|
735 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
736 if (octave::command_editor::interrupt (false)) |
20639
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
737 break; |
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
738 else |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
16381
diff
changeset
|
739 { |
23694
4a62da62af09
use m_ prefix for member variables in parser
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
740 if (retval == 0 && curr_parser.m_stmt_list) |
20639
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
741 { |
23694
4a62da62af09
use m_ prefix for member variables in parser
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
742 curr_parser.m_stmt_list->accept (tw); |
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
|
743 |
20639
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
744 if (octave_completion_matches_called) |
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
745 octave_completion_matches_called = false; |
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
746 } |
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
747 |
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
748 octave_quit (); |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
16381
diff
changeset
|
749 } |
20639
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
750 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
751 catch (const octave::execution_exception& e) |
20639
31219c56874f
don't exit debugger if an error occurs (bug #46251)
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
752 { |
20739
9e8a6d6d6de9
restore stack trace for errors that occur in debug mode
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
753 std::string stack_trace = e.info (); |
9e8a6d6d6de9
restore stack trace for errors that occur in debug mode
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
754 |
9e8a6d6d6de9
restore stack trace for errors that occur in debug mode
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
755 if (! stack_trace.empty ()) |
9e8a6d6d6de9
restore stack trace for errors that occur in debug mode
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
756 std::cerr << stack_trace; |
9e8a6d6d6de9
restore stack trace for errors that occur in debug mode
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
757 |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
758 // Ignore errors when in debugging mode; |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
759 octave::interpreter::recover_from_exception (); |
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
|
760 } |
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
|
761 } |
529 | 762 } |
763 | |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
764 namespace octave |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
765 { |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
766 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
|
767 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
768 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
|
769 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
770 std::string |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
771 terminal_reader::get_input (bool& eof) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
772 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
773 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
774 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
775 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
776 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
777 return octave_gets (eof); |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
778 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
779 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
780 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
|
781 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
782 std::string |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
783 file_reader::get_input (bool& eof) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
784 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
785 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
786 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
787 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
788 |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
789 std::string src_str = octave_fgets (m_file, eof); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
790 std::string encoding = Vmfile_encoding.compare ("system") == 0 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
791 ? octave_locale_charset_wrapper () |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
792 : Vmfile_encoding; |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
793 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
794 if (encoding.compare ("utf-8") != 0) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
795 { |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
796 // 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
|
797 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
|
798 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
|
799 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
800 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
|
801 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
|
802 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
803 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
|
804 &length); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
805 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
806 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
|
807 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
|
808 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
|
809 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
810 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
|
811 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
|
812 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
813 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
|
814 } |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
815 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
816 return src_str; |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
817 } |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
818 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
819 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
|
820 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
821 std::string |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
822 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
|
823 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
824 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
825 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
826 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
827 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
828 std::string retval; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
829 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
830 retval = m_eval_string; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
831 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
832 // 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
|
833 // 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
|
834 m_eval_string = ""; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
835 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
836 if (retval.empty ()) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
837 eof = true; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
838 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
839 return retval; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
840 } |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
841 } |
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
842 |
581 | 843 // If the user simply hits return, this will produce an empty matrix. |
844 | |
2086 | 845 static octave_value_list |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
846 get_user_input (const octave_value_list& args, int nargout) |
529 | 847 { |
3100 | 848 octave_value_list retval; |
529 | 849 |
850 int read_as_string = 0; | |
851 | |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
852 if (args.length () == 2) |
529 | 853 read_as_string++; |
854 | |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20639
diff
changeset
|
855 std::string prompt = args(0).xstring_value ("input: unrecognized argument"); |
4975 | 856 |
23060
baf03cdb28b5
move pager and diary classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
857 octave::flush_stdout (); |
529 | 858 |
23060
baf03cdb28b5
move pager and diary classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
859 octave::pager_stream::reset (); |
baf03cdb28b5
move pager and diary classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
860 octave::diary_stream::reset (); |
13266
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
861 |
4565 | 862 octave_diary << prompt; |
863 | |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
864 bool eof = false; |
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
865 |
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
866 std::string input_buf = interactive_input (prompt.c_str (), eof); |
529 | 867 |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
868 if (input_buf.empty ()) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
869 error ("input: reading user-input failed!"); |
529 | 870 |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
871 size_t len = input_buf.length (); |
4565 | 872 |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
873 octave_diary << input_buf; |
4565 | 874 |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
875 if (input_buf[len - 1] != '\n') |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
876 octave_diary << "\n"; |
3772 | 877 |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
878 if (len < 1) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
879 return read_as_string ? octave_value ("") : octave_value (Matrix ()); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
880 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
881 if (read_as_string) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
882 { |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
883 // FIXME: fix gnu_readline and octave_gets instead! |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
884 if (input_buf.length () == 1 && input_buf[0] == '\n') |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
885 retval(0) = ""; |
529 | 886 else |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
887 retval(0) = input_buf; |
529 | 888 } |
889 else | |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
890 { |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
891 int parse_status = 0; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
892 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23061
diff
changeset
|
893 retval = octave::eval_string (input_buf, true, parse_status, nargout); |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
894 |
21885
0806871e3e1e
maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents:
21852
diff
changeset
|
895 if (! Vdebugging && retval.empty ()) |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
896 retval(0) = Matrix (); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
897 } |
529 | 898 |
899 return retval; | |
900 } | |
901 | |
3100 | 902 DEFUN (input, 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
|
903 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
|
904 @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
|
905 @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
|
906 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
|
907 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
908 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
|
909 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
910 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
911 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
|
912 @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
|
913 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
914 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
915 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
|
916 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
917 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
918 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
|
919 @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
|
920 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
921 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
922 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
|
923 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
|
924 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
|
925 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
926 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
|
927 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
|
928 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
929 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
|
930 @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
|
931 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
|
932 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
|
933 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
934 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
|
935 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
|
936 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
|
937 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
|
938 @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
|
939 @end deftypefn */) |
529 | 940 { |
941 int nargin = args.length (); | |
942 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
943 if (nargin < 1 || nargin > 2) |
5823 | 944 print_usage (); |
529 | 945 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
946 return get_user_input (args, std::max (nargout, 1)); |
529 | 947 } |
948 | |
5640 | 949 bool |
950 octave_yes_or_no (const std::string& prompt) | |
951 { | |
952 std::string prompt_string = prompt + "(yes or no) "; | |
953 | |
954 while (1) | |
955 { | |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
956 bool eof = false; |
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
957 |
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
958 std::string input_buf = interactive_input (prompt_string, eof); |
5640 | 959 |
960 if (input_buf == "yes") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
961 return true; |
5640 | 962 else if (input_buf == "no") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
963 return false; |
5640 | 964 else |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23728
diff
changeset
|
965 message (nullptr, "Please answer yes or no."); |
5640 | 966 } |
967 } | |
968 | |
969 DEFUN (yes_or_no, 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
|
970 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
|
971 @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
|
972 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
|
973 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
974 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
|
975 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
976 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
|
977 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
|
978 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
|
979 @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
|
980 @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
|
981 @end deftypefn */) |
5640 | 982 { |
983 int nargin = args.length (); | |
984 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
985 if (nargin > 1) |
5823 | 986 print_usage (); |
5640 | 987 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
988 std::string prompt; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
989 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
990 if (nargin == 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
991 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
|
992 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
993 return ovl (octave_yes_or_no (prompt)); |
5640 | 994 } |
995 | |
3707 | 996 octave_value |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
997 do_keyboard (octave::interpreter& interp, const octave_value_list& args) |
3707 | 998 { |
999 octave_value retval; | |
1000 | |
1001 int nargin = args.length (); | |
1002 | |
1003 assert (nargin == 0 || nargin == 1); | |
1004 | |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
1005 octave::unwind_protect frame; |
3707 | 1006 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1007 frame.add_fcn (octave::command_history::ignore_entries, |
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1008 octave::command_history::ignoring_entries ()); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12942
diff
changeset
|
1009 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1010 octave::command_history::ignore_entries (false); |
3707 | 1011 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
1012 frame.protect_var (Vdebugging); |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
1013 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1014 octave::call_stack& cs = interp.get_call_stack (); |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1015 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1016 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
|
1017 cs.current_frame ()); |
3707 | 1018 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1019 // FIXME: probably we just want to print one line, not the |
9484
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
1020 // entire statement, which might span many lines... |
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
1021 // |
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
1022 // tree_print_code tpc (octave_stdout); |
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
1023 // stmt.accept (tpc); |
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
1024 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
1025 Vdebugging = true; |
22164
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
1026 Vtrack_line_num = false; |
3707 | 1027 |
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
|
1028 std::string prompt = "debug> "; |
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
|
1029 if (nargin > 0) |
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
|
1030 prompt = args(0).string_value (); |
4233 | 1031 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1032 get_debug_input (interp, prompt); |
3707 | 1033 |
1034 return retval; | |
1035 } | |
1036 | |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1037 octave_value |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1038 do_keyboard (const octave_value_list& args) |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1039 { |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1040 octave::interpreter& interp = octave::__get_interpreter__ ("do_keyboard"); |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1041 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1042 return do_keyboard (interp, args); |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1043 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1044 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1045 DEFMETHOD (keyboard, interp, args, , |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1046 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
|
1047 @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
|
1048 @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
|
1049 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
|
1050 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1051 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
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 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
|
1057 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1058 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
|
1059 @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
|
1060 @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
|
1061 @end deftypefn */) |
529 | 1062 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
1063 if (args.length () > 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1064 print_usage (); |
10186
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1065 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
1066 octave::unwind_protect frame; |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9482
diff
changeset
|
1067 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1068 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
|
1069 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1070 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
|
1071 cs.current_frame ()); |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9482
diff
changeset
|
1072 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1073 // 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
|
1074 cs.goto_frame_relative (0); |
10186
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1075 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22171
diff
changeset
|
1076 octave::tree_evaluator::debug_mode = true; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22171
diff
changeset
|
1077 octave::tree_evaluator::quiet_breakpoint_flag = false; |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1078 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1079 octave::tree_evaluator::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
|
1080 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1081 do_keyboard (interp, args); |
529 | 1082 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1083 return ovl (); |
529 | 1084 } |
1085 | |
2234 | 1086 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
|
1087 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
|
1088 @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
|
1089 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
|
1090 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1091 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
|
1092 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
|
1093 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
|
1094 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
|
1095 @end deftypefn */) |
2234 | 1096 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
1097 if (args.length () != 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1098 print_usage (); |
2234 | 1099 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1100 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1101 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1102 std::string hint = args(0).string_value (); |
2234 | 1103 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1104 int n = 32; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1105 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1106 string_vector list (n); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1107 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1108 int k = 0; |
2234 | 1109 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1110 for (;;) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1111 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1112 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
|
1113 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1114 if (! cmd.empty ()) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1115 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1116 if (k == n) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
1117 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1118 n *= 2; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1119 list.resize (n); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
1120 } |
2234 | 1121 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1122 list[k++] = cmd; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1123 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1124 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1125 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1126 list.resize (k); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1127 break; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1128 } |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1129 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1130 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1131 if (nargout > 0) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1132 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1133 if (! list.empty ()) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1134 retval = list; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1135 else |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1136 retval = ""; |
2234 | 1137 } |
1138 else | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1139 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1140 // 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
|
1141 // 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
|
1142 // appear in a single column. |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1143 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1144 int len = list.numel (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1145 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1146 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
|
1147 octave_stdout << list[i] << "\n"; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1148 } |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1149 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1150 octave_completion_matches_called = true; |
2234 | 1151 |
1152 return retval; | |
1153 } | |
1154 | |
20239
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1155 /* |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1156 %!assert (ischar (completion_matches (""))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1157 %!assert (ischar (completion_matches ("a"))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1158 %!assert (ischar (completion_matches (" "))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1159 %!assert (isempty (completion_matches (" "))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1160 %!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
|
1161 %!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
|
1162 %!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
|
1163 %!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
|
1164 %!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
|
1165 |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1166 %!error completion_matches () |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1167 %!error completion_matches (1, 2) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1168 */ |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1169 |
16879
cc3743a91652
Rename read_readline_init_file to readline_read_init_file.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1170 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
|
1171 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
|
1172 @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
|
1173 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
|
1174 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1175 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
|
1176 (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
|
1177 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1178 @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
|
1179 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
|
1180 @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
|
1181 @end deftypefn */) |
3189 | 1182 { |
1183 int nargin = args.length (); | |
1184 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1185 if (nargin > 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1186 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1187 |
3189 | 1188 if (nargin == 0) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1189 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
|
1190 else |
3189 | 1191 { |
5872 | 1192 std::string file = args(0).string_value (); |
3189 | 1193 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1194 octave::command_editor::read_init_file (file); |
3189 | 1195 } |
1196 | |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1197 return ovl (); |
3189 | 1198 } |
1199 | |
16880
1aebb613a5ac
Rename re_read_readline_init_file to readline_re_read_init_file.
Rik <rik@octave.org>
parents:
16879
diff
changeset
|
1200 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
|
1201 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
|
1202 @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
|
1203 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
|
1204 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1205 @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
|
1206 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
|
1207 @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
|
1208 @end deftypefn */) |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1209 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1210 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
|
1211 print_usage (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1212 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1213 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
|
1214 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1215 return ovl (); |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1216 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1217 |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1218 static int |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1219 internal_input_event_hook_fcn (void) |
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1220 { |
16378
b28ae106e316
use class for lists of input hook functions
John W. Eaton <jwe@octave.org>
parents:
16374
diff
changeset
|
1221 input_event_hook_functions.run (); |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
1222 |
16378
b28ae106e316
use class for lists of input hook functions
John W. Eaton <jwe@octave.org>
parents:
16374
diff
changeset
|
1223 if (input_event_hook_functions.empty ()) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1224 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
|
1225 |
c48847a781d5
* input.cc (input_event_hook): Return 0.
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
1226 return 0; |
3498 | 1227 } |
1228 | |
9215
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1229 DEFUN (add_input_event_hook, 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
|
1230 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
|
1231 @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
|
1232 @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
|
1233 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
|
1234 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
|
1235 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1236 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
|
1237 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1238 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1239 @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
|
1240 @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
|
1241 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1242 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
|
1243 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1244 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
|
1245 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
|
1246 @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
|
1247 @end deftypefn */) |
3498 | 1248 { |
1249 int nargin = args.length (); | |
1250 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1251 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
|
1252 print_usage (); |
3498 | 1253 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1254 octave_value user_data; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1255 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1256 if (nargin == 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1257 user_data = args(1); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1258 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1259 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
|
1260 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1261 if (input_event_hook_functions.empty ()) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1262 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
|
1263 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1264 input_event_hook_functions.insert (hook_fcn.id (), hook_fcn); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1265 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1266 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
|
1267 } |
3498 | 1268 |
9215
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1269 DEFUN (remove_input_event_hook, 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
|
1270 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
|
1271 @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
|
1272 @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
|
1273 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
|
1274 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
|
1275 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
|
1276 @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
|
1277 @end deftypefn */) |
9215
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1278 { |
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1279 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
|
1280 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1281 if (nargin < 1 || nargin > 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1282 print_usage (); |
16347
bf8397caeff1
allow add_input_event_hook to accept function handles
John W. Eaton <jwe@octave.org>
parents:
16336
diff
changeset
|
1283 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1284 std::string hook_fcn_id = args(0).string_value ("remove_input_event_hook: argument not valid as a hook function name or id"); |
3498 | 1285 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1286 bool warn = (nargin < 2); |
3498 | 1287 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1288 hook_function_list::iterator p |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1289 = input_event_hook_functions.find (hook_fcn_id); |
3498 | 1290 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1291 if (p != input_event_hook_functions.end ()) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1292 input_event_hook_functions.erase (p); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1293 else if (warn) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1294 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
|
1295 hook_fcn_id.c_str ()); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1296 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1297 if (input_event_hook_functions.empty ()) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1298 octave::command_editor::remove_event_hook (internal_input_event_hook_fcn); |
3498 | 1299 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1300 return ovl (); |
3498 | 1301 } |
1302 | |
5794 | 1303 DEFUN (PS1, 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
|
1304 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
|
1305 @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
|
1306 @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
|
1307 @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
|
1308 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
|
1309 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1310 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
|
1311 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
|
1312 |
24595
5ed2e9248ee9
doc: Tweaks to use single quotes instead of double quotes (bug #52870).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
1313 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
|
1314 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
|
1315 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1316 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1317 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
|
1318 @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
|
1319 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1320 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1321 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
|
1322 @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
|
1323 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
|
1324 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
|
1325 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1326 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
|
1327 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
|
1328 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1329 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1330 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
|
1331 @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
|
1332 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1333 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1334 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
|
1335 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1336 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
|
1337 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
|
1338 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
|
1339 @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
|
1340 @end deftypefn */) |
5794 | 1341 { |
1342 return SET_INTERNAL_VARIABLE (PS1); | |
1343 } | |
2181 | 1344 |
5794 | 1345 DEFUN (PS2, 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
|
1346 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
|
1347 @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
|
1348 @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
|
1349 @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
|
1350 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
|
1351 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1352 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
|
1353 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
|
1354 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
|
1355 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
|
1356 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
|
1357 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1358 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
|
1359 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
|
1360 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
|
1361 @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
|
1362 @end deftypefn */) |
5794 | 1363 { |
1364 return SET_INTERNAL_VARIABLE (PS2); | |
1365 } | |
2181 | 1366 |
5794 | 1367 DEFUN (completion_append_char, 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
|
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 {} {@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
|
1370 @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
|
1371 @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
|
1372 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
|
1373 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
|
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 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
|
1376 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1377 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
|
1378 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
|
1379 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
|
1380 @end deftypefn */) |
5794 | 1381 { |
1382 return SET_INTERNAL_VARIABLE (completion_append_char); | |
1383 } | |
3019 | 1384 |
6257 | 1385 DEFUN (__request_drawnow__, 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
|
1386 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
|
1387 @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
|
1388 @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
|
1389 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
|
1390 @end deftypefn */) |
6257 | 1391 { |
1392 int nargin = args.length (); | |
1393 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1394 if (nargin > 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1395 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1396 |
6257 | 1397 if (nargin == 0) |
1398 Vdrawnow_requested = true; | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1399 else |
6257 | 1400 Vdrawnow_requested = args(0).bool_value (); |
1401 | |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1402 return ovl (); |
6257 | 1403 } |
1404 | |
7294 | 1405 DEFUN (__gud_mode__, 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
|
1406 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
|
1407 @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
|
1408 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
|
1409 @end deftypefn */) |
7294 | 1410 { |
1411 int nargin = args.length (); | |
1412 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1413 if (nargin > 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1414 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1415 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1416 octave_value_list retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1417 |
7294 | 1418 if (nargin == 0) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1419 retval = ovl (Vgud_mode); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1420 else |
7294 | 1421 Vgud_mode = args(0).bool_value (); |
1422 | |
21006
ea779f11deae
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
20996
diff
changeset
|
1423 return retval; |
7294 | 1424 } |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1425 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1426 DEFUN (__mfile_encoding__, args, , |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1427 doc: /* -*- texinfo -*- |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1428 @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
|
1429 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
|
1430 @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
|
1431 { |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1432 int nargin = args.length (); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1433 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1434 if (nargin > 1) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1435 print_usage (); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1436 |
25370
9cc1ca6538e3
Always return previous mfile_encoding setting (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25361
diff
changeset
|
1437 std::string old_mfile_encoding = Vmfile_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
|
1438 if (nargin > 0) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1439 { |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1440 std::string str = args(0).xstring_value ( |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1441 "__mfile_encoding__: NEW_ENCODING must be a string designating a valid codepage."); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1442 if (str.empty ()) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1443 #if defined (OCTAVE_USE_WINDOWS_API) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1444 Vmfile_encoding = "system"; |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1445 #else |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1446 Vmfile_encoding = "utf-8"; |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1447 #endif |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1448 else |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1449 { |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1450 std::transform (str.begin (), str.end (), str.begin (), ::tolower); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1451 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1452 std::string codepage = (str.compare ("system") == 0) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1453 ? octave_locale_charset_wrapper () : str; |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1454 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1455 // check if valid codepage |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1456 void *codec = octave_iconv_open_wrapper (codepage.c_str (), "utf-8"); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1457 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1458 if (errno == EINVAL) |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1459 error ("__mfile_encoding__: Conversion from codepage '%s' not supported", |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1460 codepage.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
|
1461 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1462 octave_iconv_close_wrapper (codec); |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1463 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1464 Vmfile_encoding = str; |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1465 } |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1466 } |
25370
9cc1ca6538e3
Always return previous mfile_encoding setting (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25361
diff
changeset
|
1467 return ovl (old_mfile_encoding); |
9cc1ca6538e3
Always return previous mfile_encoding setting (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25361
diff
changeset
|
1468 } |