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