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