Mercurial > hg > octave-nkf
annotate liboctave/cmd-edit.h @ 10804:3d5c6b84ddaf
speed-up fixes to dlmread
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 20 Jul 2010 12:50:54 +0200 |
parents | 4c0cdbe0acca |
children | fd0a3ac60b0e |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
8920 | 4 2006, 2007, 2008 John W. Eaton |
2926 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2926 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2926 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_cmd_edit_h) | |
25 #define octave_cmd_edit_h 1 | |
26 | |
27 #include <cstdio> | |
28 | |
6913 | 29 #include <set> |
2926 | 30 #include <string> |
31 | |
4604 | 32 #include "str-vec.h" |
33 | |
2926 | 34 class |
6108 | 35 OCTAVE_API |
2926 | 36 command_editor |
37 { | |
38 protected: | |
39 | |
40 command_editor (void) | |
41 : command_number (0) { } | |
42 | |
43 public: | |
44 | |
4802 | 45 typedef int (*startup_hook_fcn) (void); |
3519 | 46 |
4802 | 47 typedef int (*event_hook_fcn) (void); |
2926 | 48 |
3504 | 49 typedef std::string (*completion_fcn) (const std::string&, int); |
2941 | 50 |
6979 | 51 typedef std::string (*quoting_fcn) (const std::string&, int, char); |
52 | |
53 typedef std::string (*dequoting_fcn) (const std::string&, int); | |
54 | |
55 typedef int (*char_is_quoted_fcn) (const std::string&, int); | |
56 | |
57 typedef void (*user_accept_line_fcn) (const std::string&); | |
58 | |
2926 | 59 virtual ~command_editor (void) { } |
60 | |
3504 | 61 static void set_name (const std::string& n); |
2926 | 62 |
3504 | 63 static std::string readline (const std::string& prompt); |
2926 | 64 |
3504 | 65 static std::string readline (const std::string& prompt, bool& eof); |
3219 | 66 |
2926 | 67 static void set_input_stream (FILE *f); |
68 | |
69 static FILE *get_input_stream (void); | |
70 | |
71 static void set_output_stream (FILE *f); | |
72 | |
73 static FILE *get_output_stream (void); | |
74 | |
75 static int terminal_rows (void); | |
76 | |
77 static int terminal_cols (void); | |
78 | |
79 static void clear_screen (void); | |
80 | |
3281 | 81 static void resize_terminal (void); |
82 | |
3504 | 83 static std::string decode_prompt_string (const std::string& s); |
2926 | 84 |
85 static void restore_terminal_state (void); | |
86 | |
87 static void blink_matching_paren (bool flag); | |
88 | |
4055 | 89 static void set_basic_word_break_characters (const std::string& s); |
3933 | 90 |
4055 | 91 static void set_completer_word_break_characters (const std::string& s); |
3933 | 92 |
3504 | 93 static void set_basic_quote_characters (const std::string& s); |
2926 | 94 |
6979 | 95 static void set_filename_quote_characters (const std::string& s); |
96 | |
97 static void set_completer_quote_characters (const std::string& s); | |
98 | |
2926 | 99 static void set_completion_append_character (char c); |
100 | |
2941 | 101 static void set_completion_function (completion_fcn f); |
102 | |
6979 | 103 static void set_quoting_function (quoting_fcn f); |
104 | |
105 static void set_dequoting_function (dequoting_fcn f); | |
106 | |
107 static void set_char_is_quoted_function (char_is_quoted_fcn f); | |
108 | |
109 static void set_user_accept_line_function (user_accept_line_fcn f); | |
110 | |
2941 | 111 static completion_fcn get_completion_function (void); |
2926 | 112 |
6979 | 113 static quoting_fcn get_quoting_function (void); |
114 | |
115 static dequoting_fcn get_dequoting_function (void); | |
116 | |
117 static char_is_quoted_fcn get_char_is_quoted_function (void); | |
118 | |
119 static user_accept_line_fcn get_user_accept_line_function (void); | |
120 | |
4604 | 121 static string_vector generate_filename_completions (const std::string& text); |
122 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
123 static std::string get_line_buffer (void); |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
124 |
3504 | 125 static void insert_text (const std::string& text); |
2926 | 126 |
127 static void newline (void); | |
128 | |
6979 | 129 static void accept_line (void); |
130 | |
2926 | 131 static void clear_undo_list (void); |
132 | |
6913 | 133 static void add_startup_hook (startup_hook_fcn f); |
2926 | 134 |
6913 | 135 static void remove_startup_hook (startup_hook_fcn f); |
2926 | 136 |
6913 | 137 static void add_event_hook (event_hook_fcn f); |
3215 | 138 |
6913 | 139 static void remove_event_hook (event_hook_fcn f); |
3215 | 140 |
3504 | 141 static void read_init_file (const std::string& file = std::string ()); |
3189 | 142 |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
143 static void re_read_init_file (void); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
144 |
4143 | 145 static bool filename_completion_desired (bool); |
146 | |
6979 | 147 static bool filename_quoting_desired (bool); |
148 | |
2926 | 149 static int current_command_number (void); |
150 | |
151 static void reset_current_command_number (int n); | |
152 | |
2967 | 153 static void increment_current_command_number (void); |
154 | |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
155 static void force_default_editor (void); |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
156 |
2926 | 157 private: |
158 | |
159 // No copying! | |
160 | |
161 command_editor (const command_editor&); | |
162 | |
163 command_editor& operator = (const command_editor&); | |
164 | |
165 static bool instance_ok (void); | |
166 | |
167 static void make_command_editor (void); | |
168 | |
6913 | 169 static int startup_handler (void); |
170 | |
171 static int event_handler (void); | |
172 | |
173 static std::set<startup_hook_fcn> startup_hook_set; | |
174 | |
175 static std::set<event_hook_fcn> event_hook_set; | |
176 | |
177 typedef std::set<startup_hook_fcn>::iterator startup_hook_set_iterator; | |
178 typedef std::set<startup_hook_fcn>::const_iterator startup_hook_set_const_iterator; | |
179 | |
180 typedef std::set<event_hook_fcn>::iterator event_hook_set_iterator; | |
181 typedef std::set<event_hook_fcn>::const_iterator event_hook_set_const_iterator; | |
182 | |
2926 | 183 // The real thing. |
184 static command_editor *instance; | |
185 | |
186 protected: | |
187 | |
188 // To use something other than the GNU readline library, derive a new | |
189 // class from command_editor, overload these functions as | |
190 // necessary, and make instance point to the new class. | |
191 | |
3504 | 192 virtual void do_set_name (const std::string&) { } |
2926 | 193 |
3504 | 194 std::string do_readline (const std::string& prompt) |
3219 | 195 { |
196 bool eof; | |
197 | |
198 return do_readline (prompt, eof); | |
199 } | |
200 | |
3504 | 201 virtual std::string do_readline (const std::string&, bool&) = 0; |
2926 | 202 |
203 virtual void do_set_input_stream (FILE *) = 0; | |
204 | |
205 virtual FILE *do_get_input_stream (void) = 0; | |
206 | |
207 virtual void do_set_output_stream (FILE *) = 0; | |
208 | |
209 virtual FILE *do_get_output_stream (void) = 0; | |
210 | |
211 virtual int do_terminal_rows (void) { return 24; } | |
212 | |
213 virtual int do_terminal_cols (void) { return 80; } | |
214 | |
215 virtual void do_clear_screen (void) { } | |
216 | |
3281 | 217 virtual void do_resize_terminal (void) { } |
218 | |
3504 | 219 virtual std::string do_decode_prompt_string (const std::string&); |
2926 | 220 |
3504 | 221 virtual std::string newline_chars (void) { return "\n"; } |
2926 | 222 |
223 virtual void do_restore_terminal_state (void) { } | |
224 | |
225 virtual void do_blink_matching_paren (bool) { } | |
226 | |
3933 | 227 virtual void do_set_basic_word_break_characters (const std::string&) { } |
228 | |
229 virtual void do_set_completer_word_break_characters (const std::string&) { } | |
230 | |
3504 | 231 virtual void do_set_basic_quote_characters (const std::string&) { } |
2926 | 232 |
6979 | 233 virtual void do_set_filename_quote_characters (const std::string&) { } |
234 | |
235 virtual void do_set_completer_quote_characters (const std::string&) { } | |
236 | |
2926 | 237 virtual void do_set_completion_append_character (char) { } |
238 | |
2941 | 239 virtual void do_set_completion_function (completion_fcn) { } |
240 | |
6979 | 241 virtual void do_set_quoting_function (quoting_fcn) { } |
242 | |
243 virtual void do_set_dequoting_function (dequoting_fcn) { } | |
244 | |
245 virtual void do_set_char_is_quoted_function (char_is_quoted_fcn) { } | |
246 | |
247 virtual void do_set_user_accept_line_function (user_accept_line_fcn) { } | |
248 | |
2941 | 249 virtual completion_fcn do_get_completion_function (void) const { return 0; } |
2926 | 250 |
6979 | 251 virtual quoting_fcn do_get_quoting_function (void) const { return 0; } |
252 | |
253 virtual dequoting_fcn do_get_dequoting_function (void) const { return 0; } | |
254 | |
255 virtual char_is_quoted_fcn do_get_char_is_quoted_function (void) const { return 0; } | |
256 | |
257 virtual user_accept_line_fcn do_get_user_accept_line_function (void) const { return 0; } | |
258 | |
4604 | 259 virtual string_vector do_generate_filename_completions (const std::string& text) = 0; |
260 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
261 virtual std::string do_get_line_buffer (void) const = 0; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
262 |
3504 | 263 virtual void do_insert_text (const std::string&) = 0; |
2926 | 264 |
265 virtual void do_newline (void) = 0; | |
266 | |
6979 | 267 virtual void do_accept_line (void) = 0; |
268 | |
2926 | 269 virtual void do_clear_undo_list (void) { } |
270 | |
6913 | 271 virtual void set_startup_hook (startup_hook_fcn) { } |
2926 | 272 |
6913 | 273 virtual void restore_startup_hook (void) { } |
2926 | 274 |
6913 | 275 virtual void set_event_hook (startup_hook_fcn) { } |
3215 | 276 |
6913 | 277 virtual void restore_event_hook (void) { } |
3215 | 278 |
3504 | 279 virtual void do_read_init_file (const std::string&) { } |
3189 | 280 |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
281 virtual void do_re_read_init_file (void) { } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
282 |
4143 | 283 virtual bool do_filename_completion_desired (bool) { return false; } |
284 | |
6979 | 285 virtual bool do_filename_quoting_desired (bool) { return false; } |
286 | |
3504 | 287 int read_octal (const std::string& s); |
2926 | 288 |
289 void error (int); | |
290 | |
3504 | 291 void error (const std::string&); |
2926 | 292 |
293 // The current command number. | |
294 int command_number; | |
295 }; | |
296 | |
297 #endif |