Mercurial > octave-nkf
annotate liboctave/cmd-hist.cc @ 11486:a1deab9a6e71
bash-like history control
author | Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 12 Jan 2011 03:40:19 -0500 |
parents | 944b7e20fc5a |
children | 7aeb4eb7403f |
rev | line source |
---|---|
1797 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007 |
4 John W. Eaton | |
1797 | 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. | |
1797 | 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/>. | |
1797 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
28 #include <cstring> |
1797 | 29 |
3504 | 30 #include <iostream> |
2926 | 31 #include <string> |
32 | |
33 #include "cmd-edit.h" | |
34 #include "cmd-hist.h" | |
5872 | 35 #include "file-ops.h" |
2926 | 36 #include "lo-error.h" |
37 #include "str-vec.h" | |
38 | |
39 command_history *command_history::instance = 0; | |
40 | |
41 #if defined (USE_READLINE) | |
42 | |
43 #include <cstdlib> | |
44 | |
1797 | 45 #include <sys/types.h> |
46 #include <unistd.h> | |
47 | |
10259 | 48 #include <fcntl.h> |
49 | |
3519 | 50 #include "oct-rl-hist.h" |
1797 | 51 |
2926 | 52 #include "file-stat.h" |
1797 | 53 |
2926 | 54 class |
55 gnu_history : public command_history | |
1797 | 56 { |
2926 | 57 public: |
58 | |
59 gnu_history (void) | |
60 : command_history (), mark (0) { } | |
61 | |
62 ~gnu_history (void) { } | |
63 | |
3504 | 64 void do_add (const std::string&); |
2926 | 65 |
66 void do_remove (int); | |
1797 | 67 |
2926 | 68 int do_where (void); |
69 | |
70 int do_length (void); | |
71 | |
72 int do_max_input_history (void); | |
73 | |
74 int do_base (void); | |
75 | |
76 int do_current_number (void); | |
77 | |
78 void do_stifle (int); | |
1797 | 79 |
2926 | 80 int do_unstifle (void); |
81 | |
82 int do_is_stifled (void); | |
83 | |
84 void do_set_mark (int); | |
1797 | 85 |
4802 | 86 int do_goto_mark (void); |
2926 | 87 |
3504 | 88 void do_read (const std::string&, bool); |
1797 | 89 |
3504 | 90 void do_read_range (const std::string&, int, int, bool); |
1797 | 91 |
3504 | 92 void do_write (const std::string&); |
1797 | 93 |
3504 | 94 void do_append (const std::string&); |
2926 | 95 |
3504 | 96 void do_truncate_file (const std::string&, int); |
2926 | 97 |
98 string_vector do_list (int, bool); | |
99 | |
3504 | 100 std::string do_get_entry (int); |
1797 | 101 |
3504 | 102 void do_replace_entry (int, const std::string&); |
2926 | 103 |
3504 | 104 void do_clean_up_and_save (const std::string&, int); |
1797 | 105 |
2926 | 106 private: |
107 | |
108 int mark; | |
109 }; | |
1797 | 110 |
111 void | |
3504 | 112 gnu_history::do_add (const std::string& s) |
1797 | 113 { |
2926 | 114 if (! do_ignoring_entries ()) |
1797 | 115 { |
2512 | 116 if (s.empty () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
117 || (s.length () == 1 && (s[0] == '\r' || s[0] == '\n'))) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
118 return; |
2512 | 119 |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
120 lines_this_session += ::octave_add_history (s.c_str (), history_control); |
1797 | 121 } |
122 } | |
123 | |
124 void | |
2926 | 125 gnu_history::do_remove (int n) |
1797 | 126 { |
3519 | 127 ::octave_remove_history (n); |
1797 | 128 } |
129 | |
130 int | |
2926 | 131 gnu_history::do_where (void) |
1797 | 132 { |
3519 | 133 return ::octave_where_history (); |
1797 | 134 } |
135 | |
136 int | |
2926 | 137 gnu_history::do_length (void) |
138 { | |
3519 | 139 return ::octave_history_length (); |
2926 | 140 } |
141 | |
142 int | |
143 gnu_history::do_max_input_history (void) | |
144 { | |
3519 | 145 return ::octave_max_input_history (); |
2926 | 146 } |
147 | |
148 int | |
149 gnu_history::do_base (void) | |
1797 | 150 { |
3519 | 151 return ::octave_history_base (); |
1797 | 152 } |
153 | |
154 int | |
2926 | 155 gnu_history::do_current_number (void) |
1797 | 156 { |
2926 | 157 return (xsize > 0) ? do_base () + do_where () : -1; |
1797 | 158 } |
159 | |
160 void | |
2926 | 161 gnu_history::do_stifle (int n) |
1797 | 162 { |
3519 | 163 ::octave_stifle_history (n); |
1797 | 164 } |
165 | |
166 int | |
2926 | 167 gnu_history::do_unstifle (void) |
1797 | 168 { |
3519 | 169 return ::octave_unstifle_history (); |
1797 | 170 } |
171 | |
172 int | |
2926 | 173 gnu_history::do_is_stifled (void) |
1797 | 174 { |
3519 | 175 return ::octave_history_is_stifled (); |
1797 | 176 } |
177 | |
178 void | |
2926 | 179 gnu_history::do_set_mark (int n) |
2658 | 180 { |
2926 | 181 mark = n; |
2658 | 182 } |
183 | |
4802 | 184 int |
2926 | 185 gnu_history::do_goto_mark (void) |
186 { | |
187 if (mark) | |
188 { | |
3519 | 189 char *line = ::octave_history_goto_mark (mark); |
2926 | 190 |
3519 | 191 if (line) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
192 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
193 command_editor::insert_text (line); |
2926 | 194 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
195 command_editor::clear_undo_list (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
196 } |
2926 | 197 } |
198 | |
199 mark = 0; | |
200 | |
5775 | 201 // FIXME -- for operate_and_get_next. |
6913 | 202 command_editor::remove_startup_hook (command_history::goto_mark); |
4802 | 203 |
204 return 0; | |
2926 | 205 } |
206 | |
207 void | |
3504 | 208 gnu_history::do_read (const std::string& f, bool must_exist) |
1797 | 209 { |
210 if (! f.empty ()) | |
211 { | |
3519 | 212 int status = ::octave_read_history (f.c_str ()); |
1797 | 213 |
2658 | 214 if (status != 0 && must_exist) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
215 error (status); |
1797 | 216 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
217 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
218 lines_in_file = do_where (); |
2658 | 219 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
220 ::octave_using_history (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
221 } |
1797 | 222 } |
223 else | |
2926 | 224 error ("gnu_history::read: missing file name"); |
1797 | 225 } |
226 | |
2659 | 227 void |
3504 | 228 gnu_history::do_read_range (const std::string& f, int from, int to, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
229 bool must_exist) |
1797 | 230 { |
231 if (from < 0) | |
232 from = lines_in_file; | |
233 | |
234 if (! f.empty ()) | |
235 { | |
3519 | 236 int status = ::octave_read_history_range (f.c_str (), from, to); |
1797 | 237 |
2658 | 238 if (status != 0 && must_exist) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
239 error (status); |
1797 | 240 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
241 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
242 lines_in_file = do_where (); |
2658 | 243 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
244 ::octave_using_history (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
245 } |
1797 | 246 } |
247 else | |
2926 | 248 error ("gnu_history::read_range: missing file name"); |
1797 | 249 } |
250 | |
251 void | |
3504 | 252 gnu_history::do_write (const std::string& f_arg) |
1797 | 253 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
254 if (initialized) |
1797 | 255 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
256 std::string f = f_arg; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
257 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
258 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
259 f = xfile; |
1797 | 260 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
261 if (! f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
262 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
263 int status = ::octave_write_history (f.c_str ()); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
264 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
265 if (status != 0) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
266 error (status); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
267 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
268 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
269 error ("gnu_history::write: missing file name"); |
1797 | 270 } |
271 } | |
272 | |
273 void | |
3504 | 274 gnu_history::do_append (const std::string& f_arg) |
1797 | 275 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
276 if (initialized) |
1797 | 277 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
278 if (lines_this_session) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
279 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
280 if (lines_this_session < do_where ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
281 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
282 // Create file if it doesn't already exist. |
1797 | 283 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
284 std::string f = f_arg; |
1797 | 285 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
286 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
287 f = xfile; |
1797 | 288 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
289 if (! f.empty ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
290 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
291 file_stat fs (f); |
1797 | 292 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
293 if (! fs) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
294 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
295 int tem; |
1797 | 296 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
297 tem = gnulib::open (f.c_str (), O_CREAT, 0666); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
298 gnulib::close (tem); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
299 } |
1797 | 300 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
301 int status |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
302 = ::octave_append_history (lines_this_session, f.c_str ()); |
1797 | 303 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
304 if (status != 0) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
305 error (status); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
306 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
307 lines_in_file += lines_this_session; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
308 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
309 lines_this_session = 0; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
310 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
311 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
312 error ("gnu_history::append: missing file name"); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
313 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
314 } |
1797 | 315 } |
316 } | |
317 | |
318 void | |
3504 | 319 gnu_history::do_truncate_file (const std::string& f_arg, int n) |
1797 | 320 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
321 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
322 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
323 std::string f = f_arg; |
1797 | 324 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
325 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
326 f = xfile; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
327 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
328 if (! f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
329 ::octave_history_truncate_file (f.c_str (), n); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
330 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
331 error ("gnu_history::truncate_file: missing file name"); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
332 } |
1797 | 333 } |
334 | |
335 string_vector | |
2926 | 336 gnu_history::do_list (int limit, bool number_lines) |
1797 | 337 { |
338 string_vector retval; | |
339 | |
340 if (limit) | |
3519 | 341 retval = ::octave_history_list (limit, number_lines); |
1797 | 342 |
343 return retval; | |
344 } | |
345 | |
3504 | 346 std::string |
2926 | 347 gnu_history::do_get_entry (int n) |
1797 | 348 { |
3504 | 349 std::string retval; |
1797 | 350 |
3519 | 351 char *line = ::octave_history_get (do_base () + n); |
1797 | 352 |
3519 | 353 if (line) |
354 retval = line; | |
1797 | 355 |
356 return retval; | |
357 } | |
358 | |
359 void | |
3504 | 360 gnu_history::do_replace_entry (int which, const std::string& line) |
1797 | 361 { |
3519 | 362 ::octave_replace_history_entry (which, line.c_str ()); |
1797 | 363 } |
364 | |
365 void | |
3504 | 366 gnu_history::do_clean_up_and_save (const std::string& f_arg, int n) |
1797 | 367 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
368 if (initialized) |
1797 | 369 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
370 std::string f = f_arg; |
1797 | 371 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
372 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
373 f = xfile; |
1797 | 374 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
375 if (! f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
376 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
377 if (n < 0) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
378 n = xsize; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
379 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
380 stifle (n); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
381 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
382 do_write (f.c_str ()); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
383 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
384 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
385 error ("gnu_history::clean_up_and_save: missing file name"); |
1797 | 386 } |
2926 | 387 } |
388 | |
389 #endif | |
390 | |
391 bool | |
392 command_history::instance_ok (void) | |
393 { | |
394 bool retval = true; | |
395 | |
396 if (! instance) | |
397 make_command_history (); | |
398 | |
399 if (! instance) | |
400 { | |
401 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
402 ("unable to create command history object!"); |
2926 | 403 |
404 retval = false; | |
405 } | |
406 | |
407 return retval; | |
408 } | |
409 | |
410 void | |
411 command_history::make_command_history (void) | |
412 { | |
413 #if defined (USE_READLINE) | |
414 instance = new gnu_history (); | |
415 #else | |
416 instance = new command_history (); | |
417 #endif | |
418 } | |
419 | |
420 void | |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
421 command_history::initialize (bool read_history_file, |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
422 const std::string& f_arg, int sz, |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
423 const std::string & control_arg) |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
424 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
425 if (instance_ok ()) |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
426 instance->do_initialize (read_history_file, f_arg, sz, control_arg); |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
427 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
428 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
429 bool |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
430 command_history::is_initialized (void) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
431 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
432 // We just want to check the status of an existing instance, not |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
433 // create one. |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
434 return instance && instance->do_is_initialized (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
435 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
436 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
437 void |
5872 | 438 command_history::set_file (const std::string& f_arg) |
2926 | 439 { |
440 if (instance_ok ()) | |
5872 | 441 { |
442 std::string f = file_ops::tilde_expand (f_arg); | |
443 | |
444 instance->do_set_file (f); | |
445 } | |
2926 | 446 } |
447 | |
3504 | 448 std::string |
2926 | 449 command_history::file (void) |
450 { | |
451 return (instance_ok ()) | |
3504 | 452 ? instance->do_file () : std::string (); |
2926 | 453 } |
454 | |
455 void | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
456 command_history::process_histcontrol (const std::string& control_arg) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
457 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
458 if (instance_ok ()) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
459 instance->do_process_histcontrol(control_arg); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
460 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
461 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
462 std::string |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
463 command_history::histcontrol (void) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
464 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
465 return (instance_ok ()) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
466 ? instance->do_histcontrol () : std::string (); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
467 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
468 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
469 void |
2926 | 470 command_history::set_size (int n) |
471 { | |
472 if (instance_ok ()) | |
473 instance->do_set_size (n); | |
474 } | |
475 | |
476 int | |
477 command_history::size (void) | |
478 { | |
479 return (instance_ok ()) | |
480 ? instance->do_size () : 0; | |
481 } | |
482 | |
483 void | |
484 command_history::ignore_entries (bool flag) | |
485 { | |
486 if (instance_ok ()) | |
487 instance->do_ignore_entries (flag); | |
488 } | |
489 | |
490 bool | |
491 command_history::ignoring_entries (void) | |
492 { | |
493 return (instance_ok ()) | |
494 ? instance->do_ignoring_entries () : false; | |
495 } | |
496 | |
497 void | |
3504 | 498 command_history::add (const std::string& s) |
2926 | 499 { |
500 if (instance_ok ()) | |
501 instance->do_add (s); | |
502 } | |
503 | |
504 void | |
505 command_history::remove (int n) | |
506 { | |
507 if (instance_ok ()) | |
508 instance->do_remove (n); | |
509 } | |
510 | |
511 int | |
512 command_history::where (void) | |
513 { | |
514 return (instance_ok ()) | |
515 ? instance->do_where () : 0; | |
516 } | |
517 | |
518 int | |
519 command_history::length (void) | |
520 { | |
521 return (instance_ok ()) | |
522 ? instance->do_length () : 0; | |
523 } | |
524 | |
525 int | |
526 command_history::max_input_history (void) | |
527 { | |
528 return (instance_ok ()) | |
529 ? instance->do_max_input_history () : 0; | |
530 } | |
531 | |
532 int | |
533 command_history::base (void) | |
534 { | |
535 return (instance_ok ()) | |
536 ? instance->do_base () : 0; | |
537 } | |
538 | |
539 int | |
540 command_history::current_number (void) | |
541 { | |
542 return (instance_ok ()) | |
543 ? instance->do_current_number () : 0; | |
544 } | |
545 | |
546 void | |
547 command_history::stifle (int n) | |
548 { | |
549 if (instance_ok ()) | |
550 instance->do_stifle (n); | |
551 } | |
552 | |
553 int | |
554 command_history::unstifle (void) | |
555 { | |
556 return (instance_ok ()) | |
557 ? instance->do_unstifle () : 0; | |
558 } | |
559 | |
560 int | |
561 command_history::is_stifled (void) | |
562 { | |
563 return (instance_ok ()) | |
564 ? instance->do_is_stifled () : 0; | |
565 } | |
566 | |
567 void | |
568 command_history::set_mark (int n) | |
569 { | |
570 if (instance_ok ()) | |
571 instance->do_set_mark (n); | |
572 } | |
573 | |
4802 | 574 int |
3519 | 575 command_history::goto_mark (void) |
2926 | 576 { |
4802 | 577 return (instance_ok ()) |
578 ? instance->do_goto_mark () : 0; | |
2926 | 579 } |
580 | |
581 void | |
582 command_history::read (bool must_exist) | |
583 { | |
3522 | 584 read (file (), must_exist); |
2926 | 585 } |
586 | |
587 void | |
3504 | 588 command_history::read (const std::string& f, bool must_exist) |
2926 | 589 { |
590 if (instance_ok ()) | |
591 instance->do_read (f, must_exist); | |
592 } | |
593 | |
594 void | |
595 command_history::read_range (int from, int to, bool must_exist) | |
596 { | |
3522 | 597 read_range (file (), from, to, must_exist); |
2926 | 598 } |
599 | |
600 void | |
3504 | 601 command_history::read_range (const std::string& f, int from, int to, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
602 bool must_exist) |
2926 | 603 { |
604 if (instance_ok ()) | |
605 instance->do_read_range (f, from, to, must_exist); | |
606 } | |
607 | |
608 void | |
3504 | 609 command_history::write (const std::string& f) |
2926 | 610 { |
611 if (instance_ok ()) | |
612 instance->do_write (f); | |
613 } | |
614 | |
615 void | |
3504 | 616 command_history::append (const std::string& f) |
2926 | 617 { |
618 if (instance_ok ()) | |
619 instance->do_append (f); | |
620 } | |
621 | |
622 void | |
3504 | 623 command_history::truncate_file (const std::string& f, int n) |
2926 | 624 { |
625 if (instance_ok ()) | |
626 instance->do_truncate_file (f, n); | |
627 } | |
628 | |
629 string_vector | |
630 command_history::list (int limit, bool number_lines) | |
631 { | |
632 return (instance_ok ()) | |
633 ? instance->do_list (limit, number_lines) : string_vector (); | |
634 } | |
635 | |
3504 | 636 std::string |
2926 | 637 command_history::get_entry (int n) |
638 { | |
639 return (instance_ok ()) | |
3504 | 640 ? instance->do_get_entry (n) : std::string (); |
2926 | 641 } |
642 | |
643 void | |
3504 | 644 command_history::replace_entry (int which, const std::string& line) |
2926 | 645 { |
646 if (instance_ok ()) | |
647 instance->do_replace_entry (which, line); | |
648 } | |
649 | |
650 void | |
3504 | 651 command_history::clean_up_and_save (const std::string& f, int n) |
2926 | 652 { |
653 if (instance_ok ()) | |
654 instance->do_clean_up_and_save (f, n); | |
655 } | |
656 | |
657 void | |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
658 command_history::do_initialize (bool read_history_file, |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
659 const std::string& f_arg, int sz, |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
660 const std::string & control_arg) |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
661 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
662 command_history::set_file (f_arg); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
663 command_history::set_size (sz); |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
664 command_history::process_histcontrol (control_arg); |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
665 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
666 if (read_history_file) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
667 command_history::read (false); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
668 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
669 initialized = true; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
670 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
671 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
672 bool |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
673 command_history::do_is_initialized (void) const |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
674 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
675 return initialized; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
676 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
677 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
678 void |
3504 | 679 command_history::do_set_file (const std::string& f) |
2926 | 680 { |
681 xfile = f; | |
682 } | |
683 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
684 void |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
685 command_history::do_process_histcontrol (const std::string& control_arg) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
686 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
687 history_control = 0; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
688 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
689 size_t len = control_arg.length (); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
690 size_t beg = 0; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
691 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
692 while (beg < len) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
693 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
694 if (control_arg[beg] == ':') |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
695 beg++; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
696 else |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
697 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
698 size_t end = control_arg.find (":", beg); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
699 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
700 if (end == std::string::npos) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
701 end = len; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
702 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
703 std::string tmp = control_arg.substr (beg, end-beg); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
704 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
705 if (tmp == "erasedups") |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
706 history_control |= HC_ERASEDUPS; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
707 else if (tmp == "ignoreboth") |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
708 history_control |= HC_IGNDUPS|HC_IGNSPACE; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
709 else if (tmp == "ignoredups") |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
710 history_control |= HC_IGNDUPS; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
711 else if (tmp == "ignorespace") |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
712 history_control |= HC_IGNSPACE; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
713 else |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
714 (*current_liboctave_warning_handler) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
715 ("unknown histcontrol directive %s", tmp.c_str ()); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
716 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
717 if (end != std::string::npos) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
718 beg = end + 1; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
719 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
720 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
721 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
722 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
723 std::string |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
724 command_history::do_histcontrol (void) const |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
725 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
726 // FIXME -- instead of reconstructing this value, should we just save |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
727 // the string we were given when constructing the command_history |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
728 // object? |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
729 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
730 std::string retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
731 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
732 if (history_control & HC_IGNSPACE) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
733 retval.append ("ignorespace"); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
734 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
735 if (history_control & HC_IGNDUPS) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
736 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
737 if (retval.length() > 0) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
738 retval.append (":"); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
739 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
740 retval.append ("ignoredups"); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
741 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
742 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
743 if (history_control & HC_ERASEDUPS) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
744 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
745 if (retval.length() > 0) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
746 retval.append (":"); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
747 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
748 retval.append ("erasedups"); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
749 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
750 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
751 return retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
752 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
753 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
754 |
3504 | 755 std::string |
2926 | 756 command_history::do_file (void) |
757 { | |
758 return xfile; | |
759 } | |
760 | |
761 void | |
762 command_history::do_set_size (int n) | |
763 { | |
764 xsize = n; | |
765 } | |
766 | |
767 int | |
768 command_history::do_size (void) | |
769 { | |
770 return xsize; | |
771 } | |
772 | |
773 void | |
774 command_history::do_ignore_entries (bool flag) | |
775 { | |
776 ignoring_additions = flag; | |
777 } | |
778 | |
779 bool | |
780 command_history::do_ignoring_entries (void) | |
781 { | |
782 return ignoring_additions; | |
783 } | |
784 | |
785 void | |
3504 | 786 command_history::do_add (const std::string&) |
2926 | 787 { |
788 } | |
789 | |
790 void | |
791 command_history::do_remove (int) | |
792 { | |
793 } | |
794 | |
795 int | |
796 command_history::do_where (void) | |
797 { | |
798 return 0; | |
799 } | |
800 | |
801 int | |
802 command_history::do_length (void) | |
803 { | |
804 return 0; | |
805 } | |
806 | |
807 int | |
808 command_history::do_max_input_history (void) | |
809 { | |
810 return 0; | |
811 } | |
812 | |
813 int | |
814 command_history::do_base (void) | |
815 { | |
816 return 0; | |
817 } | |
818 | |
819 int | |
820 command_history::do_current_number (void) | |
821 { | |
822 return (xsize > 0) ? do_base () + do_where () : -1; | |
823 } | |
824 | |
825 void | |
826 command_history::do_stifle (int) | |
827 { | |
828 } | |
829 | |
830 int | |
831 command_history::do_unstifle (void) | |
832 { | |
833 return -1; | |
834 } | |
835 | |
836 int | |
837 command_history::do_is_stifled (void) | |
838 { | |
839 return 0; | |
840 } | |
841 | |
842 void | |
843 command_history::do_set_mark (int) | |
844 { | |
845 } | |
846 | |
4802 | 847 int |
2926 | 848 command_history::do_goto_mark (void) |
849 { | |
4802 | 850 return 0; |
2926 | 851 } |
852 | |
853 void | |
3504 | 854 command_history::do_read (const std::string& f, bool) |
2926 | 855 { |
856 if (f.empty ()) | |
857 error ("command_history::read: missing file name"); | |
858 } | |
859 | |
860 void | |
3504 | 861 command_history::do_read_range (const std::string& f, int, int, bool) |
2926 | 862 { |
863 if (f.empty ()) | |
864 error ("command_history::read_range: missing file name"); | |
865 } | |
866 | |
867 void | |
3504 | 868 command_history::do_write (const std::string& f_arg) |
2926 | 869 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
870 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
871 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
872 std::string f = f_arg; |
2926 | 873 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
874 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
875 f = xfile; |
2926 | 876 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
877 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
878 error ("command_history::write: missing file name"); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
879 } |
2926 | 880 } |
881 | |
882 void | |
3504 | 883 command_history::do_append (const std::string& f_arg) |
2926 | 884 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
885 if (initialized) |
2926 | 886 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
887 if (lines_this_session) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
888 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
889 if (lines_this_session < do_where ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
890 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
891 // Create file if it doesn't already exist. |
2926 | 892 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
893 std::string f = f_arg; |
2926 | 894 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
895 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
896 f = xfile; |
2926 | 897 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
898 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
899 error ("command_history::append: missing file name"); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
900 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
901 } |
2926 | 902 } |
903 } | |
904 | |
905 void | |
3504 | 906 command_history::do_truncate_file (const std::string& f_arg, int) |
2926 | 907 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
908 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
909 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
910 std::string f = f_arg; |
2926 | 911 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
912 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
913 f = xfile; |
2926 | 914 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
915 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
916 error ("command_history::truncate_file: missing file name"); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
917 } |
2926 | 918 } |
919 | |
920 string_vector | |
921 command_history::do_list (int, bool) | |
922 { | |
923 return string_vector (); | |
924 } | |
925 | |
3504 | 926 std::string |
2926 | 927 command_history::do_get_entry (int) |
928 { | |
3504 | 929 return std::string (); |
2926 | 930 } |
931 | |
932 void | |
3504 | 933 command_history::do_replace_entry (int, const std::string&) |
2926 | 934 { |
935 } | |
936 | |
937 void | |
3504 | 938 command_history::do_clean_up_and_save (const std::string& f_arg, int) |
2926 | 939 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
940 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
941 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
942 std::string f = f_arg; |
2926 | 943 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
944 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
945 f = xfile; |
2926 | 946 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
947 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
948 error ("command_history::clean_up_and_save: missing file name"); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
949 } |
1797 | 950 } |
951 | |
952 void | |
2470 | 953 command_history::error (int err_num) |
1797 | 954 { |
10411 | 955 (*current_liboctave_error_handler) ("%s", gnulib::strerror (err_num)); |
1797 | 956 } |
957 | |
958 void | |
3504 | 959 command_history::error (const std::string& s) |
1797 | 960 { |
961 (*current_liboctave_error_handler) ("%s", s.c_str ()); | |
962 } |