Mercurial > octave
annotate libinterp/corefcn/input.cc @ 31105:670a0d878af1
eliminate WHO arguments from interpreter-private functions
* interpreter-private.h, inpterpreter-private.cc (__get_interpreter__,
__get_dynamic_loader__, __get_error_system__, __get_gh_manager__,
__get_help_system__, __get_input_system__, __get_load_path__,
__get_load_save_system__, __get_event_manager__,
__get_output_system__, __get_type_info__, __get_symbol_table__,
__get_current_scope__, __require_current_scope__, __get_evaluator__,
__get_bp_table__, __get_child_list__, __get_cdef_manager__,
__get_display_info__, __get_gtk_manager__): Eliminate WHO argument.
Previously, it was never displayed by __get_interpreter__. And, as
pointed out by Petter Tomner in patch #10216, passing a std::string
object could have performance issues.
(__get_interpreter__): Eliminate useless call to error. Display
message to std::cerr then abort.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Jun 2022 12:48:59 -0400 |
parents | 32d2b6604a9f |
children | f125ddb46055 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30377
diff
changeset
|
3 // Copyright (C) 1993-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
1 | 25 |
2939 | 26 // Get command input interactively or from files. |
1 | 27 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21547
diff
changeset
|
28 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
29 # include "config.h" |
1 | 30 #endif |
31 | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
32 #include <cstdio> |
1343 | 33 #include <cstdlib> |
34 #include <cstring> | |
35 #include <cassert> | |
36 | |
27748
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
37 #include <algorithm> |
3503 | 38 #include <iostream> |
29335
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
39 #include <queue> |
5765 | 40 #include <sstream> |
1728 | 41 #include <string> |
42 | |
2927 | 43 #include "cmd-edit.h" |
3189 | 44 #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
|
45 #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
|
46 #include "localcharset-wrapper.h" |
27785
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
47 #include "oct-string.h" |
4153 | 48 #include "quit.h" |
1755 | 49 #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
|
50 #include "uniconv-wrappers.h" |
1755 | 51 |
23129
35e3d199527c
Replace feval calls with direct call to C++ function (bug #50116).
Rik <rik@octave.org>
parents:
23127
diff
changeset
|
52 #include "builtin-defun-decls.h" |
1352 | 53 #include "defun.h" |
1 | 54 #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
|
55 #include "errwarn.h" |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
56 #include "event-manager.h" |
3016 | 57 #include "help.h" |
16381
f33dcbd6a005
move hook_function classes to separate file
John W. Eaton <jwe@octave.org>
parents:
16378
diff
changeset
|
58 #include "hook-fcn.h" |
1 | 59 #include "input.h" |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
60 #include "interpreter-private.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
61 #include "interpreter.h" |
5832 | 62 #include "load-path.h" |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
63 #include "octave.h" |
1352 | 64 #include "oct-map.h" |
1742 | 65 #include "oct-hist.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
66 #include "interpreter.h" |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
67 #include "event-manager.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
68 #include "ovl.h" |
16347
bf8397caeff1
allow add_input_event_hook to accept function handles
John W. Eaton <jwe@octave.org>
parents:
16336
diff
changeset
|
69 #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
|
70 #include "ov-usr-fcn.h" |
1 | 71 #include "pager.h" |
529 | 72 #include "parse.h" |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
73 #include "pt-eval.h" |
3805 | 74 #include "pt-stmt.h" |
1352 | 75 #include "sighandlers.h" |
1114 | 76 #include "sysdep.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
77 #include "interpreter.h" |
3098 | 78 #include "unwind-prot.h" |
1352 | 79 #include "utils.h" |
80 #include "variables.h" | |
529 | 81 |
3165 | 82 // 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
|
83 octave::sys::time Vlast_prompt_time = 0.0; |
3165 | 84 |
3804 | 85 // TRUE after a call to completion_matches. |
2299 | 86 bool octave_completion_matches_called = false; |
87 | |
6257 | 88 // TRUE if the plotting system has requested a call to drawnow at |
89 // the next user prompt. | |
7409 | 90 bool Vdrawnow_requested = false; |
6257 | 91 |
29960
939bef0b66e0
merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
92 OCTAVE_NAMESPACE_BEGIN |
939bef0b66e0
merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
93 |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
94 static std::string |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
95 quoting_filename (const std::string& text, int, char quote) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
96 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
97 if (quote) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
98 return text; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
99 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
100 return ("'" + text); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
101 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
102 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
103 // Try to parse a partial command line in reverse, excluding trailing TEXT. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
104 // If it appears a variable has been indexed by () or {}, |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
105 // return that expression, |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
106 // to allow autocomplete of field names of arrays of structures. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
107 static std::string |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
108 find_indexed_expression (const std::string& text) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
109 { |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
110 std::string line = command_editor::get_line_buffer (); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
111 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
112 int pos = line.length () - text.length (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
113 int curly_count = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
114 int paren_count = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
115 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
116 int last = --pos; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
117 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
118 while (pos >= 0 && (line[pos] == ')' || line[pos] == '}')) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
119 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
120 if (line[pos] == ')') |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
121 paren_count++; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
122 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
123 curly_count++; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
124 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
125 while (curly_count + paren_count > 0 && --pos >= 0) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
126 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
127 if (line[pos] == ')') |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
128 paren_count++; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
129 else if (line[pos] == '(') |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
130 paren_count--; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
131 else if (line[pos] == '}') |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
132 curly_count++; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
133 else if (line[pos] == '{') |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
134 curly_count--; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
135 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
136 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
137 while (--pos >= 0 && line[pos] == ' ') |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
138 ; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
139 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
140 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
141 while (pos >= 0 && (isalnum (line[pos]) || line[pos] == '_')) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
142 pos--; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
143 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
144 if (++pos >= 0) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
145 return (line.substr (pos, last + 1 - pos)); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
146 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
147 return std::string (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
148 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
149 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
150 static string_vector |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
151 generate_struct_completions (const std::string& text, |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
152 std::string& prefix, std::string& hint) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
153 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
154 string_vector names; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
155 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
156 std::size_t pos = text.rfind ('.'); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
157 bool array = false; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
158 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
159 if (pos != std::string::npos) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
160 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
161 if (pos == text.length ()) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
162 hint = ""; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
163 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
164 hint = text.substr (pos+1); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
165 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
166 prefix = text.substr (0, pos); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
167 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
168 if (prefix == "") |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
169 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
170 array = true; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
171 prefix = find_indexed_expression (text); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
172 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
173 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
174 std::string base_name = prefix; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
175 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
176 pos = base_name.find_first_of ("{(. "); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
177 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
178 if (pos != std::string::npos) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
179 base_name = base_name.substr (0, pos); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
180 |
31105
670a0d878af1
eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents:
30888
diff
changeset
|
181 interpreter& interp = __get_interpreter__ (); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
182 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
183 if (interp.is_variable (base_name)) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
184 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
185 int parse_status; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
186 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
187 error_system& es = interp.get_error_system (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
188 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
189 unwind_protect frame; |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
190 |
29253
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29163
diff
changeset
|
191 frame.add (&error_system::set_discard_warning_messages, &es, |
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29163
diff
changeset
|
192 es.discard_warning_messages ()); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
193 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
194 es.discard_warning_messages (true); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
195 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
196 try |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
197 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
198 octave_value tmp |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
199 = interp.eval_string (prefix, true, parse_status); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
200 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
201 frame.run (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
202 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
203 if (tmp.is_defined () |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
204 && (tmp.isstruct () || tmp.isjava () || tmp.is_classdef_object ())) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
205 names = tmp.map_keys (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
206 } |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
207 catch (const execution_exception&) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
208 { |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
209 interp.recover_from_exception (); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
210 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
211 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
212 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
213 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
214 // Undo look-back that found the array expression, |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
215 // but insert an extra "." to distinguish from the non-struct case. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
216 if (array) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
217 prefix = "."; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
218 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
219 return names; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
220 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
221 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
222 // FIXME: this will have to be much smarter to work "correctly". |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
223 static bool |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
224 looks_like_struct (const std::string& text, char prev_char) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
225 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
226 bool retval = (! text.empty () |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
227 && (text != "." || prev_char == ')' || prev_char == '}') |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
228 && text.find_first_of (sys::file_ops::dir_sep_chars ()) == std::string::npos |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
229 && text.find ("..") == std::string::npos |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
230 && text.rfind ('.') != std::string::npos); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
231 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
232 return retval; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
233 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
234 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
235 // FIXME: make this generate filenames when appropriate. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
236 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
237 static string_vector |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
238 generate_possible_completions (const std::string& text, std::string& prefix, |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
239 std::string& hint, bool& deemed_struct) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
240 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
241 string_vector names; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
242 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
243 prefix = ""; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
244 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
245 char prev_char = command_editor::get_prev_char (text.length ()); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
246 deemed_struct = looks_like_struct (text, prev_char); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
247 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
248 if (deemed_struct) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
249 names = generate_struct_completions (text, prefix, hint); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
250 else |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
251 names = make_name_list (); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
252 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
253 // Sort and remove duplicates. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
254 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
255 names.sort (true); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
256 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
257 return names; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
258 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
259 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
260 static bool |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
261 is_completing_dirfns (void) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
262 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
263 static std::string dirfns_commands[] = {"cd", "isfile", "isfolder", "ls"}; |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
264 static const std::size_t dirfns_commands_length = 4; |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
265 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
266 bool retval = false; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
267 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
268 std::string line = command_editor::get_line_buffer (); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
269 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
270 for (std::size_t i = 0; i < dirfns_commands_length; i++) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
271 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
272 int index = line.find (dirfns_commands[i] + ' '); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
273 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
274 if (index == 0) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
275 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
276 retval = true; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
277 break; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
278 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
279 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
280 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
281 return retval; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
282 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
283 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
284 static std::string |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
285 generate_completion (const std::string& text, int state) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
286 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
287 std::string retval; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
288 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
289 static std::string prefix; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
290 static std::string hint; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
291 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
292 static std::size_t hint_len = 0; |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
293 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
294 static int list_index = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
295 static int name_list_len = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
296 static int name_list_total_len = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
297 static string_vector name_list; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
298 static string_vector file_name_list; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
299 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
300 static int matches = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
301 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
302 if (state == 0) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
303 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
304 list_index = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
305 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
306 prefix = ""; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
307 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
308 hint = text; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
309 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
310 // No reason to display symbols while completing a |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
311 // file/directory operation. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
312 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
313 bool deemed_struct = false; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
314 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
315 if (is_completing_dirfns ()) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
316 name_list = string_vector (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
317 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
318 name_list = generate_possible_completions (text, prefix, hint, |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
319 deemed_struct); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
320 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
321 name_list_len = name_list.numel (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
322 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
323 // If the line was something like "a{1}." then text = "." but |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
324 // we don't want to expand all the . files. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
325 if (! deemed_struct) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
326 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
327 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
328 file_name_list = command_editor::generate_filename_completions (text); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
329 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
330 name_list.append (file_name_list); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
331 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
332 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
333 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
334 name_list_total_len = name_list.numel (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
335 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
336 hint_len = hint.length (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
337 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
338 matches = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
339 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
340 for (int i = 0; i < name_list_len; i++) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
341 if (hint == name_list[i].substr (0, hint_len)) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
342 matches++; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
343 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
344 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
345 if (name_list_total_len > 0 && matches > 0) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
346 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
347 while (list_index < name_list_total_len) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
348 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
349 std::string name = name_list[list_index]; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
350 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
351 list_index++; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
352 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
353 if (hint == name.substr (0, hint_len)) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
354 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
355 // Special case: array reference forces prefix="." |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
356 // in generate_struct_completions () |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
357 if (list_index <= name_list_len && ! prefix.empty ()) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
358 retval = (prefix == "." ? "" : prefix) + '.' + name; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
359 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
360 retval = name; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
361 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
362 char prev_char = |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
363 command_editor::get_prev_char (text.length ()); |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
364 |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
365 if (matches == 1 && looks_like_struct (retval, prev_char)) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
366 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
367 // Don't append anything, since we don't know |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
368 // whether it should be '(' or '.'. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
369 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
370 command_editor::set_completion_append_character ('\0'); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
371 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
372 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
373 { |
31105
670a0d878af1
eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents:
30888
diff
changeset
|
374 input_system& input_sys = __get_input_system__ (); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
375 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
376 command_editor::set_completion_append_character |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
377 (input_sys.completion_append_char ()); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
378 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
379 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
380 break; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
381 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
382 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
383 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
384 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
385 return retval; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
386 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
387 |
28707
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
388 static int internal_input_event_hook_fcn (void) |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
389 { |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
390 octave_quit (); |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
391 |
31105
670a0d878af1
eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents:
30888
diff
changeset
|
392 input_system& input_sys = __get_input_system__ (); |
28707
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
393 |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
394 input_sys.run_input_event_hooks (); |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
395 |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
396 return 0; |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
397 } |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
398 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
399 // Use literal "octave" in default setting for PS1 instead of |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
400 // "\\s" to avoid setting the prompt to "octave.exe" or |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
401 // "octave-gui", etc. |
6257 | 402 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
403 input_system::input_system (interpreter& interp) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
404 : m_interpreter (interp), m_PS1 (R"(octave:\#> )"), m_PS2 ("> "), |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
405 m_completion_append_char (' '), m_gud_mode (false), |
29120
eb6599cf2db5
Use UTF-8 encoding for .m files by default (bug #59387).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29117
diff
changeset
|
406 m_mfile_encoding ("utf-8"), m_auto_repeat_debug_command (true), |
28972
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
407 m_last_debugging_command ("\n"), m_input_event_hook_functions (), |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
408 m_initialized (false) |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
409 { } |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
410 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
411 void input_system::initialize (bool line_editing) |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
412 { |
28707
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
413 if (m_initialized) |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
414 return; |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
415 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
416 // Force default line editor if we don't want readline editing. |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
417 if (! line_editing) |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
418 { |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
419 command_editor::force_default_editor (); |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
420 return; |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
421 } |
6257 | 422 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
423 // If we are using readline, this allows conditional parsing of the |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
424 // .inputrc file. |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
425 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
426 command_editor::set_name ("Octave"); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
427 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
428 // FIXME: this needs to include a comma too, but that |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
429 // causes trouble for the new struct element completion code. |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
430 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
431 static const char *s = "\t\n !\"\'*+-/:;<=>(){}[\\]^`~"; |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
432 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
433 command_editor::set_basic_word_break_characters (s); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
434 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
435 command_editor::set_completer_word_break_characters (s); |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
436 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
437 command_editor::set_basic_quote_characters (R"(")"); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
438 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
439 command_editor::set_filename_quote_characters (" \t\n\\\"'@<>=;|&()#$`?*[!:{"); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
440 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
441 command_editor::set_completer_quote_characters (R"('")"); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
442 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
443 command_editor::set_completion_function (generate_completion); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
444 |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
445 command_editor::set_quoting_function (quoting_filename); |
28707
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
446 |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
447 command_editor::add_event_hook (internal_input_event_hook_fcn); |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
448 |
f0a3f4527ba6
respond to signals when readline is waiting for input (bug #54444)
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
449 m_initialized = true; |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
450 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
451 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
452 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
453 input_system::PS1 (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
454 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
455 return set_internal_variable (m_PS1, args, nargout, "PS1"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
456 } |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
457 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
458 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
459 input_system::PS2 (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
460 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
461 return set_internal_variable (m_PS2, args, nargout, "PS2"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
462 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
463 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
464 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
465 input_system::completion_append_char (const octave_value_list& args, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
466 int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
467 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
468 return set_internal_variable (m_completion_append_char, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
469 "completion_append_char"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
470 } |
22171
0a4c5a90f286
Allow tab completion of arrays of structures.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22164
diff
changeset
|
471 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
472 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
473 input_system::gud_mode (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
474 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
475 return set_internal_variable (m_gud_mode, args, nargout, "__gud_mode__"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
476 } |
269 | 477 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
478 octave_value |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
479 input_system::mfile_encoding (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
480 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
481 // Save current value in case there is an error in the additional |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
482 // validation below. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
483 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
484 std::string saved_encoding = m_mfile_encoding; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
485 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
486 // We must pass the actual variable to change here for temporary |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
487 // "local" settings to work properly. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
488 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
489 octave_value retval |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
490 = set_internal_variable (m_mfile_encoding, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
491 "__mfile_encoding__"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
492 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
493 // Additional validation if the encoding has changed. |
1358 | 494 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
495 if (m_mfile_encoding != saved_encoding) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
496 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
497 if (m_mfile_encoding.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
498 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
499 m_mfile_encoding = "system"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
500 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
501 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
502 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
503 std::transform (m_mfile_encoding.begin (), |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
504 m_mfile_encoding.end (), |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
505 m_mfile_encoding.begin (), ::tolower); |
3933 | 506 |
26880
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
507 std::string encoding = (m_mfile_encoding.compare ("system") == 0) |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
508 ? octave_locale_charset_wrapper () : m_mfile_encoding; |
3933 | 509 |
26880
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
510 // Check for valid encoding name. |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
511 void *codec |
26880
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
512 = octave_iconv_open_wrapper (encoding.c_str (), "utf-8"); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
513 |
26880
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
514 if (codec == reinterpret_cast<void *> (-1)) |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
515 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
516 m_mfile_encoding = saved_encoding; |
26880
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
517 if (errno == EINVAL) |
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
518 error ("__mfile_encoding__: conversion from encoding '%s' " |
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
519 "not supported", encoding.c_str ()); |
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
520 else |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28888
diff
changeset
|
521 error ("__mfile_encoding__: error %d opening encoding '%s'", |
26880
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
522 errno, encoding.c_str ()); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
523 } |
26880
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
524 else |
6c25c714bec4
Improve error checking for iconv_open.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
525 octave_iconv_close_wrapper (codec); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
526 } |
25700
ba8227df92ae
synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents:
25659
diff
changeset
|
527 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
528 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
529 |
25700
ba8227df92ae
synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents:
25659
diff
changeset
|
530 // Synchronize the related gui preference for editor encoding |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
531 feval ("__event_manager_gui_preference__", |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
532 ovl ("editor/default_encoding", m_mfile_encoding)); |
25700
ba8227df92ae
synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents:
25659
diff
changeset
|
533 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
534 return retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
535 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
536 |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
537 // Get part of the directory that would be added to the load path |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
538 static std::string load_path_dir (const std::string& dir) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
539 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
540 std::string lp_dir = dir; |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
541 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
542 // strip trailing filesep |
29572
aef11bb4e6d1
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29563
diff
changeset
|
543 std::size_t ipos = lp_dir.find_last_not_of (sys::file_ops::dir_sep_chars ()); |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
544 if (ipos != std::string::npos) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
545 lp_dir = lp_dir.erase (ipos+1); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
546 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
547 // strip trailing private folder |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
548 ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ()); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
549 if (ipos != std::string::npos |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
550 && lp_dir.substr (ipos+1).compare ("private") == 0) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
551 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
552 lp_dir = lp_dir.erase (ipos); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
553 ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ()); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
554 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
555 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
556 // strip trailing @class folder |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
557 if (ipos != std::string::npos && lp_dir[ipos+1] == '@') |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
558 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
559 lp_dir = lp_dir.erase (ipos); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
560 ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ()); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
561 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
562 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
563 // strip (nested) +namespace folders |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
564 while (ipos != std::string::npos && lp_dir[ipos+1] == '+') |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
565 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
566 lp_dir = lp_dir.erase (ipos); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
567 ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ()); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
568 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
569 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
570 return lp_dir; |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
571 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
572 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
573 std::string input_system::dir_encoding (const std::string& dir) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
574 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
575 std::string enc = m_mfile_encoding; |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
576 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
577 auto enc_it = m_dir_encoding.find (load_path_dir (dir)); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
578 if (enc_it != m_dir_encoding.end ()) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
579 enc = enc_it->second; |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
580 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
581 return enc; |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
582 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
583 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
584 void input_system::set_dir_encoding (const std::string& dir, |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
585 std::string& enc) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
586 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
587 // use lower case |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
588 std::transform (enc.begin (), enc.end (), enc.begin (), ::tolower); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
589 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
590 if (enc.compare ("delete") == 0) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
591 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
592 // Remove path from map |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
593 m_dir_encoding.erase (load_path_dir (dir)); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
594 return; |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
595 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
596 else if (enc.compare ("utf-8")) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
597 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
598 // Check for valid encoding name. |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
599 // FIXME: This will probably not happen very often and opening the |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
600 // encoder doesn't take long. |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
601 // Should we cache working encoding identifiers anyway? |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
602 void *codec |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
603 = octave_iconv_open_wrapper (enc.c_str (), "utf-8"); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
604 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
605 if (codec == reinterpret_cast<void *> (-1)) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
606 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
607 if (errno == EINVAL) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
608 error ("dir_encoding: conversion from encoding '%s' " |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
609 "not supported", enc.c_str ()); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
610 else |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
611 error ("dir_encoding: error %d opening encoding '%s'.", |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
612 errno, enc.c_str ()); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
613 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
614 else |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
615 octave_iconv_close_wrapper (codec); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
616 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
617 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
618 m_dir_encoding[load_path_dir (dir)] = enc; |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
619 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
620 return; |
28973 | 621 } |
29127
a948253f9976
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29120
diff
changeset
|
622 |
28972
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
623 octave_value |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
624 input_system::auto_repeat_debug_command (const octave_value_list& args, |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
625 int nargout) |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
626 { |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
627 return set_internal_variable (m_auto_repeat_debug_command, args, nargout, |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
628 "auto_repeat_debug_command"); |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
629 } |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
630 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
631 bool input_system::yes_or_no (const std::string& prompt) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
632 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
633 std::string prompt_string = prompt + "(yes or no) "; |
6367 | 634 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
635 while (1) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
636 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
637 bool eof = false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
638 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
639 std::string input_buf = interactive_input (prompt_string, eof); |
6979 | 640 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
641 if (input_buf == "yes") |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
642 return true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
643 else if (input_buf == "no") |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
644 return false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
645 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
646 message (nullptr, "Please answer yes or no."); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
647 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
648 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
649 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
650 std::string input_system::interactive_input (const std::string& s, bool& eof) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
651 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
652 Vlast_prompt_time.stamp (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
653 |
27301
a2b1ba6c92d5
eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents:
27272
diff
changeset
|
654 if (Vdrawnow_requested && m_interpreter.interactive ()) |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
655 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
656 bool eval_error = false; |
6979 | 657 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
658 try |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
659 { |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27301
diff
changeset
|
660 Fdrawnow (m_interpreter); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
661 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29127
diff
changeset
|
662 catch (const execution_exception& ee) |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
663 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
664 eval_error = true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
665 |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29127
diff
changeset
|
666 m_interpreter.handle_exception (ee); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
667 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
668 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
669 flush_stdout (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
670 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
671 // We set Vdrawnow_requested to false even if there is an error in |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
672 // drawnow so that the error doesn't reappear at every prompt. |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
673 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
674 Vdrawnow_requested = false; |
16419
16bfbf9136d3
avoid creating unnecessary octave_value objects for octave_link calls
John W. Eaton <jwe@octave.org>
parents:
16416
diff
changeset
|
675 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
676 if (eval_error) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
677 return "\n"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
678 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
679 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
680 return gnu_readline (s, eof); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
681 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
682 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
683 // If the user simply hits return, this will produce an empty matrix. |
6305 | 684 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
685 octave_value_list |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
686 input_system::get_user_input (const octave_value_list& args, int nargout) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
687 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
688 octave_value_list retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
689 |
30266
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
690 std::string prompt = args(0).xstring_value ("input: unrecognized argument"); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
691 |
30266
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
692 bool read_as_string = false; |
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
693 if (args.length () == 2) // `input (..., "s")`? |
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
694 { |
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
695 std::string literal |
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
696 = args(1).xstring_value ("input: second argument must be 's'."); |
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
697 if (literal.length () != 1 || literal[0] != 's') |
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
698 error ("input: second argument must be 's'."); |
16395
fc491da603f6
also provide a hook for exiting debugger
John W. Eaton <jwe@octave.org>
parents:
16386
diff
changeset
|
699 |
30266
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
700 read_as_string = true; |
38ee67b5ec9f
input.cc: throw error if second argument does not equal 's'
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
29961
diff
changeset
|
701 } |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
702 |
27444
160930a3e5ee
eliminate some calls to global __get_SUBSYSTEM__ functions
John W. Eaton <jwe@octave.org>
parents:
27428
diff
changeset
|
703 output_system& output_sys = m_interpreter.get_output_system (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
704 |
25435
a52e6fb674b1
eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents:
25407
diff
changeset
|
705 output_sys.reset (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
706 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
707 octave_diary << prompt; |
25402
ef2b9d4abf4a
eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
708 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
709 bool eof = false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
710 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
711 std::string input_buf = interactive_input (prompt.c_str (), eof); |
19595
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19379
diff
changeset
|
712 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
713 if (input_buf.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
714 error ("input: reading user-input failed!"); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
715 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
716 std::size_t len = input_buf.length (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
717 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
718 octave_diary << input_buf; |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
719 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
720 if (input_buf[len - 1] != '\n') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
721 octave_diary << "\n"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
722 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
723 if (read_as_string) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
724 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
725 // FIXME: fix gnu_readline and octave_gets instead! |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
726 if (input_buf.length () == 1 && input_buf[0] == '\n') |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
727 retval(0) = ""; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
728 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
729 retval(0) = input_buf; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
730 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
731 else |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
732 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
733 int parse_status = 0; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
734 |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
735 retval |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
26062
diff
changeset
|
736 = m_interpreter.eval_string (input_buf, true, parse_status, nargout); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
737 |
27037
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
738 tree_evaluator& tw = m_interpreter.get_evaluator (); |
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
739 |
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
740 if (! tw.in_debug_repl () && retval.empty ()) |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
741 retval(0) = Matrix (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
742 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
743 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
744 return retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
745 } |
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
|
746 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
747 bool input_system::have_input_event_hooks (void) const |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
748 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
749 return ! m_input_event_hook_functions.empty (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
750 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
751 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
752 void input_system::add_input_event_hook (const hook_function& hook_fcn) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
753 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
754 m_input_event_hook_functions.insert (hook_fcn.id (), hook_fcn); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
755 } |
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
|
756 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
757 bool input_system::remove_input_event_hook (const std::string& hook_fcn_id) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
758 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
759 hook_function_list::iterator p |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
760 = m_input_event_hook_functions.find (hook_fcn_id); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
761 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
762 if (p == m_input_event_hook_functions.end ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
763 return false; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
764 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
765 m_input_event_hook_functions.erase (p); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
766 return true; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
767 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
768 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
769 void input_system::clear_input_event_hooks (void) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
770 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
771 m_input_event_hook_functions.clear (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
772 } |
269 | 773 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
774 void input_system::run_input_event_hooks (void) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
775 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
776 m_input_event_hook_functions.run (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
777 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
778 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
779 std::string |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
780 input_system::gnu_readline (const std::string& s, bool& eof) const |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
781 { |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
782 octave_quit (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
783 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
784 eof = false; |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
785 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
786 std::string retval = command_editor::readline (s, eof); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
787 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
788 if (! eof && retval.empty ()) |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
789 retval = "\n"; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
790 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
791 return retval; |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
792 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
793 |
27527
73be3c628eac
refactor input_reader class and its use in lexer
John W. Eaton <jwe@octave.org>
parents:
27502
diff
changeset
|
794 std::string base_reader::octave_gets (const std::string& prompt, bool& eof) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
795 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
796 octave_quit (); |
5142 | 797 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
798 eof = false; |
16097
2f4fa62089b3
improve end of file handling for lexer input
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
799 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
800 std::string retval; |
1 | 801 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
802 // 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
|
803 // printing the prompt. |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
804 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
805 tree_evaluator& tw = m_interpreter.get_evaluator (); |
27037
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
806 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
807 event_manager& evmgr = m_interpreter.get_event_manager (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27200
diff
changeset
|
808 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
809 if (m_interpreter.interactive ()) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
810 { |
27037
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
811 if (! tw.in_debug_repl ()) |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
812 evmgr.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
|
813 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
814 evmgr.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
|
815 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
816 evmgr.set_workspace (); |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
817 } |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
818 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
819 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
|
820 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
821 input_system& input_sys = m_interpreter.get_input_system (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
822 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
823 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
|
824 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
825 output_system& output_sys = m_interpreter.get_output_system (); |
1755 | 826 |
25435
a52e6fb674b1
eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents:
25407
diff
changeset
|
827 output_sys.reset (); |
2618 | 828 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
829 octave_diary << prompt; |
1 | 830 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
831 retval = input_sys.interactive_input (prompt, eof); |
581 | 832 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
833 // 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
|
834 // user input. |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
835 if (retval != "\n" |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
836 && 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
|
837 { |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
838 load_path& lp = m_interpreter.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
839 |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
840 lp.update (); |
8841
c74389115610
auto repeat for debugging commands
John W. Eaton <jwe@octave.org>
parents:
8749
diff
changeset
|
841 |
27037
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
842 if (tw.in_debug_repl ()) |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
843 input_sys.last_debugging_command (retval); |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
844 else |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
845 input_sys.last_debugging_command ("\n"); |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
846 } |
28972
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
847 else if (tw.in_debug_repl () && input_sys.auto_repeat_debug_command ()) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
848 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
849 retval = input_sys.last_debugging_command (); |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
850 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
|
851 } |
1 | 852 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
853 if (retval != "\n") |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
854 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
855 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
|
856 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23694
diff
changeset
|
857 if (command_history::add (retval)) |
27529
886df2049d81
only increment command number when complete block of code is parsed
John W. Eaton <jwe@octave.org>
parents:
27527
diff
changeset
|
858 evmgr.append_history (retval); |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
859 } |
1 | 860 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
861 octave_diary << retval; |
3176 | 862 |
26061
cb3ead3cf859
avoid assertion failure with -D_GLIBCXX_ASSERTIONS
Orion Poplawski <orion@cora.nwra.com>
parents:
25054
diff
changeset
|
863 if (! retval.empty () && retval.back () != '\n') |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
864 octave_diary << "\n"; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
865 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
866 else |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
867 octave_diary << "\n"; |
581 | 868 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
869 // 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
|
870 // list has been updated. |
9476 | 871 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
872 if (m_interpreter.interactive ()) |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
873 evmgr.post_input_event (); |
16349
610617eb84d1
provide pre- and post-input hook functions
John W. Eaton <jwe@octave.org>
parents:
16347
diff
changeset
|
874 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
875 return retval; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
876 } |
1 | 877 |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
878 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
879 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
|
880 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
881 public: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
882 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
883 terminal_reader (interpreter& interp) |
29335
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
884 : base_reader (interp), m_eof (false), m_input_queue () |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
885 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
886 |
27527
73be3c628eac
refactor input_reader class and its use in lexer
John W. Eaton <jwe@octave.org>
parents:
27502
diff
changeset
|
887 std::string get_input (const std::string& prompt, bool& eof); |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
888 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
889 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
|
890 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
891 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
|
892 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
893 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
894 |
29335
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
895 bool m_eof; |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
896 std::queue<std::string> m_input_queue; |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
897 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
898 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
|
899 }; |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
900 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
901 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
902 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
|
903 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
904 public: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
905 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
906 file_reader (interpreter& interp, FILE *f_arg) |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
907 : base_reader (interp), m_file (f_arg) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
908 { |
29950
6549fa7558ba
eliminate some unnecessary octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
29937
diff
changeset
|
909 input_system& input_sys = interp.get_input_system (); |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
910 m_encoding = input_sys.mfile_encoding (); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
911 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
912 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
913 file_reader (interpreter& interp, FILE *f_arg, const std::string& enc) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
914 : base_reader (interp), m_file (f_arg), m_encoding (enc) { } |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
915 |
27527
73be3c628eac
refactor input_reader class and its use in lexer
John W. Eaton <jwe@octave.org>
parents:
27502
diff
changeset
|
916 std::string get_input (const std::string& prompt, bool& eof); |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
917 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
918 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
|
919 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
920 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
|
921 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
922 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
923 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
924 FILE *m_file; |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
925 |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
926 std::string m_encoding; |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
927 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
928 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
|
929 }; |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
930 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
931 class |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
932 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
|
933 { |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
934 public: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
935 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
936 eval_string_reader (interpreter& interp, const std::string& str) |
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
937 : base_reader (interp), 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
|
938 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
939 |
27527
73be3c628eac
refactor input_reader class and its use in lexer
John W. Eaton <jwe@octave.org>
parents:
27502
diff
changeset
|
940 std::string get_input (const std::string& prompt, bool& eof); |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
941 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
942 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
|
943 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
944 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
|
945 |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
946 private: |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
947 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
948 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
|
949 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
950 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
|
951 }; |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
952 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
953 input_reader::input_reader (interpreter& interp) |
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
954 : m_rep (new terminal_reader (interp)) |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
955 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
956 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
957 input_reader::input_reader (interpreter& interp, FILE *file) |
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
958 : m_rep (new file_reader (interp, file)) |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
959 { } |
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
960 |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30337
diff
changeset
|
961 input_reader::input_reader (interpreter& interp, FILE *file, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30337
diff
changeset
|
962 const std::string& enc) |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
963 : m_rep (new file_reader (interp, file, enc)) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
964 { } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
965 |
27502
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
966 input_reader::input_reader (interpreter& interp, const std::string& str) |
f62f1170ad98
in base_reader, store reference to interpreter instead of lexer
John W. Eaton <jwe@octave.org>
parents:
27474
diff
changeset
|
967 : m_rep (new eval_string_reader (interp, str)) |
24732
f079a0856321
move internal input reader classes out of header file
John W. Eaton <jwe@octave.org>
parents:
24597
diff
changeset
|
968 { } |
17731
f79bf671a493
eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents:
17323
diff
changeset
|
969 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
970 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
|
971 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
972 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
|
973 |
29335
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
974 // If octave_gets returns multiple lines, we cache the input and |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
975 // return it one line at a time. Multiple input lines may happen when |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
976 // using readline and bracketed paste mode is enabled, for example. |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
977 // Instead of queueing lines here, it might be better to modify the |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
978 // grammar in the parser to handle multiple lines when working |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
979 // interactively. See also bug #59938. |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
980 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
981 std::string |
27527
73be3c628eac
refactor input_reader class and its use in lexer
John W. Eaton <jwe@octave.org>
parents:
27502
diff
changeset
|
982 terminal_reader::get_input (const std::string& prompt, bool& eof) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
983 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
984 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
985 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
986 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
987 |
29335
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
988 if (m_input_queue.empty ()) |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
989 { |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
990 std::string input = octave_gets (prompt, m_eof); |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
991 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
992 std::size_t len = input.size (); |
29335
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
993 |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
994 if (len == 0) |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
995 { |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
996 if (m_eof) |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
997 { |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
998 eof = m_eof; |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
999 return input; |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1000 } |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1001 else |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1002 { |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1003 // Can this happen, or will the string returned from |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1004 // octave_gets always end in a newline character? |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1005 |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1006 input = "\n"; |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1007 len = 1; |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1008 } |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1009 } |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1010 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1011 std::size_t beg = 0; |
29335
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1012 while (beg < len) |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1013 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1014 std::size_t end = input.find ('\n', beg); |
29335
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1015 |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1016 if (end == std::string::npos) |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1017 { |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1018 m_input_queue.push (input.substr (beg)); |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1019 break; |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1020 } |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1021 else |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1022 { |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1023 m_input_queue.push (input.substr (beg, end-beg+1)); |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1024 beg = end + 1; |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1025 } |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1026 } |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1027 } |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1028 |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1029 std::string retval = m_input_queue.front (); |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1030 m_input_queue.pop (); |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1031 |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1032 if (m_input_queue.empty ()) |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1033 eof = m_eof; |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1034 |
3180f830d396
line buffer input in terminal_reader class
John W. Eaton <jwe@octave.org>
parents:
28972
diff
changeset
|
1035 return retval; |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1036 } |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1037 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1038 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
|
1039 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1040 std::string |
27527
73be3c628eac
refactor input_reader class and its use in lexer
John W. Eaton <jwe@octave.org>
parents:
27502
diff
changeset
|
1041 file_reader::get_input (const std::string& /*prompt*/, bool& eof) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1042 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1043 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1044 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1045 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1046 |
29937
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1047 std::string src_str = fgets (m_file, eof); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1048 |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1049 std::string mfile_encoding; |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1050 |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1051 if (m_encoding.empty ()) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1052 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1053 input_system& input_sys = m_interpreter.get_input_system (); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1054 mfile_encoding = input_sys.mfile_encoding (); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1055 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1056 else |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1057 mfile_encoding = m_encoding; |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1058 |
27748
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1059 std::string encoding; |
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1060 if (mfile_encoding.compare ("system") == 0) |
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1061 { |
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1062 encoding = octave_locale_charset_wrapper (); |
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1063 // encoding identifiers should consist of ASCII only characters |
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1064 std::transform (encoding.begin (), encoding.end (), encoding.begin (), |
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1065 ::tolower); |
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1066 } |
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1067 else |
5fc630696dc7
Compare locale charset name in lower case (bug #57304).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27529
diff
changeset
|
1068 encoding = mfile_encoding; |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1069 |
25620
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1070 if (encoding.compare ("utf-8") == 0) |
27785
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1071 { |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1072 // Check for BOM and strip it |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1073 if (src_str.compare (0, 3, "\xef\xbb\xbf") == 0) |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1074 src_str.erase (0, 3); |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1075 |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1076 // replace invalid portions of the string |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1077 // FIXME: Include file name that corresponds to m_file. |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1078 if (string::u8_validate ("get_input", src_str) > 0) |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1079 warning_with_id ("octave:get_input:invalid_utf8", |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1080 "Invalid UTF-8 byte sequences have been replaced."); |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1081 } |
25620
467729037209
Strip BOM from UTF-8 encoded .m files (bug #52574).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25441
diff
changeset
|
1082 else |
27785
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1083 { |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1084 // convert encoding to UTF-8 before returning string |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1085 const char *src = src_str.c_str (); |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1086 std::size_t srclen = src_str.length (); |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1087 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1088 std::size_t length; |
27785
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1089 uint8_t *utf8_str; |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1090 |
27785
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1091 utf8_str = octave_u8_conv_from_encoding (encoding.c_str (), src, srclen, |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1092 &length); |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1093 |
27785
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1094 if (! utf8_str) |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1095 error ("file_reader::get_input: " |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1096 "converting from codepage '%s' to UTF-8: %s", |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1097 encoding.c_str (), std::strerror (errno)); |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1098 |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28851
diff
changeset
|
1099 unwind_action free_utf8_str ([=] () { ::free (utf8_str); }); |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1100 |
27785
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1101 src_str = std::string (reinterpret_cast<char *> (utf8_str), length); |
3f5026fd8da8
Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27748
diff
changeset
|
1102 } |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1103 |
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1104 return src_str; |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1105 } |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1106 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1107 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
|
1108 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1109 std::string |
27527
73be3c628eac
refactor input_reader class and its use in lexer
John W. Eaton <jwe@octave.org>
parents:
27502
diff
changeset
|
1110 eval_string_reader::get_input (const std::string& /*prompt*/, bool& eof) |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1111 { |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1112 octave_quit (); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1113 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1114 eof = false; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1115 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1116 std::string retval; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1117 |
24833
7c88cf242111
use m_ prefix for data members in more classes
John W. Eaton <jwe@octave.org>
parents:
24732
diff
changeset
|
1118 retval = m_eval_string; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1119 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1120 // 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
|
1121 // 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
|
1122 m_eval_string = ""; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1123 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1124 if (retval.empty ()) |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1125 eof = true; |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
1126 |
23061
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1127 return retval; |
aedc662896a3
move input reader classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1128 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29950
diff
changeset
|
1129 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1130 DEFMETHOD (input, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1131 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
|
1132 @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
|
1133 @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
|
1134 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
|
1135 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1136 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
|
1137 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1138 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1139 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
|
1140 @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
|
1141 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1142 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1143 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
|
1144 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1145 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1146 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
|
1147 @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
|
1148 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1149 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1150 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
|
1151 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
|
1152 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
|
1153 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1154 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
|
1155 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
|
1156 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1157 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
|
1158 @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
|
1159 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
|
1160 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
|
1161 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1162 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
|
1163 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
|
1164 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
|
1165 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
|
1166 @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
|
1167 @end deftypefn */) |
529 | 1168 { |
1169 int nargin = args.length (); | |
1170 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1171 if (nargin < 1 || nargin > 2) |
5823 | 1172 print_usage (); |
529 | 1173 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1174 input_system& input_sys = interp.get_input_system (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1175 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1176 return input_sys.get_user_input (args, std::max (nargout, 1)); |
529 | 1177 } |
1178 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1179 DEFMETHOD (yes_or_no, interp, args, , |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1180 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
|
1181 @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
|
1182 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
|
1183 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1184 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
|
1185 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1186 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
|
1187 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
|
1188 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
|
1189 @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
|
1190 @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
|
1191 @end deftypefn */) |
5640 | 1192 { |
1193 int nargin = args.length (); | |
1194 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1195 if (nargin > 1) |
5823 | 1196 print_usage (); |
5640 | 1197 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1198 input_system& input_sys = interp.get_input_system (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1199 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1200 std::string prompt; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1201 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1202 if (nargin == 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1203 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
|
1204 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1205 return ovl (input_sys.yes_or_no (prompt)); |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1206 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
1207 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1208 DEFMETHOD (keyboard, interp, args, , |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1209 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
|
1210 @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
|
1211 @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
|
1212 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
|
1213 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1214 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
|
1215 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
|
1216 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
|
1217 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
|
1218 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
|
1219 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
|
1220 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1221 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
|
1222 @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
|
1223 @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
|
1224 @end deftypefn */) |
529 | 1225 { |
27037
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1226 int nargin = args.length (); |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9482
diff
changeset
|
1227 |
27037
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1228 if (nargin > 1) |
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1229 print_usage (); |
10186
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1230 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1231 tree_evaluator& tw = interp.get_evaluator (); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1232 |
27037
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1233 if (nargin == 1) |
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1234 { |
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1235 std::string prompt |
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1236 = args(0).xstring_value ("keyboard: PROMPT must be a string"); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1237 |
27037
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1238 tw.keyboard (prompt); |
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1239 } |
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1240 else |
8408acb7ca4f
make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents:
26884
diff
changeset
|
1241 tw.keyboard (); |
529 | 1242 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1243 return ovl (); |
529 | 1244 } |
1245 | |
2234 | 1246 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
|
1247 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1248 @deftypefn {} {@var{completion_list} =} completion_matches ("@var{hint}") |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1249 Generate possible word completions for Octave given the character sequence |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1250 @var{hint}. |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1251 |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1252 This function is provided for the benefit of programs like Emacs which might be |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1253 controlling Octave and handling user input. For example: |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1254 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1255 @example |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1256 @group |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1257 completion_matches ("sine") |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1258 @result{} |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1259 sinetone |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1260 sinewave |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1261 @end group |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1262 @end example |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1263 |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1264 Programming Note: The current command number in Octave is not incremented when |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1265 this function is called. This is a feature, not a bug. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1266 @end deftypefn */) |
2234 | 1267 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
1268 if (args.length () != 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1269 print_usage (); |
2234 | 1270 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1271 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1272 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1273 std::string hint = args(0).string_value (); |
2234 | 1274 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1275 int n = 32; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1276 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1277 string_vector list (n); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1278 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1279 int k = 0; |
2234 | 1280 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1281 for (;;) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1282 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1283 std::string cmd = generate_completion (hint, k); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1284 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1285 if (! cmd.empty ()) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1286 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1287 if (k == n) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
1288 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1289 n *= 2; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1290 list.resize (n); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10186
diff
changeset
|
1291 } |
2234 | 1292 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1293 list[k++] = cmd; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1294 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1295 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1296 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1297 list.resize (k); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1298 break; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1299 } |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1300 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20239
diff
changeset
|
1301 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1302 if (nargout > 0) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1303 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1304 if (! list.empty ()) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1305 retval = list; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1306 else |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1307 retval = ""; |
2234 | 1308 } |
1309 else | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1310 { |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1311 // 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
|
1312 // 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
|
1313 // appear in a single column. |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1314 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1315 int len = list.numel (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1316 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1317 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
|
1318 octave_stdout << list[i] << "\n"; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1319 } |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1320 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1321 octave_completion_matches_called = true; |
2234 | 1322 |
1323 return retval; | |
1324 } | |
1325 | |
20239
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1326 /* |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1327 %!assert (ischar (completion_matches (""))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1328 %!assert (ischar (completion_matches ("a"))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1329 %!assert (ischar (completion_matches (" "))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1330 %!assert (isempty (completion_matches (" "))) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1331 %!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
|
1332 %!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
|
1333 %!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
|
1334 %!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
|
1335 %!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
|
1336 |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1337 %!error completion_matches () |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1338 %!error completion_matches (1, 2) |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1339 */ |
48284e32530b
test: Add tests for 'echo' and 'completion_matches' builtins
Mike Miller <mtmiller@octave.org>
parents:
20232
diff
changeset
|
1340 |
16879
cc3743a91652
Rename read_readline_init_file to readline_read_init_file.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1341 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
|
1342 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1343 @deftypefn {} {} readline_read_init_file () |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1344 @deftypefnx {} {} readline_read_init_file (@var{file}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1345 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
|
1346 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1347 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
|
1348 (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
|
1349 |
30377
26f2daafa270
doc: Use consistent styling for @ref, @xref, @pxref statements.
Rik <rik@octave.org>
parents:
30354
diff
changeset
|
1350 @xref{Readline Init File,,,readline, GNU Readline Library}, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1351 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
|
1352 @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
|
1353 @end deftypefn */) |
3189 | 1354 { |
1355 int nargin = args.length (); | |
1356 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1357 if (nargin > 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1358 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1359 |
3189 | 1360 if (nargin == 0) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1361 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
|
1362 else |
3189 | 1363 { |
5872 | 1364 std::string file = args(0).string_value (); |
3189 | 1365 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1366 command_editor::read_init_file (file); |
3189 | 1367 } |
1368 | |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1369 return ovl (); |
3189 | 1370 } |
1371 | |
16880
1aebb613a5ac
Rename re_read_readline_init_file to readline_re_read_init_file.
Rik <rik@octave.org>
parents:
16879
diff
changeset
|
1372 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
|
1373 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
|
1374 @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
|
1375 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
|
1376 |
30377
26f2daafa270
doc: Use consistent styling for @ref, @xref, @pxref statements.
Rik <rik@octave.org>
parents:
30354
diff
changeset
|
1377 @xref{Readline Init File,,,readline, GNU Readline Library}, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1378 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
|
1379 @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
|
1380 @end deftypefn */) |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1381 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1382 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
|
1383 print_usage (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1384 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1385 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
|
1386 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1387 return ovl (); |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1388 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1389 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1390 DEFMETHOD (add_input_event_hook, interp, args, , |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1391 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
|
1392 @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
|
1393 @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
|
1394 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
|
1395 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
|
1396 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1397 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
|
1398 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1399 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1400 @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
|
1401 @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
|
1402 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1403 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
|
1404 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1405 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
|
1406 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
|
1407 @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
|
1408 @end deftypefn */) |
3498 | 1409 { |
1410 int nargin = args.length (); | |
1411 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1412 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
|
1413 print_usage (); |
3498 | 1414 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1415 octave_value user_data; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1416 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1417 if (nargin == 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1418 user_data = args(1); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1419 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1420 input_system& input_sys = interp.get_input_system (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1421 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1422 hook_function hook_fcn (args(0), user_data); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1423 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1424 input_sys.add_input_event_hook (hook_fcn); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1425 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1426 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
|
1427 } |
3498 | 1428 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1429 DEFMETHOD (remove_input_event_hook, interp, args, , |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1430 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1431 @deftypefn {} {} 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
|
1432 @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
|
1433 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
|
1434 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
|
1435 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
|
1436 @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
|
1437 @end deftypefn */) |
9215
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1438 { |
1500d0197484
allow multiple input event hook functions to be installed simultaneously
John W. Eaton <jwe@octave.org>
parents:
9134
diff
changeset
|
1439 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
|
1440 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1441 if (nargin < 1 || nargin > 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1442 print_usage (); |
16347
bf8397caeff1
allow add_input_event_hook to accept function handles
John W. Eaton <jwe@octave.org>
parents:
16336
diff
changeset
|
1443 |
26358
d527c6111425
input.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26193
diff
changeset
|
1444 std::string hook_fcn_id = args(0).xstring_value ("remove_input_event_hook: argument not valid as a hook function name or id"); |
3498 | 1445 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1446 bool warn = (nargin < 2); |
3498 | 1447 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1448 input_system& input_sys = interp.get_input_system (); |
3498 | 1449 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1450 if (! input_sys.remove_input_event_hook (hook_fcn_id) && warn) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1451 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
|
1452 hook_fcn_id.c_str ()); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1453 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1454 return ovl (); |
3498 | 1455 } |
1456 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1457 DEFMETHOD (PS1, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1458 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
|
1459 @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
|
1460 @deftypefnx {} {@var{old_val} =} PS1 (@var{new_val}) |
30588
ed17822e7662
doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1461 @deftypefnx {} {@var{old_val} =} PS1 (@var{new_val}, "local") |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1462 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
|
1463 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1464 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
|
1465 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
|
1466 |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28973
diff
changeset
|
1467 The default value of the primary prompt string is |
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28973
diff
changeset
|
1468 @qcode{'octave:@backslashchar{}#> '}. To change it, use a command like |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1469 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1470 @example |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28973
diff
changeset
|
1471 PS1 ('\u@@\H> ') |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1472 @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
|
1473 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1474 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1475 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
|
1476 @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
|
1477 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
|
1478 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
|
1479 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1480 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
|
1481 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
|
1482 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1483 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1484 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
|
1485 @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
|
1486 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1487 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1488 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
|
1489 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1490 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
|
1491 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
|
1492 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
|
1493 @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
|
1494 @end deftypefn */) |
5794 | 1495 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1496 input_system& input_sys = interp.get_input_system (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1497 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1498 return input_sys.PS1 (args, nargout); |
5794 | 1499 } |
2181 | 1500 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1501 DEFMETHOD (PS2, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1502 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
|
1503 @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
|
1504 @deftypefnx {} {@var{old_val} =} PS2 (@var{new_val}) |
30588
ed17822e7662
doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1505 @deftypefnx {} {@var{old_val} =} PS2 (@var{new_val}, "local") |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1506 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
|
1507 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1508 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
|
1509 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
|
1510 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
|
1511 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
|
1512 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
|
1513 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1514 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
|
1515 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
|
1516 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
|
1517 @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
|
1518 @end deftypefn */) |
5794 | 1519 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1520 input_system& input_sys = interp.get_input_system (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1521 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1522 return input_sys.PS2 (args, nargout); |
5794 | 1523 } |
2181 | 1524 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1525 DEFMETHOD (completion_append_char, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1526 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
|
1527 @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
|
1528 @deftypefnx {} {@var{old_val} =} completion_append_char (@var{new_val}) |
30588
ed17822e7662
doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1529 @deftypefnx {} {@var{old_val} =} completion_append_char (@var{new_val}, "local") |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1530 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
|
1531 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
|
1532 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1533 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
|
1534 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1535 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1536 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1537 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1538 @end deftypefn */) |
5794 | 1539 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1540 input_system& input_sys = interp.get_input_system (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1541 |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1542 return input_sys.completion_append_char (args, nargout); |
5794 | 1543 } |
3019 | 1544 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1545 DEFMETHOD (__request_drawnow__, , args, , |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1546 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
|
1547 @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
|
1548 @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
|
1549 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
|
1550 @end deftypefn */) |
6257 | 1551 { |
1552 int nargin = args.length (); | |
1553 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1554 if (nargin > 1) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1555 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1556 |
6257 | 1557 if (nargin == 0) |
1558 Vdrawnow_requested = true; | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1559 else |
6257 | 1560 Vdrawnow_requested = args(0).bool_value (); |
1561 | |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1562 return ovl (); |
6257 | 1563 } |
1564 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1565 DEFMETHOD (__gud_mode__, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1566 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1567 @deftypefn {} {@var{state} =} __gud_mode__ () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21920
diff
changeset
|
1568 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
|
1569 @end deftypefn */) |
7294 | 1570 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1571 input_system& input_sys = interp.get_input_system (); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1572 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1573 return input_sys.gud_mode (args, nargout); |
7294 | 1574 } |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1575 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1576 DEFMETHOD (__mfile_encoding__, interp, args, nargout, |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1577 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1578 @deftypefn {} {@var{current_encoding} =} __mfile_encoding__ () |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1579 @deftypefnx {} {} __mfile_encoding__ (@var{new_encoding}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1580 @deftypefnx {} {@var{old_encoding} =} __mfile_encoding__ (@var{new_encoding}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1581 Query or set the codepage that is used for reading m-files. |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1582 |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1583 The input and output are strings naming a particular codepage, e.g., "utf-8". |
25361
82445187633e
Add support for arbitrary character encodings in m-files (bug #53842).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
1584 @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
|
1585 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1586 input_system& input_sys = interp.get_input_system (); |
7294 | 1587 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1588 return input_sys.mfile_encoding (args, nargout); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1589 } |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25402
diff
changeset
|
1590 |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1591 DEFMETHOD (dir_encoding, interp, args, nargout, |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1592 doc: /* -*- texinfo -*- |
30354
c980f938fdd8
doc: grammarcheck C++ files in libinterp/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30266
diff
changeset
|
1593 @deftypefn {} {@var{current_encoding} =} dir_encoding (@var{dir}) |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1594 @deftypefnx {} {} dir_encoding (@var{dir}, @var{new_encoding}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1595 @deftypefnx {} {} dir_encoding (@var{dir}, "delete") |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1596 @deftypefnx {} {@var{old_encoding} =} dir_encoding (@var{dir}, @var{new_encoding}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1597 Query or set the @var{encoding} that is used for reading m-files in @var{dir}. |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1598 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1599 The per-directory encoding overrides the (globally set) m-file encoding. |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1600 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1601 The string @var{DIR} must match how the directory would appear in the load |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1602 path. |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1603 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1604 The @var{new_encoding} input must be a valid encoding identifier or |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1605 @qcode{"delete"}. In the latter case, any per-directory encoding is removed |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1606 and the (globally set) m-file encoding will be used for the given @var{dir}. |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1607 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1608 The currently or previously used encoding is returned only if an output |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
1609 argument is requested. |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1610 |
28971
02b97abbc6fc
maint: rename .oct_config files to .oct-config
John W. Eaton <jwe@octave.org>
parents:
28953
diff
changeset
|
1611 The directory encoding is automatically read from the file @file{.oct-config} |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1612 when a new path is added to the load path (for example with @code{addpath}). |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1613 To set the encoding for all files in the same folder, that file must contain |
30354
c980f938fdd8
doc: grammarcheck C++ files in libinterp/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30266
diff
changeset
|
1614 a line starting with @qcode{"encoding="} followed by the encoding identifier. |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1615 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1616 For example to set the file encoding for all files in the same folder to |
28971
02b97abbc6fc
maint: rename .oct_config files to .oct-config
John W. Eaton <jwe@octave.org>
parents:
28953
diff
changeset
|
1617 ISO 8859-1 (Latin-1), create a file @file{.oct-config} with the following |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1618 content: |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1619 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1620 @example |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1621 encoding=iso8859-1 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1622 @end example |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1623 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1624 If the file encoding is changed after the files have already been parsed, the |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1625 files have to be parsed again for that change to take effect. That can be done |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1626 with the command @code{clear all}. |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1627 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1628 @seealso{addpath, path} |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1629 @end deftypefn */) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1630 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1631 int nargin = args.length (); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1632 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1633 if (nargin < 1 || nargin > 2) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1634 print_usage (); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1635 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1636 std::string dir |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1637 = args(0).xstring_value ("dir_encoding: DIR must be a string"); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1638 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1639 octave_value retval; |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1640 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1641 input_system& input_sys = interp.get_input_system (); |
28953
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1642 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1643 if (nargout > 0) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1644 retval = input_sys.dir_encoding (dir); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1645 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1646 if (nargin > 1) |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1647 { |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1648 std::string encoding |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1649 = args(1).xstring_value ("dir_encoding: ENCODING must be a string"); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1650 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1651 input_sys.set_dir_encoding (dir, encoding); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1652 } |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1653 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1654 return ovl (retval); |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1655 |
dff830c84726
Add function "dir_encoding" to set a file encoding per directory (bug #49685).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28905
diff
changeset
|
1656 } |
28973 | 1657 |
28972
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1658 DEFMETHOD (auto_repeat_debug_command, interp, args, nargout, |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1659 doc: /* -*- texinfo -*- |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1660 @deftypefn {} {@var{val} =} auto_repeat_debug_command () |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1661 @deftypefnx {} {@var{old_val} =} auto_repeat_debug_command (@var{new_val}) |
30588
ed17822e7662
doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1662 @deftypefnx {} {@var{old_val} =} auto_repeat_debug_command (@var{new_val}, "local") |
28972
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1663 Query or set the internal variable that controls whether debugging |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1664 commands are automatically repeated when the input line is empty (typing |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1665 just @key{RET}). |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1666 |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1667 When called from inside a function with the @qcode{"local"} option, the |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1668 variable is changed locally for the function and any subroutines it calls. |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1669 The original variable value is restored when exiting the function. |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1670 @end deftypefn */) |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1671 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1672 input_system& input_sys = interp.get_input_system (); |
28972
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1673 |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1674 return input_sys.auto_repeat_debug_command (args, nargout); |
a00eca5d6cbe
allow auto repeat of debug commands to be disabled
John W. Eaton <jwe@octave.org>
parents:
28707
diff
changeset
|
1675 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29950
diff
changeset
|
1676 |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29950
diff
changeset
|
1677 OCTAVE_NAMESPACE_END |