Mercurial > hg > octave-nkf
annotate liboctave/util/cmd-hist.cc @ 19183:a66548dc07b0 stable release-3-8-2
Version 3.8.2 released.
* configure.ac (OCTAVE_VERSION): Now 3.8.2.
(OCTAVE_MINOR_VERSION): Now 2.
(OCTAVE_RELEASE_DATE): Set to 2014-06-06.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 07 Aug 2014 11:41:28 -0400 |
parents | 260b44c0ed69 |
children | 95c533ed464b |
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> |
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 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
148 (*current_liboctave_warning_handler) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
149 ("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
|
150 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
151 if (end != std::string::npos) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
152 beg = end + 1; |
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 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
157 std::string |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
158 gnu_history::do_histcontrol (void) const |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
159 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
160 // 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
|
161 // 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
|
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; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
195 |
16021
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 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
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) |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
306 { |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
307 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
|
308 |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
309 error (status, msg); |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
310 } |
1797 | 311 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
312 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
313 lines_in_file = do_where (); |
2658 | 314 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
315 ::octave_using_history (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
316 } |
1797 | 317 } |
318 else | |
2926 | 319 error ("gnu_history::read: missing file name"); |
1797 | 320 } |
321 | |
2659 | 322 void |
3504 | 323 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
|
324 bool must_exist) |
1797 | 325 { |
326 if (from < 0) | |
327 from = lines_in_file; | |
328 | |
329 if (! f.empty ()) | |
330 { | |
3519 | 331 int status = ::octave_read_history_range (f.c_str (), from, to); |
1797 | 332 |
2658 | 333 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
|
334 { |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
335 std::ostringstream buf; |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
336 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
|
337 << " from file '" << f << "'"; |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
338 |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
339 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
|
340 } |
1797 | 341 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
342 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
343 lines_in_file = do_where (); |
2658 | 344 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
345 ::octave_using_history (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
346 } |
1797 | 347 } |
348 else | |
2926 | 349 error ("gnu_history::read_range: missing file name"); |
1797 | 350 } |
351 | |
352 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
353 gnu_history::do_write (const std::string& f_arg) const |
1797 | 354 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
355 if (initialized) |
1797 | 356 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
357 std::string f = f_arg; |
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 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
360 f = xfile; |
1797 | 361 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
362 if (! f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
363 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
364 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
|
365 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
366 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
|
367 { |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
368 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
|
369 |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
370 error (status, msg); |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
371 } |
11368
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 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
374 error ("gnu_history::write: missing file name"); |
1797 | 375 } |
376 } | |
377 | |
378 void | |
3504 | 379 gnu_history::do_append (const std::string& f_arg) |
1797 | 380 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
381 if (initialized) |
1797 | 382 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
383 if (lines_this_session) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
384 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
385 if (lines_this_session < do_where ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
386 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
387 // Create file if it doesn't already exist. |
1797 | 388 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
389 std::string f = f_arg; |
1797 | 390 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
391 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
392 f = xfile; |
1797 | 393 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
394 if (! f.empty ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
395 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
396 file_stat fs (f); |
1797 | 397 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
398 if (! fs) |
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 int tem; |
1797 | 401 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
402 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
|
403 gnulib::close (tem); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
404 } |
1797 | 405 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
406 int status |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
407 = ::octave_append_history (lines_this_session, f.c_str ()); |
1797 | 408 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
409 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
|
410 { |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
411 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
|
412 |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
413 error (status, msg); |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
414 } |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
415 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
416 lines_in_file += lines_this_session; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
417 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
418 lines_this_session = 0; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
419 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
420 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
421 error ("gnu_history::append: missing file name"); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
422 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
423 } |
1797 | 424 } |
425 } | |
426 | |
427 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
428 gnu_history::do_truncate_file (const std::string& f_arg, int n) const |
1797 | 429 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
430 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
431 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
432 std::string f = f_arg; |
1797 | 433 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
434 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
435 f = xfile; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
436 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
437 if (! f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
438 ::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
|
439 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
440 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
|
441 } |
1797 | 442 } |
443 | |
444 string_vector | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
445 gnu_history::do_list (int limit, bool number_lines) const |
1797 | 446 { |
447 string_vector retval; | |
448 | |
449 if (limit) | |
3519 | 450 retval = ::octave_history_list (limit, number_lines); |
1797 | 451 |
452 return retval; | |
453 } | |
454 | |
3504 | 455 std::string |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
456 gnu_history::do_get_entry (int n) const |
1797 | 457 { |
3504 | 458 std::string retval; |
1797 | 459 |
3519 | 460 char *line = ::octave_history_get (do_base () + n); |
1797 | 461 |
3519 | 462 if (line) |
463 retval = line; | |
1797 | 464 |
465 return retval; | |
466 } | |
467 | |
468 void | |
3504 | 469 gnu_history::do_replace_entry (int which, const std::string& line) |
1797 | 470 { |
3519 | 471 ::octave_replace_history_entry (which, line.c_str ()); |
1797 | 472 } |
473 | |
474 void | |
3504 | 475 gnu_history::do_clean_up_and_save (const std::string& f_arg, int n) |
1797 | 476 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
477 if (initialized) |
1797 | 478 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
479 std::string f = f_arg; |
1797 | 480 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
481 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
482 f = xfile; |
1797 | 483 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
484 if (! f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
485 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
486 if (n < 0) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
487 n = xsize; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
488 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
489 stifle (n); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
490 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
491 do_write (f.c_str ()); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
492 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
493 else |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
494 error ("gnu_history::clean_up_and_save: missing file name"); |
1797 | 495 } |
2926 | 496 } |
497 | |
498 #endif | |
499 | |
500 bool | |
501 command_history::instance_ok (void) | |
502 { | |
503 bool retval = true; | |
504 | |
505 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
506 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
507 make_command_history (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
508 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
509 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
510 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
|
511 } |
2926 | 512 |
513 if (! instance) | |
514 { | |
515 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
516 ("unable to create command history object!"); |
2926 | 517 |
518 retval = false; | |
519 } | |
520 | |
521 return retval; | |
522 } | |
523 | |
524 void | |
525 command_history::make_command_history (void) | |
526 { | |
527 #if defined (USE_READLINE) | |
528 instance = new gnu_history (); | |
529 #else | |
530 instance = new command_history (); | |
531 #endif | |
532 } | |
533 | |
534 void | |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
535 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
|
536 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
|
537 const std::string & control_arg) |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
538 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
539 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
|
540 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
|
541 } |
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 bool |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
544 command_history::is_initialized (void) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
545 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
546 // 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
|
547 // create one. |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
548 return instance && instance->do_is_initialized (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
549 } |
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 void |
5872 | 552 command_history::set_file (const std::string& f_arg) |
2926 | 553 { |
554 if (instance_ok ()) | |
5872 | 555 { |
556 std::string f = file_ops::tilde_expand (f_arg); | |
557 | |
558 instance->do_set_file (f); | |
559 } | |
2926 | 560 } |
561 | |
3504 | 562 std::string |
2926 | 563 command_history::file (void) |
564 { | |
565 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
566 ? instance->do_file () : std::string (); |
2926 | 567 } |
568 | |
569 void | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
570 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
|
571 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
572 if (instance_ok ()) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
573 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
|
574 } |
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 std::string |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
577 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
|
578 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
579 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
580 ? 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
|
581 } |
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 void |
2926 | 584 command_history::set_size (int n) |
585 { | |
586 if (instance_ok ()) | |
587 instance->do_set_size (n); | |
588 } | |
589 | |
590 int | |
591 command_history::size (void) | |
592 { | |
593 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
594 ? instance->do_size () : 0; |
2926 | 595 } |
596 | |
597 void | |
598 command_history::ignore_entries (bool flag) | |
599 { | |
600 if (instance_ok ()) | |
601 instance->do_ignore_entries (flag); | |
602 } | |
603 | |
604 bool | |
605 command_history::ignoring_entries (void) | |
606 { | |
607 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
608 ? instance->do_ignoring_entries () : false; |
2926 | 609 } |
610 | |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
611 bool |
3504 | 612 command_history::add (const std::string& s) |
2926 | 613 { |
614 if (instance_ok ()) | |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
615 return instance->do_add (s); |
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
616 return false; |
2926 | 617 } |
618 | |
619 void | |
620 command_history::remove (int n) | |
621 { | |
622 if (instance_ok ()) | |
623 instance->do_remove (n); | |
624 } | |
625 | |
15397
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
626 void |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
627 command_history::clear (void) |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
628 { |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
629 if (instance_ok ()) |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
630 instance->do_clear (); |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
631 } |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
632 |
2926 | 633 int |
634 command_history::where (void) | |
635 { | |
636 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
637 ? instance->do_where () : 0; |
2926 | 638 } |
639 | |
640 int | |
641 command_history::length (void) | |
642 { | |
643 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
644 ? instance->do_length () : 0; |
2926 | 645 } |
646 | |
647 int | |
648 command_history::max_input_history (void) | |
649 { | |
650 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
651 ? instance->do_max_input_history () : 0; |
2926 | 652 } |
653 | |
654 int | |
655 command_history::base (void) | |
656 { | |
657 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
658 ? instance->do_base () : 0; |
2926 | 659 } |
660 | |
661 int | |
662 command_history::current_number (void) | |
663 { | |
664 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
665 ? instance->do_current_number () : 0; |
2926 | 666 } |
667 | |
668 void | |
669 command_history::stifle (int n) | |
670 { | |
671 if (instance_ok ()) | |
672 instance->do_stifle (n); | |
673 } | |
674 | |
675 int | |
676 command_history::unstifle (void) | |
677 { | |
678 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
679 ? instance->do_unstifle () : 0; |
2926 | 680 } |
681 | |
682 int | |
683 command_history::is_stifled (void) | |
684 { | |
685 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
686 ? instance->do_is_stifled () : 0; |
2926 | 687 } |
688 | |
689 void | |
690 command_history::set_mark (int n) | |
691 { | |
692 if (instance_ok ()) | |
693 instance->do_set_mark (n); | |
694 } | |
695 | |
4802 | 696 int |
3519 | 697 command_history::goto_mark (void) |
2926 | 698 { |
4802 | 699 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
700 ? instance->do_goto_mark () : 0; |
2926 | 701 } |
702 | |
703 void | |
704 command_history::read (bool must_exist) | |
705 { | |
3522 | 706 read (file (), must_exist); |
2926 | 707 } |
708 | |
709 void | |
3504 | 710 command_history::read (const std::string& f, bool must_exist) |
2926 | 711 { |
712 if (instance_ok ()) | |
713 instance->do_read (f, must_exist); | |
714 } | |
715 | |
716 void | |
717 command_history::read_range (int from, int to, bool must_exist) | |
718 { | |
3522 | 719 read_range (file (), from, to, must_exist); |
2926 | 720 } |
721 | |
722 void | |
3504 | 723 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
|
724 bool must_exist) |
2926 | 725 { |
726 if (instance_ok ()) | |
727 instance->do_read_range (f, from, to, must_exist); | |
728 } | |
729 | |
730 void | |
3504 | 731 command_history::write (const std::string& f) |
2926 | 732 { |
733 if (instance_ok ()) | |
734 instance->do_write (f); | |
735 } | |
736 | |
737 void | |
3504 | 738 command_history::append (const std::string& f) |
2926 | 739 { |
740 if (instance_ok ()) | |
741 instance->do_append (f); | |
742 } | |
743 | |
744 void | |
3504 | 745 command_history::truncate_file (const std::string& f, int n) |
2926 | 746 { |
747 if (instance_ok ()) | |
748 instance->do_truncate_file (f, n); | |
749 } | |
750 | |
751 string_vector | |
752 command_history::list (int limit, bool number_lines) | |
753 { | |
754 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
755 ? instance->do_list (limit, number_lines) : string_vector (); |
2926 | 756 } |
757 | |
3504 | 758 std::string |
2926 | 759 command_history::get_entry (int n) |
760 { | |
761 return (instance_ok ()) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
762 ? instance->do_get_entry (n) : std::string (); |
2926 | 763 } |
764 | |
765 void | |
3504 | 766 command_history::replace_entry (int which, const std::string& line) |
2926 | 767 { |
768 if (instance_ok ()) | |
769 instance->do_replace_entry (which, line); | |
770 } | |
771 | |
772 void | |
3504 | 773 command_history::clean_up_and_save (const std::string& f, int n) |
2926 | 774 { |
775 if (instance_ok ()) | |
776 instance->do_clean_up_and_save (f, n); | |
777 } | |
778 | |
779 void | |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
780 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
|
781 { |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
782 (*current_liboctave_warning_handler) |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
783 ("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
|
784 } |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
785 |
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
786 void |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
787 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
|
788 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
|
789 const std::string & control_arg) |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
790 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
791 command_history::set_file (f_arg); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
792 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
|
793 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
|
794 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
795 if (read_history_file) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
796 command_history::read (false); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
797 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
798 initialized = true; |
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 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
801 bool |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
802 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
|
803 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
804 return initialized; |
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 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
807 void |
3504 | 808 command_history::do_set_file (const std::string& f) |
2926 | 809 { |
810 xfile = f; | |
811 } | |
812 | |
3504 | 813 std::string |
2926 | 814 command_history::do_file (void) |
815 { | |
816 return xfile; | |
817 } | |
818 | |
819 void | |
820 command_history::do_set_size (int n) | |
821 { | |
822 xsize = n; | |
823 } | |
824 | |
825 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
826 command_history::do_size (void) const |
2926 | 827 { |
828 return xsize; | |
829 } | |
830 | |
831 void | |
832 command_history::do_ignore_entries (bool flag) | |
833 { | |
834 ignoring_additions = flag; | |
835 } | |
836 | |
837 bool | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
838 command_history::do_ignoring_entries (void) const |
2926 | 839 { |
840 return ignoring_additions; | |
841 } | |
842 | |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
843 bool |
3504 | 844 command_history::do_add (const std::string&) |
2926 | 845 { |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
846 return false; |
2926 | 847 } |
848 | |
849 void | |
850 command_history::do_remove (int) | |
851 { | |
852 } | |
853 | |
15397
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
854 void |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
855 command_history::do_clear (void) |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
856 { |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
857 } |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
858 |
2926 | 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_where (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_length (void) const |
2926 | 867 { |
868 return 0; | |
869 } | |
870 | |
871 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
872 command_history::do_max_input_history (void) const |
2926 | 873 { |
874 return 0; | |
875 } | |
876 | |
877 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
878 command_history::do_base (void) const |
2926 | 879 { |
880 return 0; | |
881 } | |
882 | |
883 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
884 command_history::do_current_number (void) const |
2926 | 885 { |
886 return (xsize > 0) ? do_base () + do_where () : -1; | |
887 } | |
888 | |
889 void | |
890 command_history::do_stifle (int) | |
891 { | |
892 } | |
893 | |
894 int | |
895 command_history::do_unstifle (void) | |
896 { | |
897 return -1; | |
898 } | |
899 | |
900 int | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
901 command_history::do_is_stifled (void) const |
2926 | 902 { |
903 return 0; | |
904 } | |
905 | |
906 void | |
907 command_history::do_set_mark (int) | |
908 { | |
909 } | |
910 | |
4802 | 911 int |
2926 | 912 command_history::do_goto_mark (void) |
913 { | |
4802 | 914 return 0; |
2926 | 915 } |
916 | |
917 void | |
3504 | 918 command_history::do_read (const std::string& f, bool) |
2926 | 919 { |
920 if (f.empty ()) | |
921 error ("command_history::read: missing file name"); | |
922 } | |
923 | |
924 void | |
3504 | 925 command_history::do_read_range (const std::string& f, int, int, bool) |
2926 | 926 { |
927 if (f.empty ()) | |
928 error ("command_history::read_range: missing file name"); | |
929 } | |
930 | |
931 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
932 command_history::do_write (const std::string& f_arg) const |
2926 | 933 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
934 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
935 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
936 std::string f = f_arg; |
2926 | 937 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
938 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
939 f = xfile; |
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 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
|
943 } |
2926 | 944 } |
945 | |
946 void | |
3504 | 947 command_history::do_append (const std::string& f_arg) |
2926 | 948 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
949 if (initialized) |
2926 | 950 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
951 if (lines_this_session) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
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 < do_where ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
954 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
955 // Create file if it doesn't already exist. |
2926 | 956 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
957 std::string f = f_arg; |
2926 | 958 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
959 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
960 f = xfile; |
2926 | 961 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
962 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
963 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
|
964 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
965 } |
2926 | 966 } |
967 } | |
968 | |
969 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
970 command_history::do_truncate_file (const std::string& f_arg, int) const |
2926 | 971 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
972 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
973 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
974 std::string f = f_arg; |
2926 | 975 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
976 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
977 f = xfile; |
2926 | 978 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
979 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
980 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
|
981 } |
2926 | 982 } |
983 | |
984 string_vector | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
985 command_history::do_list (int, bool) const |
2926 | 986 { |
987 return string_vector (); | |
988 } | |
989 | |
3504 | 990 std::string |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
991 command_history::do_get_entry (int) const |
2926 | 992 { |
3504 | 993 return std::string (); |
2926 | 994 } |
995 | |
996 void | |
3504 | 997 command_history::do_replace_entry (int, const std::string&) |
2926 | 998 { |
999 } | |
1000 | |
1001 void | |
3504 | 1002 command_history::do_clean_up_and_save (const std::string& f_arg, int) |
2926 | 1003 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1004 if (initialized) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1005 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1006 std::string f = f_arg; |
2926 | 1007 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1008 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1009 f = xfile; |
2926 | 1010 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1011 if (f.empty ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1012 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
|
1013 } |
1797 | 1014 } |
1015 | |
1016 void | |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1017 command_history::error (int err_num, const std::string& msg) const |
1797 | 1018 { |
17996
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1019 if (msg.empty ()) |
260b44c0ed69
improve messages when reading or writing history fails (bug #40443)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
1020 (*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
|
1021 else |
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: %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
|
1023 gnulib::strerror (err_num)); |
1797 | 1024 } |
1025 | |
1026 void | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
1027 command_history::error (const std::string& s) const |
1797 | 1028 { |
1029 (*current_liboctave_error_handler) ("%s", s.c_str ()); | |
1030 } |