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