1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
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. |
1
|
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/>. |
1
|
20 |
2939
|
21 */ |
|
22 |
|
23 /* |
|
24 |
1
|
25 The functions listed below were adapted from similar functions from |
|
26 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free |
|
27 Software Foundation, Inc. |
|
28 |
|
29 do_history edit_history_readline |
|
30 do_edit_history edit_history_add_hist |
|
31 |
|
32 */ |
|
33 |
240
|
34 #ifdef HAVE_CONFIG_H |
1192
|
35 #include <config.h> |
1
|
36 #endif |
|
37 |
1343
|
38 #include <cstdlib> |
|
39 #include <cstring> |
|
40 |
1750
|
41 #include <string> |
|
42 |
3503
|
43 #include <fstream> |
1350
|
44 |
|
45 #ifdef HAVE_UNISTD_H |
2442
|
46 #ifdef HAVE_SYS_TYPES_H |
1
|
47 #include <sys/types.h> |
2442
|
48 #endif |
1
|
49 #include <unistd.h> |
|
50 #endif |
1350
|
51 |
1799
|
52 #include "cmd-hist.h" |
1802
|
53 #include "file-ops.h" |
3016
|
54 #include "lo-mappers.h" |
2926
|
55 #include "oct-env.h" |
5305
|
56 #include "oct-time.h" |
1755
|
57 #include "str-vec.h" |
|
58 |
2492
|
59 #include <defaults.h> |
1352
|
60 #include "defun.h" |
1
|
61 #include "error.h" |
3016
|
62 #include "gripes.h" |
1
|
63 #include "input.h" |
1742
|
64 #include "oct-hist.h" |
1750
|
65 #include "oct-obj.h" |
1352
|
66 #include "pager.h" |
3018
|
67 #include "parse.h" |
1352
|
68 #include "sighandlers.h" |
1690
|
69 #include "sysdep.h" |
1750
|
70 #include "toplev.h" |
1352
|
71 #include "unwind-prot.h" |
|
72 #include "utils.h" |
2205
|
73 #include "variables.h" |
1
|
74 |
3018
|
75 // TRUE means input is coming from temporary history file. |
|
76 bool input_from_tmp_history_file = false; |
168
|
77 |
5305
|
78 static std::string |
1
|
79 default_history_file (void) |
|
80 { |
3523
|
81 std::string file; |
1
|
82 |
3523
|
83 std::string env_file = octave_env::getenv ("OCTAVE_HISTFILE"); |
1755
|
84 |
2926
|
85 if (! env_file.empty ()) |
6141
|
86 file = env_file; |
1
|
87 |
1755
|
88 if (file.empty ()) |
|
89 { |
3523
|
90 std::string home_dir = octave_env::get_home_directory (); |
2926
|
91 |
|
92 if (! home_dir.empty ()) |
1969
|
93 { |
2926
|
94 file = home_dir; |
6176
|
95 if (! file_ops::is_dir_sep (file[file.length()-1])) |
|
96 file.push_back (file_ops::dir_sep_char); |
|
97 file.append (".octave_hist"); |
1969
|
98 } |
1755
|
99 else |
|
100 file = ".octave_hist"; |
|
101 } |
1
|
102 |
|
103 return file; |
|
104 } |
|
105 |
5794
|
106 // Where history is saved. |
|
107 static std::string Vhistory_file = default_history_file (); |
|
108 |
5305
|
109 static int |
|
110 default_history_size (void) |
|
111 { |
|
112 int size = 1024; |
|
113 |
|
114 std::string env_size = octave_env::getenv ("OCTAVE_HISTSIZE"); |
|
115 |
|
116 if (! env_size.empty ()) |
|
117 { |
|
118 int val; |
|
119 |
|
120 if (sscanf (env_size.c_str (), "%d", &val) == 1) |
|
121 size = val > 0 ? val : 0; |
|
122 } |
|
123 |
|
124 return size; |
|
125 } |
|
126 |
5794
|
127 // The number of lines to keep in the history file. |
|
128 static int Vhistory_size = default_history_size (); |
|
129 |
5305
|
130 static std::string |
|
131 default_history_timestamp_format (void) |
|
132 { |
|
133 return |
|
134 std::string ("# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <") |
|
135 + octave_env::get_user_name () |
|
136 + std::string ("@") |
|
137 + octave_env::get_host_name () |
|
138 + std::string (">"); |
|
139 } |
|
140 |
5794
|
141 // The format of the timestamp marker written to the history file when |
|
142 // Octave exits. |
|
143 static std::string Vhistory_timestamp_format_string |
|
144 = default_history_timestamp_format (); |
|
145 |
|
146 // TRUE if we are saving history. |
|
147 bool Vsaving_history = true; |
|
148 |
581
|
149 // Display, save, or load history. Stolen and modified from bash. |
|
150 // |
|
151 // Arg of -w FILENAME means write file, arg of -r FILENAME |
|
152 // means read file, arg of -q means don't number lines. Arg of N |
|
153 // means only display that many items. |
|
154 |
1755
|
155 static void |
|
156 do_history (int argc, const string_vector& argv) |
1
|
157 { |
|
158 int numbered_output = 1; |
|
159 |
1755
|
160 int i; |
|
161 for (i = 1; i < argc; i++) |
1
|
162 { |
3523
|
163 std::string option = argv[i]; |
2435
|
164 |
|
165 if (option == "-r" || option == "-w" || option == "-a" |
|
166 || option == "-n") |
1
|
167 { |
1755
|
168 if (i < argc - 1) |
5872
|
169 command_history::set_file (argv[i+1]); |
1
|
170 |
2435
|
171 if (option == "-a") |
|
172 // Append `new' lines to file. |
2926
|
173 command_history::append (); |
2435
|
174 |
|
175 else if (option == "-w") |
|
176 // Write entire history. |
2926
|
177 command_history::write (); |
777
|
178 |
2435
|
179 else if (option == "-r") |
|
180 // Read entire file. |
2926
|
181 command_history::read (); |
777
|
182 |
2435
|
183 else if (option == "-n") |
|
184 // Read `new' history from file. |
2926
|
185 command_history::read_range (); |
777
|
186 |
2435
|
187 else |
|
188 panic_impossible (); |
|
189 |
1
|
190 return; |
|
191 } |
1755
|
192 else if (argv[i] == "-q") |
1
|
193 numbered_output = 0; |
1755
|
194 else if (argv[i] == "--") |
1
|
195 { |
1755
|
196 i++; |
1
|
197 break; |
|
198 } |
|
199 else |
|
200 break; |
|
201 } |
|
202 |
1799
|
203 int limit = -1; |
1
|
204 |
1755
|
205 if (i < argc) |
1
|
206 { |
1755
|
207 if (sscanf (argv[i].c_str (), "%d", &limit) != 1) |
1
|
208 { |
1755
|
209 if (argv[i][0] == '-') |
|
210 error ("history: unrecognized option `%s'", argv[i].c_str ()); |
1
|
211 else |
1755
|
212 error ("history: bad non-numeric arg `%s'", argv[i].c_str ()); |
1799
|
213 |
1
|
214 return; |
|
215 } |
|
216 |
|
217 if (limit < 0) |
|
218 limit = -limit; |
1799
|
219 } |
1
|
220 |
2926
|
221 string_vector hlist = command_history::list (limit, numbered_output); |
1
|
222 |
1799
|
223 int len = hlist.length (); |
|
224 |
2095
|
225 for (i = 0; i < len; i++) |
|
226 octave_stdout << hlist[i] << "\n"; |
1
|
227 } |
|
228 |
581
|
229 // Read the edited history lines from STREAM and return them |
|
230 // one at a time. This can read unlimited length lines. The |
2434
|
231 // caller should free the storage. |
581
|
232 |
1
|
233 static char * |
3551
|
234 edit_history_readline (std::fstream& stream) |
1
|
235 { |
|
236 char c; |
|
237 int line_len = 128; |
|
238 int lindex = 0; |
|
239 char *line = new char [line_len]; |
|
240 line[0] = '\0'; |
|
241 |
|
242 while (stream.get (c)) |
|
243 { |
|
244 if (lindex + 2 >= line_len) |
|
245 { |
|
246 char *tmp_line = new char [line_len += 128]; |
|
247 strcpy (tmp_line, line); |
|
248 delete [] line; |
|
249 line = tmp_line; |
|
250 } |
|
251 |
|
252 if (c == '\n') |
|
253 { |
|
254 line[lindex++] = '\n'; |
|
255 line[lindex++] = '\0'; |
|
256 return line; |
|
257 } |
|
258 else |
|
259 line[lindex++] = c; |
|
260 } |
|
261 |
|
262 if (! lindex) |
|
263 { |
|
264 delete [] line; |
529
|
265 return 0; |
1
|
266 } |
|
267 |
|
268 if (lindex + 2 >= line_len) |
|
269 { |
|
270 char *tmp_line = new char [lindex+3]; |
|
271 strcpy (tmp_line, line); |
|
272 delete [] line; |
|
273 line = tmp_line; |
|
274 } |
|
275 |
1358
|
276 // Finish with newline if none in file. |
1
|
277 |
|
278 line[lindex++] = '\n'; |
|
279 line[lindex++] = '\0'; |
|
280 return line; |
|
281 } |
|
282 |
581
|
283 // Use `command' to replace the last entry in the history list, which, |
|
284 // by this time, is `run_history blah...'. The intent is that the |
1799
|
285 // new command becomes the history entry, and that `fc' should never |
581
|
286 // appear in the history list. This way you can do `run_history' to |
|
287 // your heart's content. |
|
288 |
64
|
289 static void |
3523
|
290 edit_history_repl_hist (const std::string& command) |
64
|
291 { |
1799
|
292 if (! command.empty ()) |
|
293 { |
2926
|
294 string_vector hlist = command_history::list (); |
64
|
295 |
1799
|
296 int len = hlist.length (); |
64
|
297 |
1799
|
298 if (len > 0) |
|
299 { |
|
300 int i = len - 1; |
64
|
301 |
3523
|
302 std::string histent = command_history::get_entry (i); |
64
|
303 |
1799
|
304 if (! histent.empty ()) |
|
305 { |
3523
|
306 std::string cmd = command; |
64
|
307 |
1799
|
308 int cmd_len = cmd.length (); |
64
|
309 |
1799
|
310 if (cmd[cmd_len - 1] == '\n') |
|
311 cmd.resize (cmd_len - 1); |
64
|
312 |
1799
|
313 if (! cmd.empty ()) |
2926
|
314 command_history::replace_entry (i, cmd); |
1799
|
315 } |
64
|
316 } |
|
317 } |
|
318 } |
|
319 |
1
|
320 static void |
3523
|
321 edit_history_add_hist (const std::string& line) |
1
|
322 { |
1799
|
323 if (! line.empty ()) |
1
|
324 { |
3523
|
325 std::string tmp = line; |
1
|
326 |
1799
|
327 int len = tmp.length (); |
|
328 |
|
329 if (len > 0 && tmp[len-1] == '\n') |
|
330 tmp.resize (len - 1); |
|
331 |
|
332 if (! tmp.empty ()) |
2926
|
333 command_history::add (tmp); |
1
|
334 } |
|
335 } |
|
336 |
3536
|
337 static std::string |
1755
|
338 mk_tmp_hist_file (int argc, const string_vector& argv, |
2804
|
339 int insert_curr, const char *warn_for) |
1
|
340 { |
3523
|
341 std::string retval; |
1
|
342 |
2926
|
343 string_vector hlist = command_history::list (); |
1
|
344 |
1799
|
345 int hist_count = hlist.length (); |
1
|
346 |
1358
|
347 // The current command line is already part of the history list by |
|
348 // the time we get to this point. Delete it from the list. |
1
|
349 |
|
350 hist_count -= 2; |
1799
|
351 |
64
|
352 if (! insert_curr) |
2926
|
353 command_history::remove (hist_count); |
1799
|
354 |
1
|
355 hist_count--; |
|
356 |
1358
|
357 // If no numbers have been specified, the default is to edit the |
|
358 // last command in the history list. |
1
|
359 |
|
360 int hist_end = hist_count; |
|
361 int hist_beg = hist_count; |
|
362 int reverse = 0; |
|
363 |
1358
|
364 // Process options. |
1
|
365 |
|
366 int usage_error = 0; |
|
367 if (argc == 3) |
|
368 { |
1755
|
369 if (sscanf (argv[1].c_str (), "%d", &hist_beg) != 1 |
|
370 || sscanf (argv[2].c_str (), "%d", &hist_end) != 1) |
1
|
371 usage_error = 1; |
|
372 else |
|
373 { |
|
374 hist_beg--; |
|
375 hist_end--; |
|
376 } |
|
377 } |
|
378 else if (argc == 2) |
|
379 { |
1755
|
380 if (sscanf (argv[1].c_str (), "%d", &hist_beg) != 1) |
1
|
381 usage_error = 1; |
|
382 else |
|
383 { |
|
384 hist_beg--; |
|
385 hist_end = hist_beg; |
|
386 } |
|
387 } |
|
388 |
|
389 if (hist_beg < 0 || hist_end < 0 || hist_beg > hist_count |
|
390 || hist_end > hist_count) |
|
391 { |
64
|
392 error ("%s: history specification out of range", warn_for); |
1799
|
393 return retval; |
1
|
394 } |
|
395 |
|
396 if (usage_error) |
|
397 { |
64
|
398 usage ("%s [first] [last]", warn_for); |
1799
|
399 return retval; |
1
|
400 } |
|
401 |
|
402 if (hist_end < hist_beg) |
|
403 { |
|
404 int t = hist_end; |
|
405 hist_end = hist_beg; |
|
406 hist_beg = t; |
|
407 reverse = 1; |
|
408 } |
|
409 |
3523
|
410 std::string name = file_ops::tempnam ("", "oct-"); |
1
|
411 |
3551
|
412 std::fstream file (name.c_str (), std::ios::out); |
64
|
413 |
1
|
414 if (! file) |
|
415 { |
1755
|
416 error ("%s: couldn't open temporary file `%s'", warn_for, |
|
417 name.c_str ()); |
1799
|
418 return retval; |
1
|
419 } |
|
420 |
|
421 if (reverse) |
|
422 { |
|
423 for (int i = hist_end; i >= hist_beg; i--) |
1799
|
424 file << hlist[i] << "\n"; |
1
|
425 } |
|
426 else |
|
427 { |
|
428 for (int i = hist_beg; i <= hist_end; i++) |
1799
|
429 file << hlist[i] << "\n"; |
1
|
430 } |
|
431 |
|
432 file.close (); |
|
433 |
1755
|
434 return name; |
64
|
435 } |
|
436 |
1755
|
437 static void |
|
438 do_edit_history (int argc, const string_vector& argv) |
64
|
439 { |
3523
|
440 std::string name = mk_tmp_hist_file (argc, argv, 0, "edit_history"); |
64
|
441 |
1755
|
442 if (name.empty ()) |
64
|
443 return; |
|
444 |
1358
|
445 // Call up our favorite editor on the file of commands. |
1
|
446 |
5794
|
447 std::string cmd = VEDITOR; |
4469
|
448 cmd.append (" \""); |
1799
|
449 cmd.append (name); |
4469
|
450 cmd.append ("\""); |
1
|
451 |
1358
|
452 // Ignore interrupts while we are off editing commands. Should we |
|
453 // maybe avoid using system()? |
1
|
454 |
2705
|
455 volatile octave_interrupt_handler old_interrupt_handler |
2554
|
456 = octave_ignore_interrupts (); |
1443
|
457 |
1799
|
458 system (cmd.c_str ()); |
1443
|
459 |
2554
|
460 octave_set_interrupt_handler (old_interrupt_handler); |
1
|
461 |
1358
|
462 // Write the commands to the history file since parse_and_execute |
|
463 // disables command line history while it executes. |
1
|
464 |
3551
|
465 std::fstream file (name.c_str (), std::ios::in); |
1
|
466 |
|
467 char *line; |
64
|
468 int first = 1; |
529
|
469 while ((line = edit_history_readline (file)) != 0) |
1
|
470 { |
1358
|
471 // Skip blank lines. |
1
|
472 |
|
473 if (line[0] == '\n') |
|
474 { |
|
475 delete [] line; |
|
476 continue; |
|
477 } |
|
478 |
64
|
479 if (first) |
|
480 { |
|
481 first = 0; |
|
482 edit_history_repl_hist (line); |
|
483 } |
|
484 else |
|
485 edit_history_add_hist (line); |
1
|
486 } |
|
487 |
|
488 file.close (); |
|
489 |
1358
|
490 // Turn on command echo, so the output from this will make better |
|
491 // sense. |
1
|
492 |
2985
|
493 unwind_protect::begin_frame ("do_edit_history"); |
3018
|
494 |
2205
|
495 unwind_protect_int (Vecho_executing_commands); |
3018
|
496 unwind_protect_bool (input_from_tmp_history_file); |
|
497 |
2205
|
498 Vecho_executing_commands = ECHO_CMD_LINE; |
3018
|
499 input_from_tmp_history_file = true; |
1
|
500 |
2897
|
501 parse_and_execute (name); |
1
|
502 |
2985
|
503 unwind_protect::run_frame ("do_edit_history"); |
1
|
504 |
1358
|
505 // Delete the temporary file. Should probably be done with an |
|
506 // unwind_protect. |
1
|
507 |
1755
|
508 unlink (name.c_str ()); |
1
|
509 } |
|
510 |
1755
|
511 static void |
|
512 do_run_history (int argc, const string_vector& argv) |
64
|
513 { |
3523
|
514 std::string name = mk_tmp_hist_file (argc, argv, 1, "run_history"); |
64
|
515 |
1755
|
516 if (name.empty ()) |
64
|
517 return; |
|
518 |
1799
|
519 // Turn on command echo so the output from this will make better |
1358
|
520 // sense. |
64
|
521 |
2985
|
522 unwind_protect::begin_frame ("do_run_history"); |
3018
|
523 |
2205
|
524 unwind_protect_int (Vecho_executing_commands); |
3018
|
525 unwind_protect_bool (input_from_tmp_history_file); |
|
526 |
2205
|
527 Vecho_executing_commands = ECHO_CMD_LINE; |
3018
|
528 input_from_tmp_history_file = true; |
64
|
529 |
2897
|
530 parse_and_execute (name); |
64
|
531 |
2985
|
532 unwind_protect::run_frame ("do_run_history"); |
64
|
533 |
1799
|
534 // Delete the temporary file. |
|
535 |
5775
|
536 // FIXME -- should probably be done using an unwind_protect. |
64
|
537 |
1755
|
538 unlink (name.c_str ()); |
64
|
539 } |
|
540 |
5305
|
541 void |
5794
|
542 initialize_history (void) |
|
543 { |
5872
|
544 command_history::set_file (Vhistory_file); |
5800
|
545 command_history::set_size (Vhistory_size); |
|
546 |
5794
|
547 command_history::read (false); |
|
548 } |
|
549 |
|
550 void |
5305
|
551 octave_history_write_timestamp (void) |
|
552 { |
|
553 octave_localtime now; |
|
554 |
|
555 std::string timestamp = now.strftime (Vhistory_timestamp_format_string); |
|
556 |
|
557 if (! timestamp.empty ()) |
|
558 command_history::add (timestamp); |
|
559 } |
|
560 |
4208
|
561 DEFCMD (edit_history, args, , |
3332
|
562 "-*- texinfo -*-\n\ |
|
563 @deffn {Command} edit_history options\n\ |
|
564 If invoked with no arguments, @code{edit_history} allows you to edit the\n\ |
|
565 history list using the editor named by the variable @code{EDITOR}. The\n\ |
|
566 commands to be edited are first copied to a temporary file. When you\n\ |
|
567 exit the editor, Octave executes the commands that remain in the file.\n\ |
|
568 It is often more convenient to use @code{edit_history} to define functions \n\ |
|
569 rather than attempting to enter them directly on the command line.\n\ |
|
570 By default, the block of commands is executed as soon as you exit the\n\ |
|
571 editor. To avoid executing any commands, simply delete all the lines\n\ |
|
572 from the buffer before exiting the editor.\n\ |
|
573 \n\ |
|
574 The @code{edit_history} command takes two optional arguments specifying\n\ |
|
575 the history numbers of first and last commands to edit. For example,\n\ |
|
576 the command\n\ |
529
|
577 \n\ |
3332
|
578 @example\n\ |
|
579 edit_history 13\n\ |
|
580 @end example\n\ |
|
581 \n\ |
|
582 @noindent\n\ |
|
583 extracts all the commands from the 13th through the last in the history\n\ |
|
584 list. The command\n\ |
|
585 \n\ |
|
586 @example\n\ |
|
587 edit_history 13 169\n\ |
|
588 @end example\n\ |
|
589 \n\ |
|
590 @noindent\n\ |
|
591 only extracts commands 13 through 169. Specifying a larger number for\n\ |
|
592 the first command than the last command reverses the list of commands\n\ |
|
593 before placing them in the buffer to be edited. If both arguments are\n\ |
|
594 omitted, the previous command in the history list is used.\n\ |
3333
|
595 @end deffn") |
529
|
596 { |
2086
|
597 octave_value_list retval; |
529
|
598 |
1755
|
599 int argc = args.length () + 1; |
|
600 |
1968
|
601 string_vector argv = args.make_argv ("edit_history"); |
1755
|
602 |
|
603 if (error_state) |
|
604 return retval; |
529
|
605 |
|
606 do_edit_history (argc, argv); |
|
607 |
|
608 return retval; |
|
609 } |
|
610 |
4208
|
611 DEFCMD (history, args, , |
3332
|
612 "-*- texinfo -*-\n\ |
|
613 @deffn {Command} history options\n\ |
|
614 If invoked with no arguments, @code{history} displays a list of commands\n\ |
|
615 that you have executed. Valid options are:\n\ |
|
616 \n\ |
|
617 @table @code\n\ |
|
618 @item -w @var{file}\n\ |
|
619 Write the current history to the file @var{file}. If the name is\n\ |
|
620 omitted, use the default history file (normally @file{~/.octave_hist}).\n\ |
529
|
621 \n\ |
3332
|
622 @item -r @var{file}\n\ |
|
623 Read the file @var{file}, replacing the current history list with its\n\ |
|
624 contents. If the name is omitted, use the default history file\n\ |
|
625 (normally @file{~/.octave_hist}).\n\ |
|
626 \n\ |
3499
|
627 @item @var{n}\n\ |
|
628 Only display the most recent @var{n} lines of history.\n\ |
3332
|
629 \n\ |
|
630 @item -q\n\ |
|
631 Don't number the displayed lines of history. This is useful for cutting\n\ |
|
632 and pasting commands if you are using the X Window System.\n\ |
|
633 @end table\n\ |
|
634 \n\ |
|
635 For example, to display the five most recent commands that you have\n\ |
|
636 typed without displaying line numbers, use the command\n\ |
|
637 @kbd{history -q 5}.\n\ |
3333
|
638 @end deffn") |
529
|
639 { |
2086
|
640 octave_value_list retval; |
529
|
641 |
1755
|
642 int argc = args.length () + 1; |
|
643 |
1968
|
644 string_vector argv = args.make_argv ("history"); |
1755
|
645 |
|
646 if (error_state) |
|
647 return retval; |
529
|
648 |
|
649 do_history (argc, argv); |
|
650 |
|
651 return retval; |
|
652 } |
|
653 |
4208
|
654 DEFCMD (run_history, args, , |
3332
|
655 "-*- texinfo -*-\n\ |
|
656 @deffn {Command} run_history [first] [last]\n\ |
|
657 Similar to @code{edit_history}, except that the editor is not invoked,\n\ |
|
658 and the commands are simply executed as they appear in the history list.\n\ |
3333
|
659 @end deffn") |
529
|
660 { |
2086
|
661 octave_value_list retval; |
529
|
662 |
1755
|
663 int argc = args.length () + 1; |
|
664 |
1968
|
665 string_vector argv = args.make_argv ("run_history"); |
1755
|
666 |
|
667 if (error_state) |
|
668 return retval; |
529
|
669 |
|
670 do_run_history (argc, argv); |
|
671 |
|
672 return retval; |
|
673 } |
|
674 |
5794
|
675 DEFUN (history_size, args, nargout, |
|
676 "-*- texinfo -*-\n\ |
|
677 @deftypefn {Built-in Function} {@var{val} =} history_size ()\n\ |
|
678 @deftypefnx {Built-in Function} {@var{old_val} =} history_size (@var{new_val})\n\ |
|
679 Query or set the internal variable that specifies how many entries\n\ |
|
680 to store in the history file. The default value is @code{1024},\n\ |
|
681 but may be overridden by the environment variable @code{OCTAVE_HISTSIZE}.\n\ |
|
682 @seealso{history_file, history_timestamp_format, saving_history}\n\ |
|
683 @end deftypefn") |
3016
|
684 { |
5800
|
685 int saved_history_size = Vhistory_size; |
|
686 |
|
687 octave_value retval |
|
688 = SET_INTERNAL_VARIABLE_WITH_LIMITS (history_size, -1, INT_MAX); |
|
689 |
|
690 if (Vhistory_size != saved_history_size) |
|
691 command_history::set_size (Vhistory_size); |
|
692 |
|
693 return retval; |
3016
|
694 } |
|
695 |
5794
|
696 DEFUN (history_file, args, nargout, |
|
697 "-*- texinfo -*-\n\ |
|
698 @deftypefn {Built-in Function} {@var{val} =} history_file ()\n\ |
|
699 @deftypefnx {Built-in Function} {@var{old_val} =} history_file (@var{new_val})\n\ |
|
700 Query or set the internal variable that specifies the name of the\n\ |
|
701 file used to store command history. The default value is\n\ |
|
702 @code{\"~/.octave_hist\"}, but may be overridden by the environment\n\ |
|
703 variable @code{OCTAVE_HISTFILE}.\n\ |
|
704 @seealso{history_size, saving_history, history_timestamp_format_string}\n\ |
|
705 @end deftypefn") |
5305
|
706 { |
5794
|
707 std::string saved_history_file = Vhistory_file; |
5305
|
708 |
5794
|
709 octave_value retval = SET_INTERNAL_VARIABLE (history_file); |
5305
|
710 |
5794
|
711 if (Vhistory_file != saved_history_file) |
5872
|
712 command_history::set_file (Vhistory_file); |
5305
|
713 |
5800
|
714 return retval; |
3016
|
715 } |
|
716 |
5794
|
717 DEFUN (history_timestamp_format_string, args, nargout, |
|
718 "-*- texinfo -*-\n\ |
|
719 @deftypefn {Built-in Function} {@var{val} =} history_timestamp_format_string ()\n\ |
|
720 @deftypefnx {Built-in Function} {@var{old_val} =} history_timestamp_format_string (@var{new_val})\n\ |
6653
|
721 Query or set the internal variable that specifies the format string\n\ |
5794
|
722 for the comment line that is written to the history file when Octave\n\ |
|
723 exits. The format string is passed to @code{strftime}. The default\n\ |
|
724 value is\n\ |
5305
|
725 \n\ |
|
726 @example\n\ |
|
727 \"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ |
|
728 @end example\n\ |
5794
|
729 @seealso{strftime, history_file, history_size, saving_history}\n\ |
|
730 @end deftypefn") |
|
731 { |
|
732 return SET_INTERNAL_VARIABLE (history_timestamp_format_string); |
|
733 } |
5305
|
734 |
5794
|
735 DEFUN (saving_history, args, nargout, |
|
736 "-*- texinfo -*-\n\ |
|
737 @deftypefn {Built-in Function} {@var{val} =} saving_history ()\n\ |
|
738 @deftypefnx {Built-in Function} {@var{old_val} =} saving_history (@var{new_val})\n\ |
|
739 Query or set the internal variable that controls whether commands entered\n\ |
|
740 on the command line are saved in the history file.\n\ |
6615
|
741 @seealso{history_file, history_size, history_timestamp_format}\n\ |
5794
|
742 @end deftypefn") |
|
743 { |
|
744 octave_value retval = SET_INTERNAL_VARIABLE (saving_history); |
|
745 |
|
746 command_history::ignore_entries (! Vsaving_history); |
|
747 |
|
748 return retval; |
3016
|
749 } |
|
750 |
1
|
751 /* |
|
752 ;;; Local Variables: *** |
|
753 ;;; mode: C++ *** |
|
754 ;;; End: *** |
|
755 */ |