Mercurial > hg > octave-nkf
annotate liboctave/cmd-hist.cc @ 10396:a0b51ac0f88a
optimize accumdim with summation
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 05 Mar 2010 12:31:30 +0100 |
parents | 07ebe522dac2 |
children | 479cc8a0a846 |
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 | |
28 #include <cstring> | |
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 |
3519 | 120 ::octave_add_history (s.c_str ()); |
2926 | 121 |
1797 | 122 lines_this_session++; |
123 } | |
124 } | |
125 | |
126 void | |
2926 | 127 gnu_history::do_remove (int n) |
1797 | 128 { |
3519 | 129 ::octave_remove_history (n); |
1797 | 130 } |
131 | |
132 int | |
2926 | 133 gnu_history::do_where (void) |
1797 | 134 { |
3519 | 135 return ::octave_where_history (); |
1797 | 136 } |
137 | |
138 int | |
2926 | 139 gnu_history::do_length (void) |
140 { | |
3519 | 141 return ::octave_history_length (); |
2926 | 142 } |
143 | |
144 int | |
145 gnu_history::do_max_input_history (void) | |
146 { | |
3519 | 147 return ::octave_max_input_history (); |
2926 | 148 } |
149 | |
150 int | |
151 gnu_history::do_base (void) | |
1797 | 152 { |
3519 | 153 return ::octave_history_base (); |
1797 | 154 } |
155 | |
156 int | |
2926 | 157 gnu_history::do_current_number (void) |
1797 | 158 { |
2926 | 159 return (xsize > 0) ? do_base () + do_where () : -1; |
1797 | 160 } |
161 | |
162 void | |
2926 | 163 gnu_history::do_stifle (int n) |
1797 | 164 { |
3519 | 165 ::octave_stifle_history (n); |
1797 | 166 } |
167 | |
168 int | |
2926 | 169 gnu_history::do_unstifle (void) |
1797 | 170 { |
3519 | 171 return ::octave_unstifle_history (); |
1797 | 172 } |
173 | |
174 int | |
2926 | 175 gnu_history::do_is_stifled (void) |
1797 | 176 { |
3519 | 177 return ::octave_history_is_stifled (); |
1797 | 178 } |
179 | |
180 void | |
2926 | 181 gnu_history::do_set_mark (int n) |
2658 | 182 { |
2926 | 183 mark = n; |
2658 | 184 } |
185 | |
4802 | 186 int |
2926 | 187 gnu_history::do_goto_mark (void) |
188 { | |
189 if (mark) | |
190 { | |
3519 | 191 char *line = ::octave_history_goto_mark (mark); |
2926 | 192 |
3519 | 193 if (line) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
194 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
195 command_editor::insert_text (line); |
2926 | 196 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
197 command_editor::clear_undo_list (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
198 } |
2926 | 199 } |
200 | |
201 mark = 0; | |
202 | |
5775 | 203 // FIXME -- for operate_and_get_next. |
6913 | 204 command_editor::remove_startup_hook (command_history::goto_mark); |
4802 | 205 |
206 return 0; | |
2926 | 207 } |
208 | |
209 void | |
3504 | 210 gnu_history::do_read (const std::string& f, bool must_exist) |
1797 | 211 { |
212 if (! f.empty ()) | |
213 { | |
3519 | 214 int status = ::octave_read_history (f.c_str ()); |
1797 | 215 |
2658 | 216 if (status != 0 && must_exist) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
217 error (status); |
1797 | 218 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
219 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
220 lines_in_file = do_where (); |
2658 | 221 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
222 ::octave_using_history (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
223 } |
1797 | 224 } |
225 else | |
2926 | 226 error ("gnu_history::read: missing file name"); |
1797 | 227 } |
228 | |
2659 | 229 void |
3504 | 230 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
|
231 bool must_exist) |
1797 | 232 { |
233 if (from < 0) | |
234 from = lines_in_file; | |
235 | |
236 if (! f.empty ()) | |
237 { | |
3519 | 238 int status = ::octave_read_history_range (f.c_str (), from, to); |
1797 | 239 |
2658 | 240 if (status != 0 && must_exist) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
241 error (status); |
1797 | 242 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
243 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
244 lines_in_file = do_where (); |
2658 | 245 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
246 ::octave_using_history (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
247 } |
1797 | 248 } |
249 else | |
2926 | 250 error ("gnu_history::read_range: missing file name"); |
1797 | 251 } |
252 | |
253 void | |
3504 | 254 gnu_history::do_write (const std::string& f_arg) |
1797 | 255 { |
3504 | 256 std::string f = f_arg; |
1797 | 257 |
258 if (f.empty ()) | |
259 f = xfile; | |
260 | |
261 if (! f.empty ()) | |
262 { | |
3519 | 263 int status = ::octave_write_history (f.c_str ()); |
1797 | 264 |
265 if (status != 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
266 error (status); |
1797 | 267 } |
268 else | |
2926 | 269 error ("gnu_history::write: missing file name"); |
1797 | 270 } |
271 | |
272 void | |
3504 | 273 gnu_history::do_append (const std::string& f_arg) |
1797 | 274 { |
275 if (lines_this_session) | |
276 { | |
2926 | 277 if (lines_this_session < do_where ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
278 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
279 // Create file if it doesn't already exist. |
1797 | 280 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
281 std::string f = f_arg; |
1797 | 282 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
283 if (f.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
284 f = xfile; |
1797 | 285 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
286 if (! f.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
287 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
288 file_stat fs (f); |
1797 | 289 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
290 if (! fs) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
291 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
292 int tem; |
1797 | 293 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
294 tem = open (f.c_str (), O_CREAT, 0666); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
295 close (tem); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
296 } |
1797 | 297 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
298 int status |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
299 = ::octave_append_history (lines_this_session, f.c_str ()); |
1797 | 300 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
301 if (status != 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
302 error (status); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
303 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
304 lines_in_file += lines_this_session; |
1797 | 305 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
306 lines_this_session = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
307 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
308 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
309 error ("gnu_history::append: missing file name"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
310 } |
1797 | 311 } |
312 } | |
313 | |
314 void | |
3504 | 315 gnu_history::do_truncate_file (const std::string& f_arg, int n) |
1797 | 316 { |
3504 | 317 std::string f = f_arg; |
1797 | 318 |
319 if (f.empty ()) | |
320 f = xfile; | |
321 | |
322 if (! f.empty ()) | |
3519 | 323 ::octave_history_truncate_file (f.c_str (), n); |
1797 | 324 else |
2926 | 325 error ("gnu_history::truncate_file: missing file name"); |
1797 | 326 } |
327 | |
328 string_vector | |
2926 | 329 gnu_history::do_list (int limit, bool number_lines) |
1797 | 330 { |
331 string_vector retval; | |
332 | |
333 if (limit) | |
3519 | 334 retval = ::octave_history_list (limit, number_lines); |
1797 | 335 |
336 return retval; | |
337 } | |
338 | |
3504 | 339 std::string |
2926 | 340 gnu_history::do_get_entry (int n) |
1797 | 341 { |
3504 | 342 std::string retval; |
1797 | 343 |
3519 | 344 char *line = ::octave_history_get (do_base () + n); |
1797 | 345 |
3519 | 346 if (line) |
347 retval = line; | |
1797 | 348 |
349 return retval; | |
350 } | |
351 | |
352 void | |
3504 | 353 gnu_history::do_replace_entry (int which, const std::string& line) |
1797 | 354 { |
3519 | 355 ::octave_replace_history_entry (which, line.c_str ()); |
1797 | 356 } |
357 | |
358 void | |
3504 | 359 gnu_history::do_clean_up_and_save (const std::string& f_arg, int n) |
1797 | 360 { |
3504 | 361 std::string f = f_arg; |
1797 | 362 |
363 if (f.empty ()) | |
364 f = xfile; | |
365 | |
366 if (! f.empty ()) | |
367 { | |
368 if (n < 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
369 n = xsize; |
1797 | 370 |
371 stifle (n); | |
372 | |
2926 | 373 do_write (f.c_str ()); |
1797 | 374 } |
375 else | |
2926 | 376 error ("gnu_history::clean_up_and_save: missing file name"); |
377 } | |
378 | |
379 #endif | |
380 | |
381 bool | |
382 command_history::instance_ok (void) | |
383 { | |
384 bool retval = true; | |
385 | |
386 if (! instance) | |
387 make_command_history (); | |
388 | |
389 if (! instance) | |
390 { | |
391 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
392 ("unable to create command history object!"); |
2926 | 393 |
394 retval = false; | |
395 } | |
396 | |
397 return retval; | |
398 } | |
399 | |
400 void | |
401 command_history::make_command_history (void) | |
402 { | |
403 #if defined (USE_READLINE) | |
404 instance = new gnu_history (); | |
405 #else | |
406 instance = new command_history (); | |
407 #endif | |
408 } | |
409 | |
410 void | |
5872 | 411 command_history::set_file (const std::string& f_arg) |
2926 | 412 { |
413 if (instance_ok ()) | |
5872 | 414 { |
415 std::string f = file_ops::tilde_expand (f_arg); | |
416 | |
417 instance->do_set_file (f); | |
418 } | |
2926 | 419 } |
420 | |
3504 | 421 std::string |
2926 | 422 command_history::file (void) |
423 { | |
424 return (instance_ok ()) | |
3504 | 425 ? instance->do_file () : std::string (); |
2926 | 426 } |
427 | |
428 void | |
429 command_history::set_size (int n) | |
430 { | |
431 if (instance_ok ()) | |
432 instance->do_set_size (n); | |
433 } | |
434 | |
435 int | |
436 command_history::size (void) | |
437 { | |
438 return (instance_ok ()) | |
439 ? instance->do_size () : 0; | |
440 } | |
441 | |
442 void | |
443 command_history::ignore_entries (bool flag) | |
444 { | |
445 if (instance_ok ()) | |
446 instance->do_ignore_entries (flag); | |
447 } | |
448 | |
449 bool | |
450 command_history::ignoring_entries (void) | |
451 { | |
452 return (instance_ok ()) | |
453 ? instance->do_ignoring_entries () : false; | |
454 } | |
455 | |
456 void | |
3504 | 457 command_history::add (const std::string& s) |
2926 | 458 { |
459 if (instance_ok ()) | |
460 instance->do_add (s); | |
461 } | |
462 | |
463 void | |
464 command_history::remove (int n) | |
465 { | |
466 if (instance_ok ()) | |
467 instance->do_remove (n); | |
468 } | |
469 | |
470 int | |
471 command_history::where (void) | |
472 { | |
473 return (instance_ok ()) | |
474 ? instance->do_where () : 0; | |
475 } | |
476 | |
477 int | |
478 command_history::length (void) | |
479 { | |
480 return (instance_ok ()) | |
481 ? instance->do_length () : 0; | |
482 } | |
483 | |
484 int | |
485 command_history::max_input_history (void) | |
486 { | |
487 return (instance_ok ()) | |
488 ? instance->do_max_input_history () : 0; | |
489 } | |
490 | |
491 int | |
492 command_history::base (void) | |
493 { | |
494 return (instance_ok ()) | |
495 ? instance->do_base () : 0; | |
496 } | |
497 | |
498 int | |
499 command_history::current_number (void) | |
500 { | |
501 return (instance_ok ()) | |
502 ? instance->do_current_number () : 0; | |
503 } | |
504 | |
505 void | |
506 command_history::stifle (int n) | |
507 { | |
508 if (instance_ok ()) | |
509 instance->do_stifle (n); | |
510 } | |
511 | |
512 int | |
513 command_history::unstifle (void) | |
514 { | |
515 return (instance_ok ()) | |
516 ? instance->do_unstifle () : 0; | |
517 } | |
518 | |
519 int | |
520 command_history::is_stifled (void) | |
521 { | |
522 return (instance_ok ()) | |
523 ? instance->do_is_stifled () : 0; | |
524 } | |
525 | |
526 void | |
527 command_history::set_mark (int n) | |
528 { | |
529 if (instance_ok ()) | |
530 instance->do_set_mark (n); | |
531 } | |
532 | |
4802 | 533 int |
3519 | 534 command_history::goto_mark (void) |
2926 | 535 { |
4802 | 536 return (instance_ok ()) |
537 ? instance->do_goto_mark () : 0; | |
2926 | 538 } |
539 | |
540 void | |
541 command_history::read (bool must_exist) | |
542 { | |
3522 | 543 read (file (), must_exist); |
2926 | 544 } |
545 | |
546 void | |
3504 | 547 command_history::read (const std::string& f, bool must_exist) |
2926 | 548 { |
549 if (instance_ok ()) | |
550 instance->do_read (f, must_exist); | |
551 } | |
552 | |
553 void | |
554 command_history::read_range (int from, int to, bool must_exist) | |
555 { | |
3522 | 556 read_range (file (), from, to, must_exist); |
2926 | 557 } |
558 | |
559 void | |
3504 | 560 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
|
561 bool must_exist) |
2926 | 562 { |
563 if (instance_ok ()) | |
564 instance->do_read_range (f, from, to, must_exist); | |
565 } | |
566 | |
567 void | |
3504 | 568 command_history::write (const std::string& f) |
2926 | 569 { |
570 if (instance_ok ()) | |
571 instance->do_write (f); | |
572 } | |
573 | |
574 void | |
3504 | 575 command_history::append (const std::string& f) |
2926 | 576 { |
577 if (instance_ok ()) | |
578 instance->do_append (f); | |
579 } | |
580 | |
581 void | |
3504 | 582 command_history::truncate_file (const std::string& f, int n) |
2926 | 583 { |
584 if (instance_ok ()) | |
585 instance->do_truncate_file (f, n); | |
586 } | |
587 | |
588 string_vector | |
589 command_history::list (int limit, bool number_lines) | |
590 { | |
591 return (instance_ok ()) | |
592 ? instance->do_list (limit, number_lines) : string_vector (); | |
593 } | |
594 | |
3504 | 595 std::string |
2926 | 596 command_history::get_entry (int n) |
597 { | |
598 return (instance_ok ()) | |
3504 | 599 ? instance->do_get_entry (n) : std::string (); |
2926 | 600 } |
601 | |
602 void | |
3504 | 603 command_history::replace_entry (int which, const std::string& line) |
2926 | 604 { |
605 if (instance_ok ()) | |
606 instance->do_replace_entry (which, line); | |
607 } | |
608 | |
609 void | |
3504 | 610 command_history::clean_up_and_save (const std::string& f, int n) |
2926 | 611 { |
612 if (instance_ok ()) | |
613 instance->do_clean_up_and_save (f, n); | |
614 } | |
615 | |
616 void | |
3504 | 617 command_history::do_set_file (const std::string& f) |
2926 | 618 { |
619 xfile = f; | |
620 } | |
621 | |
3504 | 622 std::string |
2926 | 623 command_history::do_file (void) |
624 { | |
625 return xfile; | |
626 } | |
627 | |
628 void | |
629 command_history::do_set_size (int n) | |
630 { | |
631 xsize = n; | |
632 } | |
633 | |
634 int | |
635 command_history::do_size (void) | |
636 { | |
637 return xsize; | |
638 } | |
639 | |
640 void | |
641 command_history::do_ignore_entries (bool flag) | |
642 { | |
643 ignoring_additions = flag; | |
644 } | |
645 | |
646 bool | |
647 command_history::do_ignoring_entries (void) | |
648 { | |
649 return ignoring_additions; | |
650 } | |
651 | |
652 void | |
3504 | 653 command_history::do_add (const std::string&) |
2926 | 654 { |
655 } | |
656 | |
657 void | |
658 command_history::do_remove (int) | |
659 { | |
660 } | |
661 | |
662 int | |
663 command_history::do_where (void) | |
664 { | |
665 return 0; | |
666 } | |
667 | |
668 int | |
669 command_history::do_length (void) | |
670 { | |
671 return 0; | |
672 } | |
673 | |
674 int | |
675 command_history::do_max_input_history (void) | |
676 { | |
677 return 0; | |
678 } | |
679 | |
680 int | |
681 command_history::do_base (void) | |
682 { | |
683 return 0; | |
684 } | |
685 | |
686 int | |
687 command_history::do_current_number (void) | |
688 { | |
689 return (xsize > 0) ? do_base () + do_where () : -1; | |
690 } | |
691 | |
692 void | |
693 command_history::do_stifle (int) | |
694 { | |
695 } | |
696 | |
697 int | |
698 command_history::do_unstifle (void) | |
699 { | |
700 return -1; | |
701 } | |
702 | |
703 int | |
704 command_history::do_is_stifled (void) | |
705 { | |
706 return 0; | |
707 } | |
708 | |
709 void | |
710 command_history::do_set_mark (int) | |
711 { | |
712 } | |
713 | |
4802 | 714 int |
2926 | 715 command_history::do_goto_mark (void) |
716 { | |
4802 | 717 return 0; |
2926 | 718 } |
719 | |
720 void | |
3504 | 721 command_history::do_read (const std::string& f, bool) |
2926 | 722 { |
723 if (f.empty ()) | |
724 error ("command_history::read: missing file name"); | |
725 } | |
726 | |
727 void | |
3504 | 728 command_history::do_read_range (const std::string& f, int, int, bool) |
2926 | 729 { |
730 if (f.empty ()) | |
731 error ("command_history::read_range: missing file name"); | |
732 } | |
733 | |
734 void | |
3504 | 735 command_history::do_write (const std::string& f_arg) |
2926 | 736 { |
3504 | 737 std::string f = f_arg; |
2926 | 738 |
739 if (f.empty ()) | |
740 f = xfile; | |
741 | |
742 if (f.empty ()) | |
743 error ("command_history::write: missing file name"); | |
744 } | |
745 | |
746 void | |
3504 | 747 command_history::do_append (const std::string& f_arg) |
2926 | 748 { |
749 if (lines_this_session) | |
750 { | |
751 if (lines_this_session < do_where ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
752 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
753 // Create file if it doesn't already exist. |
2926 | 754 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
755 std::string f = f_arg; |
2926 | 756 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
757 if (f.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
758 f = xfile; |
2926 | 759 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
760 if (f.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
761 error ("command_history::append: missing file name"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
762 } |
2926 | 763 } |
764 } | |
765 | |
766 void | |
3504 | 767 command_history::do_truncate_file (const std::string& f_arg, int) |
2926 | 768 { |
3504 | 769 std::string f = f_arg; |
2926 | 770 |
771 if (f.empty ()) | |
772 f = xfile; | |
773 | |
774 if (f.empty ()) | |
775 error ("command_history::truncate_file: missing file name"); | |
776 } | |
777 | |
778 string_vector | |
779 command_history::do_list (int, bool) | |
780 { | |
781 return string_vector (); | |
782 } | |
783 | |
3504 | 784 std::string |
2926 | 785 command_history::do_get_entry (int) |
786 { | |
3504 | 787 return std::string (); |
2926 | 788 } |
789 | |
790 void | |
3504 | 791 command_history::do_replace_entry (int, const std::string&) |
2926 | 792 { |
793 } | |
794 | |
795 void | |
3504 | 796 command_history::do_clean_up_and_save (const std::string& f_arg, int) |
2926 | 797 { |
3504 | 798 std::string f = f_arg; |
2926 | 799 |
800 if (f.empty ()) | |
801 f = xfile; | |
802 | |
803 if (f.empty ()) | |
1797 | 804 error ("command_history::clean_up_and_save: missing file name"); |
805 } | |
806 | |
807 void | |
2470 | 808 command_history::error (int err_num) |
1797 | 809 { |
2470 | 810 (*current_liboctave_error_handler) ("%s", strerror (err_num)); |
1797 | 811 } |
812 | |
813 void | |
3504 | 814 command_history::error (const std::string& s) |
1797 | 815 { |
816 (*current_liboctave_error_handler) ("%s", s.c_str ()); | |
817 } |