Mercurial > octave-nkf
annotate liboctave/util/cmd-hist.cc @ 20595:c1a6c31ac29a
eliminate more simple uses of error_state
* ov-classdef.cc: Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Oct 2015 00:20:02 -0400 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
1797 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19444
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
1797 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1797 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1797 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
27 #include <cstring> |
1797 | 28 |
3504 | 29 #include <iostream> |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
30 #include <sstream> |
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" |
14071
8aa5da1b7ce3
also include singleton-cleanup.h when not using readline
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
37 #include "singleton-cleanup.h" |
2926 | 38 #include "str-vec.h" |
39 | |
40 command_history *command_history::instance = 0; | |
41 | |
42 #if defined (USE_READLINE) | |
43 | |
44 #include <cstdlib> | |
45 | |
1797 | 46 #include <sys/types.h> |
47 #include <unistd.h> | |
48 | |
10259 | 49 #include <fcntl.h> |
50 | |
3519 | 51 #include "oct-rl-hist.h" |
1797 | 52 |
2926 | 53 #include "file-stat.h" |
1797 | 54 |
2926 | 55 class |
56 gnu_history : public command_history | |
1797 | 57 { |
2926 | 58 public: |
59 | |
60 gnu_history (void) | |
61 : command_history (), mark (0) { } | |
62 | |
63 ~gnu_history (void) { } | |
64 | |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
65 void do_process_histcontrol (const std::string&); |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
66 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
67 std::string do_histcontrol (void) const; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
68 |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
69 bool do_add (const std::string&); |
2926 | 70 |
71 void do_remove (int); | |
1797 | 72 |
15397
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
73 void do_clear (void); |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
74 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
75 int do_where (void) const; |
2926 | 76 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
77 int do_length (void) const; |
2926 | 78 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
79 int do_max_input_history (void) const; |
2926 | 80 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
81 int do_base (void) const; |
2926 | 82 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
83 int do_current_number (void) const; |
2926 | 84 |
85 void do_stifle (int); | |
1797 | 86 |
2926 | 87 int do_unstifle (void); |
88 | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
89 int do_is_stifled (void) const; |
2926 | 90 |
91 void do_set_mark (int); | |
1797 | 92 |
4802 | 93 int do_goto_mark (void); |
2926 | 94 |
3504 | 95 void do_read (const std::string&, bool); |
1797 | 96 |
3504 | 97 void do_read_range (const std::string&, int, int, bool); |
1797 | 98 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
99 void do_write (const std::string&) const; |
1797 | 100 |
3504 | 101 void do_append (const std::string&); |
2926 | 102 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
103 void do_truncate_file (const std::string&, int) const; |
2926 | 104 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
105 string_vector do_list (int, bool) const; |
2926 | 106 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
107 std::string do_get_entry (int) const; |
1797 | 108 |
3504 | 109 void do_replace_entry (int, const std::string&); |
2926 | 110 |
3504 | 111 void do_clean_up_and_save (const std::string&, int); |
1797 | 112 |
2926 | 113 private: |
114 | |
115 int mark; | |
116 }; | |
1797 | 117 |
118 void | |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
119 gnu_history::do_process_histcontrol (const std::string& control_arg) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
120 { |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
121 history_control = 0; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
122 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
123 size_t len = control_arg.length (); |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
124 size_t beg = 0; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
125 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
126 while (beg < len) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
127 { |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
128 if (control_arg[beg] == ':') |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
129 beg++; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
130 else |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
131 { |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
132 size_t end = control_arg.find (":", beg); |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
133 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
134 if (end == std::string::npos) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
135 end = len; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
136 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
137 std::string tmp = control_arg.substr (beg, end-beg); |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
138 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
139 if (tmp == "erasedups") |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
140 history_control |= HC_ERASEDUPS; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
141 else if (tmp == "ignoreboth") |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
142 history_control |= HC_IGNDUPS|HC_IGNSPACE; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
143 else if (tmp == "ignoredups") |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
144 history_control |= HC_IGNDUPS; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
145 else if (tmp == "ignorespace") |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
146 history_control |= HC_IGNSPACE; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
147 else |
19444
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17996
diff
changeset
|
148 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17996
diff
changeset
|
149 ("Octave:history-control", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17996
diff
changeset
|
150 "unknown histcontrol directive %s", tmp.c_str ()); |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
151 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
152 if (end != std::string::npos) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
153 beg = end + 1; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
154 } |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
155 } |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
156 } |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
157 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
158 std::string |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
159 gnu_history::do_histcontrol (void) const |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
160 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
161 // FIXME: instead of reconstructing this value, should we just save |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
162 // the string we were given when constructing the command_history object? |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
163 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
164 std::string retval; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
165 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
166 if (history_control & HC_IGNSPACE) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
167 retval.append ("ignorespace"); |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
168 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
169 if (history_control & HC_IGNDUPS) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
170 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
171 if (retval.length () > 0) |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
172 retval.append (":"); |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
173 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
174 retval.append ("ignoredups"); |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
175 } |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
176 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
177 if (history_control & HC_ERASEDUPS) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
178 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
179 if (retval.length () > 0) |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
180 retval.append (":"); |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
181 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
182 retval.append ("erasedups"); |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
183 } |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
184 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
185 return retval; |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
186 } |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
187 |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
188 bool |
3504 | 189 gnu_history::do_add (const std::string& s) |
1797 | 190 { |
2926 | 191 if (! do_ignoring_entries ()) |
1797 | 192 { |
2512 | 193 if (s.empty () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
194 || (s.length () == 1 && (s[0] == '\r' || s[0] == '\n'))) |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
195 return false; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
196 |
16021
26cba49d7641
Prevent extra newline in history list when --no-line-editing option used.
Rik <rik@octave.org>
parents:
15397
diff
changeset
|
197 // Strip newline before adding to list |
26cba49d7641
Prevent extra newline in history list when --no-line-editing option used.
Rik <rik@octave.org>
parents:
15397
diff
changeset
|
198 std::string stmp = s; |
26cba49d7641
Prevent extra newline in history list when --no-line-editing option used.
Rik <rik@octave.org>
parents:
15397
diff
changeset
|
199 int stmp_len = stmp.length (); |
26cba49d7641
Prevent extra newline in history list when --no-line-editing option used.
Rik <rik@octave.org>
parents:
15397
diff
changeset
|
200 if (stmp[stmp_len - 1] == '\n') |
26cba49d7641
Prevent extra newline in history list when --no-line-editing option used.
Rik <rik@octave.org>
parents:
15397
diff
changeset
|
201 stmp.resize (stmp_len - 1); |
2512 | 202 |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
203 int added = ::octave_add_history (stmp.c_str (), history_control); |
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
204 lines_this_session += added; |
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
205 return (added > 0) ? true : false; |
1797 | 206 } |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
207 return false; |
1797 | 208 } |
209 | |
210 void | |
2926 | 211 gnu_history::do_remove (int n) |
1797 | 212 { |
3519 | 213 ::octave_remove_history (n); |
1797 | 214 } |
215 | |
15397
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
216 void |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
217 gnu_history::do_clear (void) |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
218 { |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
219 ::octave_clear_history (); |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
220 } |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
221 |
1797 | 222 int |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
223 gnu_history::do_where (void) const |
1797 | 224 { |
3519 | 225 return ::octave_where_history (); |
1797 | 226 } |
227 | |
228 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
229 gnu_history::do_length (void) const |
2926 | 230 { |
3519 | 231 return ::octave_history_length (); |
2926 | 232 } |
233 | |
234 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
235 gnu_history::do_max_input_history (void) const |
2926 | 236 { |
3519 | 237 return ::octave_max_input_history (); |
2926 | 238 } |
239 | |
240 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
241 gnu_history::do_base (void) const |
1797 | 242 { |
3519 | 243 return ::octave_history_base (); |
1797 | 244 } |
245 | |
246 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
247 gnu_history::do_current_number (void) const |
1797 | 248 { |
2926 | 249 return (xsize > 0) ? do_base () + do_where () : -1; |
1797 | 250 } |
251 | |
252 void | |
2926 | 253 gnu_history::do_stifle (int n) |
1797 | 254 { |
3519 | 255 ::octave_stifle_history (n); |
1797 | 256 } |
257 | |
258 int | |
2926 | 259 gnu_history::do_unstifle (void) |
1797 | 260 { |
3519 | 261 return ::octave_unstifle_history (); |
1797 | 262 } |
263 | |
264 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
265 gnu_history::do_is_stifled (void) const |
1797 | 266 { |
3519 | 267 return ::octave_history_is_stifled (); |
1797 | 268 } |
269 | |
270 void | |
2926 | 271 gnu_history::do_set_mark (int n) |
2658 | 272 { |
2926 | 273 mark = n; |
2658 | 274 } |
275 | |
4802 | 276 int |
2926 | 277 gnu_history::do_goto_mark (void) |
278 { | |
279 if (mark) | |
280 { | |
3519 | 281 char *line = ::octave_history_goto_mark (mark); |
2926 | 282 |
3519 | 283 if (line) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
284 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
285 command_editor::insert_text (line); |
2926 | 286 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
287 command_editor::clear_undo_list (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
288 } |
2926 | 289 } |
290 | |
291 mark = 0; | |
292 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
293 // FIXME: for operate_and_get_next. |
6913 | 294 command_editor::remove_startup_hook (command_history::goto_mark); |
4802 | 295 |
296 return 0; | |
2926 | 297 } |
298 | |
299 void | |
3504 | 300 gnu_history::do_read (const std::string& f, bool must_exist) |
1797 | 301 { |
302 if (! f.empty ()) | |
303 { | |
3519 | 304 int status = ::octave_read_history (f.c_str ()); |
1797 | 305 |
2658 | 306 if (status != 0 && must_exist) |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
307 { |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
308 std::string msg = "reading file '" + f + "'"; |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
309 |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
310 error (status, msg); |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
311 } |
1797 | 312 else |
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 lines_in_file = do_where (); |
2658 | 315 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
316 ::octave_using_history (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
317 } |
1797 | 318 } |
319 else | |
2926 | 320 error ("gnu_history::read: missing file name"); |
1797 | 321 } |
322 | |
2659 | 323 void |
3504 | 324 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
|
325 bool must_exist) |
1797 | 326 { |
327 if (from < 0) | |
328 from = lines_in_file; | |
329 | |
330 if (! f.empty ()) | |
331 { | |
3519 | 332 int status = ::octave_read_history_range (f.c_str (), from, to); |
1797 | 333 |
2658 | 334 if (status != 0 && must_exist) |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
335 { |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
336 std::ostringstream buf; |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
337 buf << "reading lines " << from << " to " << to |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
338 << " from file '" << f << "'"; |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
339 |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
340 error (status, buf.str ()); |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
341 } |
1797 | 342 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
343 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
344 lines_in_file = do_where (); |
2658 | 345 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
346 ::octave_using_history (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
347 } |
1797 | 348 } |
349 else | |
2926 | 350 error ("gnu_history::read_range: missing file name"); |
1797 | 351 } |
352 | |
353 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
354 gnu_history::do_write (const std::string& f_arg) const |
1797 | 355 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
356 if (initialized) |
1797 | 357 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
358 std::string f = f_arg; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
359 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
360 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
361 f = xfile; |
1797 | 362 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
363 if (! f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
364 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
365 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
|
366 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
367 if (status != 0) |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
368 { |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
369 std::string msg = "writing file '" + f + "'"; |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
370 |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
371 error (status, msg); |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
372 } |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
373 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
374 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
375 error ("gnu_history::write: missing file name"); |
1797 | 376 } |
377 } | |
378 | |
379 void | |
3504 | 380 gnu_history::do_append (const std::string& f_arg) |
1797 | 381 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
382 if (initialized) |
1797 | 383 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
384 if (lines_this_session) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
385 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
386 if (lines_this_session < do_where ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
387 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
388 // Create file if it doesn't already exist. |
1797 | 389 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
390 std::string f = f_arg; |
1797 | 391 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
392 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
393 f = xfile; |
1797 | 394 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
395 if (! f.empty ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
396 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
397 file_stat fs (f); |
1797 | 398 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
399 if (! fs) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
400 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
401 int tem; |
1797 | 402 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
403 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
|
404 gnulib::close (tem); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
405 } |
1797 | 406 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
407 int status |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
408 = ::octave_append_history (lines_this_session, f.c_str ()); |
1797 | 409 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
410 if (status != 0) |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
411 { |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
412 std::string msg = "appending to file '" + f_arg + "'"; |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
413 |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
414 error (status, msg); |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
415 } |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
416 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
417 lines_in_file += lines_this_session; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
418 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
419 lines_this_session = 0; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
420 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
421 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
422 error ("gnu_history::append: missing file name"); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
423 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
424 } |
1797 | 425 } |
426 } | |
427 | |
428 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
429 gnu_history::do_truncate_file (const std::string& f_arg, int n) const |
1797 | 430 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
431 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
432 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
433 std::string f = f_arg; |
1797 | 434 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
435 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
436 f = xfile; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
437 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
438 if (! f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
439 ::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
|
440 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
441 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
|
442 } |
1797 | 443 } |
444 | |
445 string_vector | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
446 gnu_history::do_list (int limit, bool number_lines) const |
1797 | 447 { |
448 string_vector retval; | |
449 | |
450 if (limit) | |
3519 | 451 retval = ::octave_history_list (limit, number_lines); |
1797 | 452 |
453 return retval; | |
454 } | |
455 | |
3504 | 456 std::string |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
457 gnu_history::do_get_entry (int n) const |
1797 | 458 { |
3504 | 459 std::string retval; |
1797 | 460 |
3519 | 461 char *line = ::octave_history_get (do_base () + n); |
1797 | 462 |
3519 | 463 if (line) |
464 retval = line; | |
1797 | 465 |
466 return retval; | |
467 } | |
468 | |
469 void | |
3504 | 470 gnu_history::do_replace_entry (int which, const std::string& line) |
1797 | 471 { |
3519 | 472 ::octave_replace_history_entry (which, line.c_str ()); |
1797 | 473 } |
474 | |
475 void | |
3504 | 476 gnu_history::do_clean_up_and_save (const std::string& f_arg, int n) |
1797 | 477 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
478 if (initialized) |
1797 | 479 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
480 std::string f = f_arg; |
1797 | 481 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
482 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
483 f = xfile; |
1797 | 484 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
485 if (! f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
486 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
487 if (n < 0) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
488 n = xsize; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
489 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
490 stifle (n); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
491 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
492 do_write (f.c_str ()); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
493 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
494 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
495 error ("gnu_history::clean_up_and_save: missing file name"); |
1797 | 496 } |
2926 | 497 } |
498 | |
499 #endif | |
500 | |
501 bool | |
502 command_history::instance_ok (void) | |
503 { | |
504 bool retval = true; | |
505 | |
506 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
507 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
508 make_command_history (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
509 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
510 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
511 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
512 } |
2926 | 513 |
514 if (! instance) | |
515 { | |
516 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
517 ("unable to create command history object!"); |
2926 | 518 |
519 retval = false; | |
520 } | |
521 | |
522 return retval; | |
523 } | |
524 | |
525 void | |
526 command_history::make_command_history (void) | |
527 { | |
528 #if defined (USE_READLINE) | |
529 instance = new gnu_history (); | |
530 #else | |
531 instance = new command_history (); | |
532 #endif | |
533 } | |
534 | |
535 void | |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
536 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
|
537 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
|
538 const std::string & control_arg) |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
539 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
540 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
|
541 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
|
542 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
543 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
544 bool |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
545 command_history::is_initialized (void) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
546 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
547 // 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
|
548 // create one. |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
549 return instance && instance->do_is_initialized (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
550 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
551 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
552 void |
5872 | 553 command_history::set_file (const std::string& f_arg) |
2926 | 554 { |
555 if (instance_ok ()) | |
5872 | 556 { |
557 std::string f = file_ops::tilde_expand (f_arg); | |
558 | |
559 instance->do_set_file (f); | |
560 } | |
2926 | 561 } |
562 | |
3504 | 563 std::string |
2926 | 564 command_history::file (void) |
565 { | |
566 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
567 ? instance->do_file () : std::string (); |
2926 | 568 } |
569 | |
570 void | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
571 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
|
572 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
573 if (instance_ok ()) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
574 instance->do_process_histcontrol (control_arg); |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
575 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
576 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
577 std::string |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
578 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
|
579 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
580 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
581 ? instance->do_histcontrol () : std::string (); |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
582 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
583 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
584 void |
2926 | 585 command_history::set_size (int n) |
586 { | |
587 if (instance_ok ()) | |
588 instance->do_set_size (n); | |
589 } | |
590 | |
591 int | |
592 command_history::size (void) | |
593 { | |
594 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
595 ? instance->do_size () : 0; |
2926 | 596 } |
597 | |
598 void | |
599 command_history::ignore_entries (bool flag) | |
600 { | |
601 if (instance_ok ()) | |
602 instance->do_ignore_entries (flag); | |
603 } | |
604 | |
605 bool | |
606 command_history::ignoring_entries (void) | |
607 { | |
608 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
609 ? instance->do_ignoring_entries () : false; |
2926 | 610 } |
611 | |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
612 bool |
3504 | 613 command_history::add (const std::string& s) |
2926 | 614 { |
615 if (instance_ok ()) | |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
616 return instance->do_add (s); |
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
617 return false; |
2926 | 618 } |
619 | |
620 void | |
621 command_history::remove (int n) | |
622 { | |
623 if (instance_ok ()) | |
624 instance->do_remove (n); | |
625 } | |
626 | |
15397
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
627 void |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
628 command_history::clear (void) |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
629 { |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
630 if (instance_ok ()) |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
631 instance->do_clear (); |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
632 } |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
633 |
2926 | 634 int |
635 command_history::where (void) | |
636 { | |
637 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
638 ? instance->do_where () : 0; |
2926 | 639 } |
640 | |
641 int | |
642 command_history::length (void) | |
643 { | |
644 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
645 ? instance->do_length () : 0; |
2926 | 646 } |
647 | |
648 int | |
649 command_history::max_input_history (void) | |
650 { | |
651 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
652 ? instance->do_max_input_history () : 0; |
2926 | 653 } |
654 | |
655 int | |
656 command_history::base (void) | |
657 { | |
658 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
659 ? instance->do_base () : 0; |
2926 | 660 } |
661 | |
662 int | |
663 command_history::current_number (void) | |
664 { | |
665 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
666 ? instance->do_current_number () : 0; |
2926 | 667 } |
668 | |
669 void | |
670 command_history::stifle (int n) | |
671 { | |
672 if (instance_ok ()) | |
673 instance->do_stifle (n); | |
674 } | |
675 | |
676 int | |
677 command_history::unstifle (void) | |
678 { | |
679 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
680 ? instance->do_unstifle () : 0; |
2926 | 681 } |
682 | |
683 int | |
684 command_history::is_stifled (void) | |
685 { | |
686 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
687 ? instance->do_is_stifled () : 0; |
2926 | 688 } |
689 | |
690 void | |
691 command_history::set_mark (int n) | |
692 { | |
693 if (instance_ok ()) | |
694 instance->do_set_mark (n); | |
695 } | |
696 | |
4802 | 697 int |
3519 | 698 command_history::goto_mark (void) |
2926 | 699 { |
4802 | 700 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
701 ? instance->do_goto_mark () : 0; |
2926 | 702 } |
703 | |
704 void | |
705 command_history::read (bool must_exist) | |
706 { | |
3522 | 707 read (file (), must_exist); |
2926 | 708 } |
709 | |
710 void | |
3504 | 711 command_history::read (const std::string& f, bool must_exist) |
2926 | 712 { |
713 if (instance_ok ()) | |
714 instance->do_read (f, must_exist); | |
715 } | |
716 | |
717 void | |
718 command_history::read_range (int from, int to, bool must_exist) | |
719 { | |
3522 | 720 read_range (file (), from, to, must_exist); |
2926 | 721 } |
722 | |
723 void | |
3504 | 724 command_history::read_range (const std::string& f, int from, int to, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
725 bool must_exist) |
2926 | 726 { |
727 if (instance_ok ()) | |
728 instance->do_read_range (f, from, to, must_exist); | |
729 } | |
730 | |
731 void | |
3504 | 732 command_history::write (const std::string& f) |
2926 | 733 { |
734 if (instance_ok ()) | |
735 instance->do_write (f); | |
736 } | |
737 | |
738 void | |
3504 | 739 command_history::append (const std::string& f) |
2926 | 740 { |
741 if (instance_ok ()) | |
742 instance->do_append (f); | |
743 } | |
744 | |
745 void | |
3504 | 746 command_history::truncate_file (const std::string& f, int n) |
2926 | 747 { |
748 if (instance_ok ()) | |
749 instance->do_truncate_file (f, n); | |
750 } | |
751 | |
752 string_vector | |
753 command_history::list (int limit, bool number_lines) | |
754 { | |
755 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
756 ? instance->do_list (limit, number_lines) : string_vector (); |
2926 | 757 } |
758 | |
3504 | 759 std::string |
2926 | 760 command_history::get_entry (int n) |
761 { | |
762 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
763 ? instance->do_get_entry (n) : std::string (); |
2926 | 764 } |
765 | |
766 void | |
3504 | 767 command_history::replace_entry (int which, const std::string& line) |
2926 | 768 { |
769 if (instance_ok ()) | |
770 instance->do_replace_entry (which, line); | |
771 } | |
772 | |
773 void | |
3504 | 774 command_history::clean_up_and_save (const std::string& f, int n) |
2926 | 775 { |
776 if (instance_ok ()) | |
777 instance->do_clean_up_and_save (f, n); | |
778 } | |
779 | |
780 void | |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
781 command_history::do_process_histcontrol (const std::string&) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
782 { |
19444
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17996
diff
changeset
|
783 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17996
diff
changeset
|
784 ("Octave:history-control", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17996
diff
changeset
|
785 "readline is not linked, so history control is not available"); |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
786 } |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
787 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
788 void |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
789 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
|
790 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
|
791 const std::string & control_arg) |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
792 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
793 command_history::set_file (f_arg); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
794 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
|
795 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
|
796 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
797 if (read_history_file) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
798 command_history::read (false); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
799 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
800 initialized = true; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
801 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
802 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
803 bool |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
804 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
|
805 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
806 return initialized; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
807 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
808 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
809 void |
3504 | 810 command_history::do_set_file (const std::string& f) |
2926 | 811 { |
812 xfile = f; | |
813 } | |
814 | |
3504 | 815 std::string |
2926 | 816 command_history::do_file (void) |
817 { | |
818 return xfile; | |
819 } | |
820 | |
821 void | |
822 command_history::do_set_size (int n) | |
823 { | |
824 xsize = n; | |
825 } | |
826 | |
827 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
828 command_history::do_size (void) const |
2926 | 829 { |
830 return xsize; | |
831 } | |
832 | |
833 void | |
834 command_history::do_ignore_entries (bool flag) | |
835 { | |
836 ignoring_additions = flag; | |
837 } | |
838 | |
839 bool | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
840 command_history::do_ignoring_entries (void) const |
2926 | 841 { |
842 return ignoring_additions; | |
843 } | |
844 | |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
845 bool |
3504 | 846 command_history::do_add (const std::string&) |
2926 | 847 { |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
848 return false; |
2926 | 849 } |
850 | |
851 void | |
852 command_history::do_remove (int) | |
853 { | |
854 } | |
855 | |
15397
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
856 void |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
857 command_history::do_clear (void) |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
858 { |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
859 } |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
860 |
2926 | 861 int |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
862 command_history::do_where (void) const |
2926 | 863 { |
864 return 0; | |
865 } | |
866 | |
867 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
868 command_history::do_length (void) const |
2926 | 869 { |
870 return 0; | |
871 } | |
872 | |
873 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
874 command_history::do_max_input_history (void) const |
2926 | 875 { |
876 return 0; | |
877 } | |
878 | |
879 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
880 command_history::do_base (void) const |
2926 | 881 { |
882 return 0; | |
883 } | |
884 | |
885 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
886 command_history::do_current_number (void) const |
2926 | 887 { |
888 return (xsize > 0) ? do_base () + do_where () : -1; | |
889 } | |
890 | |
891 void | |
892 command_history::do_stifle (int) | |
893 { | |
894 } | |
895 | |
896 int | |
897 command_history::do_unstifle (void) | |
898 { | |
899 return -1; | |
900 } | |
901 | |
902 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
903 command_history::do_is_stifled (void) const |
2926 | 904 { |
905 return 0; | |
906 } | |
907 | |
908 void | |
909 command_history::do_set_mark (int) | |
910 { | |
911 } | |
912 | |
4802 | 913 int |
2926 | 914 command_history::do_goto_mark (void) |
915 { | |
4802 | 916 return 0; |
2926 | 917 } |
918 | |
919 void | |
3504 | 920 command_history::do_read (const std::string& f, bool) |
2926 | 921 { |
922 if (f.empty ()) | |
923 error ("command_history::read: missing file name"); | |
924 } | |
925 | |
926 void | |
3504 | 927 command_history::do_read_range (const std::string& f, int, int, bool) |
2926 | 928 { |
929 if (f.empty ()) | |
930 error ("command_history::read_range: missing file name"); | |
931 } | |
932 | |
933 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
934 command_history::do_write (const std::string& f_arg) const |
2926 | 935 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
936 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
937 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
938 std::string f = f_arg; |
2926 | 939 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
940 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
941 f = xfile; |
2926 | 942 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
943 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
944 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
|
945 } |
2926 | 946 } |
947 | |
948 void | |
3504 | 949 command_history::do_append (const std::string& f_arg) |
2926 | 950 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
951 if (initialized) |
2926 | 952 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
953 if (lines_this_session) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
954 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
955 if (lines_this_session < do_where ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
956 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
957 // Create file if it doesn't already exist. |
2926 | 958 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
959 std::string f = f_arg; |
2926 | 960 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
961 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
962 f = xfile; |
2926 | 963 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
964 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
965 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
|
966 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
967 } |
2926 | 968 } |
969 } | |
970 | |
971 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
972 command_history::do_truncate_file (const std::string& f_arg, int) const |
2926 | 973 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
974 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
975 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
976 std::string f = f_arg; |
2926 | 977 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
978 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
979 f = xfile; |
2926 | 980 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
981 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
982 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
|
983 } |
2926 | 984 } |
985 | |
986 string_vector | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
987 command_history::do_list (int, bool) const |
2926 | 988 { |
989 return string_vector (); | |
990 } | |
991 | |
3504 | 992 std::string |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
993 command_history::do_get_entry (int) const |
2926 | 994 { |
3504 | 995 return std::string (); |
2926 | 996 } |
997 | |
998 void | |
3504 | 999 command_history::do_replace_entry (int, const std::string&) |
2926 | 1000 { |
1001 } | |
1002 | |
1003 void | |
3504 | 1004 command_history::do_clean_up_and_save (const std::string& f_arg, int) |
2926 | 1005 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1006 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1007 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1008 std::string f = f_arg; |
2926 | 1009 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1010 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1011 f = xfile; |
2926 | 1012 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1013 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1014 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
|
1015 } |
1797 | 1016 } |
1017 | |
1018 void | |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1019 command_history::error (int err_num, const std::string& msg) const |
1797 | 1020 { |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1021 if (msg.empty ()) |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1022 (*current_liboctave_error_handler) ("%s", gnulib::strerror (err_num)); |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1023 else |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1024 (*current_liboctave_error_handler) ("%s: %s", msg.c_str (), |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1025 gnulib::strerror (err_num)); |
1797 | 1026 } |
1027 | |
1028 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
1029 command_history::error (const std::string& s) const |
1797 | 1030 { |
1031 (*current_liboctave_error_handler) ("%s", s.c_str ()); | |
1032 } |