Mercurial > hg > octave-lyh
annotate liboctave/cmd-edit.h @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 8e14a01ffe9f |
children | 9b87aeb24ea9 |
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 | |
3504 | 123 static void insert_text (const std::string& text); |
2926 | 124 |
125 static void newline (void); | |
126 | |
6979 | 127 static void accept_line (void); |
128 | |
2926 | 129 static void clear_undo_list (void); |
130 | |
6913 | 131 static void add_startup_hook (startup_hook_fcn f); |
2926 | 132 |
6913 | 133 static void remove_startup_hook (startup_hook_fcn f); |
2926 | 134 |
6913 | 135 static void add_event_hook (event_hook_fcn f); |
3215 | 136 |
6913 | 137 static void remove_event_hook (event_hook_fcn f); |
3215 | 138 |
3504 | 139 static void read_init_file (const std::string& file = std::string ()); |
3189 | 140 |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
141 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
|
142 |
4143 | 143 static bool filename_completion_desired (bool); |
144 | |
6979 | 145 static bool filename_quoting_desired (bool); |
146 | |
2926 | 147 static int current_command_number (void); |
148 | |
149 static void reset_current_command_number (int n); | |
150 | |
2967 | 151 static void increment_current_command_number (void); |
152 | |
2926 | 153 private: |
154 | |
155 // No copying! | |
156 | |
157 command_editor (const command_editor&); | |
158 | |
159 command_editor& operator = (const command_editor&); | |
160 | |
161 static bool instance_ok (void); | |
162 | |
163 static void make_command_editor (void); | |
164 | |
6913 | 165 static int startup_handler (void); |
166 | |
167 static int event_handler (void); | |
168 | |
169 static std::set<startup_hook_fcn> startup_hook_set; | |
170 | |
171 static std::set<event_hook_fcn> event_hook_set; | |
172 | |
173 typedef std::set<startup_hook_fcn>::iterator startup_hook_set_iterator; | |
174 typedef std::set<startup_hook_fcn>::const_iterator startup_hook_set_const_iterator; | |
175 | |
176 typedef std::set<event_hook_fcn>::iterator event_hook_set_iterator; | |
177 typedef std::set<event_hook_fcn>::const_iterator event_hook_set_const_iterator; | |
178 | |
2926 | 179 // The real thing. |
180 static command_editor *instance; | |
181 | |
182 protected: | |
183 | |
184 // To use something other than the GNU readline library, derive a new | |
185 // class from command_editor, overload these functions as | |
186 // necessary, and make instance point to the new class. | |
187 | |
3504 | 188 virtual void do_set_name (const std::string&) { } |
2926 | 189 |
3504 | 190 std::string do_readline (const std::string& prompt) |
3219 | 191 { |
192 bool eof; | |
193 | |
194 return do_readline (prompt, eof); | |
195 } | |
196 | |
3504 | 197 virtual std::string do_readline (const std::string&, bool&) = 0; |
2926 | 198 |
199 virtual void do_set_input_stream (FILE *) = 0; | |
200 | |
201 virtual FILE *do_get_input_stream (void) = 0; | |
202 | |
203 virtual void do_set_output_stream (FILE *) = 0; | |
204 | |
205 virtual FILE *do_get_output_stream (void) = 0; | |
206 | |
207 virtual int do_terminal_rows (void) { return 24; } | |
208 | |
209 virtual int do_terminal_cols (void) { return 80; } | |
210 | |
211 virtual void do_clear_screen (void) { } | |
212 | |
3281 | 213 virtual void do_resize_terminal (void) { } |
214 | |
3504 | 215 virtual std::string do_decode_prompt_string (const std::string&); |
2926 | 216 |
3504 | 217 virtual std::string newline_chars (void) { return "\n"; } |
2926 | 218 |
219 virtual void do_restore_terminal_state (void) { } | |
220 | |
221 virtual void do_blink_matching_paren (bool) { } | |
222 | |
3933 | 223 virtual void do_set_basic_word_break_characters (const std::string&) { } |
224 | |
225 virtual void do_set_completer_word_break_characters (const std::string&) { } | |
226 | |
3504 | 227 virtual void do_set_basic_quote_characters (const std::string&) { } |
2926 | 228 |
6979 | 229 virtual void do_set_filename_quote_characters (const std::string&) { } |
230 | |
231 virtual void do_set_completer_quote_characters (const std::string&) { } | |
232 | |
2926 | 233 virtual void do_set_completion_append_character (char) { } |
234 | |
2941 | 235 virtual void do_set_completion_function (completion_fcn) { } |
236 | |
6979 | 237 virtual void do_set_quoting_function (quoting_fcn) { } |
238 | |
239 virtual void do_set_dequoting_function (dequoting_fcn) { } | |
240 | |
241 virtual void do_set_char_is_quoted_function (char_is_quoted_fcn) { } | |
242 | |
243 virtual void do_set_user_accept_line_function (user_accept_line_fcn) { } | |
244 | |
2941 | 245 virtual completion_fcn do_get_completion_function (void) const { return 0; } |
2926 | 246 |
6979 | 247 virtual quoting_fcn do_get_quoting_function (void) const { return 0; } |
248 | |
249 virtual dequoting_fcn do_get_dequoting_function (void) const { return 0; } | |
250 | |
251 virtual char_is_quoted_fcn do_get_char_is_quoted_function (void) const { return 0; } | |
252 | |
253 virtual user_accept_line_fcn do_get_user_accept_line_function (void) const { return 0; } | |
254 | |
4604 | 255 virtual string_vector do_generate_filename_completions (const std::string& text) = 0; |
256 | |
3504 | 257 virtual void do_insert_text (const std::string&) = 0; |
2926 | 258 |
259 virtual void do_newline (void) = 0; | |
260 | |
6979 | 261 virtual void do_accept_line (void) = 0; |
262 | |
2926 | 263 virtual void do_clear_undo_list (void) { } |
264 | |
6913 | 265 virtual void set_startup_hook (startup_hook_fcn) { } |
2926 | 266 |
6913 | 267 virtual void restore_startup_hook (void) { } |
2926 | 268 |
6913 | 269 virtual void set_event_hook (startup_hook_fcn) { } |
3215 | 270 |
6913 | 271 virtual void restore_event_hook (void) { } |
3215 | 272 |
3504 | 273 virtual void do_read_init_file (const std::string&) { } |
3189 | 274 |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
275 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
|
276 |
4143 | 277 virtual bool do_filename_completion_desired (bool) { return false; } |
278 | |
6979 | 279 virtual bool do_filename_quoting_desired (bool) { return false; } |
280 | |
3504 | 281 int read_octal (const std::string& s); |
2926 | 282 |
283 void error (int); | |
284 | |
3504 | 285 void error (const std::string&); |
2926 | 286 |
287 // The current command number. | |
288 int command_number; | |
289 }; | |
290 | |
291 #endif | |
292 | |
293 /* | |
294 ;;; Local Variables: *** | |
295 ;;; mode: C++ *** | |
296 ;;; End: *** | |
297 */ |